NNN40_WiFi_Demo
Dependencies: WIFI_API_32kRAM mbed
Fork of NNN40_WiFi by
main.cpp@11:0d4c4bc2274a, 2015-08-20 (annotated)
- Committer:
- gordonlu
- Date:
- Thu Aug 20 02:54:14 2015 +0000
- Revision:
- 11:0d4c4bc2274a
- Parent:
- 10:fff1a8a4b003
NNN40_WIFI_DEMO_1 (32?RAM)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Marcomissyou | 0:25ffe5869e35 | 1 | #include "mbed.h" |
Marcomissyou | 0:25ffe5869e35 | 2 | #include "WIFIDevice.h" |
Marcomissyou | 3:65c5fce3a471 | 3 | #include "EthernetInterface.h" |
Marcomissyou | 0:25ffe5869e35 | 4 | |
Marcomissyou | 0:25ffe5869e35 | 5 | WIFIDevice wifi; |
Marcomissyou | 0:25ffe5869e35 | 6 | |
gordonlu | 10:fff1a8a4b003 | 7 | const char* PC_SERVER_ADDRESS_1 = "10.0.1.2"; |
gordonlu | 10:fff1a8a4b003 | 8 | const char* PC_SERVER_ADDRESS_2 = "10.0.1.3"; |
Marcomissyou | 0:25ffe5869e35 | 9 | uint16_t PC_PORT = 5222; |
gordonlu | 10:fff1a8a4b003 | 10 | |
gordonlu | 10:fff1a8a4b003 | 11 | DigitalOut LED01(p13); |
gordonlu | 10:fff1a8a4b003 | 12 | DigitalOut LED02(p7); |
gordonlu | 11:0d4c4bc2274a | 13 | Serial pc(USBTX, USBRX);//debug port , 9600 |
gordonlu | 10:fff1a8a4b003 | 14 | |
Marcomissyou | 0:25ffe5869e35 | 15 | |
Marcomissyou | 0:25ffe5869e35 | 16 | int main(void) |
Marcomissyou | 3:65c5fce3a471 | 17 | { |
gordonlu | 11:0d4c4bc2274a | 18 | |
Marcomissyou | 0:25ffe5869e35 | 19 | EthernetInterface eth; |
Marcomissyou | 0:25ffe5869e35 | 20 | eth.init(); //Use DHCP |
Marcomissyou | 3:65c5fce3a471 | 21 | wait(1); |
gordonlu | 11:0d4c4bc2274a | 22 | printf( "Hello World, NNN40_WiFi\n"); |
Marcomissyou | 3:65c5fce3a471 | 23 | // set given SSID and PW as the highest priority |
gordonlu | 10:fff1a8a4b003 | 24 | //wifi.setNetwork("KORYO-Guest", "koryo123", 0); |
gordonlu | 11:0d4c4bc2274a | 25 | wifi.setNetwork("Airport123", "12345678", 0); |
Marcomissyou | 3:65c5fce3a471 | 26 | wait(1); |
gordonlu | 10:fff1a8a4b003 | 27 | |
Marcomissyou | 0:25ffe5869e35 | 28 | eth.connect(40000); |
gordonlu | 11:0d4c4bc2274a | 29 | printf("****IP Address:%s\n",eth.getIPAddress()); |
gordonlu | 11:0d4c4bc2274a | 30 | printf("****MAC Address:%s\n",eth.getMACAddress()); |
Marcomissyou | 3:65c5fce3a471 | 31 | |
gordonlu | 11:0d4c4bc2274a | 32 | |
gordonlu | 11:0d4c4bc2274a | 33 | |
gordonlu | 11:0d4c4bc2274a | 34 | TCPSocketConnection socket1; |
gordonlu | 11:0d4c4bc2274a | 35 | printf("Connect to %s:%d\n",PC_SERVER_ADDRESS_1,PC_PORT); |
gordonlu | 10:fff1a8a4b003 | 36 | if(0 == socket1.connect(PC_SERVER_ADDRESS_1,PC_PORT)) |
gordonlu | 10:fff1a8a4b003 | 37 | { |
gordonlu | 11:0d4c4bc2274a | 38 | LED01 = 1; |
gordonlu | 11:0d4c4bc2274a | 39 | printf("****socket1 connect ok!!!\n"); |
gordonlu | 10:fff1a8a4b003 | 40 | } |
gordonlu | 10:fff1a8a4b003 | 41 | else |
gordonlu | 10:fff1a8a4b003 | 42 | { |
gordonlu | 11:0d4c4bc2274a | 43 | printf("****socket connect1 failed !!\n"); |
gordonlu | 10:fff1a8a4b003 | 44 | } |
gordonlu | 10:fff1a8a4b003 | 45 | |
gordonlu | 11:0d4c4bc2274a | 46 | TCPSocketConnection socket2; |
gordonlu | 11:0d4c4bc2274a | 47 | printf("Connect to %s:%d\n",PC_SERVER_ADDRESS_2,PC_PORT); |
gordonlu | 10:fff1a8a4b003 | 48 | if(0 == socket2.connect(PC_SERVER_ADDRESS_2,PC_PORT)) |
gordonlu | 10:fff1a8a4b003 | 49 | { |
gordonlu | 10:fff1a8a4b003 | 50 | |
gordonlu | 10:fff1a8a4b003 | 51 | LED02 = 1; |
gordonlu | 11:0d4c4bc2274a | 52 | printf("****socket2 connect ok!!!\n"); |
gordonlu | 10:fff1a8a4b003 | 53 | } |
gordonlu | 10:fff1a8a4b003 | 54 | else |
gordonlu | 10:fff1a8a4b003 | 55 | { |
gordonlu | 11:0d4c4bc2274a | 56 | printf("****socke2 connect failed !!\n"); |
gordonlu | 10:fff1a8a4b003 | 57 | } |
gordonlu | 10:fff1a8a4b003 | 58 | |
Marcomissyou | 0:25ffe5869e35 | 59 | char msg[] = "Hello World"; |
gordonlu | 10:fff1a8a4b003 | 60 | char buf[1024]; |
gordonlu | 11:0d4c4bc2274a | 61 | |
gordonlu | 10:fff1a8a4b003 | 62 | int i = 1; |
gordonlu | 10:fff1a8a4b003 | 63 | while(1) |
gordonlu | 10:fff1a8a4b003 | 64 | { |
gordonlu | 10:fff1a8a4b003 | 65 | wait(1); |
gordonlu | 10:fff1a8a4b003 | 66 | int j = sprintf(buf, "Hello World : %d\n",i); |
gordonlu | 11:0d4c4bc2274a | 67 | printf("******************Send Message : %d \n", i++); |
gordonlu | 10:fff1a8a4b003 | 68 | socket1.send(buf, j); |
gordonlu | 10:fff1a8a4b003 | 69 | socket2.send(buf, j); |
gordonlu | 10:fff1a8a4b003 | 70 | |
gordonlu | 10:fff1a8a4b003 | 71 | if(i%2 == 0 ) LED02 = 1; |
gordonlu | 10:fff1a8a4b003 | 72 | else LED02 = 0; |
gordonlu | 10:fff1a8a4b003 | 73 | } |
gordonlu | 11:0d4c4bc2274a | 74 | printf("****socket close \n"); |
gordonlu | 11:0d4c4bc2274a | 75 | //socket1.close(); |
gordonlu | 10:fff1a8a4b003 | 76 | //socket2.close(); |
Marcomissyou | 0:25ffe5869e35 | 77 | eth.disconnect(); |
Marcomissyou | 0:25ffe5869e35 | 78 | wifi.sleep(); |
gordonlu | 10:fff1a8a4b003 | 79 | |
Marcomissyou | 0:25ffe5869e35 | 80 | } |