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.

Committer:
mapellil
Date:
Fri Nov 17 08:46:13 2017 +0000
Revision:
0:e477c0f8b2e4
Child:
5:efa13fc5d99a
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mapellil 0:e477c0f8b2e4 1 #ifndef _MQTTNETWORK_H_
mapellil 0:e477c0f8b2e4 2 #define _MQTTNETWORK_H_
mapellil 0:e477c0f8b2e4 3
mapellil 0:e477c0f8b2e4 4 #include "NetworkInterface.h"
mapellil 0:e477c0f8b2e4 5
mapellil 0:e477c0f8b2e4 6 class MQTTNetwork {
mapellil 0:e477c0f8b2e4 7 public:
mapellil 0:e477c0f8b2e4 8 MQTTNetwork(NetworkInterface* aNetwork) : network(aNetwork) {
mapellil 0:e477c0f8b2e4 9 socket = new TCPSocket();
mapellil 0:e477c0f8b2e4 10 }
mapellil 0:e477c0f8b2e4 11
mapellil 0:e477c0f8b2e4 12 ~MQTTNetwork() {
mapellil 0:e477c0f8b2e4 13 delete socket;
mapellil 0:e477c0f8b2e4 14 }
mapellil 0:e477c0f8b2e4 15
mapellil 0:e477c0f8b2e4 16 int read(unsigned char* buffer, int len, int timeout) {
mapellil 0:e477c0f8b2e4 17 socket->set_timeout(timeout);
mapellil 0:e477c0f8b2e4 18 return socket->recv(buffer, len);
mapellil 0:e477c0f8b2e4 19 }
mapellil 0:e477c0f8b2e4 20
mapellil 0:e477c0f8b2e4 21 int write(unsigned char* buffer, int len, int timeout) {
mapellil 0:e477c0f8b2e4 22 socket->set_timeout(timeout);
mapellil 0:e477c0f8b2e4 23 return socket->send(buffer, len);
mapellil 0:e477c0f8b2e4 24 }
mapellil 0:e477c0f8b2e4 25
mapellil 0:e477c0f8b2e4 26 int connect(const char* hostname, int port) {
mapellil 0:e477c0f8b2e4 27 socket->open(network);
mapellil 0:e477c0f8b2e4 28 return socket->connect(hostname, port);
mapellil 0:e477c0f8b2e4 29 }
mapellil 0:e477c0f8b2e4 30
mapellil 0:e477c0f8b2e4 31 int disconnect() {
mapellil 0:e477c0f8b2e4 32 return socket->close();
mapellil 0:e477c0f8b2e4 33 }
mapellil 0:e477c0f8b2e4 34
mapellil 0:e477c0f8b2e4 35 private:
mapellil 0:e477c0f8b2e4 36 NetworkInterface* network;
mapellil 0:e477c0f8b2e4 37 TCPSocket* socket;
mapellil 0:e477c0f8b2e4 38 };
mapellil 0:e477c0f8b2e4 39
mapellil 0:e477c0f8b2e4 40 #endif // _MQTTNETWORK_H_