DE: Ein sehr, sehr einfacher Webserver mithilfe eines ESP8266 auf dem die AT-Firmware läuft . Für Bulme Bertl. - EN: A very, very, basic web server that works using an ESP8266 running the AT-Firmware.
Dependents: BULME_BERTL17_WebServer_ESPAT Bravo Team
Click here for example code!
DE:
Ein sehr, sehr einfacher Webserver mithilfe eines ESP8266 auf dem die AT-Firmware läuft. Getestet mit einem ESP-01 Modul am Bulme Bertl 2017 (LPC11U68).
EN:
A very, very, basic web server that works using an ESP8266 running the AT-Firmware. Tested with an ESP-01 Module and Bulme Bertl 2017 (LPC11U68).
Diff: ESPAT.cpp
- Revision:
- 2:61ed6c1c9bdd
- Parent:
- 1:aa115daaaa02
--- a/ESPAT.cpp Tue Feb 19 12:49:56 2019 +0000 +++ b/ESPAT.cpp Fri Mar 29 09:12:39 2019 +0000 @@ -4,15 +4,15 @@ /* Library for using an ESP8266 (e.g. ESP-01 board) with its AT command firmware as webserver -Version: 0.1.0 +Version: 1.0.0 (C)2019 Elias Nestl */ -ESPAT::ESPAT(PinName tx, PinName rx, string _wifiName, string _wifiPass, int baud) : espSerial(tx, rx, baud) { - wifiName = _wifiName; - wifiPass = _wifiPass; +ESPAT::ESPAT(PinName tx, PinName rx, int baud) : espSerial(tx, rx, baud) { } +//Serial pc(USBTX, USBRX, 115200); + void ESPAT::readStrUntil(string * str, char until) { while (true) { char c = espSerial.getc(); @@ -25,15 +25,19 @@ } void ESPAT::waitFor(char * text) { + //string s; for (int i = 0; i < strlen(text); i++) { char c = espSerial.getc(); + //s += c; if (c != text[i]) { i = 0; } } + //pc.printf("%s", s.c_str()); } void ESPAT::sendCommand(char * cmd, bool waitOk) { + //pc.printf("%s\r\n", cmd); espSerial.printf("%s\r\n", cmd); if (waitOk) waitFor("OK"); } @@ -43,9 +47,15 @@ waitFor("ready"); } -void ESPAT::initWifi() { +void ESPAT::initWifiStation(string ssid, string pwd) { sendCommand("AT+CWMODE_CUR=1"); - string wifiCmd = "AT+CWJAP_CUR=\"" + wifiName + "\",\"" + wifiPass + "\""; + string wifiCmd = "AT+CWJAP_CUR=\"" + ssid + "\",\"" + pwd + "\""; + sendCommand((char*) wifiCmd.c_str()); +} + +void ESPAT::initWifiAP(string ssid, string pwd, string channel, string encryption) { + sendCommand("AT+CWMODE_CUR=2"); + string wifiCmd = "AT+CWSAP_CUR=\"" + ssid + "\",\"" + pwd + "\"," + channel + "," + encryption; sendCommand((char*) wifiCmd.c_str()); } @@ -72,13 +82,6 @@ } } -void ESPAT::startWebServer(void (*readyCallback)(), void (*requestHandler)(int, string)) { - resetEsp(); - initWifi(); - readyCallback(); - initServer(requestHandler); -} - void ESPAT::tcpReply(int linkId, string data) { espSerial.printf("AT+CIPSEND=%d,%d\r\n", linkId, data.length()); wait(0.1); // Can't use waitFor here as it isn't fast enough