Simple test application for the STMicroelectronics X-NUCLEO-IDW01M1 Wi-Fi expansion board.
Dependencies: NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
Fork of HelloWorld_IDW01M1v2 by
main.cpp
00001 /* SpwfInterface NetworkSocketAPI Example Program 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include "SpwfInterface.h" 00019 #include "TCPSocket.h" 00020 00021 00022 00023 //------------------------------------ 00024 // Hyperterminal configuration 00025 // 9600 bauds, 8-bit data, no parity 00026 //------------------------------------ 00027 00028 Serial pc(USBTX, USBRX); 00029 DigitalOut myled(LED1); 00030 00031 /************************************* 00032 //FRDM-K64: D9->UART1_TX, D7->UART1_RX 00033 Pin connections: 00034 FRDM IDW01M1 00035 ------ --------- 00036 +3v3 <--> +3v3 00037 GND <--> GND 00038 D9 <--> D8 00039 D7 <--> D2 00040 00041 SpwfSAInterface spwf(D9, D7, false); 00042 *************************************/ 00043 /************************************* 00044 //LPCXpresso11U68: D9->UART1_TX, D7->UART1_RX 00045 Pin connections: 00046 LPC IDW01M1 00047 ------ --------- 00048 +3v3 <--> +3v3 00049 GND <--> GND 00050 A1 <--> D8 00051 A2 <--> D2 00052 00053 SpwfSAInterface spwf(A1, A2, false); 00054 *************************************/ 00055 00056 //NUCLEO: D8->UART1_TX (PA_9), D2->UART1_RX (PA_10) 00057 SpwfSAInterface spwf(D8, D2, false); 00058 00059 int main() { 00060 int err; 00061 char * ssid = "STM"; 00062 char * seckey = "STMDemo"; 00063 00064 pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n"); 00065 pc.printf("\r\nconnecting to AP\r\n"); 00066 00067 if(spwf.connect(ssid, seckey, NSAPI_SECURITY_WPA2)) { 00068 pc.printf("\r\nnow connected\r\n"); 00069 } else { 00070 pc.printf("\r\nerror connecting to AP.\r\n"); 00071 return -1; 00072 } 00073 00074 const char *ip = spwf.get_ip_address(); 00075 const char *mac = spwf.get_mac_address(); 00076 00077 pc.printf("\r\nIP Address is: %s\r\n", (ip) ? ip : "No IP"); 00078 pc.printf("\r\nMAC Address is: %s\r\n", (mac) ? mac : "No MAC"); 00079 00080 SocketAddress addr(&spwf, "st.com"); 00081 pc.printf("\r\nst.com resolved to: %s\r\n", addr.get_ip_address()); 00082 00083 pc.printf("\r\nconnecting to http://4.ifcfg.me\r\n"); 00084 00085 TCPSocket socket(&spwf); 00086 err = socket.connect("4.ifcfg.me", 23); 00087 if(err!=0) 00088 { 00089 pc.printf("\r\nCould not connect to Socket, err = %d!!\r\n", err); 00090 return -1; 00091 } else pc.printf("\r\nconnected to host server\r\n"); 00092 00093 char buffer[100]; 00094 int count = 0; 00095 pc.printf("\r\nReceiving Data\r\n"); 00096 count = socket.recv(buffer, sizeof buffer); 00097 00098 if(count > 0) 00099 { 00100 buffer [count]='\0'; 00101 printf("%s\r\n", buffer); 00102 } 00103 else pc.printf("\r\nData not received\r\n"); 00104 00105 pc.printf("\r\nClosing Socket\r\n"); 00106 socket.close(); 00107 pc.printf("\r\nUnsecure Socket Test complete.\r\n"); 00108 printf ("Socket closed\n\r"); 00109 spwf.disconnect(); 00110 printf ("WIFI disconnected, exiting ...\n\r"); 00111 00112 while(1) { 00113 wait(1); 00114 myled = !myled; 00115 } 00116 }
Generated on Wed Jul 13 2022 11:52:15 by 1.7.2