Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NNN50_WIFI_API mbed
Fork of NNN50_CE_Test_UDP by
main.cpp
00001 /******************** (C) COPYRIGHT 2016 Delta Electronics, Inc. *************** 00002 * 00003 * File Name : main.cpp 00004 * Authors : Tsungta Wu - CPBG (tsungta.wu@deltaww.com) 00005 * Version : V.1.0.0 00006 * Date : 2016/Nov/24 00007 * 00008 * This example only show the most basic WiFi operation include AP scan and connect 00009 * The usage of TCP/UDP socket please refer to the mbed Handbook from the link below 00010 * https://developer.mbed.org/handbook/Socket 00011 * 00012 *******************************************************************************/ 00013 00014 #include "mbed.h" 00015 #include "EthernetInterface.h" 00016 #include "WIFIDevice.h" 00017 00018 #if 1 00019 const char* ECHO_SERVER_ADDRESS = "192.168.100.2"; 00020 char* AP_SSID = "HAME_A2_a5d1"; 00021 char* PASSWD = "12345678"; 00022 const int ECHO_SERVER_PORT = 5001; 00023 #else 00024 const char* ECHO_SERVER_ADDRESS = "172.20.10.4"; 00025 char* AP_SSID = "Gaan"; 00026 char* PASSWD = "12348888"; 00027 const int ECHO_SERVER_PORT = 5001; 00028 #endif 00029 00030 Serial uart(p17, p16);//temporary define for alpha release 00031 00032 int main() { 00033 00034 EthernetInterface eth; 00035 WIFIDevice wifi; 00036 00037 uart.baud(9600); 00038 00039 eth.init(); 00040 uart.printf("MAC: %s\n", eth.getMACAddress()); 00041 00042 //wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "Tsungta_iPhone", "icq87001"); 00043 //wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "Gaan", "12348888"); 00044 wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, AP_SSID, PASSWD); 00045 00046 eth.connect(); 00047 printf("IP: %s\n", eth.getIPAddress()); 00048 printf("Gateway: %s\n", eth.getGateway()); 00049 printf("NetworkMask: %s\n", eth.getNetworkMask()); 00050 00051 if(wifi.is_AP_connected()) 00052 uart.printf("Connect Success! \n"); 00053 else 00054 uart.printf("Connect Fail! \n"); 00055 00056 UDPSocket sock; 00057 sock.init(); 00058 00059 Endpoint echo_server; 00060 echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); 00061 00062 char out_buffer[1400] = "Hello World"; 00063 uart.printf("Sending message '%s' to server (%s)\n",out_buffer,ECHO_SERVER_ADDRESS); 00064 while(1) 00065 sock.sendTo(echo_server, out_buffer, sizeof(out_buffer)); 00066 00067 sock.close(); 00068 00069 eth.disconnect(); 00070 00071 wifi.sleep(); 00072 00073 while(1) { 00074 } 00075 } 00076
Generated on Tue Jul 12 2022 23:06:09 by
1.7.2
