Library für ESP01 Webserver STM32F103RB Nucleo
Dependents: Nucleo_dht11_Webserver WebServerGSOEWorkshopSlider WebServerGSOEWorkshopDynamisch WebServerGSOEWorkshopStatisch ... more
Diff: ESP8266Webserver.cpp
- Revision:
- 16:b09391fb73b4
- Parent:
- 15:e710f0431920
- Child:
- 17:87c762acb8d0
diff -r e710f0431920 -r b09391fb73b4 ESP8266Webserver.cpp --- a/ESP8266Webserver.cpp Fri Jun 18 15:33:21 2021 +0000 +++ b/ESP8266Webserver.cpp Tue Jun 22 07:45:32 2021 +0000 @@ -1,4 +1,5 @@ #include "ESP8266Webserver.h" +//#include "string" ESP8266Webserver::ESP8266Webserver() { @@ -26,8 +27,6 @@ } else { if (pDebug) printf("\nATCmdParser: OK failed\r\n"); } - - if (station==true) { @@ -70,21 +69,11 @@ if (pDebug) printf("\nATCmdParser: OK failed\r\n"); } -/* -//AT+CWJAP= “Wi-FiNetwork”,“Password” - printf("\nATCmdParser: //AT+CWJAP= \"Wi-FiNetwork\",\"Password\" \r\n"); - _parser->send("AT+CWJAP=\"x-Netz\",\"aCT3xuSbm9rt\""); - - if (_parser->recv("OK")) { - printf("\nAntw.: OK\r\n"); - } else { - printf("\nATCmdParser: OK failed\r\n"); - } -*/ + + -//AT+CIPAP="192.168.5.1","192.168.5.1","255.255.255.0" if (pDebug) printf("\nATCmdParser: //AT+CIPAP=\"%s\",\"%s\",\"%s\" \r\n",ipad.c_str(),ipad.c_str(),netzmaske); - // _parser->send("AT+CIPAP=\"192.168.5.1\",\"192.168.5.1\",\"255.255.255.0\""); + _parser->send("AT+CIPAP=\"%s\",\"%s\",\"%s\"",ipad.c_str(),ipad.c_str(),netzmaske); if (_parser->recv("OK")) { @@ -156,47 +145,28 @@ int value,value2; if (_serial->readable()) { - /* HAL_Delay(1000); - _serial->read(buf,1000); - printf("\r\n ich %s\r\n",buf); - */ - if (_parser->recv("+IPD,%d,%d:",&clientID[clientIdx],&value2)) //_parser->recv("+IPD,%d",value) + if (_parser->recv("+IPD,%d,%d:",&clientID[clientIdx],&value2)) { - - //HAL_Delay(1000); - if (dbg) printf("\r\nich Client ID=%d, Anzahl=%d",clientID[clientIdx],value2); _parser->read(recbuf, value2); - //HAL_Delay(1000); - //recbuf[value2]=0; if (dbg) printf("\r\nBuf=\n%s",recbuf); - //(cbs[1])(); gefunden=false; for (int i=0;i<hs_count&&!gefunden;i++) - { - + { if (beinhaltet(hs[i])) - { - - (cbs[i])(); - + { + (cbs[i])(); gefunden=true; } } - if (dbg) for (int i=0;i<hs_count;i++) { printf("\r\n%s\r\n",hs[i]); - } - + } if (dbg) printf("\r\nich Got\r\n"); - - //_parser->flush(); - - } - + } } return 0; @@ -207,11 +177,12 @@ { return ESP8266Webserver::send(HTTPStatus,Mimetype, webseite.c_str()); } + int ESP8266Webserver::send(int HTTPStatus,const char* Mimetype, const char* webseite) { char hilf[40]; - printf("\r\nHallo\r\n"); + //printf("\r\nHallo\r\n"); Aufrufe++; sprintf(sendstring,"HTTP/1.1 %d OK\n",HTTPStatus); strcat(sendstring,"Date: Wed, 23 Apr 2021 04:36:25 GMT\n"); @@ -225,9 +196,7 @@ strcat(sendstring,"\n\n"); strcat(sendstring,webseite); if (dbg) printf("len=%d, inhalt=\n%s",strlen(sendstring),sendstring); - //sprintf(hilf,"AT+CIPSEND=%d,%d\r\n",clientID,strlen(sendstring)); - //printf("\n %s, %d\n",hilf,strlen(hilf)); - //_serial->write(hilf,strlen(hilf)); + _parser->debug_on(true); _parser->send("AT+CIPSEND=%d,%d",clientID[clientIdx],strlen(sendstring)); _parser->debug_on(false); @@ -240,11 +209,10 @@ void ESP8266Webserver::debugOn(bool pD) { dbg=pD; - _parser->debug_on(pD); - + _parser->debug_on(pD); } -string ESP8266Webserver::gibWertString(string suchstring) +const char* ESP8266Webserver::gibWert(string suchstring) { return ESP8266Webserver::gibWert(suchstring.c_str()); } @@ -274,7 +242,7 @@ void ESP8266Webserver::listAPs() { - + int ips[4]; //_parser->debug_on(true); _parser->send("AT+CWMODE=1"); while (_parser->recv("OK")==false); @@ -304,7 +272,10 @@ _parser->send("AT+CIFSR"); HAL_Delay(100); } - _parser->read(ipadr,15); + +// _parser->read(ipadr,15); + _parser->scanf("\"%d.%d.%d.%d\"",&ips[0],&ips[1],&ips[2],&ips[3]); + sprintf(ipadr,"%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]); printf("%s",ipadr); _parser->send("AT+CIPMUX=1"); @@ -315,6 +286,35 @@ char* ESP8266Webserver::gibIP() { - return ipadr; + static char ipa[16]; + int j=0; + for (int i=0;i<strlen(ipadr);i++) + { + if (i==0 && ipadr[0]=='"'){} + else + { + switch (ipadr[i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '.': ipa[j]=ipadr[i]; + j++; + break; + default: i=10000; break; + } + if (i==10000) break; + } + } + ipa[j+1]='\0'; + + return ipa; }