This is an example of BLE GATT Client, which receives broadcast data from BLE_Server_BME280 ( a GATT server) , then transfers values up to mbed Device Connector (cloud).

Please refer details about BLEClient_mbedDevConn below. https://github.com/soramame21/BLEClient_mbedDevConn

The location of required BLE GATT server, BLE_Server_BME280, is at here. https://developer.mbed.org/users/edamame22/code/BLE_Server_BME280/

Files at this revision

API Documentation at this revision

Comitter:
Ren Boting
Date:
Tue Sep 05 11:56:13 2017 +0900
Parent:
1:8950e6a891df
Commit message:
Update all libraries and reform main.cpp

Changed in this revision

esp8266-driver.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-client.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
pal.lib Show annotated file Show diff for this revision Revisions of this file
shields/TARGET_ST_BLUENRG.lib Show annotated file Show diff for this revision Revisions of this file
--- a/esp8266-driver.lib	Wed Apr 26 11:20:41 2017 +0900
+++ b/esp8266-driver.lib	Tue Sep 05 11:56:13 2017 +0900
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/esp8266-driver/#dc37b65ca877d969aa492f348626df6e1b0b1df0
+https://github.com/ARMmbed/esp8266-driver/#44fb447c72a37fb397a413467e02208ffeddb88e
--- a/main.cpp	Wed Apr 26 11:20:41 2017 +0900
+++ b/main.cpp	Tue Sep 05 11:56:13 2017 +0900
@@ -29,7 +29,7 @@
 
 #include "security.h"
 
-#include "mbed.h"
+//#include "mbed.h"
 #include "rtos.h"
 
 #if MBED_CONF_APP_NETWORK_INTERFACE == WIFI
@@ -76,9 +76,9 @@
 Ticker status_ticker;
 // Ren, begin
 enum charType {
-	PRESSURE,
-	TEMPERATURE,
-	HUMIDITY
+    PRESSURE,
+    TEMPERATURE,
+    HUMIDITY
 };
 const char * dbg_CharType[HUMIDITY+1]={"Pressure","Temperature","Humidity"};
 const char * objName[HUMIDITY+1]={"3323","3303","3304"};
@@ -91,11 +91,12 @@
 class BME280Resource {
 public:
     BME280Resource() {
-    	// create Pressure object '3323'.
+        // create Pressure object '3323'.
         for(int m=0; m<HUMIDITY+1; m++) {
+            M2MObjectInstance* tmp_inst;
             bme280[m] = M2MInterfaceFactory::create_object(objName[m]);
-            tmp_inst[m] = bme280[m] ->create_object_instance();
-            tmp_res[m] = tmp_inst[m]->create_dynamic_resource("5700", dbg_CharType[m],
+            tmp_inst = bme280[m] ->create_object_instance();
+            tmp_res[m] = tmp_inst->create_dynamic_resource("5700", dbg_CharType[m],
                     M2MResourceInstance::STRING, true /* observable */);
             tmp_res[m]->set_operation(M2MBase::GET_ALLOWED);
             tmp_res[m]->set_value((uint8_t*)"0.0", 3);
@@ -127,12 +128,13 @@
     }
 private:
     M2MObject*  bme280[HUMIDITY+1];
-    M2MObjectInstance* tmp_inst[HUMIDITY+1];
+//    M2MObjectInstance* tmp_inst[HUMIDITY+1];
     M2MResource* tmp_res[HUMIDITY+1];
 };
 
 static BME280Resource *demo1;
-// Ren, end
+// end of BME280 resource definition
+
 
 /************************************************************BLE Stuff from here *********************************/
 BLE &ble = BLE::Instance();
@@ -152,7 +154,7 @@
     // byte 1: The key, it is the type of the data
     // byte [2..N] The value. N is equal to byte0 - 1
 
-  	//printf("Starting advertisementCallback...\r\n");
+    //printf("Starting advertisementCallback...\r\n");
     for (uint8_t i = 0; i < params->advertisingDataLen; ++i) {
 
         const uint8_t record_length = params->advertisingData[i];
@@ -217,8 +219,8 @@
         printf(" is_active[PRESSURE] = true\r\n");
     }
     else if (tmp_uuid == GattCharacteristic::UUID_TEMPERATURE_CHAR) {
-    	  bme280Characteristic[TEMPERATURE] = *characteristicP;    is_active[TEMPERATURE] = true;
-    	  printf(" is_active[TEMPERATURE] = true\r\n");
+        bme280Characteristic[TEMPERATURE] = *characteristicP;    is_active[TEMPERATURE] = true;
+        printf(" is_active[TEMPERATURE] = true\r\n");
    } else {
         bme280Characteristic[HUMIDITY] = *characteristicP;    is_active[HUMIDITY] = true;
         printf(" is_active[HUMIDITY] = true\r\n");
@@ -316,7 +318,7 @@
 
     // Ren, clear discovered Characteristic at beginning
     for(int i=0; i<HUMIDITY+1; i++)   {
-    	  dataprint[i]=0.0;     is_active[i]=false;
+        dataprint[i]=0.0;     is_active[i]=false;
     }
 
     ble.gap().onDisconnection(disconnectionCallback);
@@ -362,6 +364,7 @@
 volatile bool clicked = false;
 osThreadId mainThread;
 
+
 #ifdef TARGET_K64F
 // Set up Hardware interrupt button.
 InterruptIn obs_button(SW2);
@@ -574,9 +577,10 @@
 	  BLE_thread.start(BLE_thread_init);
     // waiting for completion of BLE_thread_init
     Thread::wait(2000);
+
     while (true) {
 
-	      printf("inside main for client\r\n");
+      printf("inside main for client\r\n");
         triggerLedCharacteristic = false;
 
         updates.wait(25000);
--- a/mbed-client.lib	Wed Apr 26 11:20:41 2017 +0900
+++ b/mbed-client.lib	Tue Sep 05 11:56:13 2017 +0900
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-client/#d41459d8b514d72d525e761fb4e34031e09f76e7
+https://github.com/ARMmbed/mbed-client/#3d97a6e4a06560b170f4416eeef883d95710f0fe
--- a/mbed-os.lib	Wed Apr 26 11:20:41 2017 +0900
+++ b/mbed-os.lib	Tue Sep 05 11:56:13 2017 +0900
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#269f58d75b752a4e67a6a2d8c5c698635ffd6752
+https://github.com/ARMmbed/mbed-os/#98ba8acb83cfc65f30a8a0771a27c71443ab093a
--- a/pal.lib	Wed Apr 26 11:20:41 2017 +0900
+++ b/pal.lib	Tue Sep 05 11:56:13 2017 +0900
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/pal/#4e46c0ea870631bb5bec3e4aa9fd7eebf3db21f0
+https://github.com/ARMmbed/pal/#ecdd901075af714d03cefed715389c7c93c62bc0
--- a/shields/TARGET_ST_BLUENRG.lib	Wed Apr 26 11:20:41 2017 +0900
+++ b/shields/TARGET_ST_BLUENRG.lib	Tue Sep 05 11:56:13 2017 +0900
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/ble-x-nucleo-idb0xa1/#dde7a56eb87aeb54d4967afa49ec1dbfb5ce4298
+https://github.com/ARMmbed/ble-x-nucleo-idb0xa1/#1616127fd90a7bbf7dafc939e108a21693da1c41