CE_Test_UDP add mult-AP setting
Dependencies: NNN50_WIFI_API mbed
Fork of NNN50_CE_Test_UDP by
main.cpp@4:da5d554dae5a, 2017-03-09 (annotated)
- Committer:
- janshiue
- Date:
- Thu Mar 09 10:09:44 2017 +0000
- Revision:
- 4:da5d554dae5a
- Parent:
- 3:ad0fd3c1247f
modify multi-AP setting
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tsungta | 0:b5f183111420 | 1 | /******************** (C) COPYRIGHT 2016 Delta Electronics, Inc. *************** |
tsungta | 0:b5f183111420 | 2 | * |
tsungta | 0:b5f183111420 | 3 | * File Name : main.cpp |
tsungta | 0:b5f183111420 | 4 | * Authors : Tsungta Wu - CPBG (tsungta.wu@deltaww.com) |
tsungta | 0:b5f183111420 | 5 | * Version : V.1.0.0 |
tsungta | 0:b5f183111420 | 6 | * Date : 2016/Nov/24 |
tsungta | 0:b5f183111420 | 7 | * |
tsungta | 0:b5f183111420 | 8 | * This example only show the most basic WiFi operation include AP scan and connect |
tsungta | 0:b5f183111420 | 9 | * The usage of TCP/UDP socket please refer to the mbed Handbook from the link below |
tsungta | 0:b5f183111420 | 10 | * https://developer.mbed.org/handbook/Socket |
tsungta | 0:b5f183111420 | 11 | * |
tsungta | 0:b5f183111420 | 12 | *******************************************************************************/ |
tsungta | 0:b5f183111420 | 13 | |
tsungta | 0:b5f183111420 | 14 | #include "mbed.h" |
tsungta | 0:b5f183111420 | 15 | #include "EthernetInterface.h" |
tsungta | 0:b5f183111420 | 16 | #include "WIFIDevice.h" |
tsungta | 0:b5f183111420 | 17 | |
janshiue | 4:da5d554dae5a | 18 | #if 1 |
janshiue | 4:da5d554dae5a | 19 | const char* ECHO_SERVER_ADDRESS = "192.168.100.2"; |
janshiue | 4:da5d554dae5a | 20 | char* AP_SSID = "HAME_A2_a5d1"; |
janshiue | 4:da5d554dae5a | 21 | char* PASSWD = "12345678"; |
janshiue | 4:da5d554dae5a | 22 | const int ECHO_SERVER_PORT = 5001; |
janshiue | 4:da5d554dae5a | 23 | #else |
janshiue | 4:da5d554dae5a | 24 | const char* ECHO_SERVER_ADDRESS = "172.20.10.4"; |
janshiue | 4:da5d554dae5a | 25 | char* AP_SSID = "Gaan"; |
janshiue | 4:da5d554dae5a | 26 | char* PASSWD = "12348888"; |
janshiue | 4:da5d554dae5a | 27 | const int ECHO_SERVER_PORT = 5001; |
janshiue | 4:da5d554dae5a | 28 | #endif |
tsungta | 1:a357a8f9ac8b | 29 | |
tsungta | 0:b5f183111420 | 30 | Serial uart(p17, p16);//temporary define for alpha release |
tsungta | 0:b5f183111420 | 31 | |
tsungta | 0:b5f183111420 | 32 | int main() { |
tsungta | 0:b5f183111420 | 33 | |
tsungta | 0:b5f183111420 | 34 | EthernetInterface eth; |
tsungta | 0:b5f183111420 | 35 | WIFIDevice wifi; |
tsungta | 0:b5f183111420 | 36 | |
tsungta | 0:b5f183111420 | 37 | uart.baud(9600); |
tsungta | 0:b5f183111420 | 38 | |
tsungta | 0:b5f183111420 | 39 | eth.init(); |
tsungta | 0:b5f183111420 | 40 | uart.printf("MAC: %s\n", eth.getMACAddress()); |
tsungta | 0:b5f183111420 | 41 | |
janshiue | 4:da5d554dae5a | 42 | //wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "Tsungta_iPhone", "icq87001"); |
janshiue | 4:da5d554dae5a | 43 | //wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "Gaan", "12348888"); |
janshiue | 4:da5d554dae5a | 44 | wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, AP_SSID, PASSWD); |
tsungta | 3:ad0fd3c1247f | 45 | |
tsungta | 0:b5f183111420 | 46 | eth.connect(); |
tsungta | 0:b5f183111420 | 47 | printf("IP: %s\n", eth.getIPAddress()); |
tsungta | 0:b5f183111420 | 48 | printf("Gateway: %s\n", eth.getGateway()); |
tsungta | 0:b5f183111420 | 49 | printf("NetworkMask: %s\n", eth.getNetworkMask()); |
tsungta | 0:b5f183111420 | 50 | |
tsungta | 0:b5f183111420 | 51 | if(wifi.is_AP_connected()) |
tsungta | 0:b5f183111420 | 52 | uart.printf("Connect Success! \n"); |
tsungta | 0:b5f183111420 | 53 | else |
tsungta | 0:b5f183111420 | 54 | uart.printf("Connect Fail! \n"); |
tsungta | 1:a357a8f9ac8b | 55 | |
tsungta | 1:a357a8f9ac8b | 56 | UDPSocket sock; |
tsungta | 1:a357a8f9ac8b | 57 | sock.init(); |
tsungta | 1:a357a8f9ac8b | 58 | |
tsungta | 1:a357a8f9ac8b | 59 | Endpoint echo_server; |
tsungta | 1:a357a8f9ac8b | 60 | echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); |
tsungta | 1:a357a8f9ac8b | 61 | |
tsungta | 3:ad0fd3c1247f | 62 | char out_buffer[1400] = "Hello World"; |
tsungta | 1:a357a8f9ac8b | 63 | uart.printf("Sending message '%s' to server (%s)\n",out_buffer,ECHO_SERVER_ADDRESS); |
tsungta | 3:ad0fd3c1247f | 64 | while(1) |
tsungta | 3:ad0fd3c1247f | 65 | sock.sendTo(echo_server, out_buffer, sizeof(out_buffer)); |
tsungta | 1:a357a8f9ac8b | 66 | |
tsungta | 1:a357a8f9ac8b | 67 | sock.close(); |
tsungta | 1:a357a8f9ac8b | 68 | |
tsungta | 1:a357a8f9ac8b | 69 | eth.disconnect(); |
tsungta | 2:92946804ed6f | 70 | |
tsungta | 2:92946804ed6f | 71 | wifi.sleep(); |
tsungta | 1:a357a8f9ac8b | 72 | |
tsungta | 0:b5f183111420 | 73 | while(1) { |
tsungta | 0:b5f183111420 | 74 | } |
tsungta | 0:b5f183111420 | 75 | } |
tsungta | 0:b5f183111420 | 76 |