Connect through Wifi to IBM MQTT cloud https://quickstart.internetofthings.ibmcloud.com

Dependencies:   MQTT NetworkSocketAPI X_NUCLEO_IDW01M1v2 X_NUCLEO_IKS01A1 mbed NDefLib X_NUCLEO_NFC01A1

Fork of IDW01M1_Cloud_IBM by ST Expansion SW Team

To start the demo the following expansion boards are required

X_NUCLEO_IDW01M1v2, X_NUCLEO_IKS01A1, X_NUCLEO_NFC01A1

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

  • Program in the application source code you local WiFi SSID and password and flash 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 brocker IBM 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).
Committer:
mridup
Date:
Fri May 13 12:24:36 2016 +0000
Revision:
8:6df01cb43137
Parent:
6:0d838d564181
Child:
10:c7b62ce013ad
changes to app and removing libs.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mridup 0:cbf8bc43bc9e 1 #include "mbed.h"
mridup 0:cbf8bc43bc9e 2 #include "SPWFInterface.h"
mridup 4:1ed7f173eec5 3 #include "TCPSocket.h"
mridup 0:cbf8bc43bc9e 4
mridup 0:cbf8bc43bc9e 5 //------------------------------------
mridup 0:cbf8bc43bc9e 6 // Hyperterminal configuration
mridup 0:cbf8bc43bc9e 7 // 9600 bauds, 8-bit data, no parity
mridup 0:cbf8bc43bc9e 8 //------------------------------------
mridup 0:cbf8bc43bc9e 9
mridup 8:6df01cb43137 10 Serial pc(SERIAL_TX, SERIAL_RX);
mridup 3:dfb8c6c8c31b 11 DigitalOut myled(LED1);
mridup 5:e913a401b174 12 SpwfSAInterface spwf(PA_9, PA_10, PC_12, PC_8, PA_12, true);
mridup 4:1ed7f173eec5 13
mridup 4:1ed7f173eec5 14 int main() {
mridup 8:6df01cb43137 15 int err;
mridup 0:cbf8bc43bc9e 16 char * ssid = "STM";
mridup 0:cbf8bc43bc9e 17 char * seckey = "STMdemoPWD";
mridup 4:1ed7f173eec5 18
mridup 6:0d838d564181 19 pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
mridup 8:6df01cb43137 20 pc.printf("\r\nconnecting to AP\r\n");
mridup 0:cbf8bc43bc9e 21
mridup 8:6df01cb43137 22 err = spwf.connect(ssid, seckey, NSAPI_SECURITY_WPA);
mridup 4:1ed7f173eec5 23 if(err!=0)
mridup 4:1ed7f173eec5 24 {
mridup 8:6df01cb43137 25 pc.printf("\r\nerror connecting to AP.\r\n");
mridup 4:1ed7f173eec5 26 return -1;
mridup 0:cbf8bc43bc9e 27 }
mridup 4:1ed7f173eec5 28
mridup 8:6df01cb43137 29 pc.printf("\r\nnow connected\r\n");
mridup 4:1ed7f173eec5 30
mridup 8:6df01cb43137 31 const char *ip = spwf.get_ip_address();
mridup 8:6df01cb43137 32 const char *mac = spwf.get_mac_address();
mridup 4:1ed7f173eec5 33
mridup 8:6df01cb43137 34 pc.printf("\r\nIP Address is: %s\r\n", (ip) ? ip : "No IP");
mridup 8:6df01cb43137 35 pc.printf("\r\nMAC Address is: %s\r\n", (mac) ? mac : "No MAC");
mridup 8:6df01cb43137 36
mridup 8:6df01cb43137 37 SocketAddress addr(&spwf, "st.com");
mridup 8:6df01cb43137 38 printf("\r\nst.com resolved to: %s\r\n", addr.get_ip_address());
mridup 8:6df01cb43137 39
mridup 8:6df01cb43137 40 pc.printf("\r\nconnecting to http://time-d.nist.gov\r\n"); //time-d.nist.gov
mridup 4:1ed7f173eec5 41
mridup 8:6df01cb43137 42 TCPSocket socket(&spwf);
mridup 8:6df01cb43137 43 err = socket.connect("time-d.nist.gov", 37);
mridup 8:6df01cb43137 44 if(err!=0)
mridup 8:6df01cb43137 45 {
mridup 8:6df01cb43137 46 pc.printf("\r\nCould not connect to Socket, err = %d!!\r\n", err);
mridup 8:6df01cb43137 47 return -1;
mridup 8:6df01cb43137 48 }
mridup 8:6df01cb43137 49 char buffer[64];
mridup 8:6df01cb43137 50 int count = 0;
mridup 8:6df01cb43137 51 pc.printf("\r\nReceiving Data\r\n");
mridup 8:6df01cb43137 52 count = socket.recv(buffer, sizeof buffer);
mridup 8:6df01cb43137 53
mridup 8:6df01cb43137 54 if(count > 0)
mridup 8:6df01cb43137 55 {
mridup 8:6df01cb43137 56 pc.printf("\r\nReceived: %ld bytes, 0x%02x 0x%02x 0x%02x 0x%02x\r\n", \
mridup 8:6df01cb43137 57 count, buffer[0], buffer[1], buffer[2], buffer[3]);
mridup 8:6df01cb43137 58 }
mridup 8:6df01cb43137 59 else pc.printf("\r\nData not received\r\n");
mridup 8:6df01cb43137 60
mridup 8:6df01cb43137 61 pc.printf("\r\nClosing Socket\r\n");
mridup 8:6df01cb43137 62 socket.close();
mridup 4:1ed7f173eec5 63
mridup 8:6df01cb43137 64 pc.printf("\r\ndisconnecting....\r\n");
mridup 8:6df01cb43137 65 spwf.disconnect();
mridup 8:6df01cb43137 66 pc.printf("\r\nTest complete.\r\n");
mridup 4:1ed7f173eec5 67
mridup 4:1ed7f173eec5 68 while(1) {
mridup 4:1ed7f173eec5 69 wait(1);
mridup 4:1ed7f173eec5 70 myled = !myled;
mridup 3:dfb8c6c8c31b 71 }
mridup 4:1ed7f173eec5 72 }