Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 5:dfea6fd1abba, committed 2020-07-21
- Comitter:
- faker_71
- Date:
- Tue Jul 21 06:42:34 2020 +0000
- Parent:
- 4:40dd020463ea
- Commit message:
- wifi
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Aug 28 01:37:50 2015 +0000
+++ b/main.cpp Tue Jul 21 06:42:34 2020 +0000
@@ -19,6 +19,10 @@
DigitalOut Out3(p8);
DigitalOut reset(p26);
+
+DigitalOut ledR(p17);
+DigitalOut ledG(p16);
+
DigitalIn In1(p9);
DigitalIn In2(p10);
DigitalIn In3(p11);
@@ -47,8 +51,13 @@
char channel[2];
char cmdbuff[32];
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 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 webdata[4096]; // This may need to be bigger depending on WEB browser used
+char webbuff[4096*4]; // Currently using 1986 characters, Increase this if more web page data added
+
void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck();
void gettime(),gettemp(),getbattery(),setRTC(),beep();
@@ -66,12 +75,14 @@
// Serial Interrupt read ESP data
void callback()
{
+ //pc.printf("\n\r------------ callback is being called --------------\n\r");
led3=1;
while (esp.readable()) {
webbuff[count] = esp.getc();
count++;
}
if(strlen(webbuff)>bufflen) {
+ pc.printf("\f\n\r------------ webbuff over bufflen --------------\n\r");
DataRX=1;
led3=0;
}
@@ -82,7 +93,7 @@
reset=0;
pc.baud(115200);
- pc.printf("\f\n\r------------ ESP8266 Hardware Reset --------------\n\r");
+ pc.printf("\f\n\r------------ ESP8266 Hardware Reset psq --------------\n\r");
wait(0.5);
reset=1;
led1=1,led2=0,led3=0;
@@ -95,12 +106,15 @@
}
beep();
startserver();
-
+
while(1) {
if(DataRX==1) {
+ pc.printf("\f\n\r------------ main while > if --------------\n\r");
+
ReadWebData();
beep();
if (servreq == 1 && weberror == 0) {
+ pc.printf("\f\n\r------------ befor send page --------------\n\r");
sendpage();
}
esp.attach(&callback);
@@ -121,81 +135,81 @@
gettime();
// WEB page data
- strcpy(webbuff, "<!DOCTYPE html>");
- strcat(webbuff, "<html><head><title>ESP8266 Mbed LPC1768</title></head>");
- strcat(webbuff, "<body>");
- strcat(webbuff, "<div style=\"text-align:center; background-color:#F4F4F4; color:#00AEDB;\"><h1>ESP8266 Mbed IoT Web Controller</h1>");
- strcat(webbuff, "Hit Count - ");
- strcat(webbuff, webcount);
- strcat(webbuff, "<br>Last Hit - ");
- strcat(webbuff, lasthit);
- strcat(webbuff, "</div><br /><hr>");
- strcat(webbuff, "<h3>Mbed RTC Time -  ");
- strcat(webbuff, timebuf);
- strcat(webbuff, "</h3>\r\n");
- strcat(webbuff, "<p><form method=\"POST\"><strong> Analog 1:  <input type=\"text\" size=6 value=\"");
- strcat(webbuff, Temp);
- strcat(webbuff, "\"> </sup>V <form method=\"POST\"> <strong>   Analog 2:  <input type=\"text\" size=4 value=\"");
- strcat(webbuff, Vcc);
- strcat(webbuff, "\"> </sup>V");
- if(led1==0) {
- strcat(webbuff, "<p><input type=\"radio\" name=\"led1\" value=\"0\" checked> LED 1 off");
- strcat(webbuff, "<br><input type=\"radio\" name=\"led1\" value=\"1\" > LED 1 on");
- } else {
- strcat(webbuff, "<p><input type=\"radio\" name=\"led1\" value=\"0\" > LED 1 off");
- strcat(webbuff, "<br><input type=\"radio\" name=\"led1\" value=\"1\" checked> LED 1 on");
- }
- if(Out1==0) {
- strcat(webbuff, "<p><input type=\"radio\" name=\"Out1\" value=\"0\" checked> Digital Out 1 off");
- strcat(webbuff, "<br><input type=\"radio\" name=\"Out1\" value=\"1\" > Digital Out 1 on");
- } else {
- 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);");
- strcat(webbuff, "-webkit-border-radius:12;border-radius: 12px;font-family: Arial;color:#ffffff;font-size:20px;padding:");
- strcat(webbuff, "10px 20px 10px 20px; border:solid #103c57 3px;text-decoration: none;");
- strcat(webbuff, "background: #3cb0fd;");
- strcat(webbuff, "background-image:-webkit-linear-gradient(top,#3cb0fd,#1a5f8a);");
- strcat(webbuff, "background-image:linear-gradient(to bottom,#3cb0fd,#1a5f8a);");
- strcat(webbuff, "text-decoration:none;\"></form></span>");
- strcat(webbuff, "<p/><h2>How to use:</h2><ul>");
- strcat(webbuff, "<li>Select the Radio buttons to control the digital out pins.</li>");
- strcat(webbuff, "<li>Click 'Send-Refresh' to send.</li>");
- strcat(webbuff, "<li>Use the 'Send-Refresh' button to refresh the data.</li>");
- strcat(webbuff, "</ul>");
- strcat(webbuff, "</body></html>");
+
+strcpy(webbuff, "<!DOCTYPE html>");
+strcat(webbuff, "<html><head><title>RobotCar</title><meta name='viewport' content='width=device-width'/>");
+strcat(webbuff, "</head><body><center><p><strong>Robot Car Remot Controller");
+strcat(webbuff, "</strong></p><td style='vertical-align:top;'><strong>Battery level ");
+strcat(webbuff, "<input type=\"text\" id=\"leftms\" size=4 value=250>%</strong>");
+strcat(webbuff, "</td></p><tr ><strong>Now speed : </strong></tr><nobr id=\"speprint\">ready");
+strcat(webbuff, "</nobr><br><tr ><strong>Now action : </strong></tr>");
+strcat(webbuff, "<nobr id=\"funprint\">ready</nobr><table><tr><td></td><td>");
+
+strcat(webbuff, "<button id='gobtn' type='button' style='width:100px;height:60px' value=\"GO\" onClick='send_mes(this.id,this.value)'>GO");
+strcat(webbuff, "</button></td><td></td></tr><tr><td>");
+strcat(webbuff, "<button id='leftbtn' type='button' style='width:100px;height:60px' value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT");
+strcat(webbuff, "</button></td><td>");
+strcat(webbuff, "<button id='stopbtn' type='button' style='width:100px;height:60px' value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP");
+strcat(webbuff, "</button></td><td>");
+strcat(webbuff, "<button id='rightbtn' type='button' style='width:100px;height:60px' value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT");
+strcat(webbuff, "</button></td></tr><td></td><td>");
+strcat(webbuff, "<button id='backbtn' type='button' style='width:100px;height:60px' value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK");
+strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>");
+/*
+strcat(webbuff, "<strong>Addition functions:</strong><table>");
+strcat(webbuff, "<td>");//ok
+
+strcat(webbuff, "<button id='avoidbtn' type='button' style='width:100px;height:60px' value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >");
+
+strcat(webbuff, "AVOIDANCE</button></td><td>");
+strcat(webbuff, "<button id='tracebtn' type='button' style='width:100px;height:60px' value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE");
+strcat(webbuff, "</button></td><td>");
+strcat(webbuff, "<button id='defbtn' type='button' style='width:100px;height:60px' value=\"DEFAULT\" onClick='send_mes_fun(this.id,this.value)' >DEFAULT");
+strcat(webbuff, "</button></td></table><table><td>");
+strcat(webbuff, "</td><strong>Speed level:</strong>");
+strcat(webbuff, "</table><td>");
+strcat(webbuff, "<button id='sp1btn' type='button' style='width:100px;height:60px' value=\"SLOW\" onClick='send_mes_spe(this.id,this.value)' >SLOW");
+strcat(webbuff, "</button></td><td>");
+strcat(webbuff, "<button id='sp2btn' type='button' style='width:100px;height:60px' value=\"FAST\" onClick='send_mes_spe(this.id,this.value)' >FAST");
+strcat(webbuff, "</button>");
+strcat(webbuff, "</td>");
+strcat(webbuff, "<td>");
+strcat(webbuff, "<button id='sp3btn' type='button' style='width:100px;height:60px' value=\"FLY\" onClick='send_mes_spe(this.id,this.value)' >FLY");
+strcat(webbuff, "</button>");
+strcat(webbuff, "</td>");
+strcat(webbuff, "<table>");
+strcat(webbuff, "<td>");
+strcat(webbuff, "</td>");
+strcat(webbuff, "</table>"); */
+strcat(webbuff, "</center>");
+
+strcat(webbuff, "</body>");
+strcat(webbuff, "</html>");
+
+strcat(webbuff, "<script language=\"javascript\" type=\"text/javascript\">");
+strcat(webbuff, "function send_mes(btnmes,btnval){");
+strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;");
+strcat(webbuff, "htmlacs(url);");
+strcat(webbuff, "console.log(url);");
+strcat(webbuff, "}");
+strcat(webbuff, "function htmlacs(url) {");
+strcat(webbuff, "var xhr = new XMLHttpRequest();");
+strcat(webbuff, "xhr.open(\"GET\", url);");
+strcat(webbuff, "xhr.send(\"\");");
+strcat(webbuff, "}");
+strcat(webbuff, "function send_mes_spe(btnmes,btnval){");
+strcat(webbuff, "console.log(btnmes);");
+strcat(webbuff, "if(document.getElementById(\"speprint\")){");
+strcat(webbuff, "document.getElementById(\"speprint\").innerHTML=btnval;");
+strcat(webbuff, "}");
+strcat(webbuff, "}");
+strcat(webbuff, "function send_mes_fun(btnmes,btnval){");
+strcat(webbuff, "console.log(btnmes);");
+strcat(webbuff, "if(document.getElementById(\"funprint\")){");
+strcat(webbuff, "document.getElementById(\"funprint\").innerHTML=btnval;");
+strcat(webbuff, "}");
+strcat(webbuff, "}");
+strcat(webbuff, "</script>");
// end of WEB page data
bufl = strlen(webbuff); // get total page buffer length
sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length.
@@ -203,6 +217,7 @@
getcount=7;
SendCMD();
getreply();
+ pc.printf("\n++++++++++ bufl is %d ++++++++++\r\n",bufl);
SendWEB(); // send web page
memset(webbuff, '\0', sizeof(webbuff));
sendcheck();
@@ -258,6 +273,28 @@
strcpy(webdata, webbuff + x);
weberror=0;
int numMatched = sscanf(webdata,"+IPD,%d,%d:%s", &linkID, &ipdLen, type);
+ int i=0;
+ pc.printf("+++++++++++++++++succed+++++++++++++++++++++");
+ pc.printf("%s",webdata);
+
+
+
+ if( strstr(webdata, "LEFT") != NULL ) {
+ ledR=!ledR;
+
+ }
+
+ if( strstr(webdata, "RIGHT") != NULL ) {
+ ledG=!ledG;
+
+ }
+ pc.printf("+++++++++++++++++succed+++++++++++++++++++++");
+
+
+ if( strstr(webdata, "sp3btn=0") != NULL ) {
+ led1=!led1;
+
+ }
if( strstr(webdata, "led1=1") != NULL ) {
led1=1;
}
@@ -376,8 +413,10 @@
while(webbuff[i]!='\0') {
esp.putc(webbuff[i]);
i++;
+ pc.printf("%s",webbuff[i]);
}
}
+ pc.printf("\n++++++++++ send web info ++++++++++\r\n");
}
// Get Command and ESP status replies
void getreply()