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
main.cpp@9:e458213a7afd, 2020-08-03 (annotated)
- Committer:
- molberry
- Date:
- Mon Aug 03 06:49:33 2020 +0000
- Revision:
- 9:e458213a7afd
- Parent:
- 8:d8e164130860
change
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
star297 | 0:e2a155f50119 | 1 | // ESP8266 Static page WEB server to control Mbed |
star297 | 0:e2a155f50119 | 2 | |
star297 | 0:e2a155f50119 | 3 | #include "mbed.h" |
4180_1 | 4:40dd020463ea | 4 | //#include "DS18B20.h" |
star297 | 0:e2a155f50119 | 5 | |
star297 | 0:e2a155f50119 | 6 | Serial pc(USBTX, USBRX); |
molberry | 9:e458213a7afd | 7 | Serial esp(p13, p14); // tx, rx |
faker_71 | 6:7c9cc335b762 | 8 | //Serial esp(p9, p10); // tx, rx |
molberry | 9:e458213a7afd | 9 | //Resetpin使用せず |
4180_1 | 4:40dd020463ea | 10 | //DS18B20 thermom(A0, DS18B20::RES_12_BIT); |
star297 | 2:d4c6bc0f2dc4 | 11 | |
star297 | 0:e2a155f50119 | 12 | // Standard Mbed LED definitions |
4180_1 | 4:40dd020463ea | 13 | DigitalOut led1(LED1); // (PTB18) |
4180_1 | 4:40dd020463ea | 14 | DigitalOut led2(LED2); // (PTB19) |
4180_1 | 4:40dd020463ea | 15 | DigitalOut led3(LED3); // (PTD1) |
star297 | 0:e2a155f50119 | 16 | |
star297 | 0:e2a155f50119 | 17 | // Digital Out and In pins, can be configured to any suitable pin depending on Platform |
molberry | 9:e458213a7afd | 18 | AnalogIn Ain1(p18);//battery |
star297 | 0:e2a155f50119 | 19 | |
star297 | 0:e2a155f50119 | 20 | Timer t1; |
star297 | 1:71ed1afbf344 | 21 | Timer t2; |
star297 | 1:71ed1afbf344 | 22 | |
star297 | 1:71ed1afbf344 | 23 | struct tm t; |
star297 | 0:e2a155f50119 | 24 | |
star297 | 3:f7febfa77784 | 25 | int bufflen, DataRX, count, getcount, replycount, servreq, timeout; |
star297 | 2:d4c6bc0f2dc4 | 26 | int bufl, ipdLen, linkID, weberror, webcounter; |
4180_1 | 4:40dd020463ea | 27 | float temperature, AdcIn, Ht; |
star297 | 0:e2a155f50119 | 28 | float R1=100000, R2=10000; // resistor values to give a 10:1 reduction of measured AnalogIn voltage |
star297 | 0:e2a155f50119 | 29 | char Vcc[10]; |
star297 | 0:e2a155f50119 | 30 | char Temp[10]; |
star297 | 0:e2a155f50119 | 31 | char temp[10]; |
star297 | 2:d4c6bc0f2dc4 | 32 | char webcount[8]; |
star297 | 3:f7febfa77784 | 33 | char lasthit[30]; |
star297 | 0:e2a155f50119 | 34 | char timebuf[30]; |
star297 | 0:e2a155f50119 | 35 | char type[16]; |
star297 | 0:e2a155f50119 | 36 | char type1[16]; |
star297 | 0:e2a155f50119 | 37 | char channel[2]; |
star297 | 3:f7febfa77784 | 38 | char cmdbuff[32]; |
4180_1 | 4:40dd020463ea | 39 | char replybuff[1024]; |
faker_71 | 5:dfea6fd1abba | 40 | |
faker_71 | 6:7c9cc335b762 | 41 | char webdata[1024]; // This may need to be bigger depending on WEB browser used |
faker_71 | 6:7c9cc335b762 | 42 | char webbuff[4096]; // Currently using 1986 characters, Increase this if more web page data added |
faker_71 | 5:dfea6fd1abba | 43 | |
faker_71 | 6:7c9cc335b762 | 44 | //char webdata[4096]; // This may need to be bigger depending on WEB browser used |
faker_71 | 6:7c9cc335b762 | 45 | //char webbuff[4096*4]; // Currently using 1986 characters, Increase this if more web page data added |
faker_71 | 5:dfea6fd1abba | 46 | |
faker_71 | 6:7c9cc335b762 | 47 | void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck(),touchuan(); |
star297 | 2:d4c6bc0f2dc4 | 48 | void gettime(),gettemp(),getbattery(),setRTC(),beep(); |
star297 | 0:e2a155f50119 | 49 | |
star297 | 1:71ed1afbf344 | 50 | // manual set RTC values |
4180_1 | 4:40dd020463ea | 51 | int minute =00; // 0-59 |
4180_1 | 4:40dd020463ea | 52 | int hour =12; // 2-23 |
4180_1 | 4:40dd020463ea | 53 | int dayofmonth =26; // 1-31 |
4180_1 | 4:40dd020463ea | 54 | int month =8; // 1-12 |
star297 | 1:71ed1afbf344 | 55 | int year =15; // last 2 digits |
star297 | 2:d4c6bc0f2dc4 | 56 | |
4180_1 | 4:40dd020463ea | 57 | int port =80; // set server port |
4180_1 | 4:40dd020463ea | 58 | int SERVtimeout =5; // set server timeout in seconds in case link breaks. |
4180_1 | 4:40dd020463ea | 59 | |
molberry | 9:e458213a7afd | 60 | char ssid[32] = "mbed02"; // enter WiFi router ssid inside the quotes |
molberry | 9:e458213a7afd | 61 | char pwd [32] = "0123456789a"; // enter WiFi router password inside the quotes |
molberry | 9:e458213a7afd | 62 | |
star297 | 0:e2a155f50119 | 63 | // Serial Interrupt read ESP data |
4180_1 | 4:40dd020463ea | 64 | void callback() |
4180_1 | 4:40dd020463ea | 65 | { |
faker_71 | 5:dfea6fd1abba | 66 | //pc.printf("\n\r------------ callback is being called --------------\n\r"); |
4180_1 | 4:40dd020463ea | 67 | led3=1; |
4180_1 | 4:40dd020463ea | 68 | while (esp.readable()) { |
4180_1 | 4:40dd020463ea | 69 | webbuff[count] = esp.getc(); |
4180_1 | 4:40dd020463ea | 70 | count++; |
4180_1 | 4:40dd020463ea | 71 | } |
4180_1 | 4:40dd020463ea | 72 | if(strlen(webbuff)>bufflen) { |
faker_71 | 5:dfea6fd1abba | 73 | pc.printf("\f\n\r------------ webbuff over bufflen --------------\n\r"); |
4180_1 | 4:40dd020463ea | 74 | DataRX=1; |
4180_1 | 4:40dd020463ea | 75 | led3=0; |
4180_1 | 4:40dd020463ea | 76 | } |
star297 | 0:e2a155f50119 | 77 | } |
star297 | 0:e2a155f50119 | 78 | |
4180_1 | 4:40dd020463ea | 79 | int main() |
4180_1 | 4:40dd020463ea | 80 | { |
4180_1 | 4:40dd020463ea | 81 | reset=0; |
star297 | 0:e2a155f50119 | 82 | pc.baud(115200); |
4180_1 | 4:40dd020463ea | 83 | |
faker_71 | 5:dfea6fd1abba | 84 | pc.printf("\f\n\r------------ ESP8266 Hardware Reset psq --------------\n\r"); |
4180_1 | 4:40dd020463ea | 85 | wait(0.5); |
4180_1 | 4:40dd020463ea | 86 | reset=1; |
4180_1 | 4:40dd020463ea | 87 | led1=1,led2=0,led3=0; |
4180_1 | 4:40dd020463ea | 88 | timeout=6000; |
4180_1 | 4:40dd020463ea | 89 | getcount=500; |
4180_1 | 4:40dd020463ea | 90 | getreply(); |
star297 | 3:f7febfa77784 | 91 | esp.baud(115200); // ESP8266 baudrate. Maximum on KLxx' is 115200, 230400 works on K20 and K22F |
4180_1 | 4:40dd020463ea | 92 | if (time(NULL) < 1420070400) { |
4180_1 | 4:40dd020463ea | 93 | setRTC(); |
4180_1 | 4:40dd020463ea | 94 | } |
star297 | 2:d4c6bc0f2dc4 | 95 | beep(); |
star297 | 0:e2a155f50119 | 96 | startserver(); |
molberry | 9:e458213a7afd | 97 | |
4180_1 | 4:40dd020463ea | 98 | while(1) { |
4180_1 | 4:40dd020463ea | 99 | if(DataRX==1) { |
faker_71 | 5:dfea6fd1abba | 100 | pc.printf("\f\n\r------------ main while > if --------------\n\r"); |
molberry | 9:e458213a7afd | 101 | |
star297 | 0:e2a155f50119 | 102 | ReadWebData(); |
star297 | 2:d4c6bc0f2dc4 | 103 | beep(); |
4180_1 | 4:40dd020463ea | 104 | if (servreq == 1 && weberror == 0) { |
molberry | 9:e458213a7afd | 105 | pc.printf("\f\n\r------------ befor send page --------------\n\r"); |
4180_1 | 4:40dd020463ea | 106 | sendpage(); |
4180_1 | 4:40dd020463ea | 107 | } |
4180_1 | 4:40dd020463ea | 108 | esp.attach(&callback); |
4180_1 | 4:40dd020463ea | 109 | 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); |
4180_1 | 4:40dd020463ea | 110 | pc.printf("\n\n HTTP Packet: \n\n%s\n", webdata); |
star297 | 0:e2a155f50119 | 111 | pc.printf(" Web Characters sent : %d\n\n", bufl); |
star297 | 0:e2a155f50119 | 112 | pc.printf(" -------------------------------------\n\n"); |
star297 | 2:d4c6bc0f2dc4 | 113 | strcpy(lasthit, timebuf); |
4180_1 | 4:40dd020463ea | 114 | servreq=0; |
4180_1 | 4:40dd020463ea | 115 | } |
star297 | 0:e2a155f50119 | 116 | } |
4180_1 | 4:40dd020463ea | 117 | } |
4180_1 | 4:40dd020463ea | 118 | // Static WEB page |
star297 | 0:e2a155f50119 | 119 | void sendpage() |
4180_1 | 4:40dd020463ea | 120 | { |
star297 | 3:f7febfa77784 | 121 | gettemp(); |
4180_1 | 4:40dd020463ea | 122 | getbattery(); |
4180_1 | 4:40dd020463ea | 123 | gettime(); |
4180_1 | 4:40dd020463ea | 124 | |
4180_1 | 4:40dd020463ea | 125 | // WEB page data |
faker_71 | 5:dfea6fd1abba | 126 | |
molberry | 9:e458213a7afd | 127 | strcpy(webbuff, "<!DOCTYPE html>"); |
molberry | 9:e458213a7afd | 128 | strcat(webbuff, "<html><head><title>RobotCar</title><meta name='viewport' content='width=device-width'/>"); |
molberry | 9:e458213a7afd | 129 | strcat(webbuff, "<style type=\"text/css\">.noselect{ width:100px;height:60px;}.light{ width:100px;height:60px;background-color:00ff66;}</style>"); |
molberry | 9:e458213a7afd | 130 | strcat(webbuff, "</head><body><center><p><strong>Robot Car Remot Controller"); |
molberry | 9:e458213a7afd | 131 | strcat(webbuff, "</strong></p><td style='vertical-align:top;'><strong>Battery level "); |
molberry | 9:e458213a7afd | 132 | strcat(webbuff, "<input type=\"text\" id=\"leftms\" size=4 value=250>%</strong>"); |
molberry | 9:e458213a7afd | 133 | strcat(webbuff, "</td></p>"); |
molberry | 9:e458213a7afd | 134 | strcat(webbuff, "<br>"); |
molberry | 9:e458213a7afd | 135 | strcat(webbuff, "<table><tr><td></td><td>"); |
faker_71 | 6:7c9cc335b762 | 136 | |
molberry | 9:e458213a7afd | 137 | switch(mode) { |
molberry | 9:e458213a7afd | 138 | case ADVANCE: |
molberry | 9:e458213a7afd | 139 | strcat(webbuff, "<button id='gobtn' type='button' class=\"light\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
molberry | 9:e458213a7afd | 140 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
molberry | 9:e458213a7afd | 141 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
molberry | 9:e458213a7afd | 142 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 143 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
molberry | 9:e458213a7afd | 144 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 145 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
molberry | 9:e458213a7afd | 146 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
molberry | 9:e458213a7afd | 147 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
molberry | 9:e458213a7afd | 148 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
molberry | 9:e458213a7afd | 149 | strcat(webbuff, "<strong>Mode</strong>"); |
molberry | 9:e458213a7afd | 150 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
molberry | 9:e458213a7afd | 151 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
molberry | 9:e458213a7afd | 152 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
molberry | 9:e458213a7afd | 153 | break; |
molberry | 9:e458213a7afd | 154 | case LEFT: |
molberry | 9:e458213a7afd | 155 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
molberry | 9:e458213a7afd | 156 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
molberry | 9:e458213a7afd | 157 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"light\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
molberry | 9:e458213a7afd | 158 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 159 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
molberry | 9:e458213a7afd | 160 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 161 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
molberry | 9:e458213a7afd | 162 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
molberry | 9:e458213a7afd | 163 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
molberry | 9:e458213a7afd | 164 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
molberry | 9:e458213a7afd | 165 | strcat(webbuff, "<strong>Mode</strong>"); |
molberry | 9:e458213a7afd | 166 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
molberry | 9:e458213a7afd | 167 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
molberry | 9:e458213a7afd | 168 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
molberry | 9:e458213a7afd | 169 | break; |
molberry | 9:e458213a7afd | 170 | case STOP: |
molberry | 9:e458213a7afd | 171 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
molberry | 9:e458213a7afd | 172 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
molberry | 9:e458213a7afd | 173 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
molberry | 9:e458213a7afd | 174 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 175 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"light\" value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
molberry | 9:e458213a7afd | 176 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 177 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
molberry | 9:e458213a7afd | 178 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
molberry | 9:e458213a7afd | 179 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
molberry | 9:e458213a7afd | 180 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
molberry | 9:e458213a7afd | 181 | strcat(webbuff, "<strong>Mode</strong>"); |
molberry | 9:e458213a7afd | 182 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
molberry | 9:e458213a7afd | 183 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
molberry | 9:e458213a7afd | 184 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
molberry | 9:e458213a7afd | 185 | break; |
molberry | 9:e458213a7afd | 186 | case RIGHT: |
molberry | 9:e458213a7afd | 187 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
molberry | 9:e458213a7afd | 188 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
molberry | 9:e458213a7afd | 189 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
molberry | 9:e458213a7afd | 190 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 191 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
molberry | 9:e458213a7afd | 192 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 193 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"light\" value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
molberry | 9:e458213a7afd | 194 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
molberry | 9:e458213a7afd | 195 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
molberry | 9:e458213a7afd | 196 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
molberry | 9:e458213a7afd | 197 | strcat(webbuff, "<strong>Mode</strong>"); |
molberry | 9:e458213a7afd | 198 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
molberry | 9:e458213a7afd | 199 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
molberry | 9:e458213a7afd | 200 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
molberry | 9:e458213a7afd | 201 | break; |
molberry | 9:e458213a7afd | 202 | case BACK: |
molberry | 9:e458213a7afd | 203 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
molberry | 9:e458213a7afd | 204 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
molberry | 9:e458213a7afd | 205 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
molberry | 9:e458213a7afd | 206 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 207 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
molberry | 9:e458213a7afd | 208 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 209 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
molberry | 9:e458213a7afd | 210 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
molberry | 9:e458213a7afd | 211 | strcat(webbuff, "<button id='backbtn' type='button' class=\"light\" value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
molberry | 9:e458213a7afd | 212 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr><td>"); |
molberry | 9:e458213a7afd | 213 | strcat(webbuff, "<strong>Mode</strong>"); |
molberry | 9:e458213a7afd | 214 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
molberry | 9:e458213a7afd | 215 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
molberry | 9:e458213a7afd | 216 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
molberry | 9:e458213a7afd | 217 | break; |
molberry | 9:e458213a7afd | 218 | case AVOIDANCE: |
molberry | 9:e458213a7afd | 219 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
molberry | 9:e458213a7afd | 220 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
molberry | 9:e458213a7afd | 221 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
molberry | 9:e458213a7afd | 222 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 223 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
molberry | 9:e458213a7afd | 224 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 225 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
molberry | 9:e458213a7afd | 226 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
molberry | 9:e458213a7afd | 227 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
molberry | 9:e458213a7afd | 228 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
molberry | 9:e458213a7afd | 229 | strcat(webbuff, "<strong>Mode</strong>"); |
molberry | 9:e458213a7afd | 230 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"light\" value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
molberry | 9:e458213a7afd | 231 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
molberry | 9:e458213a7afd | 232 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
molberry | 9:e458213a7afd | 233 | break; |
molberry | 9:e458213a7afd | 234 | case LINE_TRACE: |
molberry | 9:e458213a7afd | 235 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
molberry | 9:e458213a7afd | 236 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
molberry | 9:e458213a7afd | 237 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
molberry | 9:e458213a7afd | 238 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 239 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
molberry | 9:e458213a7afd | 240 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 241 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
molberry | 9:e458213a7afd | 242 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
molberry | 9:e458213a7afd | 243 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
molberry | 9:e458213a7afd | 244 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
molberry | 9:e458213a7afd | 245 | strcat(webbuff, "<strong>Mode</strong>"); |
molberry | 9:e458213a7afd | 246 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
molberry | 9:e458213a7afd | 247 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
molberry | 9:e458213a7afd | 248 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"light\" value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
molberry | 9:e458213a7afd | 249 | break; |
molberry | 9:e458213a7afd | 250 | case default: |
molberry | 9:e458213a7afd | 251 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); |
molberry | 9:e458213a7afd | 252 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
molberry | 9:e458213a7afd | 253 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); |
molberry | 9:e458213a7afd | 254 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 255 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.id,this.value)' >STOP"); |
molberry | 9:e458213a7afd | 256 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 257 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.id,this.value)' >RIGHT"); |
molberry | 9:e458213a7afd | 258 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
molberry | 9:e458213a7afd | 259 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.id,this.value)' >BACK"); |
molberry | 9:e458213a7afd | 260 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
molberry | 9:e458213a7afd | 261 | strcat(webbuff, "<strong>Mode</strong>"); |
molberry | 9:e458213a7afd | 262 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes_fun(this.id,this.value)' >"); |
molberry | 9:e458213a7afd | 263 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
molberry | 9:e458213a7afd | 264 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE TRACE\" onClick='send_mes_fun(this.id,this.value)' >LINE TRACE"); |
molberry | 9:e458213a7afd | 265 | break; |
molberry | 9:e458213a7afd | 266 | } |
molberry | 9:e458213a7afd | 267 | strcat(webbuff, "</button></td></tr></table>"); |
molberry | 9:e458213a7afd | 268 | strcat(webbuff, "<strong>Speed</strong>"); |
molberry | 9:e458213a7afd | 269 | strcat(webbuff, "<table><tr><td>"); |
molberry | 9:e458213a7afd | 270 | //ready示速度だけ点灯 |
molberry | 9:e458213a7afd | 271 | switch (flag_sp%3) { |
molberry | 9:e458213a7afd | 272 | case 0: |
molberry | 9:e458213a7afd | 273 | strcat(webbuff, "<button id='sp1btn' type='button' class=\"light\" value=\"SLOW\" onClick='send_mes_spe(this.id,this.value)' >SLOW"); |
molberry | 9:e458213a7afd | 274 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 275 | strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"FAST\" onClick='send_mes_spe(this.id,this.value)' >FAST"); |
molberry | 9:e458213a7afd | 276 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 277 | strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"FLY\" onClick='send_mes_spe(this.id,this.value)' >FLY"); |
molberry | 9:e458213a7afd | 278 | case 1: |
molberry | 9:e458213a7afd | 279 | strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"SLOW\" onClick='send_mes_spe(this.id,this.value)' >SLOW"); |
molberry | 9:e458213a7afd | 280 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 281 | strcat(webbuff, "<button id='sp2btn' type='button' class=\"light\" value=\"FAST\" onClick='send_mes_spe(this.id,this.value)' >FAST"); |
molberry | 9:e458213a7afd | 282 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 283 | strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"FLY\" onClick='send_mes_spe(this.id,this.value)' >FLY"); |
molberry | 9:e458213a7afd | 284 | case 2: |
molberry | 9:e458213a7afd | 285 | strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"SLOW\" onClick='send_mes_spe(this.id,this.value)' >SLOW"); |
molberry | 9:e458213a7afd | 286 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 287 | strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"FAST\" onClick='send_mes_spe(this.id,this.value)' >FAST"); |
molberry | 9:e458213a7afd | 288 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 289 | strcat(webbuff, "<button id='sp3btn' type='button' class=\"light\" value=\"FLY\" onClick='send_mes_spe(this.id,this.value)' >FLY"); |
molberry | 9:e458213a7afd | 290 | default: |
molberry | 9:e458213a7afd | 291 | strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"SLOW\" onClick='send_mes_spe(this.id,this.value)' >SLOW"); |
molberry | 9:e458213a7afd | 292 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 293 | strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"FAST\" onClick='send_mes_spe(this.id,this.value)' >FAST"); |
molberry | 9:e458213a7afd | 294 | strcat(webbuff, "</button></td><td>"); |
molberry | 9:e458213a7afd | 295 | strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"FLY\" onClick='send_mes_spe(this.id,this.value)' >FLY"); |
molberry | 9:e458213a7afd | 296 | } |
molberry | 9:e458213a7afd | 297 | strcat(webbuff, "</button></td></tr></table>"); |
faker_71 | 6:7c9cc335b762 | 298 | |
molberry | 9:e458213a7afd | 299 | strcat(webbuff, "</center>"); |
molberry | 9:e458213a7afd | 300 | strcat(webbuff, "</body>"); |
molberry | 9:e458213a7afd | 301 | strcat(webbuff, "</html>"); |
molberry | 9:e458213a7afd | 302 | strcat(webbuff, "<script language=\"javascript\" type=\"text/javascript\">"); |
molberry | 9:e458213a7afd | 303 | strcat(webbuff, "function htmlacs(url) {"); |
molberry | 9:e458213a7afd | 304 | strcat(webbuff, "var xhr = new XMLHttpRequest();"); |
molberry | 9:e458213a7afd | 305 | strcat(webbuff, "xhr.open(\"GET\", url);"); |
molberry | 9:e458213a7afd | 306 | strcat(webbuff, "xhr.send(\"\");"); |
molberry | 9:e458213a7afd | 307 | strcat(webbuff, "}"); |
molberry | 9:e458213a7afd | 308 | strcat(webbuff, "function send_mes(btnmes,btnval){"); |
molberry | 9:e458213a7afd | 309 | strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); |
molberry | 9:e458213a7afd | 310 | strcat(webbuff, "htmlacs(url);"); |
molberry | 9:e458213a7afd | 311 | strcat(webbuff, "console.log(url);"); |
molberry | 9:e458213a7afd | 312 | strcat(webbuff, "}"); |
molberry | 9:e458213a7afd | 313 | strcat(webbuff, "function send_mes_spe(btnmes,btnval){"); |
molberry | 9:e458213a7afd | 314 | strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); |
molberry | 9:e458213a7afd | 315 | strcat(webbuff, "htmlacs(url);"); |
molberry | 9:e458213a7afd | 316 | strcat(webbuff, "console.log(url);"); |
molberry | 9:e458213a7afd | 317 | strcat(webbuff, "}"); |
molberry | 9:e458213a7afd | 318 | strcat(webbuff, "}"); |
molberry | 9:e458213a7afd | 319 | strcat(webbuff, "function send_mes_fun(btnmes,btnval){"); |
molberry | 9:e458213a7afd | 320 | strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); |
molberry | 9:e458213a7afd | 321 | strcat(webbuff, "htmlacs(url);"); |
molberry | 9:e458213a7afd | 322 | strcat(webbuff, "console.log(url);"); |
molberry | 9:e458213a7afd | 323 | strcat(webbuff, "}"); |
molberry | 9:e458213a7afd | 324 | strcat(webbuff, "}"); |
molberry | 9:e458213a7afd | 325 | strcat(webbuff, "</script>"); |
4180_1 | 4:40dd020463ea | 326 | // end of WEB page data |
4180_1 | 4:40dd020463ea | 327 | bufl = strlen(webbuff); // get total page buffer length |
faker_71 | 6:7c9cc335b762 | 328 | //sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length. |
molberry | 9:e458213a7afd | 329 | |
faker_71 | 8:d8e164130860 | 330 | sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, 1500); // send IPD link channel and buffer character length. |
faker_71 | 6:7c9cc335b762 | 331 | timeout=500; |
faker_71 | 6:7c9cc335b762 | 332 | getcount=40; |
star297 | 3:f7febfa77784 | 333 | SendCMD(); |
4180_1 | 4:40dd020463ea | 334 | getreply(); |
faker_71 | 6:7c9cc335b762 | 335 | pc.printf(replybuff); |
faker_71 | 8:d8e164130860 | 336 | pc.printf("\n++++++++++ AT+CIPSENDBUF=%d,%d+++++++++\r\n", linkID, 1500); |
molberry | 9:e458213a7afd | 337 | |
faker_71 | 5:dfea6fd1abba | 338 | pc.printf("\n++++++++++ bufl is %d ++++++++++\r\n",bufl); |
molberry | 9:e458213a7afd | 339 | |
faker_71 | 6:7c9cc335b762 | 340 | //pastthrough mode |
star297 | 0:e2a155f50119 | 341 | SendWEB(); // send web page |
molberry | 9:e458213a7afd | 342 | |
star297 | 3:f7febfa77784 | 343 | memset(webbuff, '\0', sizeof(webbuff)); |
4180_1 | 4:40dd020463ea | 344 | sendcheck(); |
star297 | 0:e2a155f50119 | 345 | } |
star297 | 0:e2a155f50119 | 346 | |
faker_71 | 6:7c9cc335b762 | 347 | // Large WEB buffer data send |
faker_71 | 6:7c9cc335b762 | 348 | void SendWEB() |
faker_71 | 6:7c9cc335b762 | 349 | { |
faker_71 | 6:7c9cc335b762 | 350 | int i=0; |
faker_71 | 6:7c9cc335b762 | 351 | if(esp.writeable()) { |
faker_71 | 6:7c9cc335b762 | 352 | while(webbuff[i]!='\0') { |
faker_71 | 6:7c9cc335b762 | 353 | esp.putc(webbuff[i]); |
molberry | 9:e458213a7afd | 354 | |
molberry | 9:e458213a7afd | 355 | //**** |
molberry | 9:e458213a7afd | 356 | //output at command when 2000 |
molberry | 9:e458213a7afd | 357 | if(i==1499) { |
molberry | 9:e458213a7afd | 358 | wait_ms(10); |
molberry | 9:e458213a7afd | 359 | sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, bufl-1500); // send IPD link channel and buffer character length. |
molberry | 9:e458213a7afd | 360 | pc.printf("\r\n++++++++++ AT+CIPSENDBUF=%d,%d ++++++++++\r\n", linkID, bufl-1500); |
molberry | 9:e458213a7afd | 361 | timeout=600; |
molberry | 9:e458213a7afd | 362 | getcount=50; |
molberry | 9:e458213a7afd | 363 | SendCMD(); |
molberry | 9:e458213a7afd | 364 | getreply(); |
molberry | 9:e458213a7afd | 365 | pc.printf(replybuff); |
molberry | 9:e458213a7afd | 366 | pc.printf("\r\n+++++++++++++++++++\r\n"); |
molberry | 9:e458213a7afd | 367 | |
molberry | 9:e458213a7afd | 368 | } |
molberry | 9:e458213a7afd | 369 | |
molberry | 9:e458213a7afd | 370 | //**** |
molberry | 9:e458213a7afd | 371 | i++; |
faker_71 | 6:7c9cc335b762 | 372 | pc.printf("%c",webbuff[i]); |
faker_71 | 6:7c9cc335b762 | 373 | } |
faker_71 | 6:7c9cc335b762 | 374 | } |
molberry | 9:e458213a7afd | 375 | |
molberry | 9:e458213a7afd | 376 | |
faker_71 | 6:7c9cc335b762 | 377 | //**** |
faker_71 | 6:7c9cc335b762 | 378 | /* |
molberry | 9:e458213a7afd | 379 | sprintf(cmdbuff,"AT+CIPCLOSE\r\n"); // send IPD link channel and buffer character length. |
faker_71 | 6:7c9cc335b762 | 380 | SendCMD(); |
faker_71 | 6:7c9cc335b762 | 381 | */ |
faker_71 | 6:7c9cc335b762 | 382 | //***** |
molberry | 9:e458213a7afd | 383 | |
molberry | 9:e458213a7afd | 384 | pc.printf("\n++++++++++ send web i= %dinfo ++++++++++\r\n",i); |
faker_71 | 6:7c9cc335b762 | 385 | } |
faker_71 | 6:7c9cc335b762 | 386 | |
faker_71 | 6:7c9cc335b762 | 387 | |
star297 | 3:f7febfa77784 | 388 | // wait for ESP "SEND OK" reply, then close IP to load web page |
faker_71 | 6:7c9cc335b762 | 389 | |
faker_71 | 6:7c9cc335b762 | 390 | //touchuan mode |
molberry | 9:e458213a7afd | 391 | void touchuan() |
molberry | 9:e458213a7afd | 392 | { |
faker_71 | 6:7c9cc335b762 | 393 | strcpy(cmdbuff, "AT+CIPMUX=0\r\n"); |
faker_71 | 6:7c9cc335b762 | 394 | pc.printf("\n++++++++++ AT+CIPMUX=0\r\n+++++++++"); |
faker_71 | 6:7c9cc335b762 | 395 | timeout=500; |
faker_71 | 6:7c9cc335b762 | 396 | getcount=40; |
faker_71 | 6:7c9cc335b762 | 397 | SendCMD(); |
faker_71 | 6:7c9cc335b762 | 398 | getreply(); |
faker_71 | 6:7c9cc335b762 | 399 | pc.printf(replybuff); |
faker_71 | 6:7c9cc335b762 | 400 | strcpy(cmdbuff, "AT+CIPSTART=\"TCP\",\"192.168.4.2\",8080\r\n"); // send IPD link channel and buffer character length. |
faker_71 | 6:7c9cc335b762 | 401 | pc.printf("\n++++++++++ AT+CIPSTART=0\r\n+++++++++"); |
faker_71 | 6:7c9cc335b762 | 402 | timeout=500; |
faker_71 | 6:7c9cc335b762 | 403 | getcount=40; |
faker_71 | 6:7c9cc335b762 | 404 | SendCMD(); |
faker_71 | 6:7c9cc335b762 | 405 | getreply(); |
faker_71 | 6:7c9cc335b762 | 406 | pc.printf(replybuff); |
faker_71 | 6:7c9cc335b762 | 407 | strcpy(cmdbuff, "AT+CIPMODE=1\r\n"); // send IPD link channel and buffer character length. |
faker_71 | 6:7c9cc335b762 | 408 | pc.printf("\n++++++++++ AT+CIPMODE=1\r\n+++++++++"); |
faker_71 | 6:7c9cc335b762 | 409 | timeout=500; |
faker_71 | 6:7c9cc335b762 | 410 | getcount=40; |
faker_71 | 6:7c9cc335b762 | 411 | SendCMD(); |
faker_71 | 6:7c9cc335b762 | 412 | getreply(); |
faker_71 | 6:7c9cc335b762 | 413 | pc.printf(replybuff); |
faker_71 | 6:7c9cc335b762 | 414 | strcpy(cmdbuff, "AT+CIPSEND\r\n"); // send IPD link channel and buffer character length. |
faker_71 | 6:7c9cc335b762 | 415 | pc.printf("\n++++++++++ AT+CIPSEND\r\n+++++++++"); |
faker_71 | 6:7c9cc335b762 | 416 | timeout=500; |
faker_71 | 6:7c9cc335b762 | 417 | getcount=40; |
faker_71 | 6:7c9cc335b762 | 418 | SendCMD(); |
faker_71 | 6:7c9cc335b762 | 419 | getreply(); |
faker_71 | 6:7c9cc335b762 | 420 | pc.printf(replybuff); |
faker_71 | 6:7c9cc335b762 | 421 | } |
molberry | 9:e458213a7afd | 422 | |
star297 | 0:e2a155f50119 | 423 | void sendcheck() |
star297 | 0:e2a155f50119 | 424 | { |
4180_1 | 4:40dd020463ea | 425 | weberror=1; |
4180_1 | 4:40dd020463ea | 426 | timeout=500; |
4180_1 | 4:40dd020463ea | 427 | getcount=24; |
4180_1 | 4:40dd020463ea | 428 | t2.reset(); |
4180_1 | 4:40dd020463ea | 429 | t2.start(); |
4180_1 | 4:40dd020463ea | 430 | while(weberror==1 && t2.read() <5) { |
star297 | 0:e2a155f50119 | 431 | getreply(); |
4180_1 | 4:40dd020463ea | 432 | if (strstr(replybuff, "SEND OK") != NULL) { |
4180_1 | 4:40dd020463ea | 433 | weberror=0; // wait for valid SEND OK |
star297 | 0:e2a155f50119 | 434 | } |
4180_1 | 4:40dd020463ea | 435 | } |
4180_1 | 4:40dd020463ea | 436 | if(weberror==1) { // restart connection |
4180_1 | 4:40dd020463ea | 437 | strcpy(cmdbuff, "AT+CIPMUX=1\r\n"); |
4180_1 | 4:40dd020463ea | 438 | timeout=500; |
4180_1 | 4:40dd020463ea | 439 | getcount=10; |
4180_1 | 4:40dd020463ea | 440 | SendCMD(); |
4180_1 | 4:40dd020463ea | 441 | getreply(); |
4180_1 | 4:40dd020463ea | 442 | pc.printf(replybuff); |
star297 | 3:f7febfa77784 | 443 | sprintf(cmdbuff,"AT+CIPSERVER=1,%d\r\n", port); |
4180_1 | 4:40dd020463ea | 444 | timeout=500; |
4180_1 | 4:40dd020463ea | 445 | getcount=10; |
4180_1 | 4:40dd020463ea | 446 | SendCMD(); |
4180_1 | 4:40dd020463ea | 447 | getreply(); |
4180_1 | 4:40dd020463ea | 448 | pc.printf(replybuff); |
4180_1 | 4:40dd020463ea | 449 | } else { |
4180_1 | 4:40dd020463ea | 450 | sprintf(cmdbuff, "AT+CIPCLOSE=%s\r\n",channel); // close current connection |
4180_1 | 4:40dd020463ea | 451 | SendCMD(); |
4180_1 | 4:40dd020463ea | 452 | getreply(); |
4180_1 | 4:40dd020463ea | 453 | pc.printf(replybuff); |
4180_1 | 4:40dd020463ea | 454 | } |
4180_1 | 4:40dd020463ea | 455 | t2.reset(); |
4180_1 | 4:40dd020463ea | 456 | } |
star297 | 0:e2a155f50119 | 457 | |
4180_1 | 4:40dd020463ea | 458 | // Reads and processes GET and POST web data |
star297 | 0:e2a155f50119 | 459 | void ReadWebData() |
4180_1 | 4:40dd020463ea | 460 | { |
4180_1 | 4:40dd020463ea | 461 | wait_ms(200); |
star297 | 3:f7febfa77784 | 462 | esp.attach(NULL); |
4180_1 | 4:40dd020463ea | 463 | count=0; |
4180_1 | 4:40dd020463ea | 464 | DataRX=0; |
4180_1 | 4:40dd020463ea | 465 | weberror=0; |
4180_1 | 4:40dd020463ea | 466 | memset(webdata, '\0', sizeof(webdata)); |
star297 | 3:f7febfa77784 | 467 | int x = strcspn (webbuff,"+"); |
4180_1 | 4:40dd020463ea | 468 | if(x) { |
4180_1 | 4:40dd020463ea | 469 | strcpy(webdata, webbuff + x); |
4180_1 | 4:40dd020463ea | 470 | weberror=0; |
4180_1 | 4:40dd020463ea | 471 | int numMatched = sscanf(webdata,"+IPD,%d,%d:%s", &linkID, &ipdLen, type); |
faker_71 | 6:7c9cc335b762 | 472 | //int i=0; |
faker_71 | 5:dfea6fd1abba | 473 | pc.printf("+++++++++++++++++succed+++++++++++++++++++++"); |
faker_71 | 5:dfea6fd1abba | 474 | pc.printf("%s",webdata); |
molberry | 9:e458213a7afd | 475 | |
molberry | 9:e458213a7afd | 476 | |
molberry | 9:e458213a7afd | 477 | |
molberry | 9:e458213a7afd | 478 | if( strstr(webdata, "GO") != NULL ) { |
molberry | 9:e458213a7afd | 479 | pc.printf("+++++++++++++++++前進+++++++++++++++++++++\r\n"); |
molberry | 9:e458213a7afd | 480 | avoi_thread.stop(); // avoidanceスレッド停止 |
molberry | 9:e458213a7afd | 481 | trace_thread.stop(); // traceスレッド停止 |
molberry | 9:e458213a7afd | 482 | run = ADVANCE; // 前進 |
molberry | 9:e458213a7afd | 483 | mode = READY; // モードs変更 |
molberry | 9:e458213a7afd | 484 | motor_thread.start(); // motorスレッド再開 |
molberry | 9:e458213a7afd | 485 | display(); // ディスプレイ表示 |
molberry | 9:e458213a7afd | 486 | |
molberry | 9:e458213a7afd | 487 | } |
molberry | 9:e458213a7afd | 488 | |
faker_71 | 5:dfea6fd1abba | 489 | if( strstr(webdata, "LEFT") != NULL ) { |
molberry | 9:e458213a7afd | 490 | pc.printf("+++++++++++++++++左折+++++++++++++++++++++\r\n"); |
molberry | 9:e458213a7afd | 491 | avoi_thread.stop(); // avoidanceスレッド停止 |
molberry | 9:e458213a7afd | 492 | trace_thread.stop(); // traceスレッド停止 |
molberry | 9:e458213a7afd | 493 | run = LEFT; |
molberry | 9:e458213a7afd | 494 | mode = READY; |
molberry | 9:e458213a7afd | 495 | motor_thread.start(); // motorスレッド再開 |
molberry | 9:e458213a7afd | 496 | display(); // ディスプレイ表示 |
molberry | 9:e458213a7afd | 497 | } |
molberry | 9:e458213a7afd | 498 | |
molberry | 9:e458213a7afd | 499 | if( strstr(webdata, "STOP") != NULL ) { |
molberry | 9:e458213a7afd | 500 | pc.printf("+++++++++++++++++停止+++++++++++++++++++++\r\n"); |
molberry | 9:e458213a7afd | 501 | avoi_thread.stop(); // avoidanceスレッド停止 |
molberry | 9:e458213a7afd | 502 | trace_thread.stop(); // traceスレッド停止 |
molberry | 9:e458213a7afd | 503 | run = STOP; |
molberry | 9:e458213a7afd | 504 | mode = READY; |
molberry | 9:e458213a7afd | 505 | motor_thread.start(); // motorスレッド再開 |
molberry | 9:e458213a7afd | 506 | display(); // ディスプレイ表示 |
faker_71 | 5:dfea6fd1abba | 507 | } |
molberry | 9:e458213a7afd | 508 | |
faker_71 | 5:dfea6fd1abba | 509 | if( strstr(webdata, "RIGHT") != NULL ) { |
molberry | 9:e458213a7afd | 510 | pc.printf("+++++++++++++++++右折+++++++++++++++++++++\r\n"); |
molberry | 9:e458213a7afd | 511 | avoi_thread.stop(); // avoidanceスレッド停止 |
molberry | 9:e458213a7afd | 512 | trace_thread.stop(); // traceスレッド停止 |
molberry | 9:e458213a7afd | 513 | run = RIGHT; |
molberry | 9:e458213a7afd | 514 | mode = READY; |
molberry | 9:e458213a7afd | 515 | motor_thread.start(); // motorスレッド再開 |
molberry | 9:e458213a7afd | 516 | display(); // ディスプレイ表示 |
molberry | 9:e458213a7afd | 517 | } |
molberry | 9:e458213a7afd | 518 | |
molberry | 9:e458213a7afd | 519 | if( strstr(webdata, "BACK") != NULL ) { |
molberry | 9:e458213a7afd | 520 | pc.printf("+++++++++++++++++後進+++++++++++++++++++++\r\n"); |
molberry | 9:e458213a7afd | 521 | avoi_thread.stop(); // avoidanceスレッド停止 |
molberry | 9:e458213a7afd | 522 | trace_thread.stop(); // traceスレッド停止 |
molberry | 9:e458213a7afd | 523 | run = BACK; |
molberry | 9:e458213a7afd | 524 | mode = READY; |
molberry | 9:e458213a7afd | 525 | motor_thread.start(); // motorスレッド再開 |
molberry | 9:e458213a7afd | 526 | display(); // ディスプレイ表示 |
faker_71 | 5:dfea6fd1abba | 527 | } |
faker_71 | 5:dfea6fd1abba | 528 | pc.printf("+++++++++++++++++succed+++++++++++++++++++++"); |
molberry | 9:e458213a7afd | 529 | |
molberry | 9:e458213a7afd | 530 | if( strstr(webdata, "AVOIDANCE") != NULL ) { |
molberry | 9:e458213a7afd | 531 | pc.printf("+++++++++++++++++AVOIDANCE+++++++++++++++++++++"); |
molberry | 9:e458213a7afd | 532 | trace_thread.stop(); // traceスレッド停止 |
molberry | 9:e458213a7afd | 533 | avoi_thread.start(); // avoidanceスレッド再開 |
molberry | 9:e458213a7afd | 534 | motor_thread.start(); // motorスレッド再開 |
molberry | 9:e458213a7afd | 535 | mode=AVOIDANCE; |
molberry | 9:e458213a7afd | 536 | run = ADVANCE; |
molberry | 9:e458213a7afd | 537 | display(); // ディスプレイ表示 |
faker_71 | 5:dfea6fd1abba | 538 | } |
molberry | 9:e458213a7afd | 539 | if( strstr(webdata, "LINE TRACE") != NULL ) { |
molberry | 9:e458213a7afd | 540 | pc.printf("+++++++++++++++++LINET RACE+++++++++++++++++++++"); |
molberry | 9:e458213a7afd | 541 | avoi_thread.stop(); // avoidanceスレッド再開 |
molberry | 9:e458213a7afd | 542 | trace_thread.start(); // traceスレッド停止 |
molberry | 9:e458213a7afd | 543 | motor_thread.start(); // motorスレッド再開 |
molberry | 9:e458213a7afd | 544 | mode=LINE_TRACE; |
molberry | 9:e458213a7afd | 545 | display(); // ディスプレイ表示 |
4180_1 | 4:40dd020463ea | 546 | } |
molberry | 9:e458213a7afd | 547 | if( strstr(webdata, "DEFAULT") != NULL ) {//プログラムなくね |
molberry | 9:e458213a7afd | 548 | pc.printf("+++++++++++++++++DEFAULT+++++++++++++++++++++"); |
molberry | 9:e458213a7afd | 549 | avoi_thread.stop(); // avoidanceスレッド再開 |
molberry | 9:e458213a7afd | 550 | trace_thread.stop(); // traceスレッド停止 |
molberry | 9:e458213a7afd | 551 | run = STOP; |
molberry | 9:e458213a7afd | 552 | mode = READY; |
molberry | 9:e458213a7afd | 553 | motor_thread.start(); // motorスレッド再開 |
molberry | 9:e458213a7afd | 554 | display(); // ディスプレイ表示 |
molberry | 9:e458213a7afd | 555 | |
4180_1 | 4:40dd020463ea | 556 | } |
molberry | 9:e458213a7afd | 557 | if( strstr(webdata, "SLOW") != NULL ) { |
molberry | 9:e458213a7afd | 558 | pc.printf("++++++++++++++++++SLOW++++++++++++++++++++"); |
molberry | 9:e458213a7afd | 559 | mode = SPEED; // スピードモード |
molberry | 9:e458213a7afd | 560 | flag_sp = 0; |
molberry | 9:e458213a7afd | 561 | display(); // ディスプレイ表示 |
molberry | 9:e458213a7afd | 562 | mode = beforeMode; // 現在のモードに前回のモードを設定 |
4180_1 | 4:40dd020463ea | 563 | } |
molberry | 9:e458213a7afd | 564 | if( strstr(webdata, "FAST") != NULL ) { |
molberry | 9:e458213a7afd | 565 | pc.printf("++++++++++++++++++++FAST++++++++++++++++++"); |
molberry | 9:e458213a7afd | 566 | mode = SPEED; // スピードモード |
molberry | 9:e458213a7afd | 567 | flag_sp = 1; |
molberry | 9:e458213a7afd | 568 | display(); // ディスプレイ表示 |
molberry | 9:e458213a7afd | 569 | mode = beforeMode; // 現在のモードに前回のモードを設定 |
4180_1 | 4:40dd020463ea | 570 | } |
molberry | 9:e458213a7afd | 571 | if( strstr(webdata, "FLY") != NULL ) { |
molberry | 9:e458213a7afd | 572 | pc.printf("+++++++++++++++++++BERYFAST+++++++++++++++++++"); |
molberry | 9:e458213a7afd | 573 | mode = SPEED; // スピードモード d |
molberry | 9:e458213a7afd | 574 | flag_sp = 2; |
molberry | 9:e458213a7afd | 575 | display(); // ディスプレイ表示 |
molberry | 9:e458213a7afd | 576 | mode = beforeMode; // 現在のモードに前回のモードを設定 |
4180_1 | 4:40dd020463ea | 577 | } |
4180_1 | 4:40dd020463ea | 578 | sprintf(channel, "%d",linkID); |
4180_1 | 4:40dd020463ea | 579 | if (strstr(webdata, "GET") != NULL) { |
4180_1 | 4:40dd020463ea | 580 | servreq=1; |
4180_1 | 4:40dd020463ea | 581 | } |
4180_1 | 4:40dd020463ea | 582 | if (strstr(webdata, "POST") != NULL) { |
4180_1 | 4:40dd020463ea | 583 | servreq=1; |
4180_1 | 4:40dd020463ea | 584 | } |
star297 | 2:d4c6bc0f2dc4 | 585 | webcounter++; |
star297 | 2:d4c6bc0f2dc4 | 586 | sprintf(webcount, "%d",webcounter); |
4180_1 | 4:40dd020463ea | 587 | } else { |
4180_1 | 4:40dd020463ea | 588 | memset(webbuff, '\0', sizeof(webbuff)); |
4180_1 | 4:40dd020463ea | 589 | esp.attach(&callback); |
4180_1 | 4:40dd020463ea | 590 | weberror=1; |
4180_1 | 4:40dd020463ea | 591 | } |
star297 | 0:e2a155f50119 | 592 | } |
star297 | 0:e2a155f50119 | 593 | // Starts and restarts webserver if errors detected. |
star297 | 0:e2a155f50119 | 594 | void startserver() |
star297 | 0:e2a155f50119 | 595 | { |
4180_1 | 4:40dd020463ea | 596 | gettemp(); |
4180_1 | 4:40dd020463ea | 597 | gettime(); |
star297 | 1:71ed1afbf344 | 598 | pc.printf("\n\n RTC time %s\r\n\n",timebuf); |
4180_1 | 4:40dd020463ea | 599 | pc.printf("++++++++++ Resetting ESP ++++++++++\r\n"); |
star297 | 3:f7febfa77784 | 600 | strcpy(cmdbuff,"AT+RST\r\n"); |
4180_1 | 4:40dd020463ea | 601 | timeout=8000; |
4180_1 | 4:40dd020463ea | 602 | getcount=1000; |
star297 | 0:e2a155f50119 | 603 | SendCMD(); |
star297 | 1:71ed1afbf344 | 604 | getreply(); |
star297 | 3:f7febfa77784 | 605 | pc.printf(replybuff); |
star297 | 3:f7febfa77784 | 606 | pc.printf("%d",count); |
star297 | 3:f7febfa77784 | 607 | if (strstr(replybuff, "OK") != NULL) { |
star297 | 1:71ed1afbf344 | 608 | pc.printf("\n++++++++++ Starting Server ++++++++++\r\n"); |
4180_1 | 4:40dd020463ea | 609 | strcpy(cmdbuff, "AT+CIPMUX=1\r\n"); // set multiple connections. |
4180_1 | 4:40dd020463ea | 610 | timeout=500; |
4180_1 | 4:40dd020463ea | 611 | getcount=20; |
star297 | 1:71ed1afbf344 | 612 | SendCMD(); |
star297 | 2:d4c6bc0f2dc4 | 613 | getreply(); |
4180_1 | 4:40dd020463ea | 614 | pc.printf(replybuff); |
star297 | 3:f7febfa77784 | 615 | sprintf(cmdbuff,"AT+CIPSERVER=1,%d\r\n", port); |
4180_1 | 4:40dd020463ea | 616 | timeout=500; |
4180_1 | 4:40dd020463ea | 617 | getcount=20; |
star297 | 1:71ed1afbf344 | 618 | SendCMD(); |
star297 | 3:f7febfa77784 | 619 | getreply(); |
4180_1 | 4:40dd020463ea | 620 | pc.printf(replybuff); |
4180_1 | 4:40dd020463ea | 621 | wait(1); |
star297 | 3:f7febfa77784 | 622 | sprintf(cmdbuff,"AT+CIPSTO=%d\r\n",SERVtimeout); |
4180_1 | 4:40dd020463ea | 623 | timeout=500; |
4180_1 | 4:40dd020463ea | 624 | getcount=50; |
star297 | 3:f7febfa77784 | 625 | SendCMD(); |
star297 | 2:d4c6bc0f2dc4 | 626 | getreply(); |
4180_1 | 4:40dd020463ea | 627 | pc.printf(replybuff); |
4180_1 | 4:40dd020463ea | 628 | wait(5); |
4180_1 | 4:40dd020463ea | 629 | pc.printf("\n Getting Server IP \r\n"); |
star297 | 3:f7febfa77784 | 630 | strcpy(cmdbuff, "AT+CIFSR\r\n"); |
4180_1 | 4:40dd020463ea | 631 | timeout=2500; |
4180_1 | 4:40dd020463ea | 632 | getcount=200; |
4180_1 | 4:40dd020463ea | 633 | while(weberror==0) { |
4180_1 | 4:40dd020463ea | 634 | SendCMD(); |
4180_1 | 4:40dd020463ea | 635 | getreply(); |
4180_1 | 4:40dd020463ea | 636 | if (strstr(replybuff, "0.0.0.0") == NULL) { |
4180_1 | 4:40dd020463ea | 637 | weberror=1; // wait for valid IP |
star297 | 1:71ed1afbf344 | 638 | } |
4180_1 | 4:40dd020463ea | 639 | } |
4180_1 | 4:40dd020463ea | 640 | pc.printf("\n Enter WEB address (IP) found below in your browser \r\n\n"); |
4180_1 | 4:40dd020463ea | 641 | pc.printf("\n The MAC address is also shown below,if it is needed \r\n\n"); |
4180_1 | 4:40dd020463ea | 642 | replybuff[strlen(replybuff)-1] = '\0'; |
4180_1 | 4:40dd020463ea | 643 | //char* IP = replybuff + 5; |
4180_1 | 4:40dd020463ea | 644 | sprintf(webdata,"%s", replybuff); |
4180_1 | 4:40dd020463ea | 645 | pc.printf(webdata); |
4180_1 | 4:40dd020463ea | 646 | led2=1; |
4180_1 | 4:40dd020463ea | 647 | bufflen=200; |
4180_1 | 4:40dd020463ea | 648 | count=0; |
star297 | 1:71ed1afbf344 | 649 | pc.printf("\n\n++++++++++ Ready ++++++++++\r\n\n"); |
star297 | 1:71ed1afbf344 | 650 | esp.attach(&callback); |
4180_1 | 4:40dd020463ea | 651 | } else { |
4180_1 | 4:40dd020463ea | 652 | pc.printf("\n++++++++++ ESP8266 error, check power/connections ++++++++++\r\n"); |
4180_1 | 4:40dd020463ea | 653 | while(1) {} |
4180_1 | 4:40dd020463ea | 654 | } |
4180_1 | 4:40dd020463ea | 655 | t2.reset(); |
4180_1 | 4:40dd020463ea | 656 | t2.start(); |
4180_1 | 4:40dd020463ea | 657 | beep(); |
4180_1 | 4:40dd020463ea | 658 | } |
star297 | 0:e2a155f50119 | 659 | // ESP Command data send |
star297 | 0:e2a155f50119 | 660 | void SendCMD() |
star297 | 0:e2a155f50119 | 661 | { |
4180_1 | 4:40dd020463ea | 662 | esp.printf("%s", cmdbuff); |
4180_1 | 4:40dd020463ea | 663 | } |
4180_1 | 4:40dd020463ea | 664 | // Get Command and ESP status replies |
star297 | 0:e2a155f50119 | 665 | void getreply() |
4180_1 | 4:40dd020463ea | 666 | { |
star297 | 3:f7febfa77784 | 667 | memset(replybuff, '\0', sizeof(replybuff)); |
4180_1 | 4:40dd020463ea | 668 | t1.reset(); |
4180_1 | 4:40dd020463ea | 669 | t1.start(); |
4180_1 | 4:40dd020463ea | 670 | replycount=0; |
star297 | 3:f7febfa77784 | 671 | while(t1.read_ms()< timeout && replycount < getcount) { |
star297 | 0:e2a155f50119 | 672 | if(esp.readable()) { |
4180_1 | 4:40dd020463ea | 673 | replybuff[replycount] = esp.getc(); |
4180_1 | 4:40dd020463ea | 674 | replycount++; |
star297 | 2:d4c6bc0f2dc4 | 675 | } |
4180_1 | 4:40dd020463ea | 676 | } |
4180_1 | 4:40dd020463ea | 677 | t1.stop(); |
star297 | 0:e2a155f50119 | 678 | } |
star297 | 0:e2a155f50119 | 679 | // Analog in example |
star297 | 0:e2a155f50119 | 680 | void getbattery() |
star297 | 0:e2a155f50119 | 681 | { |
4180_1 | 4:40dd020463ea | 682 | AdcIn=Ain1.read(); |
4180_1 | 4:40dd020463ea | 683 | Ht = (AdcIn*3.3); // set the numeric to the exact MCU analog reference voltage for greater accuracy |
4180_1 | 4:40dd020463ea | 684 | sprintf(Vcc,"%2.3f",Ht); |
star297 | 0:e2a155f50119 | 685 | } |
molberry | 9:e458213a7afd | 686 | |
4180_1 | 4:40dd020463ea | 687 | // Get RTC time |
star297 | 0:e2a155f50119 | 688 | void gettime() |
star297 | 0:e2a155f50119 | 689 | { |
star297 | 0:e2a155f50119 | 690 | time_t seconds = time(NULL); |
4180_1 | 4:40dd020463ea | 691 | strftime(timebuf,50,"%H:%M:%S %a %d %b %y", localtime(&seconds)); |
star297 | 0:e2a155f50119 | 692 | } |
star297 | 0:e2a155f50119 | 693 | |
star297 | 1:71ed1afbf344 | 694 | void setRTC() |
star297 | 1:71ed1afbf344 | 695 | { |
4180_1 | 4:40dd020463ea | 696 | t.tm_sec = (0); // 0-59 |
4180_1 | 4:40dd020463ea | 697 | t.tm_min = (minute); // 0-59 |
4180_1 | 4:40dd020463ea | 698 | t.tm_hour = (hour); // 0-23 |
4180_1 | 4:40dd020463ea | 699 | t.tm_mday = (dayofmonth); // 1-31 |
4180_1 | 4:40dd020463ea | 700 | t.tm_mon = (month-1); // 0-11 "0" = Jan, -1 added for Mbed RCT clock format |
4180_1 | 4:40dd020463ea | 701 | t.tm_year = ((year)+100); // year since 1900, current DCF year + 100 + 1900 = correct year |
4180_1 | 4:40dd020463ea | 702 | set_time(mktime(&t)); // set RTC clock |
4180_1 | 4:40dd020463ea | 703 | } |