1

Dependencies:   ESP8266

Revision:
2:f149c178dd58
Parent:
1:60fc2072f184
Child:
3:24f12bc2b76d
--- a/main.cpp	Wed Jun 27 07:17:23 2018 +0000
+++ b/main.cpp	Wed Jun 27 10:33:32 2018 +0000
@@ -2,21 +2,22 @@
 #include <string>
 #include "ESP8266.h"
 
-Serial console(USBTX,USBRX);
-ESP8266 wifi(PF_7,PF_6);
-
 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);
+    console.baud(9600);    
     if (wifi.startup(1) && wifi.connect(ap,passPhrase))
         console.printf("Your IP is: %s\n",wifi.getIPAddress());
     else
@@ -26,18 +27,27 @@
 }
 
 void onReceive(void) {
+    const int maxSize = 100;
+    
     char buffer[100];
+    string buf = "";
     char IP[16];
     int port;
     int bytes;
     while(1) {
-        bytes = wifi.recv(&buffer,100,IP,&port);
+        buf = "";
+        bytes = wifi.recv(&buffer,maxSize,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");
+            for(int i = 0; i < bytes; i++) {
+                buf += buffer[i];
+            }
+            console.printf("Data: %s\n",buf);
+            processReceivedData(buf);
         }
     }
+}
+
+void processReceivedData(string data) {
+    
 }
\ No newline at end of file