Simple test application for the STMicroelectronics X-NUCLEO-IDW01M1 Wi-Fi expansion board.

Dependencies:   NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed

Fork of HelloWorld_IDW01M1v2 by ST Expansion SW Team

Introduction

HelloWorld_IDW01M1 is an example application which uses the X_NUCLEO_IDW01M1v2 mbed library.

The software can be used for testing the X-NUCLEO-IDW01M1 expansion board on mbed platforms. Current supported platforms are NUCLEO-F401RE and NUCLEO-L476RG.

Example Application

The SpwfSAInterface class needs to be instantiated with the UART RX and TX pins used. Depending on the platform used, the pin numbers may vary.

E.g. For FRDM K64F board it is: D9 and D7.

For Nucleo it is D8 and D2.

SpwfSAInterface spwf(D8, D2, false);


First of all, the example application tries to connect to the SSID/AP which is provided in the program code. In order to connect to your desired SSID/AP please change the SSID/AP settings/text to the one which is used in the user's environment. Please also remember that the SSID needs to be connected to the internet.

 char * ssid = "STM"; //Please change to local SSID/AP name
 char * seckey = "STMdemoPWD"; //Please change password


After connection the program prints its own IP address and MAC address on the serial terminal over UART. Please launch a terminal application (e.g.: TeraTerm, PuTTY on Windows, Minicom on Linux) and set the UART port to 9600 bps, 8 bit, No Parity, 1 stop bit. Thereafter the program retreives the IP address of the "st.com" webpage and outputs it to the serial terminal.

After outputting the IP address of st.com, the program tries to connect to the address "http://4.ifcfg.me" and socket 23. After connecting to the socket the program receives the IP Address from the server and outputs the IP Address it receives which denotes the public IP Address of the platform + X-Nucleo-IDW01M1 (node).

Further the program closes the socket, disconnects from the SSID and exits. This is just a simple "Hello World" style program for the X-NUCLEO-IDW01M1 Wi-Fi Expansion Board.

Committer:
mapellil
Date:
Mon Jan 16 13:26:50 2017 +0000
Revision:
12:80d8e97e81f2
Parent:
11:0b4472769b08
Moved secure socket connection to the specific TLS_HelloWorld app

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mridup 0:dee849b0e6e6 1 /* SpwfInterface NetworkSocketAPI Example Program
mridup 0:dee849b0e6e6 2 * Copyright (c) 2015 ARM Limited
mridup 0:dee849b0e6e6 3 *
mridup 0:dee849b0e6e6 4 * Licensed under the Apache License, Version 2.0 (the "License");
mridup 0:dee849b0e6e6 5 * you may not use this file except in compliance with the License.
mridup 0:dee849b0e6e6 6 * You may obtain a copy of the License at
mridup 0:dee849b0e6e6 7 *
mridup 0:dee849b0e6e6 8 * http://www.apache.org/licenses/LICENSE-2.0
mridup 0:dee849b0e6e6 9 *
mridup 0:dee849b0e6e6 10 * Unless required by applicable law or agreed to in writing, software
mridup 0:dee849b0e6e6 11 * distributed under the License is distributed on an "AS IS" BASIS,
mridup 0:dee849b0e6e6 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mridup 0:dee849b0e6e6 13 * See the License for the specific language governing permissions and
mridup 0:dee849b0e6e6 14 * limitations under the License.
mridup 0:dee849b0e6e6 15 */
mridup 0:dee849b0e6e6 16
mridup 0:dee849b0e6e6 17 #include "mbed.h"
mridup 0:dee849b0e6e6 18 #include "SpwfInterface.h"
mridup 0:dee849b0e6e6 19 #include "TCPSocket.h"
mridup 0:dee849b0e6e6 20
mapellil 8:74b827befe72 21
mapellil 10:cc61a766cd1f 22
mridup 0:dee849b0e6e6 23 //------------------------------------
mridup 0:dee849b0e6e6 24 // Hyperterminal configuration
mridup 0:dee849b0e6e6 25 // 9600 bauds, 8-bit data, no parity
mridup 0:dee849b0e6e6 26 //------------------------------------
mridup 0:dee849b0e6e6 27
mridup 2:3a87dbea07a7 28 Serial pc(USBTX, USBRX);
mridup 0:dee849b0e6e6 29 DigitalOut myled(LED1);
mridup 1:daf71fa3674c 30
mridup 1:daf71fa3674c 31 /*************************************
mridup 1:daf71fa3674c 32 //FRDM-K64: D9->UART1_TX, D7->UART1_RX
mridup 1:daf71fa3674c 33 Pin connections:
mridup 1:daf71fa3674c 34 FRDM IDW01M1
mridup 1:daf71fa3674c 35 ------ ---------
mridup 1:daf71fa3674c 36 +3v3 <--> +3v3
mridup 1:daf71fa3674c 37 GND <--> GND
mridup 1:daf71fa3674c 38 D9 <--> D8
mridup 1:daf71fa3674c 39 D7 <--> D2
mridup 1:daf71fa3674c 40
mridup 1:daf71fa3674c 41 SpwfSAInterface spwf(D9, D7, false);
mridup 1:daf71fa3674c 42 *************************************/
mridup 2:3a87dbea07a7 43 /*************************************
mridup 2:3a87dbea07a7 44 //LPCXpresso11U68: D9->UART1_TX, D7->UART1_RX
mridup 2:3a87dbea07a7 45 Pin connections:
mridup 2:3a87dbea07a7 46 LPC IDW01M1
mridup 2:3a87dbea07a7 47 ------ ---------
mridup 2:3a87dbea07a7 48 +3v3 <--> +3v3
mridup 2:3a87dbea07a7 49 GND <--> GND
mridup 2:3a87dbea07a7 50 A1 <--> D8
mridup 2:3a87dbea07a7 51 A2 <--> D2
mridup 2:3a87dbea07a7 52
mridup 2:3a87dbea07a7 53 SpwfSAInterface spwf(A1, A2, false);
mridup 2:3a87dbea07a7 54 *************************************/
mridup 1:daf71fa3674c 55
mridup 1:daf71fa3674c 56 //NUCLEO: D8->UART1_TX (PA_9), D2->UART1_RX (PA_10)
mridup 1:daf71fa3674c 57 SpwfSAInterface spwf(D8, D2, false);
mridup 2:3a87dbea07a7 58
mridup 0:dee849b0e6e6 59 int main() {
mridup 0:dee849b0e6e6 60 int err;
nikapov 7:92b5480bb3e4 61 char * ssid = "STM";
mapellil 11:0b4472769b08 62 char * seckey = "STMDemo";
mridup 0:dee849b0e6e6 63
mridup 0:dee849b0e6e6 64 pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
mridup 0:dee849b0e6e6 65 pc.printf("\r\nconnecting to AP\r\n");
mridup 0:dee849b0e6e6 66
mridup 0:dee849b0e6e6 67 if(spwf.connect(ssid, seckey, NSAPI_SECURITY_WPA2)) {
mridup 0:dee849b0e6e6 68 pc.printf("\r\nnow connected\r\n");
mridup 0:dee849b0e6e6 69 } else {
mridup 0:dee849b0e6e6 70 pc.printf("\r\nerror connecting to AP.\r\n");
mridup 0:dee849b0e6e6 71 return -1;
mridup 0:dee849b0e6e6 72 }
mapellil 8:74b827befe72 73
mridup 0:dee849b0e6e6 74 const char *ip = spwf.get_ip_address();
mridup 0:dee849b0e6e6 75 const char *mac = spwf.get_mac_address();
mridup 0:dee849b0e6e6 76
mridup 0:dee849b0e6e6 77 pc.printf("\r\nIP Address is: %s\r\n", (ip) ? ip : "No IP");
mridup 0:dee849b0e6e6 78 pc.printf("\r\nMAC Address is: %s\r\n", (mac) ? mac : "No MAC");
mridup 0:dee849b0e6e6 79
mridup 0:dee849b0e6e6 80 SocketAddress addr(&spwf, "st.com");
mridup 0:dee849b0e6e6 81 pc.printf("\r\nst.com resolved to: %s\r\n", addr.get_ip_address());
mridup 0:dee849b0e6e6 82
mridup 4:40cb51547b9f 83 pc.printf("\r\nconnecting to http://4.ifcfg.me\r\n");
mridup 0:dee849b0e6e6 84
mridup 0:dee849b0e6e6 85 TCPSocket socket(&spwf);
mridup 2:3a87dbea07a7 86 err = socket.connect("4.ifcfg.me", 23);
mridup 0:dee849b0e6e6 87 if(err!=0)
mridup 0:dee849b0e6e6 88 {
mridup 0:dee849b0e6e6 89 pc.printf("\r\nCould not connect to Socket, err = %d!!\r\n", err);
mridup 0:dee849b0e6e6 90 return -1;
mridup 0:dee849b0e6e6 91 } else pc.printf("\r\nconnected to host server\r\n");
mridup 0:dee849b0e6e6 92
mapellil 8:74b827befe72 93 char buffer[100];
mridup 0:dee849b0e6e6 94 int count = 0;
mridup 0:dee849b0e6e6 95 pc.printf("\r\nReceiving Data\r\n");
mridup 0:dee849b0e6e6 96 count = socket.recv(buffer, sizeof buffer);
mridup 0:dee849b0e6e6 97
mridup 0:dee849b0e6e6 98 if(count > 0)
mridup 0:dee849b0e6e6 99 {
mapellil 8:74b827befe72 100 buffer [count]='\0';
mapellil 8:74b827befe72 101 printf("%s\r\n", buffer);
mridup 0:dee849b0e6e6 102 }
mridup 0:dee849b0e6e6 103 else pc.printf("\r\nData not received\r\n");
mridup 0:dee849b0e6e6 104
mridup 2:3a87dbea07a7 105 pc.printf("\r\nClosing Socket\r\n");
mridup 2:3a87dbea07a7 106 socket.close();
mapellil 8:74b827befe72 107 pc.printf("\r\nUnsecure Socket Test complete.\r\n");
mapellil 8:74b827befe72 108 printf ("Socket closed\n\r");
mridup 2:3a87dbea07a7 109 spwf.disconnect();
mapellil 8:74b827befe72 110 printf ("WIFI disconnected, exiting ...\n\r");
mapellil 8:74b827befe72 111
mridup 0:dee849b0e6e6 112 while(1) {
mridup 0:dee849b0e6e6 113 wait(1);
mridup 0:dee849b0e6e6 114 myled = !myled;
mridup 0:dee849b0e6e6 115 }
mridup 0:dee849b0e6e6 116 }