Publisher for IBM Quickstart and Watson IoT cloud.

Dependencies:   MQTT NDefLib X_NUCLEO_IKS01A2 X_NUCLEO_NFC01A1

Fork of Cloud_IBM_MbedOS by ST Expansion SW Team

To start the demo the following expansion boards are required

X_NUCLEO_IDW01M1v2, X_NUCLEO_IKS01A2, X_NUCLEO_NFC01A1

and as MCU board the NUCLEO-L476RG as it include a True Random Number Generator needed for TLS.

After having mounted the board stack on the Nucleo board the below steps should be followed:

  • In case the X-NUCLEO-NFC-01A1 is on the board stack the WiFi SSID and password can be passed through the NFC tag by means of: 1) enabling the NFC support defining the X_NUCLEO_NFC01A1_PRESENT and recompiling, 2) when prompted on hyperterminal, programming the SSID and password to NFC using the Android app "NFCtools"
  • In case the NFC is not present, you local WiFi SSID and password can be programmed to mbed_app.json file and compiling and flashing the binary. Make sure the Wifi network has visible SSID.
  • Reset the Nucleo board and after few seconds the Nucleo green led will be on (it means the Nucleo is connected to the local Wifi and to the IBM cloud server)
  • Read the NFC tag with an Android device and the browser will be automatically opened and directed to the specific IBM quickstart demo page where the environmental values are displayed in form of a x-y graph. The values are updated every few seconds. On the Hyperterminal is possible to see the values sent to the IBM cloud server and the board mac address to be entered on the IBM quickstart web page if a manual connection is needed (eg. to connect from a PC browser).

In case of registered connection ( internetofthings.ibmcloud.com ) is needed ( no TLS ) comment the #define ORG_QUICKSTART than check in the mbed_app.json the following fields and change them according to your IBM MQTT broker account, MQTT_ORG_ID, MQTT_DEVICE_PASSWORD, MQTT_DEVICE_ID, MQTT_DEVICE_TYPE.

In case of registered connection ( internetofthings.ibmcloud.com ) with TLS encryption is needed, uncomment the #define TLS_EN and make sure the certificate (SSL_CA_PEM) is still valid.

In the default case the application connect to quickstart.internetofthings.ibmcloud.com without any encryption not authentication.

Revision:
2:e3846f091b6b
Parent:
0:e477c0f8b2e4
Child:
4:df4138621205
--- a/main.cpp	Mon Nov 27 16:17:37 2017 +0100
+++ b/main.cpp	Fri Dec 01 11:05:04 2017 +0100
@@ -36,7 +36,7 @@
 
 #define ORG_QUICKSTART           // comment to connect to play.internetofthings.ibmcloud.com
 //#define SUBSCRIBE              // uncomment to subscribe to broker msgs (not to be used with IBM broker) 
-//#define X_NUCLEO_NFC01A1_PRESENT // uncomment to add NFC support
+#define X_NUCLEO_NFC01A1_PRESENT // uncomment to add NFC support
     
 #define MQTT_MAX_PACKET_SIZE 400   
 #define MQTT_MAX_PAYLOAD_SIZE 300 
@@ -48,10 +48,10 @@
 #define AUTH_TOKEN ""
 #define DEFAULT_TYPE_NAME "iotsample-mbed-Nucleo"
 #else   // not def ORG_QUICKSTART
-#define ORG "play"             // connect to play.internetofthings.ibmcloud.com/ For a registered connection, replace with your org
-#define ID ""       // For a registered connection, replace with your id
-#define AUTH_TOKEN ""// For a registered connection, replace with your auth-token
-#define DEFAULT_TYPE_NAME "sensor"
+#define ORG MQTT_ORG_ID            // connect to ORG.internetofthings.ibmcloud.com/ For a registered connection, replace with your org
+#define ID MQTT_DEVICE_ID          // For a registered connection is your device id
+#define AUTH_TOKEN  MQTT_DEVICE_PASSWORD  // For a registered connection is a device auth-token
+#define DEFAULT_TYPE_NAME  MQTT_DEVICE_TYPE  // For a registered connection is device type
 #endif
 
 #define TYPE DEFAULT_TYPE_NAME       // For a registered connection, replace with your type
@@ -104,7 +104,7 @@
     // Construct clientId - d:org:type:id
     char clientId[strlen(org) + strlen(type) + strlen(id) + 5];  
     sprintf(clientId, "d:%s:%s:%s", org, type, id);  
-    sprintf(subscription_url, "%s.%s/#/device/%s/sensor/", org, "internetofthings.ibmcloud.com",id);
+    sprintf(subscription_url, "%s.%s/#/device/%s/%s/", org, "internetofthings.ibmcloud.com", id, DEFAULT_TYPE_NAME);
 
     // Network debug statements 
     LOG("=====================================\n\r");
@@ -141,6 +141,7 @@
     {        
         data.username.cstring = "use-token-auth";
         data.password.cstring = auth_token;
+        printf ("AutToken: %s\n\r", auth_token);
     }   
     if ((rc = client->connect(data)) != 0) {
         printf("rc from MQTT connect is %d\r\n", rc);