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:
Sat May 14 12:10:37 2016 +0530
Revision:
10:c7b62ce013ad
Parent:
8:6df01cb43137
Child:
11:70df7089e2da
Adding header to main.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mridup 10:c7b62ce013ad 1 /* SpwfInterface NetworkSocketAPI Example Program
mridup 10:c7b62ce013ad 2 * Copyright (c) 2015 ARM Limited
mridup 10:c7b62ce013ad 3 *
mridup 10:c7b62ce013ad 4 * Licensed under the Apache License, Version 2.0 (the "License");
mridup 10:c7b62ce013ad 5 * you may not use this file except in compliance with the License.
mridup 10:c7b62ce013ad 6 * You may obtain a copy of the License at
mridup 10:c7b62ce013ad 7 *
mridup 10:c7b62ce013ad 8 * http://www.apache.org/licenses/LICENSE-2.0
mridup 10:c7b62ce013ad 9 *
mridup 10:c7b62ce013ad 10 * Unless required by applicable law or agreed to in writing, software
mridup 10:c7b62ce013ad 11 * distributed under the License is distributed on an "AS IS" BASIS,
mridup 10:c7b62ce013ad 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mridup 10:c7b62ce013ad 13 * See the License for the specific language governing permissions and
mridup 10:c7b62ce013ad 14 * limitations under the License.
mridup 10:c7b62ce013ad 15 */
mridup 10:c7b62ce013ad 16
mridup 0:cbf8bc43bc9e 17 #include "mbed.h"
mridup 0:cbf8bc43bc9e 18 #include "SPWFInterface.h"
mridup 4:1ed7f173eec5 19 #include "TCPSocket.h"
mridup 0:cbf8bc43bc9e 20
mridup 0:cbf8bc43bc9e 21 //------------------------------------
mridup 0:cbf8bc43bc9e 22 // Hyperterminal configuration
mridup 0:cbf8bc43bc9e 23 // 9600 bauds, 8-bit data, no parity
mridup 0:cbf8bc43bc9e 24 //------------------------------------
mridup 0:cbf8bc43bc9e 25
mridup 8:6df01cb43137 26 Serial pc(SERIAL_TX, SERIAL_RX);
mridup 3:dfb8c6c8c31b 27 DigitalOut myled(LED1);
mridup 5:e913a401b174 28 SpwfSAInterface spwf(PA_9, PA_10, PC_12, PC_8, PA_12, true);
mridup 4:1ed7f173eec5 29
mridup 4:1ed7f173eec5 30 int main() {
mridup 8:6df01cb43137 31 int err;
mridup 0:cbf8bc43bc9e 32 char * ssid = "STM";
mridup 0:cbf8bc43bc9e 33 char * seckey = "STMdemoPWD";
mridup 4:1ed7f173eec5 34
mridup 6:0d838d564181 35 pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
mridup 8:6df01cb43137 36 pc.printf("\r\nconnecting to AP\r\n");
mridup 0:cbf8bc43bc9e 37
mridup 8:6df01cb43137 38 err = spwf.connect(ssid, seckey, NSAPI_SECURITY_WPA);
mridup 4:1ed7f173eec5 39 if(err!=0)
mridup 4:1ed7f173eec5 40 {
mridup 8:6df01cb43137 41 pc.printf("\r\nerror connecting to AP.\r\n");
mridup 4:1ed7f173eec5 42 return -1;
mridup 0:cbf8bc43bc9e 43 }
mridup 4:1ed7f173eec5 44
mridup 8:6df01cb43137 45 pc.printf("\r\nnow connected\r\n");
mridup 4:1ed7f173eec5 46
mridup 8:6df01cb43137 47 const char *ip = spwf.get_ip_address();
mridup 8:6df01cb43137 48 const char *mac = spwf.get_mac_address();
mridup 4:1ed7f173eec5 49
mridup 8:6df01cb43137 50 pc.printf("\r\nIP Address is: %s\r\n", (ip) ? ip : "No IP");
mridup 8:6df01cb43137 51 pc.printf("\r\nMAC Address is: %s\r\n", (mac) ? mac : "No MAC");
mridup 8:6df01cb43137 52
mridup 8:6df01cb43137 53 SocketAddress addr(&spwf, "st.com");
mridup 8:6df01cb43137 54 printf("\r\nst.com resolved to: %s\r\n", addr.get_ip_address());
mridup 8:6df01cb43137 55
mridup 10:c7b62ce013ad 56 pc.printf("\r\nconnecting to http://time-d.nist.gov\r\n");
mridup 4:1ed7f173eec5 57
mridup 8:6df01cb43137 58 TCPSocket socket(&spwf);
mridup 8:6df01cb43137 59 err = socket.connect("time-d.nist.gov", 37);
mridup 8:6df01cb43137 60 if(err!=0)
mridup 8:6df01cb43137 61 {
mridup 8:6df01cb43137 62 pc.printf("\r\nCould not connect to Socket, err = %d!!\r\n", err);
mridup 8:6df01cb43137 63 return -1;
mridup 8:6df01cb43137 64 }
mridup 10:c7b62ce013ad 65 char buffer[10];
mridup 8:6df01cb43137 66 int count = 0;
mridup 8:6df01cb43137 67 pc.printf("\r\nReceiving Data\r\n");
mridup 8:6df01cb43137 68 count = socket.recv(buffer, sizeof buffer);
mridup 8:6df01cb43137 69
mridup 8:6df01cb43137 70 if(count > 0)
mridup 8:6df01cb43137 71 {
mridup 8:6df01cb43137 72 pc.printf("\r\nReceived: %ld bytes, 0x%02x 0x%02x 0x%02x 0x%02x\r\n", \
mridup 8:6df01cb43137 73 count, buffer[0], buffer[1], buffer[2], buffer[3]);
mridup 8:6df01cb43137 74 }
mridup 8:6df01cb43137 75 else pc.printf("\r\nData not received\r\n");
mridup 8:6df01cb43137 76
mridup 8:6df01cb43137 77 pc.printf("\r\nClosing Socket\r\n");
mridup 8:6df01cb43137 78 socket.close();
mridup 4:1ed7f173eec5 79
mridup 8:6df01cb43137 80 pc.printf("\r\ndisconnecting....\r\n");
mridup 8:6df01cb43137 81 spwf.disconnect();
mridup 8:6df01cb43137 82 pc.printf("\r\nTest complete.\r\n");
mridup 4:1ed7f173eec5 83
mridup 4:1ed7f173eec5 84 while(1) {
mridup 4:1ed7f173eec5 85 wait(1);
mridup 4:1ed7f173eec5 86 myled = !myled;
mridup 3:dfb8c6c8c31b 87 }
mridup 4:1ed7f173eec5 88 }