Nikita Kakurnikov
/
UDPNode
1
Diff: main.cpp
- Revision:
- 3:24f12bc2b76d
- Parent:
- 2:f149c178dd58
- Child:
- 4:e584e034f9e1
--- a/main.cpp Wed Jun 27 10:33:32 2018 +0000 +++ b/main.cpp Mon Jul 02 09:17:05 2018 +0000 @@ -2,8 +2,8 @@ #include <string> #include "ESP8266.h" -int localOutPort = 3001; -int localInPort = 3002; +int localOutPort = 49100; +int localInPort = 49101; Serial console(USBTX,USBRX); ESP8266 wifi(PF_7,PF_6,localOutPort,localInPort); @@ -14,7 +14,7 @@ Thread listeningThread; void onReceive(void); -void processReceivedData(string); +void processReceivedData(string, char*, int); int main() { console.baud(9600); @@ -22,7 +22,7 @@ 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); + // wifi.send("privetFromESP8266",17,"192.168.0.103",8000); listeningThread.start(onReceive); } @@ -43,11 +43,14 @@ buf += buffer[i]; } console.printf("Data: %s\n",buf); - processReceivedData(buf); + processReceivedData(buf,IP,port); } } } -void processReceivedData(string data) { - +void processReceivedData(string data, char* IP, int port) { + if (port == localOutPort) { + string msg = "?HiClientImARobotClapeyron|hardvers|0.1?"; + if (data == "HiRobotClapeyronImAClient") wifi.send(msg.c_str(),msg.length(),IP,localInPort); + } } \ No newline at end of file