NNN50 CE test using UDP (select DELTA_DFCM_NNN40 to compile)

Dependencies:   NNN50_WIFI_API mbed

Fork of NNN50_WiFi_HelloWorld by Delta

Committer:
tsungta
Date:
Thu Mar 02 10:20:15 2017 +0000
Revision:
3:ad0fd3c1247f
Parent:
2:92946804ed6f
First commit for CE test using UDP

Who changed what in which revision?

UserRevisionLine numberNew 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
tsungta 3:ad0fd3c1247f 18 const char* ECHO_SERVER_ADDRESS = "172.20.10.3";
tsungta 1:a357a8f9ac8b 19 const int ECHO_SERVER_PORT = 1030;
tsungta 1:a357a8f9ac8b 20
tsungta 0:b5f183111420 21 Serial uart(p17, p16);//temporary define for alpha release
tsungta 0:b5f183111420 22
tsungta 0:b5f183111420 23 int main() {
tsungta 0:b5f183111420 24
tsungta 0:b5f183111420 25 EthernetInterface eth;
tsungta 0:b5f183111420 26 WIFIDevice wifi;
tsungta 0:b5f183111420 27
tsungta 0:b5f183111420 28 uart.baud(9600);
tsungta 0:b5f183111420 29
tsungta 0:b5f183111420 30 eth.init();
tsungta 0:b5f183111420 31 uart.printf("MAC: %s\n", eth.getMACAddress());
tsungta 0:b5f183111420 32
tsungta 3:ad0fd3c1247f 33 wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "Tsungta_iPhone", "icq87001");
tsungta 3:ad0fd3c1247f 34
tsungta 0:b5f183111420 35 eth.connect();
tsungta 0:b5f183111420 36 printf("IP: %s\n", eth.getIPAddress());
tsungta 0:b5f183111420 37 printf("Gateway: %s\n", eth.getGateway());
tsungta 0:b5f183111420 38 printf("NetworkMask: %s\n", eth.getNetworkMask());
tsungta 0:b5f183111420 39
tsungta 0:b5f183111420 40 if(wifi.is_AP_connected())
tsungta 0:b5f183111420 41 uart.printf("Connect Success! \n");
tsungta 0:b5f183111420 42 else
tsungta 0:b5f183111420 43 uart.printf("Connect Fail! \n");
tsungta 1:a357a8f9ac8b 44
tsungta 1:a357a8f9ac8b 45 UDPSocket sock;
tsungta 1:a357a8f9ac8b 46 sock.init();
tsungta 1:a357a8f9ac8b 47
tsungta 1:a357a8f9ac8b 48 Endpoint echo_server;
tsungta 1:a357a8f9ac8b 49 echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
tsungta 1:a357a8f9ac8b 50
tsungta 3:ad0fd3c1247f 51 char out_buffer[1400] = "Hello World";
tsungta 1:a357a8f9ac8b 52 uart.printf("Sending message '%s' to server (%s)\n",out_buffer,ECHO_SERVER_ADDRESS);
tsungta 3:ad0fd3c1247f 53 while(1)
tsungta 3:ad0fd3c1247f 54 sock.sendTo(echo_server, out_buffer, sizeof(out_buffer));
tsungta 1:a357a8f9ac8b 55
tsungta 1:a357a8f9ac8b 56 sock.close();
tsungta 1:a357a8f9ac8b 57
tsungta 1:a357a8f9ac8b 58 eth.disconnect();
tsungta 2:92946804ed6f 59
tsungta 2:92946804ed6f 60 wifi.sleep();
tsungta 1:a357a8f9ac8b 61
tsungta 0:b5f183111420 62 while(1) {
tsungta 0:b5f183111420 63 }
tsungta 0:b5f183111420 64 }
tsungta 0:b5f183111420 65