Library für ESP01 Webserver STM32F103RB Nucleo
Dependents: Nucleo_dht11_Webserver WebServerGSOEWorkshopSlider WebServerGSOEWorkshopDynamisch WebServerGSOEWorkshopStatisch ... more
ESP8266Webserver.cpp@41:b31ca06263ed, 2021-12-02 (annotated)
- Committer:
- jack1930
- Date:
- Thu Dec 02 09:53:15 2021 +0000
- Revision:
- 41:b31ca06263ed
- Parent:
- 40:6d79431a08aa
dbg=false
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 | 19:e0bcbb2a3480 | 8 | DigitalOut ch_pd(CH_PD); |
jack1930 | 19:e0bcbb2a3480 | 9 | DigitalOut rst(RST); |
jack1930 | 19:e0bcbb2a3480 | 10 | ch_pd=1; |
jack1930 | 19:e0bcbb2a3480 | 11 | rst=0; |
jack1930 | 19:e0bcbb2a3480 | 12 | HAL_Delay(100); |
jack1930 | 19:e0bcbb2a3480 | 13 | rst=1; |
jack1930 | 13:ed5c59ed4ae5 | 14 | hs_count=0; |
jack1930 | 13:ed5c59ed4ae5 | 15 | clientIdx=0; |
jack1930 | 13:ed5c59ed4ae5 | 16 | if (pDebug) printf("\nATCmdParser with ESP8266 example"); |
jack1930 | 13:ed5c59ed4ae5 | 17 | port=Port; |
jack1930 | 13:ed5c59ed4ae5 | 18 | |
jack1930 | 13:ed5c59ed4ae5 | 19 | dbg=pDebug; |
jack1930 | 13:ed5c59ed4ae5 | 20 | _serial = new BufferedSerial(tx,rx, ESP8266_DEFAULT_BAUD_RATE); |
jack1930 | 38:848feec26df5 | 21 | _parser = new ATCmdParser(_serial, "\r\n",1000); |
jack1930 | 17:87c762acb8d0 | 22 | _parser->debug_on(true); |
jack1930 | 13:ed5c59ed4ae5 | 23 | |
jack1930 | 17:87c762acb8d0 | 24 | _parser->set_timeout(2000); |
jack1930 | 13:ed5c59ed4ae5 | 25 | |
jack1930 | 13:ed5c59ed4ae5 | 26 | //AT |
jack1930 | 13:ed5c59ed4ae5 | 27 | if (pDebug) printf("\nATCmdParser: AT\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 28 | _parser->send("AT"); |
jack1930 | 13:ed5c59ed4ae5 | 29 | |
jack1930 | 13:ed5c59ed4ae5 | 30 | if (_parser->recv("OK")) { |
jack1930 | 13:ed5c59ed4ae5 | 31 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 32 | } else { |
jack1930 | 17:87c762acb8d0 | 33 | printf("\nATCmdParser: AT OK failed\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 34 | } |
jack1930 | 15:e710f0431920 | 35 | |
jack1930 | 15:e710f0431920 | 36 | if (station==true) |
jack1930 | 15:e710f0431920 | 37 | { |
jack1930 | 15:e710f0431920 | 38 | listAPs(); |
jack1930 | 15:e710f0431920 | 39 | printf("%s",ipadr); |
jack1930 | 15:e710f0431920 | 40 | } |
jack1930 | 15:e710f0431920 | 41 | else { |
jack1930 | 15:e710f0431920 | 42 | _parser->send("ATE0"); |
jack1930 | 15:e710f0431920 | 43 | strcpy(ipadr,ip); |
jack1930 | 13:ed5c59ed4ae5 | 44 | |
jack1930 | 15:e710f0431920 | 45 | if (pDebug) printf("\nATCmdParser: //AT+CWMODE=2 \r\n"); |
jack1930 | 17:87c762acb8d0 | 46 | |
jack1930 | 15:e710f0431920 | 47 | _parser->send("AT+CWMODE=2"); |
jack1930 | 17:87c762acb8d0 | 48 | HAL_Delay(1000); |
jack1930 | 15:e710f0431920 | 49 | |
jack1930 | 15:e710f0431920 | 50 | if (_parser->recv("OK")) { |
jack1930 | 15:e710f0431920 | 51 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 15:e710f0431920 | 52 | } else { |
jack1930 | 17:87c762acb8d0 | 53 | printf("\nATCmdParser: AT+CWMODE=2 OK failed\r\n"); |
jack1930 | 15:e710f0431920 | 54 | } |
jack1930 | 15:e710f0431920 | 55 | |
jack1930 | 13:ed5c59ed4ae5 | 56 | //AT+CWMODE? |
jack1930 | 13:ed5c59ed4ae5 | 57 | if (pDebug) printf("\nATCmdParser: //AT+CWMODE? \r\n"); |
jack1930 | 17:87c762acb8d0 | 58 | |
jack1930 | 13:ed5c59ed4ae5 | 59 | _parser->send("AT+CWMODE?"); |
jack1930 | 13:ed5c59ed4ae5 | 60 | |
jack1930 | 13:ed5c59ed4ae5 | 61 | if (_parser->recv("OK")) { |
jack1930 | 13:ed5c59ed4ae5 | 62 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 63 | } else { |
jack1930 | 17:87c762acb8d0 | 64 | printf("\nATCmdParser: AT+CWMODE? OK failed\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 65 | } |
jack1930 | 13:ed5c59ed4ae5 | 66 | |
jack1930 | 17:87c762acb8d0 | 67 | |
jack1930 | 17:87c762acb8d0 | 68 | //AT+CIPAP="192.168.5.1","192.168.5.1","255.255.255.0" |
jack1930 | 15:e710f0431920 | 69 | if (pDebug) printf("\nATCmdParser: //AT+CIPAP=\"%s\",\"%s\",\"%s\" \r\n",ipad.c_str(),ipad.c_str(),netzmaske); |
jack1930 | 17:87c762acb8d0 | 70 | do |
jack1930 | 17:87c762acb8d0 | 71 | { |
jack1930 | 17:87c762acb8d0 | 72 | _parser->send("AT+CIPAP=\"%s\",\"%s\",\"%s\"",ipad.c_str(),ipad.c_str(),netzmaske); |
jack1930 | 17:87c762acb8d0 | 73 | erg=_parser->recv("OK"); |
jack1930 | 17:87c762acb8d0 | 74 | if (erg==true) { |
jack1930 | 17:87c762acb8d0 | 75 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 17:87c762acb8d0 | 76 | } else { |
jack1930 | 17:87c762acb8d0 | 77 | printf("\nATCmdParser: AT+CIPAP OK failed\r\n"); |
jack1930 | 17:87c762acb8d0 | 78 | HAL_Delay(1000); |
jack1930 | 17:87c762acb8d0 | 79 | } |
jack1930 | 17:87c762acb8d0 | 80 | } |
jack1930 | 17:87c762acb8d0 | 81 | while (erg==false); |
jack1930 | 15:e710f0431920 | 82 | |
jack1930 | 15:e710f0431920 | 83 | |
jack1930 | 13:ed5c59ed4ae5 | 84 | |
jack1930 | 13:ed5c59ed4ae5 | 85 | //AT+CIPMUX=1 |
jack1930 | 13:ed5c59ed4ae5 | 86 | if (pDebug) printf("\nATCmdParser: //AT+CIPMUX=1"); |
jack1930 | 13:ed5c59ed4ae5 | 87 | _parser->send("AT+CIPMUX=1"); |
jack1930 | 13:ed5c59ed4ae5 | 88 | |
jack1930 | 13:ed5c59ed4ae5 | 89 | if (_parser->recv("OK")) { |
jack1930 | 13:ed5c59ed4ae5 | 90 | if (pDebug) printf("\nAntw.: OK\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 91 | } else { |
jack1930 | 17:87c762acb8d0 | 92 | printf("\nATCmdParser: AT+CIPMUX=1 OK failed\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 93 | } |
jack1930 | 15:e710f0431920 | 94 | } |
jack1930 | 13:ed5c59ed4ae5 | 95 | } |
jack1930 | 13:ed5c59ed4ae5 | 96 | |
jack1930 | 13:ed5c59ed4ae5 | 97 | int ESP8266Webserver::on(const char* handlestring,Callback< void()> func) |
jack1930 | 13:ed5c59ed4ae5 | 98 | { |
jack1930 | 13:ed5c59ed4ae5 | 99 | if (hs_count>9) return -1; |
jack1930 | 13:ed5c59ed4ae5 | 100 | else |
jack1930 | 13:ed5c59ed4ae5 | 101 | { |
jack1930 | 13:ed5c59ed4ae5 | 102 | strcpy(hs[hs_count],handlestring); |
jack1930 | 13:ed5c59ed4ae5 | 103 | if (dbg) printf("\r\n\r\n%s, %s\r\n",handlestring,hs[hs_count]); |
jack1930 | 13:ed5c59ed4ae5 | 104 | cbs[hs_count]=func; |
jack1930 | 13:ed5c59ed4ae5 | 105 | hs_count++; |
jack1930 | 13:ed5c59ed4ae5 | 106 | return 0; |
jack1930 | 13:ed5c59ed4ae5 | 107 | } |
jack1930 | 13:ed5c59ed4ae5 | 108 | |
jack1930 | 13:ed5c59ed4ae5 | 109 | } |
jack1930 | 13:ed5c59ed4ae5 | 110 | |
jack1930 | 13:ed5c59ed4ae5 | 111 | int ESP8266Webserver::begin(void) |
jack1930 | 13:ed5c59ed4ae5 | 112 | { |
jack1930 | 13:ed5c59ed4ae5 | 113 | //AT+CIPSERVER=1,80 |
jack1930 | 15:e710f0431920 | 114 | if (dbg) printf("\nATCmdParser: //AT+CIPSERVER=1,%d",Port); |
jack1930 | 15:e710f0431920 | 115 | _parser->send("AT+CIPSERVER=1,%d",Port); |
jack1930 | 13:ed5c59ed4ae5 | 116 | if (_parser->recv("OK")) { |
jack1930 | 13:ed5c59ed4ae5 | 117 | if (dbg) printf("\nAntw.: OK\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 118 | return 0; |
jack1930 | 13:ed5c59ed4ae5 | 119 | } else { |
jack1930 | 17:87c762acb8d0 | 120 | printf("\nATCmdParser: AT+CIPSERVER=1 OK failed\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 121 | return -1; |
jack1930 | 13:ed5c59ed4ae5 | 122 | } |
jack1930 | 13:ed5c59ed4ae5 | 123 | } |
jack1930 | 13:ed5c59ed4ae5 | 124 | |
jack1930 | 13:ed5c59ed4ae5 | 125 | //durchsucht recbuf nach suchstring |
jack1930 | 13:ed5c59ed4ae5 | 126 | bool ESP8266Webserver::beinhaltet(char* suchstring) |
jack1930 | 13:ed5c59ed4ae5 | 127 | { |
jack1930 | 13:ed5c59ed4ae5 | 128 | char* referer; |
jack1930 | 13:ed5c59ed4ae5 | 129 | char* fundort; |
jack1930 | 13:ed5c59ed4ae5 | 130 | char* favicon; |
jack1930 | 37:4680b876f77b | 131 | char* post; |
jack1930 | 37:4680b876f77b | 132 | post=strstr(recbuf,"POST"); |
jack1930 | 36:e943a93d07f6 | 133 | favicon=strstr(recbuf,"favicon"); |
jack1930 | 36:e943a93d07f6 | 134 | if (favicon!=NULL) return true; |
jack1930 | 13:ed5c59ed4ae5 | 135 | referer=strstr(recbuf,"Referer"); |
jack1930 | 13:ed5c59ed4ae5 | 136 | fundort=strstr(recbuf, suchstring); |
jack1930 | 13:ed5c59ed4ae5 | 137 | if (strstr(recbuf,"ERROR")==NULL) |
jack1930 | 13:ed5c59ed4ae5 | 138 | if( fundort != NULL&&(fundort<referer||referer==NULL)) return true; |
jack1930 | 37:4680b876f77b | 139 | if (fundort != NULL&&post!=NULL) return true; |
jack1930 | 13:ed5c59ed4ae5 | 140 | return false; |
jack1930 | 13:ed5c59ed4ae5 | 141 | } |
jack1930 | 13:ed5c59ed4ae5 | 142 | |
jack1930 | 13:ed5c59ed4ae5 | 143 | int ESP8266Webserver::handleClient(void) |
jack1930 | 13:ed5c59ed4ae5 | 144 | { |
jack1930 | 36:e943a93d07f6 | 145 | char favicon[]="favicon.ico"; |
jack1930 | 36:e943a93d07f6 | 146 | const char ico[1150]={ |
jack1930 | 35:79b85c333b02 | 147 | 0x00,0x00,0x01,0x00,0x01,0x00,0x10,0x10,0x00,0x00,0x01,0x00,0x20,0x00,0x68,0x04,0x00,0x00, |
jack1930 | 35:79b85c333b02 | 148 | 0x16,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x01,0x00, |
jack1930 | 35:79b85c333b02 | 149 | 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
jack1930 | 35:79b85c333b02 | 150 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 151 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 36:e943a93d07f6 | 152 | 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 153 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 154 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00, |
jack1930 | 36:e943a93d07f6 | 155 | 0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 156 | 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 157 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 158 | 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 159 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 160 | 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 161 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 162 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 163 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 36:e943a93d07f6 | 164 | 0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00, |
jack1930 | 36:e943a93d07f6 | 165 | 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF, |
jack1930 | 36:e943a93d07f6 | 166 | 0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 167 | 0xFF,0xFF,0x00,0x00,0x00,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 36:e943a93d07f6 | 168 | 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03, |
jack1930 | 36:e943a93d07f6 | 169 | 0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 170 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03, |
jack1930 | 35:79b85c333b02 | 171 | 0x91,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 36:e943a93d07f6 | 172 | 0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 173 | 0xFF,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 36:e943a93d07f6 | 174 | 0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00, |
jack1930 | 36:e943a93d07f6 | 175 | 0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 176 | 0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00, |
jack1930 | 36:e943a93d07f6 | 177 | 0x00,0xFF,0x00,0x00,0x00,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF, |
jack1930 | 36:e943a93d07f6 | 178 | 0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00, |
jack1930 | 36:e943a93d07f6 | 179 | 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 180 | 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03, |
jack1930 | 36:e943a93d07f6 | 181 | 0x91,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF, |
jack1930 | 36:e943a93d07f6 | 182 | 0x07,0x03,0x91,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 183 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 36:e943a93d07f6 | 184 | 0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 185 | 0xFF,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 36:e943a93d07f6 | 186 | 0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 187 | 0xFF,0xFF,0x00,0x00,0x00,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF, |
jack1930 | 36:e943a93d07f6 | 188 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 189 | 0xFF,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 190 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03, |
jack1930 | 36:e943a93d07f6 | 191 | 0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 192 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00, |
jack1930 | 36:e943a93d07f6 | 193 | 0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 35:79b85c333b02 | 194 | 0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03, |
jack1930 | 36:e943a93d07f6 | 195 | 0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x03,0x91,0xFF, |
jack1930 | 36:e943a93d07f6 | 196 | 0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF, |
jack1930 | 36:e943a93d07f6 | 197 | 0xFF,0xFF,0x00,0x00,0x00,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF, |
jack1930 | 35:79b85c333b02 | 198 | 0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03, |
jack1930 | 35:79b85c333b02 | 199 | 0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF, |
jack1930 | 36:e943a93d07f6 | 200 | 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03, |
jack1930 | 36:e943a93d07f6 | 201 | 0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF, |
jack1930 | 36:e943a93d07f6 | 202 | 0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03, |
jack1930 | 36:e943a93d07f6 | 203 | 0x91,0xFF,0x07,0x03,0x91,0xFF,0x07,0x03,0x91,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 35:79b85c333b02 | 204 | 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00, |
jack1930 | 35:79b85c333b02 | 205 | 0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF, |
jack1930 | 36:e943a93d07f6 | 206 | 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00, |
jack1930 | 36:e943a93d07f6 | 207 | 0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
jack1930 | 35:79b85c333b02 | 208 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
jack1930 | 35:79b85c333b02 | 209 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
jack1930 | 36:e943a93d07f6 | 210 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 |
jack1930 | 35:79b85c333b02 | 211 | |
jack1930 | 35:79b85c333b02 | 212 | }; |
jack1930 | 13:ed5c59ed4ae5 | 213 | int value,value2; |
jack1930 | 36:e943a93d07f6 | 214 | static int diag=0; |
jack1930 | 13:ed5c59ed4ae5 | 215 | if (_serial->readable()) |
jack1930 | 13:ed5c59ed4ae5 | 216 | { |
jack1930 | 16:b09391fb73b4 | 217 | if (_parser->recv("+IPD,%d,%d:",&clientID[clientIdx],&value2)) |
jack1930 | 13:ed5c59ed4ae5 | 218 | { |
jack1930 | 38:848feec26df5 | 219 | if (dbg) printf("\r\n >>> Client ID=%d, Anzahl=%d",clientID[clientIdx],value2); |
jack1930 | 13:ed5c59ed4ae5 | 220 | _parser->read(recbuf, value2); |
jack1930 | 13:ed5c59ed4ae5 | 221 | |
jack1930 | 38:848feec26df5 | 222 | |
jack1930 | 38:848feec26df5 | 223 | if (dbg) printf("\r\nBuf=\n%s\n\n",recbuf); |
jack1930 | 13:ed5c59ed4ae5 | 224 | |
jack1930 | 36:e943a93d07f6 | 225 | if (beinhaltet(favicon)) |
jack1930 | 35:79b85c333b02 | 226 | { |
jack1930 | 36:e943a93d07f6 | 227 | printf("\n\nfavicon request %d\n\n",diag); |
jack1930 | 36:e943a93d07f6 | 228 | diag++; |
jack1930 | 36:e943a93d07f6 | 229 | send(404,"image/x-icon",""); |
jack1930 | 35:79b85c333b02 | 230 | } |
jack1930 | 35:79b85c333b02 | 231 | else |
jack1930 | 35:79b85c333b02 | 232 | { |
jack1930 | 35:79b85c333b02 | 233 | gefunden=false; |
jack1930 | 35:79b85c333b02 | 234 | for (int i=0;i<hs_count&&!gefunden;i++) |
jack1930 | 35:79b85c333b02 | 235 | { |
jack1930 | 35:79b85c333b02 | 236 | if (beinhaltet(hs[i])) |
jack1930 | 35:79b85c333b02 | 237 | { |
jack1930 | 35:79b85c333b02 | 238 | (cbs[i])(); |
jack1930 | 35:79b85c333b02 | 239 | gefunden=true; |
jack1930 | 35:79b85c333b02 | 240 | } |
jack1930 | 35:79b85c333b02 | 241 | } |
jack1930 | 35:79b85c333b02 | 242 | } |
jack1930 | 13:ed5c59ed4ae5 | 243 | if (dbg) for (int i=0;i<hs_count;i++) |
jack1930 | 13:ed5c59ed4ae5 | 244 | { |
jack1930 | 13:ed5c59ed4ae5 | 245 | printf("\r\n%s\r\n",hs[i]); |
jack1930 | 16:b09391fb73b4 | 246 | } |
jack1930 | 38:848feec26df5 | 247 | if (dbg) printf("\r\n>>> Got\r\n"); |
jack1930 | 16:b09391fb73b4 | 248 | } |
jack1930 | 13:ed5c59ed4ae5 | 249 | } |
jack1930 | 13:ed5c59ed4ae5 | 250 | |
jack1930 | 13:ed5c59ed4ae5 | 251 | return 0; |
jack1930 | 13:ed5c59ed4ae5 | 252 | } |
jack1930 | 13:ed5c59ed4ae5 | 253 | |
jack1930 | 13:ed5c59ed4ae5 | 254 | |
jack1930 | 13:ed5c59ed4ae5 | 255 | int ESP8266Webserver::send(int HTTPStatus,const char* Mimetype, string webseite) |
jack1930 | 13:ed5c59ed4ae5 | 256 | { |
jack1930 | 13:ed5c59ed4ae5 | 257 | return ESP8266Webserver::send(HTTPStatus,Mimetype, webseite.c_str()); |
jack1930 | 13:ed5c59ed4ae5 | 258 | } |
jack1930 | 16:b09391fb73b4 | 259 | |
jack1930 | 13:ed5c59ed4ae5 | 260 | int ESP8266Webserver::send(int HTTPStatus,const char* Mimetype, const char* webseite) |
jack1930 | 13:ed5c59ed4ae5 | 261 | { |
jack1930 | 13:ed5c59ed4ae5 | 262 | char hilf[40]; |
jack1930 | 35:79b85c333b02 | 263 | char statustext[40]; |
jack1930 | 35:79b85c333b02 | 264 | |
jack1930 | 35:79b85c333b02 | 265 | sprintf(statustext,"OK"); |
jack1930 | 35:79b85c333b02 | 266 | |
jack1930 | 35:79b85c333b02 | 267 | switch (HTTPStatus) |
jack1930 | 35:79b85c333b02 | 268 | { |
jack1930 | 35:79b85c333b02 | 269 | case 404: sprintf(statustext,"Not Found"); break; |
jack1930 | 35:79b85c333b02 | 270 | case 206: sprintf(statustext,"Partial Content"); break; |
jack1930 | 35:79b85c333b02 | 271 | case 401: sprintf(statustext,"Unauthorized"); break; |
jack1930 | 35:79b85c333b02 | 272 | case 403: sprintf(statustext,"Forbidden"); break; |
jack1930 | 35:79b85c333b02 | 273 | case 307: |
jack1930 | 35:79b85c333b02 | 274 | case 302: sprintf(statustext,"Moved Temporarily"); break; |
jack1930 | 35:79b85c333b02 | 275 | case 301: sprintf(statustext,"Moved Permanently"); break; |
jack1930 | 35:79b85c333b02 | 276 | case 304: sprintf(statustext,"Not Modified"); break; |
jack1930 | 35:79b85c333b02 | 277 | |
jack1930 | 35:79b85c333b02 | 278 | } |
jack1930 | 35:79b85c333b02 | 279 | |
jack1930 | 13:ed5c59ed4ae5 | 280 | |
jack1930 | 16:b09391fb73b4 | 281 | //printf("\r\nHallo\r\n"); |
jack1930 | 13:ed5c59ed4ae5 | 282 | Aufrufe++; |
jack1930 | 35:79b85c333b02 | 283 | switch (HTTPStatus) |
jack1930 | 35:79b85c333b02 | 284 | { |
jack1930 | 35:79b85c333b02 | 285 | case 206: |
jack1930 | 35:79b85c333b02 | 286 | case 200: sprintf(sendstring,"HTTP/1.1 %d %s\n",HTTPStatus,statustext); |
jack1930 | 35:79b85c333b02 | 287 | strcat(sendstring,"Date: Wed, 23 Apr 2021 04:36:25 GMT\n"); |
jack1930 | 35:79b85c333b02 | 288 | strcat(sendstring,"Connection: close\n"); |
jack1930 | 35:79b85c333b02 | 289 | strcat(sendstring,"Content-Type: "); |
jack1930 | 35:79b85c333b02 | 290 | strcat(sendstring,Mimetype); |
jack1930 | 35:79b85c333b02 | 291 | strcat(sendstring,"\n"); |
jack1930 | 35:79b85c333b02 | 292 | sprintf(hilf,"%d",strlen(webseite)); |
jack1930 | 35:79b85c333b02 | 293 | strcat(sendstring,"Content-Length: "); |
jack1930 | 35:79b85c333b02 | 294 | strcat(sendstring,hilf); |
jack1930 | 35:79b85c333b02 | 295 | strcat(sendstring,"\n\n"); |
jack1930 | 35:79b85c333b02 | 296 | strcat(sendstring,webseite); |
jack1930 | 35:79b85c333b02 | 297 | break; |
jack1930 | 37:4680b876f77b | 298 | |
jack1930 | 37:4680b876f77b | 299 | case 301: |
jack1930 | 37:4680b876f77b | 300 | case 302: sprintf(sendstring,"HTTP/1.1 %d %s\n",HTTPStatus,statustext); |
jack1930 | 37:4680b876f77b | 301 | strcat(sendstring,"Date: Wed, 23 Apr 2021 04:36:25 GMT\n"); |
jack1930 | 37:4680b876f77b | 302 | strcat(sendstring,"Connection: close\n"); |
jack1930 | 37:4680b876f77b | 303 | strcat(sendstring,"Location: http://www.gsoe.de/"); |
jack1930 | 37:4680b876f77b | 304 | strcat(sendstring,"\n\n"); |
jack1930 | 37:4680b876f77b | 305 | break; |
jack1930 | 35:79b85c333b02 | 306 | |
jack1930 | 35:79b85c333b02 | 307 | default: sprintf(sendstring,"HTTP/1.1 %d %s\n",HTTPStatus,statustext); |
jack1930 | 35:79b85c333b02 | 308 | strcat(sendstring,"Date: Wed, 23 Apr 2021 04:36:25 GMT\n"); |
jack1930 | 35:79b85c333b02 | 309 | strcat(sendstring,"Connection: close\n"); |
jack1930 | 35:79b85c333b02 | 310 | // strcat(sendstring,"Content-Type: "); |
jack1930 | 35:79b85c333b02 | 311 | // strcat(sendstring,Mimetype); |
jack1930 | 35:79b85c333b02 | 312 | // strcat(sendstring,"\n"); |
jack1930 | 35:79b85c333b02 | 313 | strcat(sendstring,"Content-Length: 0"); |
jack1930 | 35:79b85c333b02 | 314 | strcat(sendstring,"\n\n"); |
jack1930 | 35:79b85c333b02 | 315 | break; |
jack1930 | 35:79b85c333b02 | 316 | } |
jack1930 | 35:79b85c333b02 | 317 | |
jack1930 | 13:ed5c59ed4ae5 | 318 | if (dbg) printf("len=%d, inhalt=\n%s",strlen(sendstring),sendstring); |
jack1930 | 16:b09391fb73b4 | 319 | |
jack1930 | 13:ed5c59ed4ae5 | 320 | _parser->debug_on(true); |
jack1930 | 13:ed5c59ed4ae5 | 321 | _parser->send("AT+CIPSEND=%d,%d",clientID[clientIdx],strlen(sendstring)); |
jack1930 | 13:ed5c59ed4ae5 | 322 | _parser->debug_on(false); |
jack1930 | 13:ed5c59ed4ae5 | 323 | _parser->write(sendstring,strlen(sendstring)); |
jack1930 | 13:ed5c59ed4ae5 | 324 | HAL_Delay(200); |
jack1930 | 13:ed5c59ed4ae5 | 325 | _parser->send("AT+CIPCLOSE=%d",clientID[clientIdx]); |
jack1930 | 13:ed5c59ed4ae5 | 326 | return 0; |
jack1930 | 13:ed5c59ed4ae5 | 327 | } |
jack1930 | 13:ed5c59ed4ae5 | 328 | |
jack1930 | 36:e943a93d07f6 | 329 | int ESP8266Webserver::send(int HTTPStatus,const char* Mimetype, const char* webseite, int length) |
jack1930 | 36:e943a93d07f6 | 330 | { |
jack1930 | 36:e943a93d07f6 | 331 | char hilf[40]; |
jack1930 | 36:e943a93d07f6 | 332 | char statustext[40]; |
jack1930 | 36:e943a93d07f6 | 333 | |
jack1930 | 36:e943a93d07f6 | 334 | sprintf(statustext,"OK"); |
jack1930 | 36:e943a93d07f6 | 335 | |
jack1930 | 36:e943a93d07f6 | 336 | switch (HTTPStatus) |
jack1930 | 36:e943a93d07f6 | 337 | { |
jack1930 | 36:e943a93d07f6 | 338 | case 404: sprintf(statustext,"Not Found"); break; |
jack1930 | 36:e943a93d07f6 | 339 | case 206: sprintf(statustext,"Partial Content"); break; |
jack1930 | 36:e943a93d07f6 | 340 | case 401: sprintf(statustext,"Unauthorized"); break; |
jack1930 | 36:e943a93d07f6 | 341 | case 403: sprintf(statustext,"Forbidden"); break; |
jack1930 | 36:e943a93d07f6 | 342 | case 307: |
jack1930 | 36:e943a93d07f6 | 343 | case 302: sprintf(statustext,"Moved Temporarily"); break; |
jack1930 | 36:e943a93d07f6 | 344 | case 301: sprintf(statustext,"Moved Permanently"); break; |
jack1930 | 36:e943a93d07f6 | 345 | case 304: sprintf(statustext,"Not Modified"); break; |
jack1930 | 36:e943a93d07f6 | 346 | |
jack1930 | 36:e943a93d07f6 | 347 | } |
jack1930 | 36:e943a93d07f6 | 348 | |
jack1930 | 36:e943a93d07f6 | 349 | |
jack1930 | 36:e943a93d07f6 | 350 | //printf("\r\nHallo\r\n"); |
jack1930 | 36:e943a93d07f6 | 351 | Aufrufe++; |
jack1930 | 36:e943a93d07f6 | 352 | switch (HTTPStatus) |
jack1930 | 36:e943a93d07f6 | 353 | { |
jack1930 | 36:e943a93d07f6 | 354 | case 206: |
jack1930 | 36:e943a93d07f6 | 355 | case 200: sprintf(sendstring,"HTTP/1.1 %d %s\n",HTTPStatus,statustext); |
jack1930 | 36:e943a93d07f6 | 356 | strcat(sendstring,"Date: Wed, 23 Apr 2021 04:36:25 GMT\n"); |
jack1930 | 36:e943a93d07f6 | 357 | strcat(sendstring,"Connection: close\n"); |
jack1930 | 36:e943a93d07f6 | 358 | strcat(sendstring,"Content-Type: "); |
jack1930 | 36:e943a93d07f6 | 359 | strcat(sendstring,Mimetype); |
jack1930 | 36:e943a93d07f6 | 360 | strcat(sendstring,"\n"); |
jack1930 | 36:e943a93d07f6 | 361 | sprintf(hilf,"%d",length); |
jack1930 | 36:e943a93d07f6 | 362 | strcat(sendstring,"Content-Length: "); |
jack1930 | 36:e943a93d07f6 | 363 | strcat(sendstring,hilf); |
jack1930 | 36:e943a93d07f6 | 364 | strcat(sendstring,"\n\n"); |
jack1930 | 36:e943a93d07f6 | 365 | strcat(sendstring,webseite); |
jack1930 | 36:e943a93d07f6 | 366 | break; |
jack1930 | 36:e943a93d07f6 | 367 | |
jack1930 | 36:e943a93d07f6 | 368 | default: sprintf(sendstring,"HTTP/1.1 %d %s\n",HTTPStatus,statustext); |
jack1930 | 36:e943a93d07f6 | 369 | strcat(sendstring,"Date: Wed, 23 Apr 2021 04:36:25 GMT\n"); |
jack1930 | 36:e943a93d07f6 | 370 | strcat(sendstring,"Connection: close\n"); |
jack1930 | 36:e943a93d07f6 | 371 | // strcat(sendstring,"Content-Type: "); |
jack1930 | 36:e943a93d07f6 | 372 | // strcat(sendstring,Mimetype); |
jack1930 | 36:e943a93d07f6 | 373 | // strcat(sendstring,"\n"); |
jack1930 | 36:e943a93d07f6 | 374 | strcat(sendstring,"Content-Length: 0"); |
jack1930 | 36:e943a93d07f6 | 375 | strcat(sendstring,"\n\n"); |
jack1930 | 36:e943a93d07f6 | 376 | break; |
jack1930 | 36:e943a93d07f6 | 377 | } |
jack1930 | 36:e943a93d07f6 | 378 | |
jack1930 | 36:e943a93d07f6 | 379 | if (dbg) printf("len=%d, inhalt=\n%s",strlen(sendstring),sendstring); |
jack1930 | 36:e943a93d07f6 | 380 | |
jack1930 | 36:e943a93d07f6 | 381 | _parser->debug_on(true); |
jack1930 | 36:e943a93d07f6 | 382 | _parser->send("AT+CIPSEND=%d,%d",clientID[clientIdx],strlen(sendstring)+length); |
jack1930 | 36:e943a93d07f6 | 383 | _parser->debug_on(false); |
jack1930 | 36:e943a93d07f6 | 384 | _parser->write(sendstring,strlen(sendstring)); |
jack1930 | 36:e943a93d07f6 | 385 | HAL_Delay(200); |
jack1930 | 36:e943a93d07f6 | 386 | _parser->send("AT+CIPCLOSE=%d",clientID[clientIdx]); |
jack1930 | 36:e943a93d07f6 | 387 | return 0; |
jack1930 | 36:e943a93d07f6 | 388 | } |
jack1930 | 36:e943a93d07f6 | 389 | |
jack1930 | 36:e943a93d07f6 | 390 | |
jack1930 | 13:ed5c59ed4ae5 | 391 | void ESP8266Webserver::debugOn(bool pD) |
jack1930 | 13:ed5c59ed4ae5 | 392 | { |
jack1930 | 13:ed5c59ed4ae5 | 393 | dbg=pD; |
jack1930 | 16:b09391fb73b4 | 394 | _parser->debug_on(pD); |
jack1930 | 13:ed5c59ed4ae5 | 395 | } |
jack1930 | 13:ed5c59ed4ae5 | 396 | |
jack1930 | 16:b09391fb73b4 | 397 | const char* ESP8266Webserver::gibWert(string suchstring) |
jack1930 | 13:ed5c59ed4ae5 | 398 | { |
jack1930 | 13:ed5c59ed4ae5 | 399 | return ESP8266Webserver::gibWert(suchstring.c_str()); |
jack1930 | 13:ed5c59ed4ae5 | 400 | } |
jack1930 | 13:ed5c59ed4ae5 | 401 | |
jack1930 | 13:ed5c59ed4ae5 | 402 | const char* ESP8266Webserver::gibWert(const char* suchstring) |
jack1930 | 13:ed5c59ed4ae5 | 403 | { |
jack1930 | 40:6d79431a08aa | 404 | static char hilf[40]; |
jack1930 | 13:ed5c59ed4ae5 | 405 | |
jack1930 | 13:ed5c59ed4ae5 | 406 | char *fundort; |
jack1930 | 20:7924d3383786 | 407 | char *error; |
jack1930 | 20:7924d3383786 | 408 | char* referer; |
jack1930 | 20:7924d3383786 | 409 | char* favicon; |
jack1930 | 38:848feec26df5 | 410 | char* post; |
jack1930 | 40:6d79431a08aa | 411 | |
jack1930 | 38:848feec26df5 | 412 | post=strstr(recbuf,"POST"); |
jack1930 | 20:7924d3383786 | 413 | favicon=strstr(recbuf,"favicon"); |
jack1930 | 20:7924d3383786 | 414 | //if (favicon!=NULL) return NULL; |
jack1930 | 20:7924d3383786 | 415 | error=strstr(recbuf,"ERROR"); |
jack1930 | 20:7924d3383786 | 416 | //if (error==NULL) return NULL; |
jack1930 | 20:7924d3383786 | 417 | |
jack1930 | 20:7924d3383786 | 418 | referer=strstr(recbuf,"Referer"); |
jack1930 | 40:6d79431a08aa | 419 | |
jack1930 | 13:ed5c59ed4ae5 | 420 | int i=0; |
jack1930 | 38:848feec26df5 | 421 | fundort=strstr(recbuf,suchstring); |
jack1930 | 38:848feec26df5 | 422 | if (post==NULL) |
jack1930 | 38:848feec26df5 | 423 | { |
jack1930 | 20:7924d3383786 | 424 | if (fundort!=NULL&&(fundort<referer||referer==NULL)) |
jack1930 | 20:7924d3383786 | 425 | { |
jack1930 | 38:848feec26df5 | 426 | fundort=fundort+strlen(suchstring)+1; |
jack1930 | 38:848feec26df5 | 427 | while(i<20 && fundort[i]!=38 && fundort[i]>32 ) //space, & |
jack1930 | 38:848feec26df5 | 428 | { |
jack1930 | 38:848feec26df5 | 429 | hilf[i]=fundort[i]; |
jack1930 | 38:848feec26df5 | 430 | i++; |
jack1930 | 38:848feec26df5 | 431 | } |
jack1930 | 38:848feec26df5 | 432 | hilf[i]=0; |
jack1930 | 40:6d79431a08aa | 433 | |
jack1930 | 38:848feec26df5 | 434 | if (dbg) printf("\r\nsuchergebnis=%s\r\n",hilf); |
jack1930 | 40:6d79431a08aa | 435 | |
jack1930 | 40:6d79431a08aa | 436 | return hilf; |
jack1930 | 20:7924d3383786 | 437 | } |
jack1930 | 38:848feec26df5 | 438 | else return NULL; |
jack1930 | 38:848feec26df5 | 439 | } |
jack1930 | 38:848feec26df5 | 440 | else |
jack1930 | 38:848feec26df5 | 441 | { |
jack1930 | 38:848feec26df5 | 442 | if (fundort!=NULL) |
jack1930 | 38:848feec26df5 | 443 | { |
jack1930 | 38:848feec26df5 | 444 | fundort=fundort+strlen(suchstring)+1; |
jack1930 | 40:6d79431a08aa | 445 | |
jack1930 | 40:6d79431a08aa | 446 | while(i<40 && fundort[i]!='&' && fundort[i]!=0)//i<sizeof(fundort) ) |
jack1930 | 38:848feec26df5 | 447 | { |
jack1930 | 38:848feec26df5 | 448 | hilf[i]=fundort[i]; |
jack1930 | 38:848feec26df5 | 449 | i++; |
jack1930 | 38:848feec26df5 | 450 | } |
jack1930 | 38:848feec26df5 | 451 | hilf[i]=0; |
jack1930 | 41:b31ca06263ed | 452 | |
jack1930 | 38:848feec26df5 | 453 | if (dbg) printf("\r\nsuchergebnis=%s\r\n",hilf); |
jack1930 | 41:b31ca06263ed | 454 | |
jack1930 | 40:6d79431a08aa | 455 | for (int i=0;i<1000;i++) recbuf[i]=0; |
jack1930 | 38:848feec26df5 | 456 | return hilf; |
jack1930 | 38:848feec26df5 | 457 | } |
jack1930 | 38:848feec26df5 | 458 | else return NULL; |
jack1930 | 38:848feec26df5 | 459 | } |
jack1930 | 14:d17cfd8131b1 | 460 | } |
jack1930 | 14:d17cfd8131b1 | 461 | |
jack1930 | 15:e710f0431920 | 462 | void ESP8266Webserver::listAPs() |
jack1930 | 14:d17cfd8131b1 | 463 | { |
jack1930 | 16:b09391fb73b4 | 464 | int ips[4]; |
jack1930 | 15:e710f0431920 | 465 | //_parser->debug_on(true); |
jack1930 | 15:e710f0431920 | 466 | _parser->send("AT+CWMODE=1"); |
jack1930 | 17:87c762acb8d0 | 467 | HAL_Delay(300); |
jack1930 | 15:e710f0431920 | 468 | while (_parser->recv("OK")==false); |
jack1930 | 15:e710f0431920 | 469 | HAL_Delay(1000); |
jack1930 | 15:e710f0431920 | 470 | if (scanAPs==true) |
jack1930 | 14:d17cfd8131b1 | 471 | { |
jack1930 | 15:e710f0431920 | 472 | _parser->send("AT+CWLAP"); |
jack1930 | 15:e710f0431920 | 473 | while (!_serial->readable()); |
jack1930 | 15:e710f0431920 | 474 | HAL_Delay(10000); |
jack1930 | 15:e710f0431920 | 475 | printf("\r\nBuf="); |
jack1930 | 15:e710f0431920 | 476 | while (_serial->readable()) |
jack1930 | 15:e710f0431920 | 477 | { |
jack1930 | 15:e710f0431920 | 478 | _parser->read(recbuf, 1); |
jack1930 | 15:e710f0431920 | 479 | printf("%s",recbuf); |
jack1930 | 15:e710f0431920 | 480 | } |
jack1930 | 15:e710f0431920 | 481 | printf("\r\n"); |
jack1930 | 14:d17cfd8131b1 | 482 | } |
jack1930 | 15:e710f0431920 | 483 | for (int i=0;i<5;i++) |
jack1930 | 15:e710f0431920 | 484 | { |
jack1930 | 15:e710f0431920 | 485 | _parser->send("AT+CWJAP=\"%s\",\"%s\"",ssid,passwort); |
jack1930 | 15:e710f0431920 | 486 | HAL_Delay(1000); |
jack1930 | 15:e710f0431920 | 487 | if (_parser->recv("WIFI GOT IP")) i=6; |
jack1930 | 15:e710f0431920 | 488 | } |
jack1930 | 15:e710f0431920 | 489 | _parser->send("AT+CIFSR"); |
jack1930 | 15:e710f0431920 | 490 | while (_parser->recv("+CIFSR:STAIP,")==false) |
jack1930 | 15:e710f0431920 | 491 | { |
jack1930 | 15:e710f0431920 | 492 | _parser->send("AT+CIFSR"); |
jack1930 | 15:e710f0431920 | 493 | HAL_Delay(100); |
jack1930 | 15:e710f0431920 | 494 | } |
jack1930 | 16:b09391fb73b4 | 495 | |
jack1930 | 16:b09391fb73b4 | 496 | // _parser->read(ipadr,15); |
jack1930 | 16:b09391fb73b4 | 497 | _parser->scanf("\"%d.%d.%d.%d\"",&ips[0],&ips[1],&ips[2],&ips[3]); |
jack1930 | 16:b09391fb73b4 | 498 | sprintf(ipadr,"%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]); |
jack1930 | 15:e710f0431920 | 499 | printf("%s",ipadr); |
jack1930 | 15:e710f0431920 | 500 | |
jack1930 | 15:e710f0431920 | 501 | _parser->send("AT+CIPMUX=1"); |
jack1930 | 15:e710f0431920 | 502 | while (_parser->recv("OK")==false); |
jack1930 | 15:e710f0431920 | 503 | |
jack1930 | 15:e710f0431920 | 504 | //_parser->debug_on(false); |
jack1930 | 14:d17cfd8131b1 | 505 | } |
jack1930 | 14:d17cfd8131b1 | 506 | |
jack1930 | 15:e710f0431920 | 507 | char* ESP8266Webserver::gibIP() |
jack1930 | 14:d17cfd8131b1 | 508 | { |
jack1930 | 16:b09391fb73b4 | 509 | static char ipa[16]; |
jack1930 | 16:b09391fb73b4 | 510 | int j=0; |
jack1930 | 16:b09391fb73b4 | 511 | for (int i=0;i<strlen(ipadr);i++) |
jack1930 | 16:b09391fb73b4 | 512 | { |
jack1930 | 16:b09391fb73b4 | 513 | if (i==0 && ipadr[0]=='"'){} |
jack1930 | 16:b09391fb73b4 | 514 | else |
jack1930 | 16:b09391fb73b4 | 515 | { |
jack1930 | 16:b09391fb73b4 | 516 | switch (ipadr[i]) |
jack1930 | 16:b09391fb73b4 | 517 | { |
jack1930 | 16:b09391fb73b4 | 518 | case '0': |
jack1930 | 16:b09391fb73b4 | 519 | case '1': |
jack1930 | 16:b09391fb73b4 | 520 | case '2': |
jack1930 | 16:b09391fb73b4 | 521 | case '3': |
jack1930 | 16:b09391fb73b4 | 522 | case '4': |
jack1930 | 16:b09391fb73b4 | 523 | case '5': |
jack1930 | 16:b09391fb73b4 | 524 | case '6': |
jack1930 | 16:b09391fb73b4 | 525 | case '7': |
jack1930 | 16:b09391fb73b4 | 526 | case '8': |
jack1930 | 16:b09391fb73b4 | 527 | case '9': |
jack1930 | 16:b09391fb73b4 | 528 | case '.': ipa[j]=ipadr[i]; |
jack1930 | 16:b09391fb73b4 | 529 | j++; |
jack1930 | 16:b09391fb73b4 | 530 | break; |
jack1930 | 16:b09391fb73b4 | 531 | default: i=10000; break; |
jack1930 | 16:b09391fb73b4 | 532 | } |
jack1930 | 16:b09391fb73b4 | 533 | if (i==10000) break; |
jack1930 | 16:b09391fb73b4 | 534 | } |
jack1930 | 16:b09391fb73b4 | 535 | } |
jack1930 | 16:b09391fb73b4 | 536 | ipa[j+1]='\0'; |
jack1930 | 16:b09391fb73b4 | 537 | |
jack1930 | 16:b09391fb73b4 | 538 | return ipa; |
jack1930 | 14:d17cfd8131b1 | 539 | } |
jack1930 | 14:d17cfd8131b1 | 540 |