An mbed BLE-to-Cloud Gateway using Nucleo-F429ZI+X-Nucleo-IDB05A1 or Nucleo-L476RG+X-Nucleo-IDB05A1+X-Nucleo-IDW01M1.

Information

Nucleo- F429ZI configuration requires two hardware patches:

  1. on Nucleo-F429ZI open SB121 and close SB122
  2. on X-Nucleo-IDB05A1 move R4 to R6

The BLE client searches for and connects to a MotEnv node.

Files at this revision

API Documentation at this revision

Comitter:
nikapov
Date:
Fri Oct 20 19:04:58 2017 +0200
Parent:
3:39c8d17bed52
Commit message:
Add support to Nucleo_F429ZI and ethernet.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
diff -r 39c8d17bed52 -r d5f5559b48f7 main.cpp
--- a/main.cpp	Thu Oct 12 18:23:08 2017 +0200
+++ b/main.cpp	Fri Oct 20 19:04:58 2017 +0200
@@ -52,7 +52,11 @@
 
 // Status indication
 DigitalOut red_led(RED_LED);
+#ifdef NUCLEO_F429ZI
+DigitalOut green_led(NC);   // avoid interference with SPI_CLK
+#else
 DigitalOut green_led(GREEN_LED);
+#endif
 DigitalOut blue_led(BLUE_LED);
 
 
@@ -73,7 +77,7 @@
 
 
 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) {
-    // parse the advertising payload, looking for data type MANUFACTURER_SPECIFIC_DATA
+    // parse the advertising payload, looking for data type COMPLETE_LOCAL_NAME
     // The advertising payload is a collection of key/value records where
     // byte 0: length of the record excluding this byte
     // byte 1: The key, it is the type of the data
@@ -98,27 +102,15 @@
 			devName[strLength] = '\0';
 			printf("Found a device with name: %s\n\r", devName);
 			
-			if (memcmp(value, "BlueMbedOS", value_length) == 0) {
+			if (memcmp(value, "MotEnvMbed", 10) == 0) { // search for MotEnvMbedXX devices
 				printf("Found an mbed device node\n");
 				BLEProtocol::AddressBytes_t devAddress;
 			    memcpy (devAddress, params->peerAddr,BLEProtocol::ADDR_LEN);
-				eventQueue.call(BLEConnect,devAddress);
+				BLEConnect(devAddress);
 				break;
 			}
 		}
-/*
-        if(type == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) {
-			printf("length: %d - mask: 0x%x\n\r", value_length, *((uint32_t*)(value+2)));
-            if (((value_length == 6) || (value_length == 12)) && (*((uint32_t*)(value+2)) & 0x00001C00) == 0x00001C00) {
-                printf("Found an ST device with environmental data\n");
-                //BLE::Instance().gap().connect(params->peerAddr, Gap::ADDR_TYPE_RANDOM_STATIC, NULL, NULL);
-				BLEProtocol::AddressBytes_t devAddress;
-			    memcpy (devAddress, params->peerAddr,BLEProtocol::ADDR_LEN);
-				eventQueue.call(BLEConnect,devAddress);
-                break;
-            } 
-        }
-*/
+
         i += record_length;
     } 
 }
@@ -143,20 +135,19 @@
 		//printf("Reading environmental data\n\n");
         envCharacteristic.read();
 		envDataAvailable = true;
+#ifdef NUCLEO_F429ZI
+		red_led = LED_ON;
+#else
+		green_led = LED_ON;
+#endif
     } else {
 		envDataAvailable = false;
 	}
-	
 }
 
 
 void characteristicDiscoveryCallback(const DiscoveredCharacteristic *characteristicP) {
-	/*
-    printf("  C UUID-%x valueAttr[%u] props[%x]\r\n", characteristicP->getUUID().getShortUUID(), characteristicP->getValueHandle(), (uint8_t)characteristicP->getProperties().broadcast());
-    if (characteristicP->getUUID().getShortUUID() == 0xA001) { /* !ALERT! Alter this filter to suit your device. */
-    /*    optCharacteristic        = *characteristicP;
-        triggerLedCharacteristic = true;
-	}*/
+	
 	printf("Found environmental data\n");
 	envCharacteristic        = *characteristicP;
 	triggerEnvCharacteristic = true;
@@ -168,7 +159,7 @@
 	
     if (triggerEnvCharacteristic) {
         triggerEnvCharacteristic = false;
-        eventQueue.call(updateEnvCharacteristic);
+        eventQueue.call_in(500, updateEnvCharacteristic); 
     } 
 }
 
@@ -200,13 +191,35 @@
 		//printf("Humidity: %f\r\n", (uint32_t)((dataforClient[7]<<8) | dataforClient[6])/10.0);
 		//printf("Pressure: %f\r\n\r\n\r\n", (uint32_t)((dataforClient[5]<<24) |(dataforClient[4]<<16) |(dataforClient[3]<<8) | dataforClient[2])/100.0);
 		
-		eventQueue.call(updateEnvCharacteristic);  // triggering BLE data read again
+		eventQueue.call_in(500, updateEnvCharacteristic);  // triggering BLE data read again in 0.5s
     } 
 }
 
+void triggerNotify(const GattHVXCallbackParams *response) {
+	
+	if (response->handle == envCharacteristic.getValueHandle()) {
+		payload_length = response-> len;
+		for(int i=0; i< response-> len; i++) {
+//			printf("%02x", response->data[i]);
+			dataforClient[i] = response -> data[i];
+	//		printf("%d", dataforClient[i]);
+		}
+	
+		//printf("Temperature: %f\r\n", (uint32_t)((dataforClient[9]<<8) | dataforClient[8])/10.0);
+		//printf("Humidity: %f\r\n", (uint32_t)((dataforClient[7]<<8) | dataforClient[6])/10.0);
+		//printf("Pressure: %f\r\n\r\n\r\n", (uint32_t)((dataforClient[5]<<24) |(dataforClient[4]<<16) |(dataforClient[3]<<8) | dataforClient[2])/100.0);
+
+    }
+}
+
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *) {
     printf("Got disconnected from the device!\r\n");
     /* Start scanning and try to connect again */
+#ifdef NUCLEO_F429ZI
+	red_led = LED_OFF;
+#else
+	green_led = LED_OFF;
+#endif
     BLE::Instance().gap().startScan(advertisementCallback);
 }
 
@@ -240,7 +253,7 @@
 
 // On reading data, call triggerRead function.
     ble.gattClient().onDataRead(triggerRead);
-		
+	//ble.gattClient().onHVX(triggerNotify);
 		// scan interval: 400ms and scan window: 400ms.
     // Every 400ms the device will scan for 400ms
     // This means that the device will scan continuously.
@@ -412,6 +425,7 @@
     srand(seed);
     red_led = LED_OFF;
     blue_led = LED_OFF;
+	green_led = LED_OFF;
 
     // Keep track of the main thread
     mainThread = osThreadGetId();
diff -r 39c8d17bed52 -r d5f5559b48f7 mbed_app.json
--- a/mbed_app.json	Thu Oct 12 18:23:08 2017 +0200
+++ b/mbed_app.json	Fri Oct 20 19:04:58 2017 +0200
@@ -2,7 +2,7 @@
     "config": {
         "network-interface":{
             "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD, CELLULAR_ONBOARD, WIFI_IDW01M1",
-            "value": "WIFI_IDW01M1"
+            "value": "ETHERNET"
         },
         "mesh_radio_type": {
             "help": "options are ATMEL, MCR20, SPIRIT1, EFR32",
@@ -55,6 +55,11 @@
             "target.extra_labels_add": ["ST_BLUENRG"],
 			"wifi-tx": "PA_9",
             "wifi-rx": "PA_10"
+        },
+		"NUCLEO_F429ZI": {
+			"target.macros_add": ["BLUENRG_PIN_SPI_SCK=D13","BLUENRG_PIN_SPI_MOSI=PB_5"],
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["ST_BLUENRG"]
         }
     }
 }