Library für ESP01 Webserver STM32F103RB Nucleo
Dependents: Nucleo_dht11_Webserver WebServerGSOEWorkshopSlider WebServerGSOEWorkshopDynamisch WebServerGSOEWorkshopStatisch ... more
ESP8266Webserver.cpp@17:87c762acb8d0, 2021-06-22 (annotated)
- Committer:
- jack1930
- Date:
- Tue Jun 22 09:58:10 2021 +0000
- Revision:
- 17:87c762acb8d0
- Parent:
- 16:b09391fb73b4
- Child:
- 19:e0bcbb2a3480
kleinere Bugs beseitigt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jack1930 | 13:ed5c59ed4ae5 | 1 | #include "ESP8266Webserver.h" |
jack1930 | 16:b09391fb73b4 | 2 | //#include "string" |
jack1930 | 13:ed5c59ed4ae5 | 3 | |
jack1930 | 14:d17cfd8131b1 | 4 | ESP8266Webserver::ESP8266Webserver() |
jack1930 | 13:ed5c59ed4ae5 | 5 | { |
jack1930 | 17:87c762acb8d0 | 6 | bool erg; |
jack1930 | 13:ed5c59ed4ae5 | 7 | //HAL_Delay(1000); |
jack1930 | 13:ed5c59ed4ae5 | 8 | hs_count=0; |
jack1930 | 13:ed5c59ed4ae5 | 9 | clientIdx=0; |
jack1930 | 13:ed5c59ed4ae5 | 10 | if (pDebug) printf("\nATCmdParser with ESP8266 example"); |
jack1930 | 13:ed5c59ed4ae5 | 11 | port=Port; |
jack1930 | 13:ed5c59ed4ae5 | 12 | |
jack1930 | 13:ed5c59ed4ae5 | 13 | dbg=pDebug; |
jack1930 | 13:ed5c59ed4ae5 | 14 | _serial = new BufferedSerial(tx,rx, ESP8266_DEFAULT_BAUD_RATE); |
jack1930 | 13:ed5c59ed4ae5 | 15 | _parser = new ATCmdParser(_serial, "\r\n"); |
jack1930 | 17:87c762acb8d0 | 16 | _parser->debug_on(true); |
jack1930 | 13:ed5c59ed4ae5 | 17 | |
jack1930 | 17:87c762acb8d0 | 18 | _parser->set_timeout(2000); |
jack1930 | 13:ed5c59ed4ae5 | 19 | |
jack1930 | 13:ed5c59ed4ae5 | 20 | //AT |
jack1930 | 13:ed5c59ed4ae5 | 21 | if (pDebug) printf("\nATCmdParser: AT\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 22 | _parser->send("AT"); |
jack1930 | 13:ed5c59ed4ae5 | 23 | |
jack1930 | 13:ed5c59ed4ae5 | 24 | if (_parser->recv("OK")) { |
jack1930 | 13:ed5c59ed4ae5 | 25 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 26 | } else { |
jack1930 | 17:87c762acb8d0 | 27 | printf("\nATCmdParser: AT OK failed\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 28 | } |
jack1930 | 15:e710f0431920 | 29 | |
jack1930 | 15:e710f0431920 | 30 | if (station==true) |
jack1930 | 15:e710f0431920 | 31 | { |
jack1930 | 15:e710f0431920 | 32 | listAPs(); |
jack1930 | 15:e710f0431920 | 33 | printf("%s",ipadr); |
jack1930 | 15:e710f0431920 | 34 | } |
jack1930 | 15:e710f0431920 | 35 | else { |
jack1930 | 15:e710f0431920 | 36 | _parser->send("ATE0"); |
jack1930 | 15:e710f0431920 | 37 | strcpy(ipadr,ip); |
jack1930 | 13:ed5c59ed4ae5 | 38 | |
jack1930 | 15:e710f0431920 | 39 | if (pDebug) printf("\nATCmdParser: //AT+CWMODE=2 \r\n"); |
jack1930 | 17:87c762acb8d0 | 40 | |
jack1930 | 15:e710f0431920 | 41 | _parser->send("AT+CWMODE=2"); |
jack1930 | 17:87c762acb8d0 | 42 | HAL_Delay(1000); |
jack1930 | 15:e710f0431920 | 43 | |
jack1930 | 15:e710f0431920 | 44 | if (_parser->recv("OK")) { |
jack1930 | 15:e710f0431920 | 45 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 15:e710f0431920 | 46 | } else { |
jack1930 | 17:87c762acb8d0 | 47 | printf("\nATCmdParser: AT+CWMODE=2 OK failed\r\n"); |
jack1930 | 15:e710f0431920 | 48 | } |
jack1930 | 15:e710f0431920 | 49 | |
jack1930 | 13:ed5c59ed4ae5 | 50 | //AT+CWMODE? |
jack1930 | 13:ed5c59ed4ae5 | 51 | if (pDebug) printf("\nATCmdParser: //AT+CWMODE? \r\n"); |
jack1930 | 17:87c762acb8d0 | 52 | |
jack1930 | 13:ed5c59ed4ae5 | 53 | _parser->send("AT+CWMODE?"); |
jack1930 | 13:ed5c59ed4ae5 | 54 | |
jack1930 | 13:ed5c59ed4ae5 | 55 | if (_parser->recv("OK")) { |
jack1930 | 13:ed5c59ed4ae5 | 56 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 57 | } else { |
jack1930 | 17:87c762acb8d0 | 58 | printf("\nATCmdParser: AT+CWMODE? OK failed\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 59 | } |
jack1930 | 13:ed5c59ed4ae5 | 60 | |
jack1930 | 17:87c762acb8d0 | 61 | |
jack1930 | 17:87c762acb8d0 | 62 | //AT+CIPAP="192.168.5.1","192.168.5.1","255.255.255.0" |
jack1930 | 15:e710f0431920 | 63 | if (pDebug) printf("\nATCmdParser: //AT+CIPAP=\"%s\",\"%s\",\"%s\" \r\n",ipad.c_str(),ipad.c_str(),netzmaske); |
jack1930 | 17:87c762acb8d0 | 64 | do |
jack1930 | 17:87c762acb8d0 | 65 | { |
jack1930 | 17:87c762acb8d0 | 66 | _parser->send("AT+CIPAP=\"%s\",\"%s\",\"%s\"",ipad.c_str(),ipad.c_str(),netzmaske); |
jack1930 | 17:87c762acb8d0 | 67 | erg=_parser->recv("OK"); |
jack1930 | 17:87c762acb8d0 | 68 | if (erg==true) { |
jack1930 | 17:87c762acb8d0 | 69 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 17:87c762acb8d0 | 70 | } else { |
jack1930 | 17:87c762acb8d0 | 71 | printf("\nATCmdParser: AT+CIPAP OK failed\r\n"); |
jack1930 | 17:87c762acb8d0 | 72 | HAL_Delay(1000); |
jack1930 | 17:87c762acb8d0 | 73 | } |
jack1930 | 17:87c762acb8d0 | 74 | } |
jack1930 | 17:87c762acb8d0 | 75 | while (erg==false); |
jack1930 | 15:e710f0431920 | 76 | |
jack1930 | 15:e710f0431920 | 77 | |
jack1930 | 13:ed5c59ed4ae5 | 78 | |
jack1930 | 13:ed5c59ed4ae5 | 79 | //AT+CIPMUX=1 |
jack1930 | 13:ed5c59ed4ae5 | 80 | if (pDebug) printf("\nATCmdParser: //AT+CIPMUX=1"); |
jack1930 | 13:ed5c59ed4ae5 | 81 | _parser->send("AT+CIPMUX=1"); |
jack1930 | 13:ed5c59ed4ae5 | 82 | |
jack1930 | 13:ed5c59ed4ae5 | 83 | if (_parser->recv("OK")) { |
jack1930 | 13:ed5c59ed4ae5 | 84 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 85 | } else { |
jack1930 | 17:87c762acb8d0 | 86 | printf("\nATCmdParser: AT+CIPMUX=1 OK failed\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 87 | } |
jack1930 | 15:e710f0431920 | 88 | } |
jack1930 | 13:ed5c59ed4ae5 | 89 | } |
jack1930 | 13:ed5c59ed4ae5 | 90 | |
jack1930 | 13:ed5c59ed4ae5 | 91 | int ESP8266Webserver::on(const char* handlestring,Callback< void()> func) |
jack1930 | 13:ed5c59ed4ae5 | 92 | { |
jack1930 | 13:ed5c59ed4ae5 | 93 | if (hs_count>9) return -1; |
jack1930 | 13:ed5c59ed4ae5 | 94 | else |
jack1930 | 13:ed5c59ed4ae5 | 95 | { |
jack1930 | 13:ed5c59ed4ae5 | 96 | strcpy(hs[hs_count],handlestring); |
jack1930 | 13:ed5c59ed4ae5 | 97 | if (dbg) printf("\r\n\r\n%s, %s\r\n",handlestring,hs[hs_count]); |
jack1930 | 13:ed5c59ed4ae5 | 98 | cbs[hs_count]=func; |
jack1930 | 13:ed5c59ed4ae5 | 99 | hs_count++; |
jack1930 | 13:ed5c59ed4ae5 | 100 | return 0; |
jack1930 | 13:ed5c59ed4ae5 | 101 | } |
jack1930 | 13:ed5c59ed4ae5 | 102 | |
jack1930 | 13:ed5c59ed4ae5 | 103 | } |
jack1930 | 13:ed5c59ed4ae5 | 104 | |
jack1930 | 13:ed5c59ed4ae5 | 105 | int ESP8266Webserver::begin(void) |
jack1930 | 13:ed5c59ed4ae5 | 106 | { |
jack1930 | 13:ed5c59ed4ae5 | 107 | //AT+CIPSERVER=1,80 |
jack1930 | 15:e710f0431920 | 108 | if (dbg) printf("\nATCmdParser: //AT+CIPSERVER=1,%d",Port); |
jack1930 | 15:e710f0431920 | 109 | _parser->send("AT+CIPSERVER=1,%d",Port); |
jack1930 | 13:ed5c59ed4ae5 | 110 | if (_parser->recv("OK")) { |
jack1930 | 13:ed5c59ed4ae5 | 111 | if (dbg) printf("\nAntw.: OK\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 112 | return 0; |
jack1930 | 13:ed5c59ed4ae5 | 113 | } else { |
jack1930 | 17:87c762acb8d0 | 114 | printf("\nATCmdParser: AT+CIPSERVER=1 OK failed\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 115 | return -1; |
jack1930 | 13:ed5c59ed4ae5 | 116 | } |
jack1930 | 13:ed5c59ed4ae5 | 117 | } |
jack1930 | 13:ed5c59ed4ae5 | 118 | |
jack1930 | 13:ed5c59ed4ae5 | 119 | //durchsucht recbuf nach suchstring |
jack1930 | 13:ed5c59ed4ae5 | 120 | bool ESP8266Webserver::beinhaltet(char* suchstring) |
jack1930 | 13:ed5c59ed4ae5 | 121 | { |
jack1930 | 13:ed5c59ed4ae5 | 122 | char* referer; |
jack1930 | 13:ed5c59ed4ae5 | 123 | char* fundort; |
jack1930 | 13:ed5c59ed4ae5 | 124 | char* favicon; |
jack1930 | 13:ed5c59ed4ae5 | 125 | favicon=strstr(recbuf,"favicon"); |
jack1930 | 13:ed5c59ed4ae5 | 126 | if (favicon!=NULL) return false; |
jack1930 | 13:ed5c59ed4ae5 | 127 | referer=strstr(recbuf,"Referer"); |
jack1930 | 13:ed5c59ed4ae5 | 128 | fundort=strstr(recbuf, suchstring); |
jack1930 | 13:ed5c59ed4ae5 | 129 | if (strstr(recbuf,"ERROR")==NULL) |
jack1930 | 13:ed5c59ed4ae5 | 130 | if( fundort != NULL&&(fundort<referer||referer==NULL)) return true; |
jack1930 | 13:ed5c59ed4ae5 | 131 | return false; |
jack1930 | 13:ed5c59ed4ae5 | 132 | } |
jack1930 | 13:ed5c59ed4ae5 | 133 | |
jack1930 | 13:ed5c59ed4ae5 | 134 | int ESP8266Webserver::handleClient(void) |
jack1930 | 13:ed5c59ed4ae5 | 135 | { |
jack1930 | 13:ed5c59ed4ae5 | 136 | int value,value2; |
jack1930 | 13:ed5c59ed4ae5 | 137 | if (_serial->readable()) |
jack1930 | 13:ed5c59ed4ae5 | 138 | { |
jack1930 | 16:b09391fb73b4 | 139 | if (_parser->recv("+IPD,%d,%d:",&clientID[clientIdx],&value2)) |
jack1930 | 13:ed5c59ed4ae5 | 140 | { |
jack1930 | 13:ed5c59ed4ae5 | 141 | if (dbg) printf("\r\nich Client ID=%d, Anzahl=%d",clientID[clientIdx],value2); |
jack1930 | 13:ed5c59ed4ae5 | 142 | _parser->read(recbuf, value2); |
jack1930 | 13:ed5c59ed4ae5 | 143 | |
jack1930 | 13:ed5c59ed4ae5 | 144 | if (dbg) printf("\r\nBuf=\n%s",recbuf); |
jack1930 | 13:ed5c59ed4ae5 | 145 | |
jack1930 | 13:ed5c59ed4ae5 | 146 | gefunden=false; |
jack1930 | 13:ed5c59ed4ae5 | 147 | for (int i=0;i<hs_count&&!gefunden;i++) |
jack1930 | 16:b09391fb73b4 | 148 | { |
jack1930 | 13:ed5c59ed4ae5 | 149 | if (beinhaltet(hs[i])) |
jack1930 | 16:b09391fb73b4 | 150 | { |
jack1930 | 16:b09391fb73b4 | 151 | (cbs[i])(); |
jack1930 | 13:ed5c59ed4ae5 | 152 | gefunden=true; |
jack1930 | 13:ed5c59ed4ae5 | 153 | } |
jack1930 | 13:ed5c59ed4ae5 | 154 | } |
jack1930 | 13:ed5c59ed4ae5 | 155 | if (dbg) for (int i=0;i<hs_count;i++) |
jack1930 | 13:ed5c59ed4ae5 | 156 | { |
jack1930 | 13:ed5c59ed4ae5 | 157 | printf("\r\n%s\r\n",hs[i]); |
jack1930 | 16:b09391fb73b4 | 158 | } |
jack1930 | 13:ed5c59ed4ae5 | 159 | if (dbg) printf("\r\nich Got\r\n"); |
jack1930 | 16:b09391fb73b4 | 160 | } |
jack1930 | 13:ed5c59ed4ae5 | 161 | } |
jack1930 | 13:ed5c59ed4ae5 | 162 | |
jack1930 | 13:ed5c59ed4ae5 | 163 | return 0; |
jack1930 | 13:ed5c59ed4ae5 | 164 | } |
jack1930 | 13:ed5c59ed4ae5 | 165 | |
jack1930 | 13:ed5c59ed4ae5 | 166 | |
jack1930 | 13:ed5c59ed4ae5 | 167 | int ESP8266Webserver::send(int HTTPStatus,const char* Mimetype, string webseite) |
jack1930 | 13:ed5c59ed4ae5 | 168 | { |
jack1930 | 13:ed5c59ed4ae5 | 169 | return ESP8266Webserver::send(HTTPStatus,Mimetype, webseite.c_str()); |
jack1930 | 13:ed5c59ed4ae5 | 170 | } |
jack1930 | 16:b09391fb73b4 | 171 | |
jack1930 | 13:ed5c59ed4ae5 | 172 | int ESP8266Webserver::send(int HTTPStatus,const char* Mimetype, const char* webseite) |
jack1930 | 13:ed5c59ed4ae5 | 173 | { |
jack1930 | 13:ed5c59ed4ae5 | 174 | char hilf[40]; |
jack1930 | 13:ed5c59ed4ae5 | 175 | |
jack1930 | 16:b09391fb73b4 | 176 | //printf("\r\nHallo\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 177 | Aufrufe++; |
jack1930 | 13:ed5c59ed4ae5 | 178 | sprintf(sendstring,"HTTP/1.1 %d OK\n",HTTPStatus); |
jack1930 | 13:ed5c59ed4ae5 | 179 | strcat(sendstring,"Date: Wed, 23 Apr 2021 04:36:25 GMT\n"); |
jack1930 | 13:ed5c59ed4ae5 | 180 | strcat(sendstring,"Connection: close\n"); |
jack1930 | 13:ed5c59ed4ae5 | 181 | strcat(sendstring,"Content-Type: "); |
jack1930 | 13:ed5c59ed4ae5 | 182 | strcat(sendstring,Mimetype); |
jack1930 | 13:ed5c59ed4ae5 | 183 | strcat(sendstring,"\n"); |
jack1930 | 13:ed5c59ed4ae5 | 184 | sprintf(hilf,"%d",strlen(webseite)); |
jack1930 | 13:ed5c59ed4ae5 | 185 | strcat(sendstring,"Content-Length: "); |
jack1930 | 13:ed5c59ed4ae5 | 186 | strcat(sendstring,hilf); |
jack1930 | 13:ed5c59ed4ae5 | 187 | strcat(sendstring,"\n\n"); |
jack1930 | 13:ed5c59ed4ae5 | 188 | strcat(sendstring,webseite); |
jack1930 | 13:ed5c59ed4ae5 | 189 | if (dbg) printf("len=%d, inhalt=\n%s",strlen(sendstring),sendstring); |
jack1930 | 16:b09391fb73b4 | 190 | |
jack1930 | 13:ed5c59ed4ae5 | 191 | _parser->debug_on(true); |
jack1930 | 13:ed5c59ed4ae5 | 192 | _parser->send("AT+CIPSEND=%d,%d",clientID[clientIdx],strlen(sendstring)); |
jack1930 | 13:ed5c59ed4ae5 | 193 | _parser->debug_on(false); |
jack1930 | 13:ed5c59ed4ae5 | 194 | _parser->write(sendstring,strlen(sendstring)); |
jack1930 | 13:ed5c59ed4ae5 | 195 | HAL_Delay(200); |
jack1930 | 13:ed5c59ed4ae5 | 196 | _parser->send("AT+CIPCLOSE=%d",clientID[clientIdx]); |
jack1930 | 13:ed5c59ed4ae5 | 197 | return 0; |
jack1930 | 13:ed5c59ed4ae5 | 198 | } |
jack1930 | 13:ed5c59ed4ae5 | 199 | |
jack1930 | 13:ed5c59ed4ae5 | 200 | void ESP8266Webserver::debugOn(bool pD) |
jack1930 | 13:ed5c59ed4ae5 | 201 | { |
jack1930 | 13:ed5c59ed4ae5 | 202 | dbg=pD; |
jack1930 | 16:b09391fb73b4 | 203 | _parser->debug_on(pD); |
jack1930 | 13:ed5c59ed4ae5 | 204 | } |
jack1930 | 13:ed5c59ed4ae5 | 205 | |
jack1930 | 16:b09391fb73b4 | 206 | const char* ESP8266Webserver::gibWert(string suchstring) |
jack1930 | 13:ed5c59ed4ae5 | 207 | { |
jack1930 | 13:ed5c59ed4ae5 | 208 | return ESP8266Webserver::gibWert(suchstring.c_str()); |
jack1930 | 13:ed5c59ed4ae5 | 209 | } |
jack1930 | 13:ed5c59ed4ae5 | 210 | |
jack1930 | 13:ed5c59ed4ae5 | 211 | const char* ESP8266Webserver::gibWert(const char* suchstring) |
jack1930 | 13:ed5c59ed4ae5 | 212 | { |
jack1930 | 13:ed5c59ed4ae5 | 213 | static char hilf[20]; |
jack1930 | 13:ed5c59ed4ae5 | 214 | |
jack1930 | 13:ed5c59ed4ae5 | 215 | char *fundort; |
jack1930 | 13:ed5c59ed4ae5 | 216 | int i=0; |
jack1930 | 13:ed5c59ed4ae5 | 217 | fundort=strstr(recbuf,suchstring); |
jack1930 | 13:ed5c59ed4ae5 | 218 | if (fundort!=NULL) |
jack1930 | 13:ed5c59ed4ae5 | 219 | { |
jack1930 | 13:ed5c59ed4ae5 | 220 | fundort=fundort+strlen(suchstring)+1; |
jack1930 | 13:ed5c59ed4ae5 | 221 | while(i<20 && fundort[i]!=38 && fundort[i]>32 ) //space, & |
jack1930 | 13:ed5c59ed4ae5 | 222 | { |
jack1930 | 13:ed5c59ed4ae5 | 223 | hilf[i]=fundort[i]; |
jack1930 | 13:ed5c59ed4ae5 | 224 | i++; |
jack1930 | 13:ed5c59ed4ae5 | 225 | } |
jack1930 | 13:ed5c59ed4ae5 | 226 | hilf[i]=0; |
jack1930 | 13:ed5c59ed4ae5 | 227 | if (dbg) printf("\r\nsuchergebnis=%s\r\n",hilf); |
jack1930 | 13:ed5c59ed4ae5 | 228 | return hilf; |
jack1930 | 13:ed5c59ed4ae5 | 229 | } |
jack1930 | 13:ed5c59ed4ae5 | 230 | else |
jack1930 | 13:ed5c59ed4ae5 | 231 | return NULL; |
jack1930 | 14:d17cfd8131b1 | 232 | } |
jack1930 | 14:d17cfd8131b1 | 233 | |
jack1930 | 15:e710f0431920 | 234 | void ESP8266Webserver::listAPs() |
jack1930 | 14:d17cfd8131b1 | 235 | { |
jack1930 | 16:b09391fb73b4 | 236 | int ips[4]; |
jack1930 | 15:e710f0431920 | 237 | //_parser->debug_on(true); |
jack1930 | 15:e710f0431920 | 238 | _parser->send("AT+CWMODE=1"); |
jack1930 | 17:87c762acb8d0 | 239 | HAL_Delay(300); |
jack1930 | 15:e710f0431920 | 240 | while (_parser->recv("OK")==false); |
jack1930 | 15:e710f0431920 | 241 | HAL_Delay(1000); |
jack1930 | 15:e710f0431920 | 242 | if (scanAPs==true) |
jack1930 | 14:d17cfd8131b1 | 243 | { |
jack1930 | 15:e710f0431920 | 244 | _parser->send("AT+CWLAP"); |
jack1930 | 15:e710f0431920 | 245 | while (!_serial->readable()); |
jack1930 | 15:e710f0431920 | 246 | HAL_Delay(10000); |
jack1930 | 15:e710f0431920 | 247 | printf("\r\nBuf="); |
jack1930 | 15:e710f0431920 | 248 | while (_serial->readable()) |
jack1930 | 15:e710f0431920 | 249 | { |
jack1930 | 15:e710f0431920 | 250 | _parser->read(recbuf, 1); |
jack1930 | 15:e710f0431920 | 251 | printf("%s",recbuf); |
jack1930 | 15:e710f0431920 | 252 | } |
jack1930 | 15:e710f0431920 | 253 | printf("\r\n"); |
jack1930 | 14:d17cfd8131b1 | 254 | } |
jack1930 | 15:e710f0431920 | 255 | for (int i=0;i<5;i++) |
jack1930 | 15:e710f0431920 | 256 | { |
jack1930 | 15:e710f0431920 | 257 | _parser->send("AT+CWJAP=\"%s\",\"%s\"",ssid,passwort); |
jack1930 | 15:e710f0431920 | 258 | HAL_Delay(1000); |
jack1930 | 15:e710f0431920 | 259 | if (_parser->recv("WIFI GOT IP")) i=6; |
jack1930 | 15:e710f0431920 | 260 | } |
jack1930 | 15:e710f0431920 | 261 | _parser->send("AT+CIFSR"); |
jack1930 | 15:e710f0431920 | 262 | while (_parser->recv("+CIFSR:STAIP,")==false) |
jack1930 | 15:e710f0431920 | 263 | { |
jack1930 | 15:e710f0431920 | 264 | _parser->send("AT+CIFSR"); |
jack1930 | 15:e710f0431920 | 265 | HAL_Delay(100); |
jack1930 | 15:e710f0431920 | 266 | } |
jack1930 | 16:b09391fb73b4 | 267 | |
jack1930 | 16:b09391fb73b4 | 268 | // _parser->read(ipadr,15); |
jack1930 | 16:b09391fb73b4 | 269 | _parser->scanf("\"%d.%d.%d.%d\"",&ips[0],&ips[1],&ips[2],&ips[3]); |
jack1930 | 16:b09391fb73b4 | 270 | sprintf(ipadr,"%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]); |
jack1930 | 15:e710f0431920 | 271 | printf("%s",ipadr); |
jack1930 | 15:e710f0431920 | 272 | |
jack1930 | 15:e710f0431920 | 273 | _parser->send("AT+CIPMUX=1"); |
jack1930 | 15:e710f0431920 | 274 | while (_parser->recv("OK")==false); |
jack1930 | 15:e710f0431920 | 275 | |
jack1930 | 15:e710f0431920 | 276 | //_parser->debug_on(false); |
jack1930 | 14:d17cfd8131b1 | 277 | } |
jack1930 | 14:d17cfd8131b1 | 278 | |
jack1930 | 15:e710f0431920 | 279 | char* ESP8266Webserver::gibIP() |
jack1930 | 14:d17cfd8131b1 | 280 | { |
jack1930 | 16:b09391fb73b4 | 281 | static char ipa[16]; |
jack1930 | 16:b09391fb73b4 | 282 | int j=0; |
jack1930 | 16:b09391fb73b4 | 283 | for (int i=0;i<strlen(ipadr);i++) |
jack1930 | 16:b09391fb73b4 | 284 | { |
jack1930 | 16:b09391fb73b4 | 285 | if (i==0 && ipadr[0]=='"'){} |
jack1930 | 16:b09391fb73b4 | 286 | else |
jack1930 | 16:b09391fb73b4 | 287 | { |
jack1930 | 16:b09391fb73b4 | 288 | switch (ipadr[i]) |
jack1930 | 16:b09391fb73b4 | 289 | { |
jack1930 | 16:b09391fb73b4 | 290 | case '0': |
jack1930 | 16:b09391fb73b4 | 291 | case '1': |
jack1930 | 16:b09391fb73b4 | 292 | case '2': |
jack1930 | 16:b09391fb73b4 | 293 | case '3': |
jack1930 | 16:b09391fb73b4 | 294 | case '4': |
jack1930 | 16:b09391fb73b4 | 295 | case '5': |
jack1930 | 16:b09391fb73b4 | 296 | case '6': |
jack1930 | 16:b09391fb73b4 | 297 | case '7': |
jack1930 | 16:b09391fb73b4 | 298 | case '8': |
jack1930 | 16:b09391fb73b4 | 299 | case '9': |
jack1930 | 16:b09391fb73b4 | 300 | case '.': ipa[j]=ipadr[i]; |
jack1930 | 16:b09391fb73b4 | 301 | j++; |
jack1930 | 16:b09391fb73b4 | 302 | break; |
jack1930 | 16:b09391fb73b4 | 303 | default: i=10000; break; |
jack1930 | 16:b09391fb73b4 | 304 | } |
jack1930 | 16:b09391fb73b4 | 305 | if (i==10000) break; |
jack1930 | 16:b09391fb73b4 | 306 | } |
jack1930 | 16:b09391fb73b4 | 307 | } |
jack1930 | 16:b09391fb73b4 | 308 | ipa[j+1]='\0'; |
jack1930 | 16:b09391fb73b4 | 309 | |
jack1930 | 16:b09391fb73b4 | 310 | return ipa; |
jack1930 | 14:d17cfd8131b1 | 311 | } |
jack1930 | 14:d17cfd8131b1 | 312 |