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.
main.cpp
- Committer:
- nikitoslav
- Date:
- 2018-06-27
- Revision:
- 2:f149c178dd58
- Parent:
- 1:60fc2072f184
- Child:
- 3:24f12bc2b76d
File content as of revision 2:f149c178dd58:
#include "mbed.h" #include <string> #include "ESP8266.h" int localOutPort = 3001; int localInPort = 3002; Serial console(USBTX,USBRX); ESP8266 wifi(PF_7,PF_6,localOutPort,localInPort); const char* ap = "Clapeyron_Industries"; const char* passPhrase = "06737184"; Thread listeningThread; void onReceive(void); void processReceivedData(string); int main() { console.baud(9600); if (wifi.startup(1) && wifi.connect(ap,passPhrase)) console.printf("Your IP is: %s\n",wifi.getIPAddress()); else console.printf("Can not connect to the Wi-Fi router\n"); wifi.send("privetFromESP8266",17,"192.168.0.103",8000); listeningThread.start(onReceive); } void onReceive(void) { const int maxSize = 100; char buffer[100]; string buf = ""; char IP[16]; int port; int bytes; while(1) { buf = ""; bytes = wifi.recv(&buffer,maxSize,IP,&port); if (bytes != -1) { console.printf("Bytes received: %d; from %s:%d\n",bytes,IP,port); for(int i = 0; i < bytes; i++) { buf += buffer[i]; } console.printf("Data: %s\n",buf); processReceivedData(buf); } } } void processReceivedData(string data) { }