jah

Dependencies:   ESP8266 mbed

Files at this revision

API Documentation at this revision

Comitter:
2016US_AhmedPopovic
Date:
Mon May 16 20:44:32 2016 +0000
Commit message:
jah

Changed in this revision

ESP8266.lib Show annotated file Show diff for this revision Revisions of this file
WiFi.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 510ec65bf38b ESP8266.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ESP8266.lib	Mon May 16 20:44:32 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/quevedo/code/ESP8266/#77388e8f0697
diff -r 000000000000 -r 510ec65bf38b WiFi.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WiFi.h	Mon May 16 20:44:32 2016 +0000
@@ -0,0 +1,87 @@
+#include "ESP8266.h"
+#include <string>
+
+using namespace std;
+
+class WiFi
+{
+private:
+    char rcv[2048];
+    char snd[255];
+    ESP8266 * esp;
+    Serial * pc;
+    
+public:
+    WiFi(char * ssid, char * pw, Serial * pc)
+    {
+        this->pc = pc;
+        this->pc->baud(115200);
+        esp = new ESP8266(PTE0, PTE1, 115200);
+        
+        SetupModule();
+        ConnectToWifi(ssid, pw);
+    }
+    
+    string GetPage(string ip, string page)
+    {
+        strcpy(snd, "AT+CIPSTART=0,\"TCP\",\"173.236.171.131\",80");
+        esp->SendCMD(snd);
+        esp->RcvReply(rcv, 400);
+        pc->printf("%s", rcv);
+        
+        wait(2);
+        strcpy(snd, "AT+CIPSEND=0,39");
+        esp->SendCMD(snd);
+        esp->RcvReply(rcv, 2048);
+        pc->printf("%s", rcv);
+        wait(2);
+        
+        strcpy(snd, "GET / HTTP/1.1\r\nHost: liliumdev.com\r\n\r\n");
+        esp->SendCMD(snd);
+        while(true)
+        {
+            esp->RcvReply(rcv, 2048);
+            pc->printf("%s", rcv);   
+        }
+    }        
+        
+    bool SetupModule()
+    {
+        wait(3);    
+        pc->printf("Sending AT\r\n");
+        strcpy(snd, "AT");
+        esp->SendCMD(snd);
+        esp->RcvReply(rcv, 400);
+        pc->printf("%s", rcv);
+        wait(2);
+        pc->printf("Set mode to STA\r\n");
+        esp->SetMode(1);
+        esp->RcvReply(rcv, 1000);
+        pc->printf("%s", rcv);
+        
+        strcpy(snd, "AT+CIPMUX=1");
+        esp->SendCMD(snd);
+        esp->RcvReply(rcv, 400);
+        
+        return true;
+    }
+    
+    bool ConnectToWifi(char * ssid, char * pw)
+    {
+        pc->printf("Receiving Wifi List\r\n");
+        esp->GetList(rcv);
+        pc->printf("%s", rcv);
+        
+        pc->printf("Connecting to AP\r\n");
+        esp->Join(ssid, pw);
+        esp->RcvReply(rcv, 1000);
+        pc->printf("%s", rcv);
+        wait(8);
+        pc->printf("Getting IP\r\n");
+        esp->GetIP(rcv);
+        
+        pc->printf("%s", rcv);
+        
+        return true;
+    }
+};
\ No newline at end of file
diff -r 000000000000 -r 510ec65bf38b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 16 20:44:32 2016 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+#include "WiFi.h"
+
+Serial pc(USBTX, USBRX);
+ 
+int main() {
+    pc.baud(115200);
+    wait(3);
+    
+    pc.printf("START\r\n");
+    
+    WiFi wifi("LAB-2-13", "", &pc);
+    wifi.GetPage("","");
+            
+  /*  strcpy(snd, "AT+CIPMUX=1");
+    esp.SendCMD(snd);
+    esp.RcvReply(rcv, 400);
+    pc.printf("%s", rcv);
+    
+    
+    strcpy(snd, "AT+CIPSTART=0,\"TCP\",\"80.65.65.71\",80");
+    esp.SendCMD(snd);
+    esp.RcvReply(rcv, 400);
+    pc.printf("%s", rcv);
+    
+    wait(2);
+    strcpy(snd, "AT+CIPSEND=0,18");
+    esp.SendCMD(snd);
+    esp.RcvReply(rcv, 400);
+    pc.printf("%s", rcv);
+    wait(2);
+    
+    strcpy(snd, "GET / HTTP/1.1\r\n\r\n");
+    esp.SendCMD(snd);
+    while(true)
+    {
+        
+        esp.RcvReply(rcv, 400);
+        pc.printf("%s", rcv);   
+        /*wait(2); 
+        esp.RcvReply(rcv, 400);
+        pc.printf("%s", rcv);
+    }
+    */
+    
+    
+    while(1);
+}
diff -r 000000000000 -r 510ec65bf38b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 16 20:44:32 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file