1

Dependencies:   ESP8266

Revision:
1:60fc2072f184
Parent:
0:bed9e78dd09c
Child:
2:f149c178dd58
--- a/main.cpp	Wed Jun 27 06:51:02 2018 +0000
+++ b/main.cpp	Wed Jun 27 07:17:23 2018 +0000
@@ -1,19 +1,43 @@
 #include "mbed.h"
 #include <string>
-#include "ESP8266UDPNode.h"
+#include "ESP8266.h"
 
 Serial console(USBTX,USBRX);
-ESP8266UDPNode esp8266UDPNode(PF_7,PF_6);
+ESP8266 wifi(PF_7,PF_6);
+
+int localOutPort = 3001;
+int localInPort = 3002;
+
+const char* ap = "Clapeyron_Industries";
+const char* passPhrase = "06737184";
+
+Thread listeningThread;
+
+void onReceive(void);
 
 int main() {
     console.baud(9600);
-    console.printf("Hello\n");
-    if (esp8266UDPNode.getOnline("Clapeyron_Industries","06737184")) {
-        char* ch = esp8266UDPNode.getIPAddress();
-        console.printf("Your IP is: %c\n",ch[0]);
-        console.printf("Your IP is: %s\n",ch);
-    }
+    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");
-    esp8266UDPNode.send("privetFromESP8266",17,"192.168.0.103",8000);
+    wifi.send("privetFromESP8266",17,"192.168.0.103",8000);
+    listeningThread.start(onReceive);
+}
+
+void onReceive(void) {
+    char buffer[100];
+    char IP[16];
+    int port;
+    int bytes;
+    while(1) {
+        bytes = wifi.recv(&buffer,100,IP,&port);
+        if (bytes != -1) {
+            console.printf("Bytes received: %d; from %s:%d\n",bytes,IP,port);
+            console.printf("Data: ");
+            for(int i = 0; i < bytes; i++)
+                console.printf("%c",buffer[i]);
+            console.printf("\n");
+        }
+    }
 }
\ No newline at end of file