Voor Arne

Fork of ESP8266Interface by ESP8266

Revision:
49:5a4798ccba07
Parent:
47:1f4dd0e91837
Child:
50:3727afa4c1b5
--- a/ESP8266/ESP8266.cpp	Mon Jun 08 21:32:12 2015 +0000
+++ b/ESP8266/ESP8266.cpp	Mon Dec 05 15:36:40 2016 +0000
@@ -18,7 +18,7 @@
 
 #include "mbed.h"
 #include "ESP8266.h"
-#include "Endpoint.h"
+
 #include <string>
 #include <algorithm>
 
@@ -42,6 +42,11 @@
 #define ESP_MAX_TRY_JOIN 3
 #define ESP_MAXID 4 // the largest possible ID Value (max num of sockets possible)
 
+
+DigitalOut led4(PTA14); // RGB LED
+DigitalOut led3(PTA13); // RGB LED
+RawSerial pc(USBTX, USBRX); // Serial interface
+
 ESP8266 * ESP8266::inst;
 char* ip = NULL;
 
@@ -80,15 +85,18 @@
     if( sendCommand( cmd.c_str(), "OK", NULL, 10000) ) {
         // successfully joined the network
         state.associated = true;
-        INFO("ssid: %s, phrase: %s", this->ssid, this->phrase);
+        pc.printf("connected");
+        //INFO("ssid: %s, phrase: %s", this->ssid, this->phrase);
         return true;
     }
+    pc.printf(" not connected");
     return false;
 }
 
 bool ESP8266::connect()
 {
-    sendCommand("AT+CWDHCP=1,1","OK",NULL,1000); // DHCP Enabled in Station Mode
+    pc.printf("connect");
+    //sendCommand("AT+CWDHCP=1,1","OK",NULL,1000); // DHCP Enabled in Station Mode
     return ESP8266::join();
 }
 
@@ -232,12 +240,18 @@
 */
 char* ESP8266::getIPAddress()
 {
+    pc.printf("getting ip\n");
     char result[30] = {0};
     int check = 0;
-    check = sendCommand("AT+CIFSR", NULL, result, 1000);
-    //pc.printf("\r\nReceivedInfo for IP Command is: %s\r\n",result);
-    ip = ipString;
-    if(check) {
+    check = sendCommand("AT", "OK", NULL, 1000);
+    pc.printf("\r\nReceivedInfo for IP Command is: %s\r\n",result);
+    
+    check = sendCommand("AT+CIFSR", NULL, result, 3000);
+    pc.printf("\r\nReceivedInfo for IP Command is: %s\r\n",result);    
+    
+    
+    //ip = ipString;
+ /*   if(check) {
         // Success
         string resultString(result);
         uint8_t pos1 = 0, pos2 = 0;
@@ -249,15 +263,15 @@
         //pos4 = resultString.find('"',pos3+1);
         strncpy(ipString,resultString.substr(pos1,pos2).c_str(),sizeof(ipString));
         ipString[pos2 - pos1 +1] = 0; // null terminate string correctly.
-        INFO("IP: %s",ipString);
+        pc.printf(ipString);
         ip = ipString;
 
     } else {
         // Failure
-        ERR("getIPAddress() failed");
+        pc.printf("getIPAddress() failed");
         ip = NULL;
     }
-    return ip;
+*/    return ip;
 }
 
 bool ESP8266::gethostbyname(const char * host, char * ip)
@@ -287,6 +301,7 @@
     reset_pin = 0;
     wait_us(20);
     reset_pin = 1;
+    led4 = 1;
     //wait(1);
     //reset_pin = !reset_pin
     //send("+++",3);
@@ -295,7 +310,7 @@
     sendCommand("AT", "OK", NULL, 1000);
     sendCommand("AT+RST", "ready", NULL, 10000);
     state.associated = false;
-
+    led4 =0;
 }
 
 bool ESP8266::reboot()
@@ -310,6 +325,7 @@
     char c;
     while (wifi.readable()) {
         c=wifi.getc();
+        //pc.putc(c);
         buf_ESP8266.queue(c);
         //if (state.cmdMode) pc.printf("%c",c); //debug echo, needs fast serial console to prevent UART overruns
     }
@@ -418,7 +434,7 @@
                 return -1;
             } else if (readable()) {
                 read = getc();
-                //printf("%c",read); //debug echo
+                pc.putc(read); //debug echo
                 if ( read != '\r' && read != '\n') {
                     checking += read;
                     found = checking.find(ACK);