real time wifi
Dependencies: RemoteIR TextLCD
main.cpp@2:1bf376317a43, 2020-08-25 (annotated)
- Committer:
- faker_71
- Date:
- Tue Aug 25 00:10:20 2020 +0000
- Revision:
- 2:1bf376317a43
- Parent:
- 1:a45cf46c1adc
- Child:
- 3:4c5c556c97a3
0825
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
faker_71 | 0:2e9a86765692 | 1 | #include "mbed.h" |
faker_71 | 0:2e9a86765692 | 2 | #include "ReceiverIR.h" |
faker_71 | 0:2e9a86765692 | 3 | #include "rtos.h" |
faker_71 | 0:2e9a86765692 | 4 | #include <stdint.h> |
faker_71 | 0:2e9a86765692 | 5 | #include "platform/mbed_thread.h" |
faker_71 | 0:2e9a86765692 | 6 | #include "TextLCD.h" |
faker_71 | 0:2e9a86765692 | 7 | RawSerial pc(USBTX, USBRX); |
faker_71 | 0:2e9a86765692 | 8 | //Serial esp(p28, p27); // tx, rx |
faker_71 | 0:2e9a86765692 | 9 | |
faker_71 | 0:2e9a86765692 | 10 | RawSerial esp(p13, p14); // tx, rx |
faker_71 | 0:2e9a86765692 | 11 | // Standard Mbed LED definitions |
faker_71 | 0:2e9a86765692 | 12 | DigitalOut led1(LED1); |
faker_71 | 0:2e9a86765692 | 13 | DigitalOut led2(LED2); |
faker_71 | 0:2e9a86765692 | 14 | DigitalOut led3(LED3); |
faker_71 | 0:2e9a86765692 | 15 | DigitalOut led4(LED4); |
faker_71 | 0:2e9a86765692 | 16 | |
faker_71 | 0:2e9a86765692 | 17 | Timer t1; |
faker_71 | 0:2e9a86765692 | 18 | Timer t2; |
faker_71 | 0:2e9a86765692 | 19 | |
faker_71 | 0:2e9a86765692 | 20 | struct tm t; |
faker_71 | 0:2e9a86765692 | 21 | |
faker_71 | 0:2e9a86765692 | 22 | |
faker_71 | 0:2e9a86765692 | 23 | int bufflen, DataRX, count_wifi, getcount, replycount, servreq, timeout; |
faker_71 | 0:2e9a86765692 | 24 | int bufl, ipdLen, linkID, weberror, webcounter,click_flag; |
faker_71 | 0:2e9a86765692 | 25 | float temperature, AdcIn, Ht; |
faker_71 | 0:2e9a86765692 | 26 | float R1=100000, R2=10000; // resistor values to give a 10:1 reduction of measured AnalogIn voltage |
faker_71 | 0:2e9a86765692 | 27 | char Vcc[10]; |
faker_71 | 0:2e9a86765692 | 28 | char webcount[8]; |
faker_71 | 0:2e9a86765692 | 29 | char type[16]; |
faker_71 | 0:2e9a86765692 | 30 | char type1[16]; |
faker_71 | 0:2e9a86765692 | 31 | char channel[2]; |
faker_71 | 0:2e9a86765692 | 32 | char cmdbuff[32]; |
faker_71 | 0:2e9a86765692 | 33 | char replybuff[1024]; |
faker_71 | 0:2e9a86765692 | 34 | |
faker_71 | 0:2e9a86765692 | 35 | char webdata[1024]; // This may need to be bigger depending on WEB browser used |
faker_71 | 0:2e9a86765692 | 36 | char webbuff[4096*4]; // Currently using 1986 characters, Increase this if more web page data added |
faker_71 | 0:2e9a86765692 | 37 | |
faker_71 | 0:2e9a86765692 | 38 | |
faker_71 | 2:1bf376317a43 | 39 | void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),sendpage2(),SendWEB(),sendcheck(),touchuan(); |
faker_71 | 0:2e9a86765692 | 40 | void wifi(void const *argument); |
faker_71 | 0:2e9a86765692 | 41 | |
faker_71 | 0:2e9a86765692 | 42 | Thread wifi_thread(wifi, NULL, osPriorityNormal); // decodeIRをスレッド化 :+3 |
faker_71 | 2:1bf376317a43 | 43 | int count_test=1; //test |
faker_71 | 2:1bf376317a43 | 44 | char battery_ch[8]; |
faker_71 | 0:2e9a86765692 | 45 | int port =80; // set server port |
faker_71 | 0:2e9a86765692 | 46 | int SERVtimeout =5; // set server timeout in seconds in case link breaks. |
faker_71 | 0:2e9a86765692 | 47 | |
faker_71 | 0:2e9a86765692 | 48 | // Serial Interrupt read ESP data |
faker_71 | 0:2e9a86765692 | 49 | void callback() |
faker_71 | 0:2e9a86765692 | 50 | { |
faker_71 | 0:2e9a86765692 | 51 | //pc.printf("\n\r------------ callback is being called --------------\n\r"); |
faker_71 | 0:2e9a86765692 | 52 | led3=1; |
faker_71 | 0:2e9a86765692 | 53 | while (esp.readable()) { |
faker_71 | 0:2e9a86765692 | 54 | webbuff[count_wifi] = esp.getc(); |
faker_71 | 0:2e9a86765692 | 55 | count_wifi++; |
faker_71 | 0:2e9a86765692 | 56 | } |
faker_71 | 0:2e9a86765692 | 57 | if(strlen(webbuff)>bufflen) { |
faker_71 | 0:2e9a86765692 | 58 | pc.printf("\f\n\r------------ webbuff over bufflen --------------\n\r"); |
faker_71 | 0:2e9a86765692 | 59 | DataRX=1; |
faker_71 | 0:2e9a86765692 | 60 | led3=0; |
faker_71 | 0:2e9a86765692 | 61 | } |
faker_71 | 0:2e9a86765692 | 62 | } |
faker_71 | 0:2e9a86765692 | 63 | |
faker_71 | 0:2e9a86765692 | 64 | void wifi(void const *argument){ |
faker_71 | 0:2e9a86765692 | 65 | pc.baud(115200); |
faker_71 | 0:2e9a86765692 | 66 | |
faker_71 | 0:2e9a86765692 | 67 | pc.printf("\f\n\r------------ ESP8266 Hardware Reset psq --------------\n\r"); |
faker_71 | 0:2e9a86765692 | 68 | wait(0.5); |
faker_71 | 0:2e9a86765692 | 69 | led1=1,led2=0,led3=0; |
faker_71 | 0:2e9a86765692 | 70 | timeout=6000; |
faker_71 | 0:2e9a86765692 | 71 | getcount=500; |
faker_71 | 0:2e9a86765692 | 72 | getreply(); |
faker_71 | 0:2e9a86765692 | 73 | esp.baud(115200); // ESP8266 baudrate. Maximum on KLxx' is 115200, 230400 works on K20 and K22F |
faker_71 | 0:2e9a86765692 | 74 | startserver(); |
faker_71 | 0:2e9a86765692 | 75 | |
faker_71 | 0:2e9a86765692 | 76 | while(1) { |
faker_71 | 0:2e9a86765692 | 77 | if(DataRX==1) { |
faker_71 | 0:2e9a86765692 | 78 | pc.printf("\f\n\r------------ main while > if --------------\n\r"); |
faker_71 | 0:2e9a86765692 | 79 | click_flag = 1; |
faker_71 | 0:2e9a86765692 | 80 | ReadWebData(); |
faker_71 | 0:2e9a86765692 | 81 | pc.printf("\f\n\r------------ click_flag=%d --------------\n\r",click_flag); |
faker_71 | 0:2e9a86765692 | 82 | //if ((servreq == 1 && weberror == 0) && click_flag == 1) { |
faker_71 | 0:2e9a86765692 | 83 | if (servreq == 1 && weberror == 0) { |
faker_71 | 0:2e9a86765692 | 84 | pc.printf("\f\n\r------------ befor send page --------------\n\r"); |
faker_71 | 0:2e9a86765692 | 85 | sendpage(); |
faker_71 | 0:2e9a86765692 | 86 | } |
faker_71 | 0:2e9a86765692 | 87 | pc.printf("\f\n\r------------ send_check begin --------------\n\r"); |
faker_71 | 0:2e9a86765692 | 88 | |
faker_71 | 0:2e9a86765692 | 89 | //sendcheck(); |
faker_71 | 0:2e9a86765692 | 90 | pc.printf("\f\n\r------------ ssend_check end--------------\n\r"); |
faker_71 | 0:2e9a86765692 | 91 | |
faker_71 | 0:2e9a86765692 | 92 | esp.attach(&callback); |
faker_71 | 0:2e9a86765692 | 93 | pc.printf(" IPD Data:\r\n\n Link ID = %d,\r\n IPD Header Length = %d \r\n IPD Type = %s\r\n", linkID, ipdLen, type); |
faker_71 | 0:2e9a86765692 | 94 | pc.printf("\n\n HTTP Packet: \n\n%s\n", webdata); |
faker_71 | 0:2e9a86765692 | 95 | pc.printf(" Web Characters sent : %d\n\n", bufl); |
faker_71 | 0:2e9a86765692 | 96 | pc.printf(" -------------------------------------\n\n"); |
faker_71 | 0:2e9a86765692 | 97 | servreq=0; |
faker_71 | 0:2e9a86765692 | 98 | } |
faker_71 | 0:2e9a86765692 | 99 | } |
faker_71 | 0:2e9a86765692 | 100 | } |
faker_71 | 0:2e9a86765692 | 101 | int main() |
faker_71 | 0:2e9a86765692 | 102 | { |
faker_71 | 0:2e9a86765692 | 103 | while(1){ |
faker_71 | 0:2e9a86765692 | 104 | Thread::wait(100); |
faker_71 | 0:2e9a86765692 | 105 | } |
faker_71 | 0:2e9a86765692 | 106 | } |
faker_71 | 0:2e9a86765692 | 107 | // Static WEB page |
faker_71 | 0:2e9a86765692 | 108 | void sendpage() |
faker_71 | 0:2e9a86765692 | 109 | { |
faker_71 | 0:2e9a86765692 | 110 | // WEB page data |
faker_71 | 0:2e9a86765692 | 111 | |
faker_71 | 0:2e9a86765692 | 112 | strcpy(webbuff, "<!DOCTYPE html>"); |
faker_71 | 0:2e9a86765692 | 113 | strcat(webbuff, "<html><head><title>RobotCar</title><meta name='viewport' content='width=device-width'/>"); |
faker_71 | 0:2e9a86765692 | 114 | strcat(webbuff, "</head><body><center><p><strong>Robot Car Remot Controller"); |
faker_71 | 0:2e9a86765692 | 115 | strcat(webbuff, "</strong></p><td style='vertical-align:top;'><strong>Battery level "); |
faker_71 | 0:2e9a86765692 | 116 | strcat(webbuff, "<input type=\"text\" id=\"leftms\" size=4 value=250>%</strong>"); |
faker_71 | 0:2e9a86765692 | 117 | strcat(webbuff, "</td></p><tr ><strong>Now speed : </strong></tr><nobr id=\"speprint\">ready"); |
faker_71 | 0:2e9a86765692 | 118 | strcat(webbuff, "</nobr><br><tr ><strong>Now action : </strong></tr>"); |
faker_71 | 0:2e9a86765692 | 119 | strcat(webbuff, "<nobr id=\"funprint\">ready</nobr><table><tr><td></td><td>"); |
faker_71 | 0:2e9a86765692 | 120 | |
faker_71 | 0:2e9a86765692 | 121 | strcat(webbuff, "<button id='gobtn' type='button' style='width:100px;height:60px' value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
faker_71 | 0:2e9a86765692 | 122 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
faker_71 | 0:2e9a86765692 | 123 | strcat(webbuff, "<button id='leftbtn' type='button' style='width:100px;height:60px' value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
faker_71 | 0:2e9a86765692 | 124 | strcat(webbuff, "</button></td><td>"); |
faker_71 | 0:2e9a86765692 | 125 | |
faker_71 | 0:2e9a86765692 | 126 | strcat(webbuff, "<button id='stopbtn' type='button' style='width:100px;height:60px' value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
faker_71 | 0:2e9a86765692 | 127 | strcat(webbuff, "</button></td><td>"); |
faker_71 | 0:2e9a86765692 | 128 | strcat(webbuff, "<button id='rightbtn' type='button' style='width:100px;height:60px' value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
faker_71 | 0:2e9a86765692 | 129 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
faker_71 | 0:2e9a86765692 | 130 | strcat(webbuff, "<button id='backbtn' type='button' style='width:100px;height:60px' value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
faker_71 | 0:2e9a86765692 | 131 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
faker_71 | 0:2e9a86765692 | 132 | |
faker_71 | 0:2e9a86765692 | 133 | |
faker_71 | 0:2e9a86765692 | 134 | |
faker_71 | 0:2e9a86765692 | 135 | //begin |
faker_71 | 0:2e9a86765692 | 136 | strcat(webbuff, "<strong>Addition functions:</strong><table>"); |
faker_71 | 0:2e9a86765692 | 137 | strcat(webbuff, "<td>");//ok |
faker_71 | 0:2e9a86765692 | 138 | strcat(webbuff, "<button id='avoidbtn' type='button' style='width:100px;height:60px' value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
faker_71 | 0:2e9a86765692 | 139 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
faker_71 | 0:2e9a86765692 | 140 | strcat(webbuff, "<button id='tracebtn' type='button' style='width:100px;height:60px' value=\"LINETRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
faker_71 | 0:2e9a86765692 | 141 | strcat(webbuff, "</button></td></table><table><td>"); |
faker_71 | 0:2e9a86765692 | 142 | strcat(webbuff, "</td><strong>Speed level:</strong>"); |
faker_71 | 0:2e9a86765692 | 143 | strcat(webbuff, "</table><table><td>"); |
faker_71 | 0:2e9a86765692 | 144 | strcat(webbuff, "<button id='sp1btn' type='button' style='width:100px;height:60px' value=\"SLOW\" onClick='send_mes_spe(this.id,this.value)' >SLOW"); |
faker_71 | 0:2e9a86765692 | 145 | strcat(webbuff, "</button></td><td>"); |
faker_71 | 0:2e9a86765692 | 146 | strcat(webbuff, "<button id='sp2btn' type='button' style='width:100px;height:60px' value=\"FAST\" onClick='send_mes_spe(this.id,this.value)' >FAST"); |
faker_71 | 0:2e9a86765692 | 147 | strcat(webbuff, "</button>"); |
faker_71 | 0:2e9a86765692 | 148 | strcat(webbuff, "</td>"); |
faker_71 | 0:2e9a86765692 | 149 | strcat(webbuff, "<td>"); |
faker_71 | 0:2e9a86765692 | 150 | strcat(webbuff, "<button id='sp3btn' type='button' style='width:100px;height:60px' value=\"VERYFAST\" onClick='send_mes_spe(this.id,this.value)' >FLY"); |
faker_71 | 0:2e9a86765692 | 151 | strcat(webbuff, "</button>"); |
faker_71 | 0:2e9a86765692 | 152 | strcat(webbuff, "</td></table>"); |
faker_71 | 0:2e9a86765692 | 153 | strcat(webbuff, "<table>"); |
faker_71 | 0:2e9a86765692 | 154 | strcat(webbuff, "<td>"); |
faker_71 | 0:2e9a86765692 | 155 | strcat(webbuff, "</td>"); |
faker_71 | 0:2e9a86765692 | 156 | strcat(webbuff, "</table>"); //end |
faker_71 | 0:2e9a86765692 | 157 | |
faker_71 | 0:2e9a86765692 | 158 | |
faker_71 | 0:2e9a86765692 | 159 | |
faker_71 | 0:2e9a86765692 | 160 | strcat(webbuff, "</center>"); |
faker_71 | 0:2e9a86765692 | 161 | strcat(webbuff, "</body>"); |
faker_71 | 0:2e9a86765692 | 162 | strcat(webbuff, "</html>"); |
faker_71 | 0:2e9a86765692 | 163 | strcat(webbuff, "<script language=\"javascript\" type=\"text/javascript\">"); |
faker_71 | 0:2e9a86765692 | 164 | strcat(webbuff, "function send_mes(btnmes,btnval){"); |
faker_71 | 0:2e9a86765692 | 165 | strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); |
faker_71 | 0:2e9a86765692 | 166 | strcat(webbuff, "htmlacs(url);"); |
faker_71 | 0:2e9a86765692 | 167 | strcat(webbuff, "console.log(url);"); |
faker_71 | 0:2e9a86765692 | 168 | strcat(webbuff, "}"); |
faker_71 | 2:1bf376317a43 | 169 | |
faker_71 | 0:2e9a86765692 | 170 | strcat(webbuff, "function htmlacs(url) {"); |
faker_71 | 0:2e9a86765692 | 171 | strcat(webbuff, "var xhr = new XMLHttpRequest();"); |
faker_71 | 2:1bf376317a43 | 172 | strcat(webbuff, "xhr.open(\"GET\", url ,true);"); |
faker_71 | 2:1bf376317a43 | 173 | strcat(webbuff, "xhr.send();"); |
faker_71 | 0:2e9a86765692 | 174 | strcat(webbuff, "}"); |
faker_71 | 2:1bf376317a43 | 175 | |
faker_71 | 2:1bf376317a43 | 176 | |
faker_71 | 2:1bf376317a43 | 177 | //0824 battery update auto |
faker_71 | 2:1bf376317a43 | 178 | strcat(webbuff, "function battery_update() {"); |
faker_71 | 2:1bf376317a43 | 179 | strcat(webbuff, "var url1 = \"http://\" + window.location.hostname+ \"/cargo?a=responseBattery\";"); |
faker_71 | 2:1bf376317a43 | 180 | strcat(webbuff, "var xhr1 = new XMLHttpRequest();"); |
faker_71 | 2:1bf376317a43 | 181 | strcat(webbuff, "xhr1.open(\"GET\", url1);"); |
faker_71 | 2:1bf376317a43 | 182 | //0820 |
faker_71 | 2:1bf376317a43 | 183 | strcat(webbuff, "xhr1.onreadystatechange = function(){"); |
faker_71 | 2:1bf376317a43 | 184 | //strcat(webbuff, "console.log(\"onready function is being reload!\");"); |
faker_71 | 2:1bf376317a43 | 185 | strcat(webbuff, "if(this.readyState == 4 && this.status == 200){"); |
faker_71 | 2:1bf376317a43 | 186 | //strcat(webbuff, "console.log(\"state is being reload!\");"); |
faker_71 | 2:1bf376317a43 | 187 | strcat(webbuff, "var res1 = xhr1.responseText;"); |
faker_71 | 2:1bf376317a43 | 188 | strcat(webbuff, "document.getElementById('leftms').value=res1;}};"); |
faker_71 | 2:1bf376317a43 | 189 | //strcat(webbuff, "console.log(res);}};"); |
faker_71 | 2:1bf376317a43 | 190 | //0820 |
faker_71 | 2:1bf376317a43 | 191 | |
faker_71 | 2:1bf376317a43 | 192 | strcat(webbuff, "xhr1.send();"); |
faker_71 | 2:1bf376317a43 | 193 | strcat(webbuff, "}"); |
faker_71 | 2:1bf376317a43 | 194 | strcat(webbuff, "setInterval(battery_update,10000);"); |
faker_71 | 2:1bf376317a43 | 195 | |
faker_71 | 2:1bf376317a43 | 196 | //0824 battery update auto |
faker_71 | 2:1bf376317a43 | 197 | /* |
faker_71 | 0:2e9a86765692 | 198 | strcat(webbuff, "function send_mes_spe(btnmes,btnval){"); |
faker_71 | 0:2e9a86765692 | 199 | strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); |
faker_71 | 0:2e9a86765692 | 200 | strcat(webbuff, "htmlacs(url);"); |
faker_71 | 0:2e9a86765692 | 201 | strcat(webbuff, "if(document.getElementById(\"speprint\")){"); |
faker_71 | 0:2e9a86765692 | 202 | strcat(webbuff, "document.getElementById(\"speprint\").innerHTML=btnval;"); |
faker_71 | 0:2e9a86765692 | 203 | strcat(webbuff, "}"); |
faker_71 | 0:2e9a86765692 | 204 | strcat(webbuff, "}"); |
faker_71 | 0:2e9a86765692 | 205 | strcat(webbuff, "function send_mes_fun(btnmes,btnval){"); |
faker_71 | 0:2e9a86765692 | 206 | strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); |
faker_71 | 0:2e9a86765692 | 207 | strcat(webbuff, "htmlacs(url);"); |
faker_71 | 0:2e9a86765692 | 208 | strcat(webbuff, "if(document.getElementById(\"funprint\")){"); |
faker_71 | 0:2e9a86765692 | 209 | strcat(webbuff, "document.getElementById(\"funprint\").innerHTML=btnval;"); |
faker_71 | 0:2e9a86765692 | 210 | strcat(webbuff, "}"); |
faker_71 | 0:2e9a86765692 | 211 | strcat(webbuff, "}"); |
faker_71 | 2:1bf376317a43 | 212 | */ |
faker_71 | 0:2e9a86765692 | 213 | strcat(webbuff, "</script>"); |
faker_71 | 0:2e9a86765692 | 214 | // end of WEB page data |
faker_71 | 0:2e9a86765692 | 215 | bufl = strlen(webbuff); // get total page buffer length |
faker_71 | 0:2e9a86765692 | 216 | //sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length. |
faker_71 | 0:2e9a86765692 | 217 | |
faker_71 | 0:2e9a86765692 | 218 | sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, (bufl>2048?2048:bufl)); // send IPD link channel and buffer character length. |
faker_71 | 0:2e9a86765692 | 219 | timeout=500; |
faker_71 | 0:2e9a86765692 | 220 | getcount=40; |
faker_71 | 0:2e9a86765692 | 221 | SendCMD(); |
faker_71 | 0:2e9a86765692 | 222 | getreply(); |
faker_71 | 0:2e9a86765692 | 223 | pc.printf(replybuff); |
faker_71 | 0:2e9a86765692 | 224 | pc.printf("\n++++++++++ AT+CIPSENDBUF=%d,%d+++++++++\r\n", linkID, (bufl>2048?2048:bufl)); |
faker_71 | 0:2e9a86765692 | 225 | |
faker_71 | 0:2e9a86765692 | 226 | pc.printf("\n++++++++++ bufl is %d ++++++++++\r\n",bufl); |
faker_71 | 0:2e9a86765692 | 227 | |
faker_71 | 0:2e9a86765692 | 228 | //pastthrough mode |
faker_71 | 0:2e9a86765692 | 229 | SendWEB(); // send web page |
faker_71 | 0:2e9a86765692 | 230 | pc.printf("\n++++++++++ webbuff clear ++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 231 | |
faker_71 | 0:2e9a86765692 | 232 | memset(webbuff, '\0', sizeof(webbuff)); |
faker_71 | 0:2e9a86765692 | 233 | sendcheck(); |
faker_71 | 0:2e9a86765692 | 234 | } |
faker_71 | 0:2e9a86765692 | 235 | |
faker_71 | 2:1bf376317a43 | 236 | |
faker_71 | 2:1bf376317a43 | 237 | void sendpage2() |
faker_71 | 0:2e9a86765692 | 238 | { |
faker_71 | 2:1bf376317a43 | 239 | // WEB page data |
faker_71 | 2:1bf376317a43 | 240 | |
faker_71 | 2:1bf376317a43 | 241 | //strcpy(webbuff, "<script language=\"javascript\" type=\"text/javascript\">"); |
faker_71 | 2:1bf376317a43 | 242 | //strcat(webbuff, "document.getElementById('leftms').value=\"100\";"); |
faker_71 | 2:1bf376317a43 | 243 | count_test++; |
faker_71 | 2:1bf376317a43 | 244 | sprintf(battery_ch,"%d",count_test); |
faker_71 | 2:1bf376317a43 | 245 | strcpy(webbuff, battery_ch); |
faker_71 | 2:1bf376317a43 | 246 | |
faker_71 | 2:1bf376317a43 | 247 | //strcpy(webbuff, "document.getElementById('leftms').value=\"100\";"); |
faker_71 | 2:1bf376317a43 | 248 | |
faker_71 | 2:1bf376317a43 | 249 | //strcat(webbuff, "</script>"); |
faker_71 | 2:1bf376317a43 | 250 | // end of WEB page data |
faker_71 | 2:1bf376317a43 | 251 | bufl = strlen(webbuff); // get total page buffer length |
faker_71 | 2:1bf376317a43 | 252 | //sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length. |
faker_71 | 2:1bf376317a43 | 253 | |
faker_71 | 2:1bf376317a43 | 254 | sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, (bufl>2048?2048:bufl)); // send IPD link channel and buffer character length. |
faker_71 | 2:1bf376317a43 | 255 | timeout=500; |
faker_71 | 2:1bf376317a43 | 256 | getcount=40; |
faker_71 | 2:1bf376317a43 | 257 | SendCMD(); |
faker_71 | 2:1bf376317a43 | 258 | getreply(); |
faker_71 | 2:1bf376317a43 | 259 | pc.printf(replybuff); |
faker_71 | 2:1bf376317a43 | 260 | pc.printf("\n++++++++++ AT+CIPSENDBUF=%d,%d+++++++++\r\n", linkID, (bufl>2048?2048:bufl)); |
faker_71 | 2:1bf376317a43 | 261 | |
faker_71 | 2:1bf376317a43 | 262 | pc.printf("\n++++++++++ bufl is %d ++++++++++\r\n",bufl); |
faker_71 | 2:1bf376317a43 | 263 | |
faker_71 | 2:1bf376317a43 | 264 | //pastthrough mode |
faker_71 | 2:1bf376317a43 | 265 | SendWEB(); // send web page |
faker_71 | 2:1bf376317a43 | 266 | pc.printf("\n++++++++++ webbuff clear ++++++++++\r\n"); |
faker_71 | 2:1bf376317a43 | 267 | |
faker_71 | 2:1bf376317a43 | 268 | memset(webbuff, '\0', sizeof(webbuff)); |
faker_71 | 2:1bf376317a43 | 269 | sendcheck(); |
faker_71 | 0:2e9a86765692 | 270 | } |
faker_71 | 0:2e9a86765692 | 271 | |
faker_71 | 0:2e9a86765692 | 272 | |
faker_71 | 0:2e9a86765692 | 273 | // Reads and processes GET and POST web data |
faker_71 | 0:2e9a86765692 | 274 | void ReadWebData() |
faker_71 | 0:2e9a86765692 | 275 | { |
faker_71 | 0:2e9a86765692 | 276 | pc.printf("+++++++++++++++++Read Web Data+++++++++++++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 277 | wait_ms(200); |
faker_71 | 0:2e9a86765692 | 278 | esp.attach(NULL); |
faker_71 | 0:2e9a86765692 | 279 | count_wifi=0; |
faker_71 | 0:2e9a86765692 | 280 | DataRX=0; |
faker_71 | 0:2e9a86765692 | 281 | weberror=0; |
faker_71 | 0:2e9a86765692 | 282 | memset(webdata, '\0', sizeof(webdata)); |
faker_71 | 0:2e9a86765692 | 283 | int x = strcspn (webbuff,"+"); |
faker_71 | 0:2e9a86765692 | 284 | if(x) { |
faker_71 | 0:2e9a86765692 | 285 | strcpy(webdata, webbuff + x); |
faker_71 | 0:2e9a86765692 | 286 | weberror=0; |
faker_71 | 0:2e9a86765692 | 287 | int numMatched = sscanf(webdata,"+IPD,%d,%d:%s", &linkID, &ipdLen, type); |
faker_71 | 0:2e9a86765692 | 288 | //int i=0; |
faker_71 | 0:2e9a86765692 | 289 | pc.printf("+++++++++++++++++succed rec begin+++++++++++++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 290 | pc.printf("%s",webdata); |
faker_71 | 0:2e9a86765692 | 291 | pc.printf("+++++++++++++++++succed rec end+++++++++++++++++++++\r\n"); |
faker_71 | 2:1bf376317a43 | 292 | if( strstr(webdata, "responseBattery") != NULL ) { |
faker_71 | 0:2e9a86765692 | 293 | click_flag = 0; |
faker_71 | 0:2e9a86765692 | 294 | led4=!led4; |
faker_71 | 2:1bf376317a43 | 295 | pc.printf("\r\n++++++++++++++mode = LEFT++++++++++++++\r\n"); |
faker_71 | 2:1bf376317a43 | 296 | sendpage2(); |
faker_71 | 2:1bf376317a43 | 297 | /* |
faker_71 | 2:1bf376317a43 | 298 | strcpy(webbuff, "<script language=\"javascript\" type=\"text/javascript\">"); |
faker_71 | 2:1bf376317a43 | 299 | strcat(webbuff, "document.getElementById('leftms').value=\"96\";"); |
faker_71 | 2:1bf376317a43 | 300 | strcat(webbuff, "let request = new XMLHttpRequest();"); |
faker_71 | 2:1bf376317a43 | 301 | strcat(webbuff, "request.open('GET', url);request.responseType = 'text';"); |
faker_71 | 2:1bf376317a43 | 302 | strcat(webbuff, "request.onload = function() { poemDisplay.textContent = request.response;};"); |
faker_71 | 2:1bf376317a43 | 303 | |
faker_71 | 2:1bf376317a43 | 304 | strcat(webbuff, "request.send();"); |
faker_71 | 2:1bf376317a43 | 305 | strcat(webbuff, "</script>"); |
faker_71 | 2:1bf376317a43 | 306 | bufl = strlen(webbuff); // get total page buffer length |
faker_71 | 2:1bf376317a43 | 307 | sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length. |
faker_71 | 2:1bf376317a43 | 308 | timeout=500; |
faker_71 | 2:1bf376317a43 | 309 | getcount=40; |
faker_71 | 2:1bf376317a43 | 310 | SendCMD(); |
faker_71 | 2:1bf376317a43 | 311 | getreply(); |
faker_71 | 2:1bf376317a43 | 312 | SendWEB(); |
faker_71 | 2:1bf376317a43 | 313 | memset(webbuff, '\0', sizeof(webbuff)); |
faker_71 | 2:1bf376317a43 | 314 | sendcheck(); |
faker_71 | 2:1bf376317a43 | 315 | pc.printf("\r\n++++++++++++++mode = LEFT++++++++++++++\r\n"); |
faker_71 | 2:1bf376317a43 | 316 | */ |
faker_71 | 2:1bf376317a43 | 317 | |
faker_71 | 2:1bf376317a43 | 318 | /* mode = LEFT; // 左折モード |
faker_71 | 0:2e9a86765692 | 319 | run = LEFT; // 左折 |
faker_71 | 2:1bf376317a43 | 320 | display(); */ |
faker_71 | 2:1bf376317a43 | 321 | |
faker_71 | 0:2e9a86765692 | 322 | } |
faker_71 | 2:1bf376317a43 | 323 | /* |
faker_71 | 0:2e9a86765692 | 324 | if( strstr(webdata, "RIGHT") != NULL ) { |
faker_71 | 0:2e9a86765692 | 325 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 326 | pc.printf("mode = RIGHT\r\n"); |
faker_71 | 0:2e9a86765692 | 327 | mode = RIGHT; // 右折モード |
faker_71 | 0:2e9a86765692 | 328 | run = RIGHT; // 右折 |
faker_71 | 0:2e9a86765692 | 329 | display(); // ディスプレイ表示 |
faker_71 | 0:2e9a86765692 | 330 | } |
faker_71 | 0:2e9a86765692 | 331 | |
faker_71 | 0:2e9a86765692 | 332 | if( strstr(webdata, "GO") != NULL ) { |
faker_71 | 0:2e9a86765692 | 333 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 334 | pc.printf("mode = ADVANCE\r\n"); |
faker_71 | 0:2e9a86765692 | 335 | mode = ADVANCE; // 前進モード |
faker_71 | 0:2e9a86765692 | 336 | run = ADVANCE; // 前進 |
faker_71 | 0:2e9a86765692 | 337 | display(); // ディスプレイ表示 |
faker_71 | 0:2e9a86765692 | 338 | } |
faker_71 | 0:2e9a86765692 | 339 | |
faker_71 | 0:2e9a86765692 | 340 | if( strstr(webdata, "BACK") != NULL ) { |
faker_71 | 0:2e9a86765692 | 341 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 342 | pc.printf("mode = BACK\r\n"); |
faker_71 | 0:2e9a86765692 | 343 | mode = BACK; // 後退モード |
faker_71 | 0:2e9a86765692 | 344 | run = BACK; // 後退 |
faker_71 | 0:2e9a86765692 | 345 | display(); // ディスプレイ表示 |
faker_71 | 0:2e9a86765692 | 346 | } |
faker_71 | 0:2e9a86765692 | 347 | |
faker_71 | 0:2e9a86765692 | 348 | if( strstr(webdata, "STOP") != NULL ) { |
faker_71 | 0:2e9a86765692 | 349 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 350 | pc.printf("mode = STOP\r\n"); |
faker_71 | 0:2e9a86765692 | 351 | mode = STOP; // 停止モード |
faker_71 | 0:2e9a86765692 | 352 | run = STOP; // 停止 |
faker_71 | 0:2e9a86765692 | 353 | display(); // ディスプレイ表示 |
faker_71 | 0:2e9a86765692 | 354 | } |
faker_71 | 0:2e9a86765692 | 355 | |
faker_71 | 0:2e9a86765692 | 356 | if( strstr(webdata, "AVOIDANCE") != NULL ) { |
faker_71 | 0:2e9a86765692 | 357 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 358 | pc.printf("mode = AVOIDANCE\r\n"); |
faker_71 | 0:2e9a86765692 | 359 | mode=AVOIDANCE; // 障害物回避モード |
faker_71 | 0:2e9a86765692 | 360 | run = ADVANCE; // 前進 |
faker_71 | 0:2e9a86765692 | 361 | display(); |
faker_71 | 0:2e9a86765692 | 362 | } |
faker_71 | 0:2e9a86765692 | 363 | |
faker_71 | 0:2e9a86765692 | 364 | if( strstr(webdata, "LINETRACE") != NULL ) { |
faker_71 | 0:2e9a86765692 | 365 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 366 | pc.printf("mode = LINE_TRACE\r\n"); |
faker_71 | 0:2e9a86765692 | 367 | mode=LINE_TRACE; // ライントレースモード |
faker_71 | 0:2e9a86765692 | 368 | display(); |
faker_71 | 0:2e9a86765692 | 369 | } |
faker_71 | 0:2e9a86765692 | 370 | |
faker_71 | 0:2e9a86765692 | 371 | if( strstr(webdata, "SLOW") != NULL ) { |
faker_71 | 0:2e9a86765692 | 372 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 373 | pc.printf("\r\n+++++++++++++++++bbutton right clicked+++++++++++++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 374 | } |
faker_71 | 0:2e9a86765692 | 375 | |
faker_71 | 0:2e9a86765692 | 376 | if( strstr(webdata, "FAST") != NULL ) { |
faker_71 | 0:2e9a86765692 | 377 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 378 | pc.printf("\r\n+++++++++++++++++bbutton right clicked+++++++++++++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 379 | } |
faker_71 | 0:2e9a86765692 | 380 | |
faker_71 | 0:2e9a86765692 | 381 | if( strstr(webdata, "VERYFAST") != NULL ) { |
faker_71 | 0:2e9a86765692 | 382 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 383 | pc.printf("\r\n+++++++++++++++++bbutton right clicked+++++++++++++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 384 | }*/ |
faker_71 | 0:2e9a86765692 | 385 | sprintf(channel, "%d",linkID); |
faker_71 | 0:2e9a86765692 | 386 | if (strstr(webdata, "GET") != NULL) { |
faker_71 | 0:2e9a86765692 | 387 | servreq=1; |
faker_71 | 0:2e9a86765692 | 388 | pc.printf("\r\n+++++++++++++++++GET+++++++++++++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 389 | |
faker_71 | 0:2e9a86765692 | 390 | } |
faker_71 | 0:2e9a86765692 | 391 | if (strstr(webdata, "POST") != NULL) { |
faker_71 | 0:2e9a86765692 | 392 | servreq=1; |
faker_71 | 0:2e9a86765692 | 393 | pc.printf("\r\n+++++++++++++++++POST+++++++++++++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 394 | } |
faker_71 | 0:2e9a86765692 | 395 | webcounter++; |
faker_71 | 0:2e9a86765692 | 396 | sprintf(webcount, "%d",webcounter); |
faker_71 | 0:2e9a86765692 | 397 | } else { |
faker_71 | 0:2e9a86765692 | 398 | pc.printf("\n++++++++++ webbuff clear ++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 399 | memset(webbuff, '\0', sizeof(webbuff)); |
faker_71 | 0:2e9a86765692 | 400 | esp.attach(&callback); |
faker_71 | 0:2e9a86765692 | 401 | weberror=1; |
faker_71 | 0:2e9a86765692 | 402 | } |
faker_71 | 0:2e9a86765692 | 403 | } |
faker_71 | 2:1bf376317a43 | 404 | // Large WEB buffer data send |
faker_71 | 2:1bf376317a43 | 405 | void SendWEB() |
faker_71 | 2:1bf376317a43 | 406 | { |
faker_71 | 2:1bf376317a43 | 407 | int i=0; |
faker_71 | 2:1bf376317a43 | 408 | if(esp.writeable()) { |
faker_71 | 2:1bf376317a43 | 409 | while(webbuff[i]!='\0') { |
faker_71 | 2:1bf376317a43 | 410 | esp.putc(webbuff[i]); |
faker_71 | 2:1bf376317a43 | 411 | |
faker_71 | 2:1bf376317a43 | 412 | //**** |
faker_71 | 2:1bf376317a43 | 413 | //output at command when 2000 |
faker_71 | 2:1bf376317a43 | 414 | if(((i%2047)==0) && (i>0)){ |
faker_71 | 2:1bf376317a43 | 415 | //wait_ms(10); |
faker_71 | 2:1bf376317a43 | 416 | sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, (bufl-2048)>2048?2048:(bufl-2048)); // send IPD link channel and buffer character length. |
faker_71 | 2:1bf376317a43 | 417 | pc.printf("\r\n++++++++++ AT+CIPSENDBUF=%d,%d ++++++++++\r\n", linkID, (bufl-2048)>2048?2048:(bufl-2048)); |
faker_71 | 2:1bf376317a43 | 418 | timeout=600; |
faker_71 | 2:1bf376317a43 | 419 | getcount=50; |
faker_71 | 2:1bf376317a43 | 420 | SendCMD(); |
faker_71 | 2:1bf376317a43 | 421 | getreply(); |
faker_71 | 2:1bf376317a43 | 422 | pc.printf(replybuff); |
faker_71 | 2:1bf376317a43 | 423 | pc.printf("\r\n+++++++++++++++++++\r\n"); |
faker_71 | 2:1bf376317a43 | 424 | } |
faker_71 | 2:1bf376317a43 | 425 | //**** |
faker_71 | 2:1bf376317a43 | 426 | i++; |
faker_71 | 2:1bf376317a43 | 427 | pc.printf("%c",webbuff[i]); |
faker_71 | 2:1bf376317a43 | 428 | } |
faker_71 | 2:1bf376317a43 | 429 | } |
faker_71 | 2:1bf376317a43 | 430 | pc.printf("\n++++++++++ send web i= %dinfo ++++++++++\r\n",i); |
faker_71 | 2:1bf376317a43 | 431 | } |
faker_71 | 2:1bf376317a43 | 432 | |
faker_71 | 2:1bf376317a43 | 433 | |
faker_71 | 2:1bf376317a43 | 434 | |
faker_71 | 2:1bf376317a43 | 435 | void sendcheck() |
faker_71 | 2:1bf376317a43 | 436 | { |
faker_71 | 2:1bf376317a43 | 437 | weberror=1; |
faker_71 | 2:1bf376317a43 | 438 | timeout=500; |
faker_71 | 2:1bf376317a43 | 439 | getcount=24; |
faker_71 | 2:1bf376317a43 | 440 | t2.reset(); |
faker_71 | 2:1bf376317a43 | 441 | t2.start(); |
faker_71 | 2:1bf376317a43 | 442 | |
faker_71 | 2:1bf376317a43 | 443 | /* |
faker_71 | 2:1bf376317a43 | 444 | while(weberror==1 && t2.read() <5) { |
faker_71 | 2:1bf376317a43 | 445 | getreply(); |
faker_71 | 2:1bf376317a43 | 446 | if (strstr(replybuff, "SEND OK") != NULL) { |
faker_71 | 2:1bf376317a43 | 447 | weberror=0; // wait for valid SEND OK |
faker_71 | 2:1bf376317a43 | 448 | } |
faker_71 | 2:1bf376317a43 | 449 | } |
faker_71 | 2:1bf376317a43 | 450 | */ |
faker_71 | 2:1bf376317a43 | 451 | if(weberror==1) { // restart connection |
faker_71 | 2:1bf376317a43 | 452 | strcpy(cmdbuff, "AT+CIPMUX=1\r\n"); |
faker_71 | 2:1bf376317a43 | 453 | timeout=500; |
faker_71 | 2:1bf376317a43 | 454 | getcount=10; |
faker_71 | 2:1bf376317a43 | 455 | SendCMD(); |
faker_71 | 2:1bf376317a43 | 456 | getreply(); |
faker_71 | 2:1bf376317a43 | 457 | pc.printf(replybuff); |
faker_71 | 2:1bf376317a43 | 458 | sprintf(cmdbuff,"AT+CIPSERVER=1,%d\r\n", port); |
faker_71 | 2:1bf376317a43 | 459 | timeout=500; |
faker_71 | 2:1bf376317a43 | 460 | getcount=10; |
faker_71 | 2:1bf376317a43 | 461 | SendCMD(); |
faker_71 | 2:1bf376317a43 | 462 | getreply(); |
faker_71 | 2:1bf376317a43 | 463 | pc.printf(replybuff); |
faker_71 | 2:1bf376317a43 | 464 | } else { |
faker_71 | 2:1bf376317a43 | 465 | sprintf(cmdbuff, "AT+CIPCLOSE=%s\r\n",channel); // close current connection |
faker_71 | 2:1bf376317a43 | 466 | SendCMD(); |
faker_71 | 2:1bf376317a43 | 467 | getreply(); |
faker_71 | 2:1bf376317a43 | 468 | pc.printf(replybuff); |
faker_71 | 2:1bf376317a43 | 469 | } |
faker_71 | 2:1bf376317a43 | 470 | t2.reset(); |
faker_71 | 2:1bf376317a43 | 471 | } |
faker_71 | 2:1bf376317a43 | 472 | |
faker_71 | 0:2e9a86765692 | 473 | // Starts and restarts webserver if errors detected. |
faker_71 | 0:2e9a86765692 | 474 | void startserver() |
faker_71 | 0:2e9a86765692 | 475 | { |
faker_71 | 0:2e9a86765692 | 476 | pc.printf("++++++++++ Resetting ESP ++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 477 | strcpy(cmdbuff,"AT+RST\r\n"); |
faker_71 | 0:2e9a86765692 | 478 | timeout=8000; |
faker_71 | 0:2e9a86765692 | 479 | getcount=1000; |
faker_71 | 0:2e9a86765692 | 480 | SendCMD(); |
faker_71 | 0:2e9a86765692 | 481 | getreply(); |
faker_71 | 0:2e9a86765692 | 482 | pc.printf(replybuff); |
faker_71 | 0:2e9a86765692 | 483 | pc.printf("%d",count_wifi); |
faker_71 | 0:2e9a86765692 | 484 | if (strstr(replybuff, "OK") != NULL) { |
faker_71 | 0:2e9a86765692 | 485 | pc.printf("\n++++++++++ Starting Server ++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 486 | strcpy(cmdbuff, "AT+CIPMUX=1\r\n"); // set multiple connections. |
faker_71 | 0:2e9a86765692 | 487 | timeout=500; |
faker_71 | 0:2e9a86765692 | 488 | getcount=20; |
faker_71 | 0:2e9a86765692 | 489 | SendCMD(); |
faker_71 | 0:2e9a86765692 | 490 | getreply(); |
faker_71 | 0:2e9a86765692 | 491 | pc.printf(replybuff); |
faker_71 | 0:2e9a86765692 | 492 | sprintf(cmdbuff,"AT+CIPSERVER=1,%d\r\n", port); |
faker_71 | 0:2e9a86765692 | 493 | timeout=500; |
faker_71 | 0:2e9a86765692 | 494 | getcount=20; |
faker_71 | 0:2e9a86765692 | 495 | SendCMD(); |
faker_71 | 0:2e9a86765692 | 496 | getreply(); |
faker_71 | 0:2e9a86765692 | 497 | pc.printf(replybuff); |
faker_71 | 0:2e9a86765692 | 498 | wait(1); |
faker_71 | 0:2e9a86765692 | 499 | sprintf(cmdbuff,"AT+CIPSTO=%d\r\n",SERVtimeout); |
faker_71 | 0:2e9a86765692 | 500 | timeout=500; |
faker_71 | 0:2e9a86765692 | 501 | getcount=50; |
faker_71 | 0:2e9a86765692 | 502 | SendCMD(); |
faker_71 | 0:2e9a86765692 | 503 | getreply(); |
faker_71 | 0:2e9a86765692 | 504 | pc.printf(replybuff); |
faker_71 | 1:a45cf46c1adc | 505 | //wait(5); |
faker_71 | 1:a45cf46c1adc | 506 | wait(1); |
faker_71 | 0:2e9a86765692 | 507 | pc.printf("\n Getting Server IP \r\n"); |
faker_71 | 0:2e9a86765692 | 508 | strcpy(cmdbuff, "AT+CIFSR\r\n"); |
faker_71 | 0:2e9a86765692 | 509 | timeout=2500; |
faker_71 | 0:2e9a86765692 | 510 | getcount=200; |
faker_71 | 0:2e9a86765692 | 511 | while(weberror==0) { |
faker_71 | 0:2e9a86765692 | 512 | SendCMD(); |
faker_71 | 0:2e9a86765692 | 513 | getreply(); |
faker_71 | 0:2e9a86765692 | 514 | if (strstr(replybuff, "0.0.0.0") == NULL) { |
faker_71 | 0:2e9a86765692 | 515 | weberror=1; // wait for valid IP |
faker_71 | 0:2e9a86765692 | 516 | } |
faker_71 | 0:2e9a86765692 | 517 | } |
faker_71 | 0:2e9a86765692 | 518 | pc.printf("\n Enter WEB address (IP) found below in your browser \r\n\n"); |
faker_71 | 0:2e9a86765692 | 519 | pc.printf("\n The MAC address is also shown below,if it is needed \r\n\n"); |
faker_71 | 0:2e9a86765692 | 520 | replybuff[strlen(replybuff)-1] = '\0'; |
faker_71 | 0:2e9a86765692 | 521 | //char* IP = replybuff + 5; |
faker_71 | 0:2e9a86765692 | 522 | sprintf(webdata,"%s", replybuff); |
faker_71 | 0:2e9a86765692 | 523 | pc.printf(webdata); |
faker_71 | 0:2e9a86765692 | 524 | led2=1; |
faker_71 | 0:2e9a86765692 | 525 | bufflen=200; |
faker_71 | 0:2e9a86765692 | 526 | //bufflen=100; |
faker_71 | 0:2e9a86765692 | 527 | count_wifi=0; |
faker_71 | 0:2e9a86765692 | 528 | pc.printf("\n\n++++++++++ Ready ++++++++++\r\n\n"); |
faker_71 | 0:2e9a86765692 | 529 | esp.attach(&callback); |
faker_71 | 0:2e9a86765692 | 530 | } else { |
faker_71 | 0:2e9a86765692 | 531 | pc.printf("\n++++++++++ ESP8266 error, check power/connections ++++++++++\r\n"); |
faker_71 | 0:2e9a86765692 | 532 | led1=1; |
faker_71 | 0:2e9a86765692 | 533 | led2=1; |
faker_71 | 0:2e9a86765692 | 534 | led3=1; |
faker_71 | 0:2e9a86765692 | 535 | led4=1; |
faker_71 | 0:2e9a86765692 | 536 | while(1) { |
faker_71 | 0:2e9a86765692 | 537 | led1=!led1; |
faker_71 | 0:2e9a86765692 | 538 | led2=!led2; |
faker_71 | 0:2e9a86765692 | 539 | led3=!led3; |
faker_71 | 0:2e9a86765692 | 540 | led4=!led4; |
faker_71 | 0:2e9a86765692 | 541 | wait(1); |
faker_71 | 0:2e9a86765692 | 542 | } |
faker_71 | 0:2e9a86765692 | 543 | } |
faker_71 | 0:2e9a86765692 | 544 | t2.reset(); |
faker_71 | 0:2e9a86765692 | 545 | t2.start(); |
faker_71 | 0:2e9a86765692 | 546 | } |
faker_71 | 0:2e9a86765692 | 547 | // ESP Command data send |
faker_71 | 0:2e9a86765692 | 548 | void SendCMD() |
faker_71 | 0:2e9a86765692 | 549 | { |
faker_71 | 0:2e9a86765692 | 550 | esp.printf("%s", cmdbuff); |
faker_71 | 0:2e9a86765692 | 551 | } |
faker_71 | 0:2e9a86765692 | 552 | // Get Command and ESP status replies |
faker_71 | 0:2e9a86765692 | 553 | void getreply() |
faker_71 | 0:2e9a86765692 | 554 | { |
faker_71 | 0:2e9a86765692 | 555 | memset(replybuff, '\0', sizeof(replybuff)); |
faker_71 | 0:2e9a86765692 | 556 | t1.reset(); |
faker_71 | 0:2e9a86765692 | 557 | t1.start(); |
faker_71 | 0:2e9a86765692 | 558 | replycount=0; |
faker_71 | 0:2e9a86765692 | 559 | while(t1.read_ms()< timeout && replycount < getcount) { |
faker_71 | 0:2e9a86765692 | 560 | if(esp.readable()) { |
faker_71 | 0:2e9a86765692 | 561 | replybuff[replycount] = esp.getc(); |
faker_71 | 0:2e9a86765692 | 562 | replycount++; |
faker_71 | 0:2e9a86765692 | 563 | } |
faker_71 | 0:2e9a86765692 | 564 | } |
faker_71 | 0:2e9a86765692 | 565 | t1.stop(); |
faker_71 | 0:2e9a86765692 | 566 | } |