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 06:29:47 2016 +0000
Revision:
5:e913a401b174
Parent:
4:1ed7f173eec5
Child:
6:0d838d564181
main initializes SpwfInterface

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 4:1ed7f173eec5 24 pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
mridup 4:1ed7f173eec5 25
mridup 5:e913a401b174 26 err = spwf.init();
mridup 0:cbf8bc43bc9e 27 if(err!=0)
mridup 0:cbf8bc43bc9e 28 {
mridup 4:1ed7f173eec5 29 pc.printf("\r\n[APP] error initializing.\r\n");
mridup 0:cbf8bc43bc9e 30 return -1;
mridup 0:cbf8bc43bc9e 31 }
mridup 4:1ed7f173eec5 32
mridup 4:1ed7f173eec5 33 pc.printf("\r\n[APP] connecting to AP\r\n");
mridup 0:cbf8bc43bc9e 34
mridup 5:e913a401b174 35 err = spwf.connect(ssid, seckey, NS_SECURITY_WPA);
mridup 4:1ed7f173eec5 36 if(err!=0)
mridup 4:1ed7f173eec5 37 {
mridup 4:1ed7f173eec5 38 pc.printf("\r\n[APP] error connecting to AP.\r\n");
mridup 4:1ed7f173eec5 39 return -1;
mridup 0:cbf8bc43bc9e 40 }
mridup 4:1ed7f173eec5 41
mridup 4:1ed7f173eec5 42 pc.printf("\r\n[APP] now connected\r\n");
mridup 4:1ed7f173eec5 43
mridup 5:e913a401b174 44 const char *ip = spwf.getIPAddress();
mridup 5:e913a401b174 45 const char *mac = spwf.getMACAddress();
mridup 4:1ed7f173eec5 46
mridup 4:1ed7f173eec5 47 pc.printf("\r\n[APP] IP Address is: %s\r\n", (ip) ? ip : "No IP");
mridup 4:1ed7f173eec5 48 pc.printf("\r\n[APP] MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
mridup 4:1ed7f173eec5 49
mridup 4:1ed7f173eec5 50 pc.printf("\r\n[APP] opening socket\r\n");
mridup 4:1ed7f173eec5 51
mridup 5:e913a401b174 52 err = tcp_.open("time-d.nist.gov", 37);
mridup 4:1ed7f173eec5 53
mridup 4:1ed7f173eec5 54 if(err==0)
mridup 4:1ed7f173eec5 55 {
mridup 4:1ed7f173eec5 56 pc.printf("\r\n[APP] socket open OK\r\n");
mridup 5:e913a401b174 57 pc.printf("\r\n[APP] hostname resolved to: %s\r\n", tcp_.getIPAddress());
mridup 4:1ed7f173eec5 58
mridup 5:e913a401b174 59 err = tcp_.send(data, len);
mridup 4:1ed7f173eec5 60
mridup 4:1ed7f173eec5 61 if(err == 0)
mridup 4:1ed7f173eec5 62 pc.printf("\r\n[APP] socket send OK\r\n");
mridup 4:1ed7f173eec5 63 else
mridup 4:1ed7f173eec5 64 pc.printf("\r\n[APP] socket send error\r\n");
mridup 4:1ed7f173eec5 65
mridup 4:1ed7f173eec5 66 char received[4];
mridup 4:1ed7f173eec5 67 int32_t size = 0;
mridup 4:1ed7f173eec5 68 pc.printf("\r\n[APP] waiting for data recv\r\n");
mridup 5:e913a401b174 69 size = tcp_.recv(received, sizeof(received));
mridup 4:1ed7f173eec5 70 if(size==0)
mridup 4:1ed7f173eec5 71 pc.printf("\r\n[APP] Receive error.");
mridup 4:1ed7f173eec5 72 else
mridup 4:1ed7f173eec5 73 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 74 }
mridup 4:1ed7f173eec5 75 else
mridup 4:1ed7f173eec5 76 pc.printf("\r\n[APP] socket open Error\r\n");
mridup 4:1ed7f173eec5 77
mridup 4:1ed7f173eec5 78 while(1) {
mridup 4:1ed7f173eec5 79 wait(1);
mridup 4:1ed7f173eec5 80 myled = !myled;
mridup 3:dfb8c6c8c31b 81 }
mridup 4:1ed7f173eec5 82 }