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:
Tue Apr 19 07:19:55 2016 +0000
Revision:
6:0d838d564181
Parent:
5:e913a401b174
Child:
8:6df01cb43137
removing init() from main

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 0:cbf8bc43bc9e 10 Serial pc(SERIAL_TX, SERIAL_RX);
mridup 4:1ed7f173eec5 11
mridup 3:dfb8c6c8c31b 12 DigitalOut myled(LED1);
mridup 4:1ed7f173eec5 13
mridup 5:e913a401b174 14 SpwfSAInterface spwf(PA_9, PA_10, PC_12, PC_8, PA_12, true);
mridup 5:e913a401b174 15 TCPSocket tcp_(&spwf);
mridup 4:1ed7f173eec5 16
mridup 4:1ed7f173eec5 17 int main() {
mridup 4:1ed7f173eec5 18 int32_t err;
mridup 0:cbf8bc43bc9e 19 char * ssid = "STM";
mridup 0:cbf8bc43bc9e 20 char * seckey = "STMdemoPWD";
mridup 4:1ed7f173eec5 21 char * data = "Hello World!\r\n";
mridup 4:1ed7f173eec5 22 uint32_t len = strlen(data);
mridup 4:1ed7f173eec5 23
mridup 6:0d838d564181 24 pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
mridup 4:1ed7f173eec5 25 pc.printf("\r\n[APP] connecting to AP\r\n");
mridup 0:cbf8bc43bc9e 26
mridup 5:e913a401b174 27 err = spwf.connect(ssid, seckey, NS_SECURITY_WPA);
mridup 4:1ed7f173eec5 28 if(err!=0)
mridup 4:1ed7f173eec5 29 {
mridup 4:1ed7f173eec5 30 pc.printf("\r\n[APP] error connecting to AP.\r\n");
mridup 4:1ed7f173eec5 31 return -1;
mridup 0:cbf8bc43bc9e 32 }
mridup 4:1ed7f173eec5 33
mridup 4:1ed7f173eec5 34 pc.printf("\r\n[APP] now connected\r\n");
mridup 4:1ed7f173eec5 35
mridup 5:e913a401b174 36 const char *ip = spwf.getIPAddress();
mridup 5:e913a401b174 37 const char *mac = spwf.getMACAddress();
mridup 4:1ed7f173eec5 38
mridup 4:1ed7f173eec5 39 pc.printf("\r\n[APP] IP Address is: %s\r\n", (ip) ? ip : "No IP");
mridup 4:1ed7f173eec5 40 pc.printf("\r\n[APP] MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
mridup 4:1ed7f173eec5 41
mridup 4:1ed7f173eec5 42 pc.printf("\r\n[APP] opening socket\r\n");
mridup 4:1ed7f173eec5 43
mridup 5:e913a401b174 44 err = tcp_.open("time-d.nist.gov", 37);
mridup 4:1ed7f173eec5 45
mridup 4:1ed7f173eec5 46 if(err==0)
mridup 4:1ed7f173eec5 47 {
mridup 4:1ed7f173eec5 48 pc.printf("\r\n[APP] socket open OK\r\n");
mridup 5:e913a401b174 49 pc.printf("\r\n[APP] hostname resolved to: %s\r\n", tcp_.getIPAddress());
mridup 4:1ed7f173eec5 50
mridup 5:e913a401b174 51 err = tcp_.send(data, len);
mridup 4:1ed7f173eec5 52
mridup 4:1ed7f173eec5 53 if(err == 0)
mridup 4:1ed7f173eec5 54 pc.printf("\r\n[APP] socket send OK\r\n");
mridup 4:1ed7f173eec5 55 else
mridup 4:1ed7f173eec5 56 pc.printf("\r\n[APP] socket send error\r\n");
mridup 4:1ed7f173eec5 57
mridup 4:1ed7f173eec5 58 char received[4];
mridup 4:1ed7f173eec5 59 int32_t size = 0;
mridup 4:1ed7f173eec5 60 pc.printf("\r\n[APP] waiting for data recv\r\n");
mridup 5:e913a401b174 61 size = tcp_.recv(received, sizeof(received));
mridup 4:1ed7f173eec5 62 if(size==0)
mridup 4:1ed7f173eec5 63 pc.printf("\r\n[APP] Receive error.");
mridup 4:1ed7f173eec5 64 else
mridup 4:1ed7f173eec5 65 pc.printf("\r\n[APP] Received: %ld bytes, 0x%02x 0x%02x 0x%02x 0x%02x\r\n", size, received[0], received[1], received[2], received[3]);
mridup 4:1ed7f173eec5 66 }
mridup 4:1ed7f173eec5 67 else
mridup 4:1ed7f173eec5 68 pc.printf("\r\n[APP] socket open Error\r\n");
mridup 4:1ed7f173eec5 69
mridup 4:1ed7f173eec5 70 while(1) {
mridup 4:1ed7f173eec5 71 wait(1);
mridup 4:1ed7f173eec5 72 myled = !myled;
mridup 3:dfb8c6c8c31b 73 }
mridup 4:1ed7f173eec5 74 }