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: WIFI_API_32kRAM mbed
Fork of NNN40_WiFi by
main.cpp
00001 #include "mbed.h" 00002 #include "WIFIDevice.h" 00003 #include "EthernetInterface.h" 00004 00005 WIFIDevice wifi; 00006 00007 uint16_t ECHO_SERVER_PORT = 5222; 00008 00009 int main(void) 00010 { 00011 printf("NNN40 init...\n"); 00012 wifi.setAccessPoint("NNN40_TTWU", "0123456789", SECURITY_WPA2_TKIP_PSK, 2); 00013 EthernetInterface eth; 00014 eth.init(); 00015 wait(1); 00016 00017 eth.connect(40000); 00018 00019 printf("IP Address: %s\n",eth.getIPAddress()); 00020 printf("MAC Address: %s\n",eth.getMACAddress()); 00021 printf("Gateway Address: %s\n",eth.getGateway()); 00022 printf("Network Mask: %s\n",eth.getNetworkMask()); 00023 00024 TCPSocketServer server; 00025 server.bind(ECHO_SERVER_PORT); 00026 server.listen(); 00027 00028 while (true) { 00029 printf("\nWait for new connection...\n"); 00030 TCPSocketConnection client; 00031 server.accept(client); 00032 client.set_blocking(false, 5000); // Timeout after (5)s 00033 00034 printf("Connection from: %s\n", client.get_address()); 00035 char buffer[256]; 00036 while (true) { 00037 int n = client.receive(buffer, sizeof(buffer)); 00038 if (n <= 0) break; 00039 00040 // print received message to terminal 00041 buffer[n] = '\0'; 00042 printf("Received message from Client :'%s'\n",buffer); 00043 00044 // reverse the message 00045 char temp; 00046 for(int f = 0, l = n-1; f<l; f++,l--){ 00047 temp = buffer[f]; 00048 buffer[f] = buffer[l]; 00049 buffer[l] = temp; 00050 } 00051 00052 // print reversed message to terminal 00053 printf("Sending message to Client: '%s'\n",buffer); 00054 00055 // Echo received message back to client 00056 client.send_all(buffer, n); 00057 if (n <= 0) break; 00058 } 00059 00060 client.close(); 00061 } 00062 }
Generated on Thu Jul 14 2022 06:40:41 by
1.7.2
