diff --git a/examples/AccessPoint_Server/AccessPoint_Server.ino b/examples/AccessPoint_Server/AccessPoint_Server.ino index 957d0e7..dc6cecf 100644 --- a/examples/AccessPoint_Server/AccessPoint_Server.ino +++ b/examples/AccessPoint_Server/AccessPoint_Server.ino @@ -16,14 +16,30 @@ #include #include +const char* ssid = "ESP_AP"; +const char* password = "123456789"; + SoftwareSerial espSerial(9, 10); // RX, TX +void onClientRequest(ESP8266proConnection* connection, + char* buffer, int length, boolean completed) +{ + if (completed) + { + Serial.println(F("onClientRequest")); + + // Send response from PROGMEM to miminize SRAM usage + connection->send(F("HTTP/1.0 200 OK")); + connection->send(F("Server: ESP8266pro\r\n")); + connection->send(F("Content-Type: text/html\r\n\r\n")); + connection->send(F("

Hello from ESP8266pro

")); + connection->close(); + } +} + ESP8266pro wifi(espSerial, Serial); // ESP, DBG ESP8266proServer server(wifi, onClientRequest); -const char* ssid = "ESP_AP"; -const char* password = "123456789"; - void setup() { espSerial.begin(9600); @@ -70,18 +86,3 @@ void loop() } } -void onClientRequest(ESP8266proConnection* connection, - char* buffer, int length, boolean completed) -{ - if (completed) - { - Serial.println(F("onClientRequest")); - - // Send response from PROGMEM to miminize SRAM usage - connection->send(F("HTTP/1.0 200 OK")); - connection->send(F("Server: ESP8266pro\r\n")); - connection->send(F("Content-Type: text/html\r\n\r\n")); - connection->send(F("

Hello from ESP8266pro

")); - connection->close(); - } -} diff --git a/examples/SimpleWebServer/SimpleWebServer.ino b/examples/SimpleWebServer/SimpleWebServer.ino index e4f08fd..961be7c 100644 --- a/examples/SimpleWebServer/SimpleWebServer.ino +++ b/examples/SimpleWebServer/SimpleWebServer.ino @@ -18,8 +18,6 @@ SoftwareSerial espSerial(9, 10); // RX, TX -ESP8266pro wifi(espSerial, Serial); -ESP8266proServer server(wifi, onClientRequest); String requestPaths[ESP_MAX_CONNECTIONS]; const char* ssid = "YouWiFi"; @@ -27,54 +25,6 @@ const char* password = "youpasswordhere"; const int ledPin = 13; -void setup() -{ - pinMode(ledPin, OUTPUT); - - espSerial.begin(9600); - Serial.begin(9600); - - while (!Serial) { - ; // wait for serial port to connect. Needed for Leonardo only - } - - // Initialize ESP - wifi.begin(); - - // Connect to WiFi network - // In future ESP should automatically reconnect - // to this network, if requried - do - { - if (!wifi.stationConnect(ssid, password)) - delay(3000); - } while (wifi.stationIP() == NULL_IP); - -// Start server on port 80 - server.start(80); - - // Get AP ip address - String ip = wifi.stationIP(); - - Serial.println(); - Serial.println("================================="); - Serial.println("Server started: http://" + ip); - Serial.println("================================="); -} - -void loop() -{ - // Process incoming requests - server.processRequests(); -} - -// Optional method to process remote response -void printResponse(ESP8266proConnection* connection, - char* buffer, int length, boolean completed) -{ - Serial.print(buffer); -} - void onClientRequest(ESP8266proConnection* connection, char* buffer, int length, boolean completed) { @@ -123,3 +73,55 @@ void onClientRequest(ESP8266proConnection* connection, connection->close(); } } + +ESP8266pro wifi(espSerial, Serial); +ESP8266proServer server(wifi, onClientRequest); + +void setup() +{ + pinMode(ledPin, OUTPUT); + + espSerial.begin(9600); + Serial.begin(9600); + + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // Initialize ESP + wifi.begin(); + + // Connect to WiFi network + // In future ESP should automatically reconnect + // to this network, if requried + do + { + if (!wifi.stationConnect(ssid, password)) + delay(3000); + } while (wifi.stationIP() == NULL_IP); + +// Start server on port 80 + server.start(80); + + // Get AP ip address + String ip = wifi.stationIP(); + + Serial.println(); + Serial.println("================================="); + Serial.println("Server started: http://" + ip); + Serial.println("================================="); +} + +void loop() +{ + // Process incoming requests + server.processRequests(); +} + +// Optional method to process remote response +void printResponse(ESP8266proConnection* connection, + char* buffer, int length, boolean completed) +{ + Serial.print(buffer); +} + diff --git a/examples/Station_DownloadPage/Station_DownloadPage.ino b/examples/Station_DownloadPage/Station_DownloadPage.ino index 32bfd23..a566b7d 100644 --- a/examples/Station_DownloadPage/Station_DownloadPage.ino +++ b/examples/Station_DownloadPage/Station_DownloadPage.ino @@ -49,6 +49,13 @@ void setup() Serial.println(wifi.stationIP()); } +// Optional method to process remote response +void printResponse(ESP8266proConnection* connection, + char* buffer, int length, boolean completed) +{ + Serial.print(buffer); +} + void loop() { // Send request @@ -59,11 +66,4 @@ void loop() con.close(); delay(5000); -} - -// Optional method to process remote response -void printResponse(ESP8266proConnection* connection, - char* buffer, int length, boolean completed) -{ - Serial.print(buffer); } \ No newline at end of file