wui0iuytdsaertyuio

Dependencies:   mbed

Fork of ESP8266-WEB-Mbed-LPC1768-Controller by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
biswajit007
Date:
Thu Jun 14 10:24:07 2018 +0000
Parent:
4:40dd020463ea
Commit message:
wert8

Changed in this revision

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 40dd020463ea -r 3d29774cc3e2 main.cpp
--- a/main.cpp	Fri Aug 28 01:37:50 2015 +0000
+++ b/main.cpp	Thu Jun 14 10:24:07 2018 +0000
@@ -4,7 +4,7 @@
 //#include "DS18B20.h"
 
 Serial pc(USBTX, USBRX);
-Serial esp(p28, p27); // tx, rx
+Serial esp(PA_13, PA_14); // tx, rx
 
 //DS18B20 thermom(A0, DS18B20::RES_12_BIT);
 
@@ -14,18 +14,7 @@
 DigitalOut  led3(LED3);     // (PTD1)
 
 // Digital Out and In pins, can be configured to any suitable pin depending on Platform
-DigitalOut  Out1(p6);
-DigitalOut  Out2(p7);
-DigitalOut  Out3(p8);
-DigitalOut  reset(p26);
-
-DigitalIn  In1(p9);
-DigitalIn  In2(p10);
-DigitalIn  In3(p11);
-
-PwmOut speaker(p21);
-AnalogIn   Ain1(p18);
-AnalogIn   Ain2(p19);
+DigitalOut  Out1(D13);
 
 Timer t1;
 Timer t2;
@@ -49,9 +38,10 @@
 char replybuff[1024];
 char webdata[1024]; // This may need to be bigger depending on WEB browser used
 char webbuff[4096];     // Currently using 1986 characters, Increase this if more web page data added
-
+char ssid[32] = "cdi_WIFI";     // enter WiFi router ssid inside the quotes
+char pwd [32] = "cdilab@7"; // enter WiFi router password inside the quotes
 void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck();
-void gettime(),gettemp(),getbattery(),setRTC(),beep();
+
 
 // manual set RTC values
 int minute      =00;    // 0-59
@@ -79,27 +69,24 @@
 
 int main()
 {
-    reset=0;
-    pc.baud(115200);
+   // reset=0;
+    pc.baud(9600);
 
     pc.printf("\f\n\r------------ ESP8266 Hardware Reset --------------\n\r");
     wait(0.5);
-    reset=1;
+    //reset=1;
     led1=1,led2=0,led3=0;
     timeout=6000;
     getcount=500;
     getreply();
-    esp.baud(115200);   // ESP8266 baudrate. Maximum on KLxx' is 115200, 230400 works on K20 and K22F
-    if (time(NULL) < 1420070400) {
-        setRTC();
-    }
-    beep();
+    esp.baud(9600);   // ESP8266 baudrate. Maximum on KLxx' is 115200, 230400 works on K20 and K22F
+    
     startserver();
 
     while(1) {
         if(DataRX==1) {
             ReadWebData();
-            beep();
+         
             if (servreq == 1 && weberror == 0) {
                 sendpage();
             }
@@ -116,9 +103,7 @@
 // Static WEB page
 void sendpage()
 {
-    gettemp();
-    getbattery();
-    gettime();
+    
 
 // WEB page data
     strcpy(webbuff, "<!DOCTYPE html>");
@@ -152,35 +137,7 @@
         strcat(webbuff, "<p><input type=\"radio\" name=\"Out1\" value=\"0\" >  Digital Out 1 off");
         strcat(webbuff, "<br><input type=\"radio\" name=\"Out1\" value=\"1\" checked>  Digital Out 1 on");
     }
-    if(Out2==0) {
-        strcat(webbuff, "<p><input type=\"radio\" name=\"Out2\" value=\"0\" checked>  Digital Out 2 off");
-        strcat(webbuff, "<br><input type=\"radio\" name=\"Out2\" value=\"1\" >  Digital Out 2 on");
-    } else {
-        strcat(webbuff, "<p><input type=\"radio\" name=\"Out2\" value=\"0\" >  Digital Out 2 off");
-        strcat(webbuff, "<br><input type=\"radio\" name=\"Out2\" value=\"1\" checked>  Digital Out 2 on");
-    }
-    if(Out3==0) {
-        strcat(webbuff, "<p><input type=\"radio\" name=\"Out3\" value=\"0\" checked>  Digital Out 3 off");
-        strcat(webbuff, "<br><input type=\"radio\" name=\"Out3\" value=\"1\" >  Digital Out 3 on");
-    } else {
-        strcat(webbuff, "<p><input type=\"radio\" name=\"Out3\" value=\"0\" >  Digital Out 3 off");
-        strcat(webbuff, "<br><input type=\"radio\" name=\"Out3\" value=\"1\" checked>  Digital Out 3 on");
-    }
-    if(In1==0) {
-        strcat(webbuff, "<p><input type=\"radio\" name=\"In1\" value=\"0\" >  Digital In 1");
-    } else {
-        strcat(webbuff, "<p><input type=\"radio\" name=\"In1\" value=\"1\" checked>  Digital In 1");
-    }
-    if(In2==0) {
-        strcat(webbuff, "<br><input type=\"radio\" name=\"In2\" value=\"0\" >  Digital In 2");
-    } else {
-        strcat(webbuff, "<br><input type=\"radio\" name=\"In2\" value=\"1\" checked>  Digital In 2");
-    }
-    if(In3==0) {
-        strcat(webbuff, "<br><input type=\"radio\" name=\"In3\" value=\"0\" >  Digital In 3");
-    } else {
-        strcat(webbuff, "<br><input type=\"radio\" name=\"In3\" value=\"1\" checked>  Digital In 3");
-    }
+   
     strcat(webbuff, "</strong><p><input type=\"submit\" value=\"send-refresh\" style=\"background: #3498db;");
     strcat(webbuff, "background-image:-webkit-linear-gradient(top, #3498db, #2980b9);");
     strcat(webbuff, "background-image:linear-gradient(to bottom, #3498db, #2980b9);");
@@ -270,18 +227,7 @@
         if( strstr(webdata, "Out1=0") != NULL ) {
             Out1=0;
         }
-        if( strstr(webdata, "Out2=1") != NULL ) {
-            Out2=1;
-        }
-        if( strstr(webdata, "Out2=0") != NULL ) {
-            Out2=0;
-        }
-        if( strstr(webdata, "Out3=1") != NULL ) {
-            Out3=1;
-        }
-        if( strstr(webdata, "Out3=0") != NULL ) {
-            Out3=0;
-        }
+       
         sprintf(channel, "%d",linkID);
         if (strstr(webdata, "GET") != NULL) {
             servreq=1;
@@ -300,8 +246,7 @@
 // Starts and restarts webserver if errors detected.
 void startserver()
 {
-    gettemp();
-    gettime();
+    
     pc.printf("\n\n RTC time   %s\r\n\n",timebuf);
     pc.printf("++++++++++ Resetting ESP ++++++++++\r\n");
     strcpy(cmdbuff,"AT+RST\r\n");
@@ -319,6 +264,28 @@
         SendCMD();
         getreply();
         pc.printf(replybuff);
+         pc.printf("\n---------- Setting Mode ----------\r\n");
+    strcpy(cmdbuff, "AT+CWMODE=2\r\n");
+    SendCMD();
+    timeout=4;
+    getreply();
+    pc.printf(replybuff);
+
+    wait(2);
+    pc.printf("\n---------- Setting Connection Mode ----------\r\n");
+  strcpy(cmdbuff, "AT+CWSAP=\"");
+    strcat(cmdbuff, ssid);
+    strcat(cmdbuff, "\",\"");
+    strcat(cmdbuff, pwd);
+    strcat(cmdbuff, "\",5,");
+    strcat(cmdbuff, "3\r\n");
+  //  strcat(snd, "\"");
+    SendCMD();
+    timeout=10;
+    getreply();
+    pc.printf(replybuff);
+    
+    wait(2);
         sprintf(cmdbuff,"AT+CIPSERVER=1,%d\r\n", port);
         timeout=500;
         getcount=20;
@@ -361,7 +328,7 @@
     }
     t2.reset();
     t2.start();
-    beep();
+   
 }
 // ESP Command data send
 void SendCMD()
@@ -395,34 +362,8 @@
     t1.stop();
 }
 // Analog in example
-void getbattery()
-{
-    AdcIn=Ain1.read();
-    Ht = (AdcIn*3.3); // set the numeric to the exact MCU analog reference voltage for greater accuracy
-    sprintf(Vcc,"%2.3f",Ht);
-}
-// Temperature example
-void gettemp()
-{
- 
-    AdcIn=Ain2.read();
-    Ht = (AdcIn*3.3); // set the numeric to the exact MCU analog reference voltage for greater accuracy  
-    sprintf(Temp,"%2.3f",Ht);
-}
-// Get RTC time
-void gettime()
-{
-    time_t seconds = time(NULL);
-    strftime(timebuf,50,"%H:%M:%S %a %d %b %y", localtime(&seconds));
-}
 
-void beep()
-{
-    speaker.period(1.0/2000); // 2000hz period
-    speaker = 0.5; //50% duty cycle - max volume
-    wait_ms(60);
-    speaker=0.0; // turn off audio
-}
+    
 
 void setRTC()
 {
diff -r 40dd020463ea -r 3d29774cc3e2 mbed.bld
--- a/mbed.bld	Fri Aug 28 01:37:50 2015 +0000
+++ b/mbed.bld	Thu Jun 14 10:24:07 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/093f2bd7b9eb
\ No newline at end of file