From 9dfdfd5577a001191d91c975f03a2f592715bbf4 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 22 Nov 2018 16:26:16 +0100 Subject: [PATCH 01/28] update examples --- .../BearSSL_CertStore/BearSSL_CertStore.ino | 9 +- .../BearSSL_MaxFragmentLength.ino | 9 +- .../BearSSL_Server/BearSSL_Server.ino | 9 +- .../BearSSL_ServerClientCert.ino | 9 +- .../BearSSL_Sessions/BearSSL_Sessions.ino | 9 +- .../BearSSL_Validation/BearSSL_Validation.ino | 9 +- .../examples/HTTPSRequest/HTTPSRequest.ino | 18 +-- .../HTTPSRequestCACert/HTTPSRequestCACert.ino | 17 ++- .../examples/NTPClient/NTPClient.ino | 9 +- .../WiFiAccessPoint/WiFiAccessPoint.ino | 9 +- .../examples/WiFiClient/WiFiClient.ino | 15 +- .../WiFiClientBasic/WiFiClientBasic.ino | 9 +- .../examples/WiFiEvents/WiFiEvents.ino | 9 +- .../WiFiHTTPSServer/WiFiHTTPSServer.ino | 9 +- .../WiFiManualWebServer.ino} | 57 ++++---- .../WiFiTelnetToSerial/WiFiTelnetToSerial.ino | 134 ++++++++++++------ libraries/ESP8266WiFi/examples/udp/udp.ino | 8 +- libraries/ESP8266WiFi/src/WiFiClientSecure.h | 12 +- .../examples/httpUpdate/httpUpdate.ino | 7 +- .../httpUpdateSPIFFS/httpUpdateSPIFFS.ino | 7 +- .../httpUpdateSecure/httpUpdateSecure.ino | 7 +- 21 files changed, 268 insertions(+), 113 deletions(-) rename libraries/ESP8266WiFi/examples/{WiFiWebServer/WiFiWebServer.ino => WiFiManualWebServer/WiFiManualWebServer.ino} (56%) diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino index 19d609a6d6..30f923d1ed 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino @@ -37,8 +37,13 @@ #include #include -const char *ssid = "...."; -const char *pass = "...."; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char *ssid = SSID; +const char *pass = PSK; // A single, global CertStore which can be used by all // connections. Needs to stay live the entire time any of diff --git a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino index c609e085d5..a85aa9d257 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino @@ -6,8 +6,13 @@ #include -const char *ssid = "...."; -const char *pass = "...."; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char *ssid = SSID; +const char *pass = PSK; void fetch(BearSSL::WiFiClientSecure *client) { client->write("GET / HTTP/1.0\r\nHost: tls.mbed.org\r\nUser-Agent: ESP8266\r\n\r\n"); diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino index 51ba64dae2..207d87d0b5 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino @@ -37,8 +37,13 @@ #include #include -const char *ssid = "...."; -const char *pass = "...."; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char *ssid = SSID; +const char *pass = PSK; // The HTTPS server BearSSL::WiFiServerSecure server(443); diff --git a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino index e4ea4badb8..c7ef3ec445 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino @@ -65,8 +65,13 @@ #include #include -const char *ssid = "...."; -const char *pass = "...."; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char *ssid = SSID; +const char *pass = PSK; // The server which will require a client cert signed by the trusted CA BearSSL::WiFiServerSecure server(443); diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino index 10588ee896..0c00f66816 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino @@ -6,8 +6,13 @@ #include #include -const char *ssid = "...."; -const char *pass = "...."; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char *ssid = SSID; +const char *pass = PSK; const char * host = "api.github.com"; const uint16_t port = 443; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino index b1c0b96019..a4147fb711 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino @@ -7,8 +7,13 @@ #include #include -const char *ssid = "...."; -const char *pass = "...."; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char *ssid = SSID; +const char *pass = PSK; const char * host = "api.github.com"; const uint16_t port = 443; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino index 88d8b8288c..3091803eb3 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino @@ -19,15 +19,20 @@ #include #include -const char* ssid = "........"; -const char* password = "........"; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char* ssid = SSID; +const char* password = PSK; const char* host = "api.github.com"; const int httpsPort = 443; // Use web browser to view and copy // SHA1 fingerprint of the certificate -const char* fingerprint = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76"; +const char fingerprint[] PROGMEM = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76"; void setup() { Serial.begin(115200); @@ -54,11 +59,8 @@ void setup() { return; } - if (client.verify(fingerprint, host)) { - Serial.println("certificate matches"); - } else { - Serial.println("certificate doesn't match"); - } + Serial.printf("Using fingerprint '%s'\n", fingerprint); + client.setFingerprint(fingerprint); String url = "/repos/esp8266/Arduino/commits/master/status"; Serial.print("requesting URL: "); diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino index 1a63e6f658..650fef3258 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino @@ -17,10 +17,21 @@ #include #include -#include -const char* ssid = "........"; -const char* password = "........"; +// force use of AxTLS (BearSSL is now default) +#include +using namespace AxTLS; + +// uncomment the line below to run the sketch +#error Keeping this example for history, watch BearSSL_Validation example instead + +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char* ssid = SSID; +const char* password = PSK; const char* host = "api.github.com"; const int httpsPort = 443; diff --git a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino index 52e20eeeb7..d45e523655 100644 --- a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino +++ b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino @@ -21,8 +21,13 @@ #include #include -char ssid[] = "*************"; // your network SSID (name) -char pass[] = "********"; // your network password +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +char ssid[] = SSID; // your network SSID (name) +char pass[] = PSK; // your network password unsigned int localPort = 2390; // local port to listen for UDP packets diff --git a/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino b/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino index ec2bae6faa..6fea68f590 100644 --- a/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino +++ b/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino @@ -34,9 +34,14 @@ #include #include +#ifndef APSSID +#define APSSID "ESPap" +#define APPSK "thereisnospoon" +#endif + /* Set these to your desired credentials. */ -const char *ssid = "ESPap"; -const char *password = "thereisnospoon"; +const char *ssid = APSSID; +const char *password = APPSK; ESP8266WebServer server(80); diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index 111ed05b17..7466f7811c 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -5,8 +5,13 @@ #include -const char* ssid = "your-ssid"; -const char* password = "your-password"; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char* ssid = SSID; +const char* password = PSK; const char* host = "djxmmx.net"; const uint16_t port = 17; @@ -54,7 +59,10 @@ void loop() { // This will send a string to the server Serial.println("sending data to server"); - client.println("hello from ESP8266"); + if (client.connected()) + client.println("hello from ESP8266"); + + // wait for data to be available unsigned long timeout = millis(); while (client.available() == 0) { if (millis() - timeout > 5000) { @@ -67,6 +75,7 @@ void loop() { // Read all the lines of the reply from server and print them to Serial Serial.println("receiving from remote server"); + // not testing 'client.connected()' since we do not need to send data here while (client.available()) { char ch = static_cast(client.read()); Serial.print(ch); diff --git a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino index 056958c8c7..712049460a 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino @@ -7,8 +7,13 @@ #include #include -const char* ssid = "your-ssid"; -const char* password = "your-password"; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char* ssid = SSID; +const char* password = PSK; const char* host = "192.168.1.1"; const uint16_t port = 3000; diff --git a/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino b/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino index 9c0d5e355e..d72985a9c1 100644 --- a/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino +++ b/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino @@ -16,8 +16,13 @@ #include #include -const char* ssid = "ap-ssid"; -const char* password = "ap-password"; +#ifndef APSSID +#define APSSID "esp8266" +#define APPSK "esp8266" +#endif + +const char* ssid = APSSID; +const char* password = APPSK; WiFiEventHandler stationConnectedHandler; WiFiEventHandler stationDisconnectedHandler; diff --git a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino index 2e3034bd21..d3b5c6f658 100644 --- a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino @@ -43,8 +43,13 @@ #include -const char* ssid = "your-ssid"; -const char* password = "your-password"; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char* ssid = SSID; +const char* password = PSK; // The certificate is stored in PMEM static const uint8_t x509[] PROGMEM = { diff --git a/libraries/ESP8266WiFi/examples/WiFiWebServer/WiFiWebServer.ino b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino similarity index 56% rename from libraries/ESP8266WiFi/examples/WiFiWebServer/WiFiWebServer.ino rename to libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino index fb052f1711..157b6f6584 100644 --- a/libraries/ESP8266WiFi/examples/WiFiWebServer/WiFiWebServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino @@ -9,8 +9,13 @@ #include -const char* ssid = "your-ssid"; -const char* password = "your-password"; +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +const char* ssid = SSID; +const char* password = PSK; // Create an instance of the server // specify the port to listen on as an argument @@ -19,9 +24,9 @@ WiFiServer server(80); void setup() { Serial.begin(115200); - // prepare GPIO2 - pinMode(2, OUTPUT); - digitalWrite(2, 0); + // prepare LED + pinMode(BUILTIN_LED, OUTPUT); + digitalWrite(BUILTIN_LED, 0); // Connect to WiFi network Serial.println(); @@ -53,17 +58,14 @@ void loop() { if (!client) { return; } - - // Wait until the client sends some data Serial.println("new client"); - while (!client.available()) { - delay(1); - } + + client.setTimeout(5000); // default is 1000 // Read the first line of the request String req = client.readStringUntil('\r'); + Serial.println("request: "); Serial.println(req); - client.flush(); // Match the request int val; @@ -77,22 +79,25 @@ void loop() { return; } - // Set GPIO2 according to the request - digitalWrite(2, val); + // Set LED according to the request + digitalWrite(BUILTIN_LED, val); - client.flush(); - - // Prepare the response - String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nGPIO is now "; - s += (val) ? "high" : "low"; - s += "\n"; + // read/ignore the rest of the request + // do not client.flush(): it is for output only, see below + while (client.available()) + // byte by byte is not very efficient + client.read(); // Send the response to the client - client.print(s); - delay(1); - Serial.println("Client disonnected"); - - // The client will actually be disconnected - // when the function returns and 'client' object is detroyed + // it is OK for multiple small client.print/write, + // because nagle algorithm will group them into one single packet + // ::print*_P(F("string")) is always usable and saves RAM + client.print_P(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nGPIO is now ")); + client.print_P((val) ? F("high" ): F("low")); + client.print_P(F("\n")); + + // The client will actually be *flushed* then disconnected + // when the function returns and 'client' object is destroyed (out-of-scope) + // flush = ensure written data are received by the other side + Serial.println("Disconnecting from client"); } - diff --git a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino index 5bf828e0ee..db8cbd4d8c 100644 --- a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino +++ b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino @@ -20,83 +20,129 @@ */ #include +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif + +/* SWAP_PINS: + * 0: use Serial1 for logging (legacy example) + * 1: configure Serial port on RX:GPIO13 TX:GPIO15 + * and use SoftwareSerial for logging on standard serial pins + */ +#define SWAP_PINS 1 + +#if SWAP_PINS +#include +SoftwareSerial* logguer = nullptr; +#else +#define logguer (&Serial1) +#endif + +#define STACK_PROTECTOR 512 // bytes + //how many clients should be able to telnet to this ESP8266 -#define MAX_SRV_CLIENTS 1 -const char* ssid = "**********"; -const char* password = "**********"; +#define MAX_SRV_CLIENTS 2 +const char* ssid = SSID; +const char* password = PSK; + +const int port = 23; -WiFiServer server(23); +WiFiServer server(port); WiFiClient serverClients[MAX_SRV_CLIENTS]; void setup() { - Serial1.begin(115200); + +#if SWAP_PINS + Serial.swap(); + // Hardware serial is now on RX:GPIO13 TX:GPIO15 + // use SoftwareSerial on regular RX(3)/TX(1) for logging + logger = new SoftwareSerial(3, 1); +#endif + logger->begin(115200); + WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); - Serial1.print("\nConnecting to "); Serial1.println(ssid); + logger->print("\nConnecting to "); + logger->println(ssid); uint8_t i = 0; - while (WiFi.status() != WL_CONNECTED && i++ < 20) { + while (WiFi.status() != WL_CONNECTED) { + logger->print('.'); delay(500); } - if (i == 21) { - Serial1.print("Could not connect to"); Serial1.println(ssid); - while (1) { - delay(500); - } - } + logger->println(); + logger->println("connected, address=" + WiFi.localIP()); + //start UART and the server Serial.begin(115200); server.begin(); server.setNoDelay(true); - Serial1.print("Ready! Use 'telnet "); - Serial1.print(WiFi.localIP()); - Serial1.println(" 23' to connect"); + logger->print("Ready! Use 'telnet "); + logger->print(WiFi.localIP()); + logger->printf(" %d' to connect", port); } void loop() { uint8_t i; //check if there are any new clients if (server.hasClient()) { - for (i = 0; i < MAX_SRV_CLIENTS; i++) { - //find free/disconnected spot - if (!serverClients[i] || !serverClients[i].connected()) { - if (serverClients[i]) { - serverClients[i].stop(); - } + //find free/disconnected spot + for (i = 0; i < MAX_SRV_CLIENTS; i++) + if (!serverClients[i]) { // equivalent to !serverClients[i].connected() serverClients[i] = server.available(); - Serial1.print("New client: "); Serial1.print(i); + logger->print("New client: "); + logger->print(i); break; } - } + //no free/disconnected spot so reject if (i == MAX_SRV_CLIENTS) { - WiFiClient serverClient = server.available(); - serverClient.stop(); - Serial1.println("Connection rejected "); + server.available()->println("busy"); + // hints: server.available() is a WiFiClient with short-term scope + // when out of scope, a WiFiClient will + // - flush() - all data will be sent + // - stop() - automatically too + logger->printf("server is busy with %d active connections\n", MAX_SRV_CLIENTS); } } - //check clients for data - for (i = 0; i < MAX_SRV_CLIENTS; i++) { - if (serverClients[i] && serverClients[i].connected()) { - if (serverClients[i].available()) { - //get data from the telnet client and push it to the UART - while (serverClients[i].available()) { - Serial.write(serverClients[i].read()); - } + + //check TCP clients for data + for (i = 0; i < MAX_SRV_CLIENTS; i++) + while (serverClients[i].available() && Serial.availableForWrite() > 0) + // working char by char is not very efficient + // every single read() will send a TCP ACK + Serial.write(serverClients[i].read()); + + // determine maximum output size "fair TCP use" + // client.availableForWrite() returns 0 when !client.connected() + size_t maxToTcp = 0; + for (i = 0; i < MAX_SRV_CLIENTS; i++) + if (serverClients[i]) { + size_t afw = serverClients[i].availableForWrite(); + if (afw) { + if (!maxToTcp) + maxToTcp = afw; + else + maxToTcp = std::min(maxToTcp, afw); + } else { + // warn but ignore congested clients + logguer->println("one client is congested"); } } - } + //check UART for data - if (Serial.available()) { - size_t len = Serial.available(); + size_t len = std::min(Serial.available(), maxToTcp); + len = std::min(len, STACK_PROTECTOR); + if (len) { uint8_t sbuf[len]; Serial.readBytes(sbuf, len); - //push UART data to all connected telnet clients - for (i = 0; i < MAX_SRV_CLIENTS; i++) { - if (serverClients[i] && serverClients[i].connected()) { + // push UART data to all connected telnet clients + for (i = 0; i < MAX_SRV_CLIENTS; i++) + // if client.availableForWrite() was 0 (congested) + // and increased since then, + // ensure write space is sufficient: + if (serverClient[i].availableForWrite() >= len) serverClients[i].write(sbuf, len); - delay(1); - } - } } } diff --git a/libraries/ESP8266WiFi/examples/udp/udp.ino b/libraries/ESP8266WiFi/examples/udp/udp.ino index 5759905bd2..0a4e15293d 100644 --- a/libraries/ESP8266WiFi/examples/udp/udp.ino +++ b/libraries/ESP8266WiFi/examples/udp/udp.ino @@ -18,8 +18,10 @@ #include #include -#define SSID "ssid" -#define PSK "psk" +#ifndef SSID +#define SSID "your-ssid" +#define PSK "your-password" +#endif unsigned int localPort = 8888; // local port to listen on @@ -75,6 +77,6 @@ void loop() { /* test (shell/netcat): - --------------- + -------------------- nc -u 192.168.esp.address 8888 */ diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.h b/libraries/ESP8266WiFi/src/WiFiClientSecure.h index 6d1d4df845..9c3664c2e0 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.h @@ -23,5 +23,15 @@ #include "WiFiClientSecureAxTLS.h" #include "WiFiClientSecureBearSSL.h" +//using namespace axTLS; +using namespace BearSSL; + +/* !! Now BearSSL is the default !! + + While not advised, + to keep legacy code without updating, use: + +#include "WiFiClientSecureAxTLS.h" using namespace axTLS; -// using namespace BearSSL; + +*/ diff --git a/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino b/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino index 3763bd1f79..34ca179429 100644 --- a/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino +++ b/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino @@ -15,6 +15,11 @@ #define USE_SERIAL Serial +#ifndef APSSID +#define APSSID "APSSID" +#define APPSK "APPSK" +#endif + ESP8266WiFiMulti WiFiMulti; void setup() { @@ -33,7 +38,7 @@ void setup() { } WiFi.mode(WIFI_STA); - WiFiMulti.addAP("SSID", "PASSWORD"); + WiFiMulti.addAP(APSSID, APPSK); } diff --git a/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino b/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino index 9253e8379f..8e035fde63 100644 --- a/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino +++ b/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino @@ -17,6 +17,11 @@ ESP8266WiFiMulti WiFiMulti; +#ifndef APSSID +#define APSSID "APSSID" +#define APPSK "APPSK" +#endif + void setup() { USE_SERIAL.begin(115200); @@ -33,7 +38,7 @@ void setup() { } WiFi.mode(WIFI_STA); - WiFiMulti.addAP("SSID", "PASSWORD"); + WiFiMulti.addAP(APSSID, APPSK); } diff --git a/libraries/ESP8266httpUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino b/libraries/ESP8266httpUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino index 546e20f886..e50ef54f5e 100644 --- a/libraries/ESP8266httpUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino +++ b/libraries/ESP8266httpUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino @@ -15,6 +15,11 @@ #define USE_SERIAL Serial +#ifndef APSSID +#define APSSID "APSSID" +#define APPSK "APPSK" +#endif + ESP8266WiFiMulti WiFiMulti; // A single, global CertStore which can be used by all @@ -93,7 +98,7 @@ void setup() { } WiFi.mode(WIFI_STA); - WiFiMulti.addAP("SSID", "PASSWORD"); + WiFiMulti.addAP(APSSID, APPSK); SPIFFS.begin(); From a28b183c3d201076c316abf7dcf46c5721691b3f Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 23 Nov 2018 15:36:43 +0100 Subject: [PATCH 02/28] fix serial<->tcp example, use STASSID instead of SSID (name collision) --- .../BearSSL_CertStore/BearSSL_CertStore.ino | 6 +- .../BearSSL_MaxFragmentLength.ino | 6 +- .../BearSSL_Server/BearSSL_Server.ino | 6 +- .../BearSSL_ServerClientCert.ino | 6 +- .../BearSSL_Sessions/BearSSL_Sessions.ino | 6 +- .../BearSSL_Validation/BearSSL_Validation.ino | 6 +- .../examples/HTTPSRequest/HTTPSRequest.ino | 6 +- .../HTTPSRequestCACert/HTTPSRequestCACert.ino | 6 +- .../examples/NTPClient/NTPClient.ino | 8 +- .../examples/WiFiClient/WiFiClient.ino | 6 +- .../WiFiClientBasic/WiFiClientBasic.ino | 6 +- .../WiFiHTTPSServer/WiFiHTTPSServer.ino | 6 +- .../WiFiManualWebServer.ino | 6 +- .../WiFiTelnetToSerial/WiFiTelnetToSerial.ino | 116 +++++++++++++----- libraries/ESP8266WiFi/examples/udp/udp.ino | 6 +- 15 files changed, 130 insertions(+), 72 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino index 30f923d1ed..a98636f2e9 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino @@ -37,12 +37,12 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char *ssid = SSID; +const char *ssid = STASSID; const char *pass = PSK; // A single, global CertStore which can be used by all diff --git a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino index a85aa9d257..1a24dd658e 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino @@ -6,12 +6,12 @@ #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char *ssid = SSID; +const char *ssid = STASSID; const char *pass = PSK; void fetch(BearSSL::WiFiClientSecure *client) { diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino index 207d87d0b5..2810d8da3b 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino @@ -37,12 +37,12 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char *ssid = SSID; +const char *ssid = STASSID; const char *pass = PSK; // The HTTPS server diff --git a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino index c7ef3ec445..7fa6997878 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino @@ -65,12 +65,12 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char *ssid = SSID; +const char *ssid = STASSID; const char *pass = PSK; // The server which will require a client cert signed by the trusted CA diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino index 0c00f66816..1de0073465 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino @@ -6,12 +6,12 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char *ssid = SSID; +const char *ssid = STASSID; const char *pass = PSK; const char * host = "api.github.com"; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino index a4147fb711..781554dd96 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino @@ -7,12 +7,12 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char *ssid = SSID; +const char *ssid = STASSID; const char *pass = PSK; const char * host = "api.github.com"; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino index 3091803eb3..959c88c9cb 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino @@ -19,12 +19,12 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char* ssid = SSID; +const char* ssid = STASSID; const char* password = PSK; const char* host = "api.github.com"; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino index 650fef3258..d910a32286 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino @@ -25,12 +25,12 @@ using namespace AxTLS; // uncomment the line below to run the sketch #error Keeping this example for history, watch BearSSL_Validation example instead -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char* ssid = SSID; +const char* ssid = STASSID; const char* password = PSK; const char* host = "api.github.com"; diff --git a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino index d45e523655..9193839b52 100644 --- a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino +++ b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino @@ -21,13 +21,13 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -char ssid[] = SSID; // your network SSID (name) -char pass[] = PSK; // your network password +char ssid[] = STASSID; // your network SSID (name) +char pass[] = PSK; // your network password unsigned int localPort = 2390; // local port to listen for UDP packets diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index 7466f7811c..e07a5fb684 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -5,12 +5,12 @@ #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char* ssid = SSID; +const char* ssid = STASSID; const char* password = PSK; const char* host = "djxmmx.net"; diff --git a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino index 712049460a..ebb20d6d4b 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino @@ -7,12 +7,12 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char* ssid = SSID; +const char* ssid = STASSID; const char* password = PSK; const char* host = "192.168.1.1"; diff --git a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino index d3b5c6f658..cf45c775cc 100644 --- a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino @@ -43,12 +43,12 @@ #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char* ssid = SSID; +const char* ssid = STASSID; const char* password = PSK; // The certificate is stored in PMEM diff --git a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino index 157b6f6584..9c8e3d9a4e 100644 --- a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino @@ -9,12 +9,12 @@ #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -const char* ssid = SSID; +const char* ssid = STASSID; const char* password = PSK; // Create an instance of the server diff --git a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino index db8cbd4d8c..9711c73640 100644 --- a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino +++ b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino @@ -20,30 +20,55 @@ */ #include -#ifndef SSID -#define SSID "your-ssid" +#include + +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif -/* SWAP_PINS: - * 0: use Serial1 for logging (legacy example) - * 1: configure Serial port on RX:GPIO13 TX:GPIO15 - * and use SoftwareSerial for logging on standard serial pins - */ +/* + SWAP_PINS: + 0: use Serial1 for logging (legacy example) + 1: configure Hardware Serial port on RX:GPIO13 TX:GPIO15 + and use SoftwareSerial for logging on + standard Serial pins RX:GPIO3 and TX:GPIO1 +*/ + #define SWAP_PINS 1 +/* + SERIAL_LOOPBACK + 0: normal serial operations + 1: RX-TX are internally connected (loopback) +*/ + +#define SERIAL_LOOPBACK 0 + +#define BAUD_SERIAL 115200 +#define BAUD_LOGGER 115200 +#define RXBUFFERSIZE 1024 + +//////////////////////////////////////////////////////////// + +#if SERIAL_LOOPBACK +#undef BAUD_SERIAL +#define BAUD_SERIAL 3000000 +#include +#endif + #if SWAP_PINS #include -SoftwareSerial* logguer = nullptr; +SoftwareSerial* logger = nullptr; #else -#define logguer (&Serial1) +#define logger (&Serial1) #endif #define STACK_PROTECTOR 512 // bytes //how many clients should be able to telnet to this ESP8266 #define MAX_SRV_CLIENTS 2 -const char* ssid = SSID; +const char* ssid = STASSID; const char* password = PSK; const int port = 23; @@ -53,52 +78,66 @@ WiFiClient serverClients[MAX_SRV_CLIENTS]; void setup() { + Serial.begin(BAUD_SERIAL); + Serial.setRxBufferSize(RXBUFFERSIZE); + #if SWAP_PINS Serial.swap(); // Hardware serial is now on RX:GPIO13 TX:GPIO15 // use SoftwareSerial on regular RX(3)/TX(1) for logging logger = new SoftwareSerial(3, 1); + logger->begin(BAUD_LOGGER); + logger->println("\n\nUsing SoftwareSerial for logging"); +#else + logger->begin(BAUD_LOGGER); + logger->println("\n\nUsing Serial1 for logging"); +#endif + logger->println(ESP.getFullVersion()); + logger->printf("Serial baud: %d (8n1: %d KB/s)\n", BAUD_SERIAL, BAUD_SERIAL * 8 / 10 / 1024); + logger->printf("Serial receive buffer size: %d bytes\n", RXBUFFERSIZE); + +#if SERIAL_LOOPBACK + USC0(0) |= (1 << UCLBE); // incomplete HardwareSerial API + logger->println("Serial Internal Loopback enabled"); #endif - logger->begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); logger->print("\nConnecting to "); logger->println(ssid); - uint8_t i = 0; while (WiFi.status() != WL_CONNECTED) { logger->print('.'); delay(500); } logger->println(); - logger->println("connected, address=" + WiFi.localIP()); + logger->print("connected, address="); + logger->println(WiFi.localIP()); - //start UART and the server - Serial.begin(115200); + //start server server.begin(); server.setNoDelay(true); logger->print("Ready! Use 'telnet "); logger->print(WiFi.localIP()); - logger->printf(" %d' to connect", port); + logger->printf(" %d' to connect\n", port); } void loop() { - uint8_t i; //check if there are any new clients if (server.hasClient()) { //find free/disconnected spot + int i; for (i = 0; i < MAX_SRV_CLIENTS; i++) if (!serverClients[i]) { // equivalent to !serverClients[i].connected() serverClients[i] = server.available(); - logger->print("New client: "); + logger->print("New client: index "); logger->print(i); break; } //no free/disconnected spot so reject if (i == MAX_SRV_CLIENTS) { - server.available()->println("busy"); + server.available().println("busy"); // hints: server.available() is a WiFiClient with short-term scope // when out of scope, a WiFiClient will // - flush() - all data will be sent @@ -108,16 +147,31 @@ void loop() { } //check TCP clients for data - for (i = 0; i < MAX_SRV_CLIENTS; i++) +#if 1 + // Incredibly, this code is faster than the bufferred one below - #4620 is needed + // loopback/3000000baud average 348KB/s + for (int i = 0; i < MAX_SRV_CLIENTS; i++) while (serverClients[i].available() && Serial.availableForWrite() > 0) // working char by char is not very efficient - // every single read() will send a TCP ACK Serial.write(serverClients[i].read()); +#else + // loopback/3000000baud average: 312KB/s + for (int i = 0; i < MAX_SRV_CLIENTS; i++) + while (serverClients[i].available() && Serial.availableForWrite() > 0) { + size_t maxToSerial = std::min(serverClients[i].available(), Serial.availableForWrite()); + maxToSerial = std::min(maxToSerial, (size_t)STACK_PROTECTOR); + uint8_t buf[maxToSerial]; + size_t tcp_got = serverClients[i].read(buf, maxToSerial); + size_t serial_sent = Serial.write(buf, tcp_got); + if (serial_sent != maxToSerial) + logger->printf("len mismatch: available:%zd tcp-read:%zd serial-write:%zd\n", maxToSerial, tcp_got, serial_sent); + } +#endif // determine maximum output size "fair TCP use" // client.availableForWrite() returns 0 when !client.connected() size_t maxToTcp = 0; - for (i = 0; i < MAX_SRV_CLIENTS; i++) + for (int i = 0; i < MAX_SRV_CLIENTS; i++) if (serverClients[i]) { size_t afw = serverClients[i].availableForWrite(); if (afw) { @@ -127,22 +181,26 @@ void loop() { maxToTcp = std::min(maxToTcp, afw); } else { // warn but ignore congested clients - logguer->println("one client is congested"); + logger->println("one client is congested"); } } //check UART for data - size_t len = std::min(Serial.available(), maxToTcp); - len = std::min(len, STACK_PROTECTOR); + size_t len = std::min((size_t)Serial.available(), maxToTcp); + len = std::min(len, (size_t)STACK_PROTECTOR); if (len) { uint8_t sbuf[len]; - Serial.readBytes(sbuf, len); + size_t serial_got = Serial.readBytes(sbuf, len); // push UART data to all connected telnet clients - for (i = 0; i < MAX_SRV_CLIENTS; i++) + for (int i = 0; i < MAX_SRV_CLIENTS; i++) // if client.availableForWrite() was 0 (congested) // and increased since then, // ensure write space is sufficient: - if (serverClient[i].availableForWrite() >= len) - serverClients[i].write(sbuf, len); + if (serverClients[i].availableForWrite() >= serial_got) + { + size_t tcp_sent = serverClients[i].write(sbuf, serial_got); + if (tcp_sent != len) + logger->printf("len mismatch: available:%zd serial-read:%zd tcp-write:%zd\n", len, serial_got, tcp_sent); + } } } diff --git a/libraries/ESP8266WiFi/examples/udp/udp.ino b/libraries/ESP8266WiFi/examples/udp/udp.ino index 0a4e15293d..5fa06239b2 100644 --- a/libraries/ESP8266WiFi/examples/udp/udp.ino +++ b/libraries/ESP8266WiFi/examples/udp/udp.ino @@ -18,8 +18,8 @@ #include #include -#ifndef SSID -#define SSID "your-ssid" +#ifndef STASSID +#define STASSID "your-ssid" #define PSK "your-password" #endif @@ -34,7 +34,7 @@ WiFiUDP Udp; void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); - WiFi.begin(SSID, PSK); + WiFi.begin(STASSID, PSK); while (WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(500); From be3c5cf22481e6a78c008e259f85cf6d43256c99 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 23 Nov 2018 17:05:18 +0100 Subject: [PATCH 03/28] fix HTTPSRequest.ino --- .../ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino index 959c88c9cb..982322b17d 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino @@ -54,14 +54,15 @@ void setup() { WiFiClientSecure client; Serial.print("connecting to "); Serial.println(host); + + Serial.printf("Using fingerprint '%s'\n", fingerprint); + client.setFingerprint(fingerprint); + if (!client.connect(host, httpsPort)) { Serial.println("connection failed"); return; } - Serial.printf("Using fingerprint '%s'\n", fingerprint); - client.setFingerprint(fingerprint); - String url = "/repos/esp8266/Arduino/commits/master/status"; Serial.print("requesting URL: "); Serial.println(url); From 7e40b184a03f78f89df57e4c72e9f304440569ea Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 01:05:23 +0100 Subject: [PATCH 04/28] update AxTLS HTTPS examples, update AxTLS API to deprecated --- .../HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino | 102 ++++++++++++++++++ .../CACert.ino | 0 .../HTTPSRequestCACertAxTLS.ino} | 5 +- libraries/ESP8266WiFi/src/ESP8266WiFi.h | 8 +- libraries/ESP8266WiFi/src/WiFiClientSecure.h | 15 +-- .../ESP8266WiFi/src/WiFiClientSecureAxTLS.h | 2 +- .../ESP8266WiFi/src/WiFiClientSecureBearSSL.h | 19 +++- .../ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp | 4 + 8 files changed, 136 insertions(+), 19 deletions(-) create mode 100644 libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino rename libraries/ESP8266WiFi/examples/{HTTPSRequestCACert => HTTPSRequestCACertAxTLS}/CACert.ino (100%) rename libraries/ESP8266WiFi/examples/{HTTPSRequestCACert/HTTPSRequestCACert.ino => HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino} (95%) diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino new file mode 100644 index 0000000000..55445a6366 --- /dev/null +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino @@ -0,0 +1,102 @@ +/* + HTTP over TLS (HTTPS) example sketch + + This example demonstrates how to use + WiFiClientSecure class to access HTTPS API. + We fetch and display the status of + esp8266/Arduino project continuous integration + build. + + Limitations: + only RSA certificates + no support of Perfect Forward Secrecy (PFS) + TLSv1.2 is supported since version 2.4.0-rc1 + + Created by Ivan Grokhotkov, 2015. + This example is in public domain. +*/ + +#include + +// force use of AxTLS (BearSSL is now default) +#include +using namespace axTLS; + +#ifndef STASSID +#define STASSID "your-ssid" +#define PSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = PSK; + +const char* host = "api.github.com"; +const int httpsPort = 443; + +// Use web browser to view and copy +// SHA1 fingerprint of the certificate +const char* fingerprint = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76"; + +void setup() { + Serial.begin(115200); + Serial.println(); + Serial.print("connecting to "); + Serial.println(ssid); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + + // Use WiFiClientSecure class to create TLS connection + WiFiClientSecure client; + Serial.print("connecting to "); + Serial.println(host); + if (!client.connect(host, httpsPort)) { + Serial.println("connection failed"); + return; + } + + if (client.verify(fingerprint, host)) { + Serial.println("certificate matches"); + } else { + Serial.println("certificate doesn't match"); + } + + String url = "/repos/esp8266/Arduino/commits/master/status"; + Serial.print("requesting URL: "); + Serial.println(url); + + client.print(String("GET ") + url + " HTTP/1.1\r\n" + + "Host: " + host + "\r\n" + + "User-Agent: BuildFailureDetectorESP8266\r\n" + + "Connection: close\r\n\r\n"); + + Serial.println("request sent"); + while (client.connected()) { + String line = client.readStringUntil('\n'); + if (line == "\r") { + Serial.println("headers received"); + break; + } + } + String line = client.readStringUntil('\n'); + if (line.startsWith("{\"state\":\"success\"")) { + Serial.println("esp8266/Arduino CI successfull!"); + } else { + Serial.println("esp8266/Arduino CI has failed"); + } + Serial.println("reply was:"); + Serial.println("=========="); + Serial.println(line); + Serial.println("=========="); + Serial.println("closing connection"); +} + +void loop() { +} diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/CACert.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/CACert.ino similarity index 100% rename from libraries/ESP8266WiFi/examples/HTTPSRequestCACert/CACert.ino rename to libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/CACert.ino diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino similarity index 95% rename from libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino rename to libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino index d910a32286..0949bec106 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino @@ -20,10 +20,7 @@ // force use of AxTLS (BearSSL is now default) #include -using namespace AxTLS; - -// uncomment the line below to run the sketch -#error Keeping this example for history, watch BearSSL_Validation example instead +using namespace axTLS; #ifndef STASSID #define STASSID "your-ssid" diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.h b/libraries/ESP8266WiFi/src/ESP8266WiFi.h index 2ff5208a97..117a3e341c 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.h @@ -38,10 +38,10 @@ extern "C" { #include "WiFiClient.h" #include "WiFiServer.h" -#include "WiFiServerSecure.h" -#include "WiFiClientSecure.h" -#include "BearSSLHelpers.h" -#include "CertStoreBearSSL.h" +//#include "WiFiServerSecure.h" +//#include "WiFiClientSecure.h" +//#include "BearSSLHelpers.h" +//#include "CertStoreBearSSL.h" #ifdef DEBUG_ESP_WIFI #ifdef DEBUG_ESP_PORT diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.h b/libraries/ESP8266WiFi/src/WiFiClientSecure.h index 9c3664c2e0..847a742698 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.h @@ -20,18 +20,21 @@ */ -#include "WiFiClientSecureAxTLS.h" -#include "WiFiClientSecureBearSSL.h" - +//#include "WiFiClientSecureAxTLS.h" //using namespace axTLS; + +#include "WiFiClientSecureBearSSL.h" using namespace BearSSL; -/* !! Now BearSSL is the default !! +/********************************** + * !! Now BearSSL is the default !! While not advised, - to keep legacy code without updating, use: + Use legacy API without updating with: +//#include #include "WiFiClientSecureAxTLS.h" using namespace axTLS; -*/ + * + **********************************/ diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureAxTLS.h b/libraries/ESP8266WiFi/src/WiFiClientSecureAxTLS.h index fabfb5e4ef..fc7202ef3e 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureAxTLS.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureAxTLS.h @@ -32,7 +32,7 @@ class SSLContext; class WiFiClientSecure : public WiFiClient { public: - WiFiClientSecure(); + WiFiClientSecure() __attribute__((deprecated("Upgrade to BearSSL is advised, check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))); ~WiFiClientSecure() override; int connect(IPAddress ip, uint16_t port) override; diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h index ade6dc6a0a..46b2e87d68 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h @@ -121,10 +121,6 @@ class WiFiClientSecure : public WiFiClient { static bool probeMaxFragmentLength(const char *hostname, uint16_t port, uint16_t len); static bool probeMaxFragmentLength(const String host, uint16_t port, uint16_t len); - // AXTLS compatible wrappers - // Cannot implement this mode, we need FP before we can connect: bool verify(const char* fingerprint, const char* domain_name) - bool verifyCertChain(const char* domain_name) { (void)domain_name; return connected(); } // If we're connected, the cert passed validation during handshake - bool setCACert(const uint8_t* pk, size_t size); bool setCertificate(const uint8_t* pk, size_t size); bool setPrivateKey(const uint8_t* pk, size_t size); @@ -152,6 +148,21 @@ class WiFiClientSecure : public WiFiClient { return loadCACert(file, file.size()); } + // AxTLS API deprecated warnings to help upgrading + + bool verify(const char* fingerprint, const char* domain_name) + __attribute__((deprecated("This is deprecated AxTLS API, check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))) { + (void)fingerprint; + (void)domain_name; + return connected(); + } + + bool verifyCertChain(const char* domain_name) + __attribute__((deprecated("This is deprecated AxTLS API, check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))) { + (void)domain_name; + return connected(); + } + private: void _clear(); void _clearAuthenticationSettings(); diff --git a/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp b/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp index 4cb3ae5cf3..61ae84309d 100644 --- a/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp @@ -30,6 +30,7 @@ extern "C" { #include "ESP8266WiFi.h" #include "WiFiClient.h" #include "WiFiServer.h" +#include "WiFiClientSecureAxTLS.h" #include "lwip/opt.h" #include "lwip/tcp.h" #include "lwip/inet.h" @@ -77,7 +78,10 @@ WiFiClientSecure WiFiServerSecure::available(uint8_t* status) } optimistic_yield(1000); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" return WiFiClientSecure(); +#pragma GCC diagnostic pop } }; From 3e94897d733e613d962359dace7df3404f46fad0 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 01:36:15 +0100 Subject: [PATCH 05/28] fixes --- .../BearSSL_CertStore/BearSSL_CertStore.ino | 4 +- .../BearSSL_MaxFragmentLength.ino | 4 +- .../BearSSL_Server/BearSSL_Server.ino | 4 +- .../BearSSL_ServerClientCert.ino | 4 +- .../BearSSL_Sessions/BearSSL_Sessions.ino | 4 +- .../BearSSL_Validation/BearSSL_Validation.ino | 4 +- .../examples/HTTPSRequest/HTTPSRequest.ino | 4 +- .../HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino | 4 +- .../HTTPSRequestCACertAxTLS.ino | 4 +- .../examples/NTPClient/NTPClient.ino | 4 +- .../WiFiAccessPoint/WiFiAccessPoint.ino | 4 +- .../examples/WiFiClient/WiFiClient.ino | 9 ++-- .../WiFiClientBasic/WiFiClientBasic.ino | 4 +- .../examples/WiFiEvents/WiFiEvents.ino | 4 +- .../WiFiHTTPSServer/WiFiHTTPSServer.ino | 4 +- .../WiFiManualWebServer.ino | 10 ++-- .../WiFiTelnetToSerial/WiFiTelnetToSerial.ino | 48 ++++++++++--------- libraries/ESP8266WiFi/examples/udp/udp.ino | 4 +- libraries/ESP8266WiFi/src/WiFiClientSecure.h | 2 +- .../ESP8266WiFi/src/include/SSLContext.h | 1 + 20 files changed, 69 insertions(+), 61 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino index a98636f2e9..f3cf9507f0 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino @@ -38,8 +38,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino index 1a24dd658e..7461e0f097 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino @@ -7,8 +7,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino index 2810d8da3b..841e8c9894 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino @@ -38,8 +38,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino index 7fa6997878..b83596089e 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino @@ -66,8 +66,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino index 1de0073465..1cbf2efdc9 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino @@ -7,8 +7,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino index 781554dd96..6160f21f67 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino @@ -8,8 +8,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino index 982322b17d..1fc22bc44e 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino @@ -20,8 +20,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino index 55445a6366..b7bba43cf8 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino @@ -23,8 +23,8 @@ using namespace axTLS; #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino index 0949bec106..9e00ad1178 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino @@ -23,8 +23,8 @@ using namespace axTLS; #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino index 9193839b52..a6c7af88e7 100644 --- a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino +++ b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino @@ -22,8 +22,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif char ssid[] = STASSID; // your network SSID (name) diff --git a/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino b/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino index 6fea68f590..3e488409dd 100644 --- a/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino +++ b/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino @@ -35,8 +35,8 @@ #include #ifndef APSSID -#define APSSID "ESPap" -#define APPSK "thereisnospoon" + #define APSSID "ESPap" + #define APPSK "thereisnospoon" #endif /* Set these to your desired credentials. */ diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index e07a5fb684..d70a68777f 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -6,8 +6,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char* ssid = STASSID; @@ -59,8 +59,9 @@ void loop() { // This will send a string to the server Serial.println("sending data to server"); - if (client.connected()) - client.println("hello from ESP8266"); + if (client.connected()) { + client.println("hello from ESP8266"); + } // wait for data to be available unsigned long timeout = millis(); diff --git a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino index ebb20d6d4b..351d1c6158 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino @@ -8,8 +8,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino b/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino index d72985a9c1..2f1ef92755 100644 --- a/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino +++ b/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino @@ -17,8 +17,8 @@ #include #ifndef APSSID -#define APSSID "esp8266" -#define APPSK "esp8266" + #define APSSID "esp8266" + #define APPSK "esp8266" #endif const char* ssid = APSSID; diff --git a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino index cf45c775cc..3097610002 100644 --- a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino @@ -44,8 +44,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino index 9c8e3d9a4e..8d5e85a53a 100644 --- a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino @@ -10,8 +10,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif const char* ssid = STASSID; @@ -59,7 +59,7 @@ void loop() { return; } Serial.println("new client"); - + client.setTimeout(5000); // default is 1000 // Read the first line of the request @@ -86,14 +86,16 @@ void loop() { // do not client.flush(): it is for output only, see below while (client.available()) // byte by byte is not very efficient + { client.read(); + } // Send the response to the client // it is OK for multiple small client.print/write, // because nagle algorithm will group them into one single packet // ::print*_P(F("string")) is always usable and saves RAM client.print_P(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nGPIO is now ")); - client.print_P((val) ? F("high" ): F("low")); + client.print_P((val) ? F("high") : F("low")); client.print_P(F("\n")); // The client will actually be *flushed* then disconnected diff --git a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino index 9711c73640..96cfad310e 100644 --- a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino +++ b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino @@ -23,8 +23,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif /* @@ -52,16 +52,16 @@ //////////////////////////////////////////////////////////// #if SERIAL_LOOPBACK -#undef BAUD_SERIAL -#define BAUD_SERIAL 3000000 -#include + #undef BAUD_SERIAL + #define BAUD_SERIAL 3000000 + #include #endif #if SWAP_PINS -#include -SoftwareSerial* logger = nullptr; + #include + SoftwareSerial* logger = nullptr; #else -#define logger (&Serial1) + #define logger (&Serial1) #endif #define STACK_PROTECTOR 512 // bytes @@ -81,25 +81,25 @@ void setup() { Serial.begin(BAUD_SERIAL); Serial.setRxBufferSize(RXBUFFERSIZE); -#if SWAP_PINS + #if SWAP_PINS Serial.swap(); // Hardware serial is now on RX:GPIO13 TX:GPIO15 // use SoftwareSerial on regular RX(3)/TX(1) for logging logger = new SoftwareSerial(3, 1); logger->begin(BAUD_LOGGER); logger->println("\n\nUsing SoftwareSerial for logging"); -#else + #else logger->begin(BAUD_LOGGER); logger->println("\n\nUsing Serial1 for logging"); -#endif + #endif logger->println(ESP.getFullVersion()); logger->printf("Serial baud: %d (8n1: %d KB/s)\n", BAUD_SERIAL, BAUD_SERIAL * 8 / 10 / 1024); logger->printf("Serial receive buffer size: %d bytes\n", RXBUFFERSIZE); -#if SERIAL_LOOPBACK + #if SERIAL_LOOPBACK USC0(0) |= (1 << UCLBE); // incomplete HardwareSerial API logger->println("Serial Internal Loopback enabled"); -#endif + #endif WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); @@ -147,14 +147,16 @@ void loop() { } //check TCP clients for data -#if 1 + #if 1 // Incredibly, this code is faster than the bufferred one below - #4620 is needed // loopback/3000000baud average 348KB/s for (int i = 0; i < MAX_SRV_CLIENTS; i++) while (serverClients[i].available() && Serial.availableForWrite() > 0) + { // working char by char is not very efficient Serial.write(serverClients[i].read()); -#else + } + #else // loopback/3000000baud average: 312KB/s for (int i = 0; i < MAX_SRV_CLIENTS; i++) while (serverClients[i].available() && Serial.availableForWrite() > 0) { @@ -163,10 +165,11 @@ void loop() { uint8_t buf[maxToSerial]; size_t tcp_got = serverClients[i].read(buf, maxToSerial); size_t serial_sent = Serial.write(buf, tcp_got); - if (serial_sent != maxToSerial) + if (serial_sent != maxToSerial) { logger->printf("len mismatch: available:%zd tcp-read:%zd serial-write:%zd\n", maxToSerial, tcp_got, serial_sent); + } } -#endif + #endif // determine maximum output size "fair TCP use" // client.availableForWrite() returns 0 when !client.connected() @@ -175,10 +178,11 @@ void loop() { if (serverClients[i]) { size_t afw = serverClients[i].availableForWrite(); if (afw) { - if (!maxToTcp) + if (!maxToTcp) { maxToTcp = afw; - else + } else { maxToTcp = std::min(maxToTcp, afw); + } } else { // warn but ignore congested clients logger->println("one client is congested"); @@ -196,11 +200,11 @@ void loop() { // if client.availableForWrite() was 0 (congested) // and increased since then, // ensure write space is sufficient: - if (serverClients[i].availableForWrite() >= serial_got) - { + if (serverClients[i].availableForWrite() >= serial_got) { size_t tcp_sent = serverClients[i].write(sbuf, serial_got); - if (tcp_sent != len) + if (tcp_sent != len) { logger->printf("len mismatch: available:%zd serial-read:%zd tcp-write:%zd\n", len, serial_got, tcp_sent); + } } } } diff --git a/libraries/ESP8266WiFi/examples/udp/udp.ino b/libraries/ESP8266WiFi/examples/udp/udp.ino index 5fa06239b2..3fcf97a6a1 100644 --- a/libraries/ESP8266WiFi/examples/udp/udp.ino +++ b/libraries/ESP8266WiFi/examples/udp/udp.ino @@ -19,8 +19,8 @@ #include #ifndef STASSID -#define STASSID "your-ssid" -#define PSK "your-password" + #define STASSID "your-ssid" + #define PSK "your-password" #endif unsigned int localPort = 8888; // local port to listen on diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.h b/libraries/ESP8266WiFi/src/WiFiClientSecure.h index 847a742698..dbbcae7298 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.h @@ -28,7 +28,7 @@ using namespace BearSSL; /********************************** * !! Now BearSSL is the default !! - + While not advised, Use legacy API without updating with: diff --git a/libraries/ESP8266WiFi/src/include/SSLContext.h b/libraries/ESP8266WiFi/src/include/SSLContext.h index 006fcd8743..f7d824fbf9 100644 --- a/libraries/ESP8266WiFi/src/include/SSLContext.h +++ b/libraries/ESP8266WiFi/src/include/SSLContext.h @@ -38,6 +38,7 @@ extern "C" #include "lwip/inet.h" #include "lwip/netif.h" #include +#include #include "c_types.h" namespace axTLS { From c2301e23ddd0b2b3f74d108a164b1a30c671d2e2 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 02:09:30 +0100 Subject: [PATCH 06/28] fixes + fix astyle (no preproc directives) + restyling script --- .../src/ESP8266WebServerSecureAxTLS.cpp | 8 +++++ .../src/ESP8266WebServerSecureAxTLS.h | 3 +- .../BearSSL_CertStore/BearSSL_CertStore.ino | 10 +++--- .../BearSSL_MaxFragmentLength.ino | 4 +-- .../BearSSL_Server/BearSSL_Server.ino | 4 +-- .../BearSSL_ServerClientCert.ino | 4 +-- .../BearSSL_Sessions/BearSSL_Sessions.ino | 4 +-- .../BearSSL_Validation/BearSSL_Validation.ino | 4 +-- .../examples/HTTPSRequest/HTTPSRequest.ino | 4 +-- .../HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino | 4 +-- .../HTTPSRequestCACertAxTLS.ino | 4 +-- .../examples/NTPClient/NTPClient.ino | 4 +-- .../WiFiAccessPoint/WiFiAccessPoint.ino | 4 +-- .../examples/WiFiClient/WiFiClient.ino | 4 +-- .../WiFiClientBasic/WiFiClientBasic.ino | 4 +-- .../examples/WiFiEvents/WiFiEvents.ino | 4 +-- .../WiFiHTTPSServer/WiFiHTTPSServer.ino | 4 +-- .../WiFiManualWebServer.ino | 4 +-- .../WiFiTelnetToSerial/WiFiTelnetToSerial.ino | 35 +++++++++---------- libraries/ESP8266WiFi/examples/udp/udp.ino | 4 +-- .../OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino | 4 +-- .../UdpNtpClient_Pedantic.ino | 4 +-- .../CallSDKFunctions/CallSDKFunctions.ino | 4 +-- .../examples/NTP-TZ-DST/NTP-TZ-DST.ino | 6 ++-- tests/examples_restyle.sh | 3 ++ tests/examples_style.conf | 8 ++--- 26 files changed, 80 insertions(+), 69 deletions(-) create mode 100755 tests/examples_restyle.sh diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp index fb62b75ef7..033e575665 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp @@ -36,6 +36,9 @@ namespace axTLS { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + ESP8266WebServerSecure::ESP8266WebServerSecure(IPAddress addr, int port) : _serverSecure(addr, port) { @@ -46,6 +49,8 @@ ESP8266WebServerSecure::ESP8266WebServerSecure(int port) { } +#pragma GCC diagnostic pop + void ESP8266WebServerSecure::setServerKeyAndCert_P(const uint8_t *key, int keyLen, const uint8_t *cert, int certLen) { _serverSecure.setServerKeyAndCert_P(key, keyLen, cert, certLen); @@ -131,7 +136,10 @@ void ESP8266WebServerSecure::handleClient() { } if (!keepCurrentClient) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" _currentClientSecure = WiFiClientSecure(); +#pragma GCC diagnostic pop _currentStatus = HC_NONE; _currentUpload.reset(); } diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.h b/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.h index abc351ea43..a53d6fa834 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.h @@ -24,7 +24,8 @@ #define ESP8266WEBSERVERSECURE_H #include -#include +#include +#include namespace axTLS { diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino index f3cf9507f0..84ad541582 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino @@ -38,8 +38,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char *ssid = STASSID; @@ -197,11 +197,11 @@ void setup() { Serial.println(); Serial.println(); - #ifdef USE_SDCARD +#ifdef USE_SDCARD SD.begin(); - #else +#else SPIFFS.begin(); - #endif +#endif // We start by connecting to a WiFi network Serial.print("Connecting to "); diff --git a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino index 7461e0f097..1a24dd658e 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino @@ -7,8 +7,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino index 841e8c9894..2810d8da3b 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino @@ -38,8 +38,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino index b83596089e..7fa6997878 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino @@ -66,8 +66,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino index 1cbf2efdc9..1de0073465 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino @@ -7,8 +7,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino index 6160f21f67..781554dd96 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino @@ -8,8 +8,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char *ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino index 1fc22bc44e..982322b17d 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino @@ -20,8 +20,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino index b7bba43cf8..55445a6366 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino @@ -23,8 +23,8 @@ using namespace axTLS; #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino index 9e00ad1178..0949bec106 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino @@ -23,8 +23,8 @@ using namespace axTLS; #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino index a6c7af88e7..9193839b52 100644 --- a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino +++ b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino @@ -22,8 +22,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif char ssid[] = STASSID; // your network SSID (name) diff --git a/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino b/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino index 3e488409dd..6fea68f590 100644 --- a/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino +++ b/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino @@ -35,8 +35,8 @@ #include #ifndef APSSID - #define APSSID "ESPap" - #define APPSK "thereisnospoon" +#define APSSID "ESPap" +#define APPSK "thereisnospoon" #endif /* Set these to your desired credentials. */ diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index d70a68777f..2977e0cfca 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -6,8 +6,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino index 351d1c6158..ebb20d6d4b 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino @@ -8,8 +8,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino b/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino index 2f1ef92755..d72985a9c1 100644 --- a/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino +++ b/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino @@ -17,8 +17,8 @@ #include #ifndef APSSID - #define APSSID "esp8266" - #define APPSK "esp8266" +#define APSSID "esp8266" +#define APPSK "esp8266" #endif const char* ssid = APSSID; diff --git a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino index 3097610002..cf45c775cc 100644 --- a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino @@ -44,8 +44,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino index 8d5e85a53a..bbda306eae 100644 --- a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino @@ -10,8 +10,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif const char* ssid = STASSID; diff --git a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino index 96cfad310e..61115a4296 100644 --- a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino +++ b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino @@ -23,8 +23,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif /* @@ -52,16 +52,16 @@ //////////////////////////////////////////////////////////// #if SERIAL_LOOPBACK - #undef BAUD_SERIAL - #define BAUD_SERIAL 3000000 - #include +#undef BAUD_SERIAL +#define BAUD_SERIAL 3000000 +#include #endif #if SWAP_PINS - #include - SoftwareSerial* logger = nullptr; +#include +SoftwareSerial* logger = nullptr; #else - #define logger (&Serial1) +#define logger (&Serial1) #endif #define STACK_PROTECTOR 512 // bytes @@ -81,25 +81,25 @@ void setup() { Serial.begin(BAUD_SERIAL); Serial.setRxBufferSize(RXBUFFERSIZE); - #if SWAP_PINS +#if SWAP_PINS Serial.swap(); // Hardware serial is now on RX:GPIO13 TX:GPIO15 // use SoftwareSerial on regular RX(3)/TX(1) for logging logger = new SoftwareSerial(3, 1); logger->begin(BAUD_LOGGER); logger->println("\n\nUsing SoftwareSerial for logging"); - #else +#else logger->begin(BAUD_LOGGER); logger->println("\n\nUsing Serial1 for logging"); - #endif +#endif logger->println(ESP.getFullVersion()); logger->printf("Serial baud: %d (8n1: %d KB/s)\n", BAUD_SERIAL, BAUD_SERIAL * 8 / 10 / 1024); logger->printf("Serial receive buffer size: %d bytes\n", RXBUFFERSIZE); - #if SERIAL_LOOPBACK +#if SERIAL_LOOPBACK USC0(0) |= (1 << UCLBE); // incomplete HardwareSerial API logger->println("Serial Internal Loopback enabled"); - #endif +#endif WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); @@ -147,16 +147,15 @@ void loop() { } //check TCP clients for data - #if 1 +#if 1 // Incredibly, this code is faster than the bufferred one below - #4620 is needed // loopback/3000000baud average 348KB/s for (int i = 0; i < MAX_SRV_CLIENTS; i++) - while (serverClients[i].available() && Serial.availableForWrite() > 0) - { + while (serverClients[i].available() && Serial.availableForWrite() > 0) { // working char by char is not very efficient Serial.write(serverClients[i].read()); } - #else +#else // loopback/3000000baud average: 312KB/s for (int i = 0; i < MAX_SRV_CLIENTS; i++) while (serverClients[i].available() && Serial.availableForWrite() > 0) { @@ -169,7 +168,7 @@ void loop() { logger->printf("len mismatch: available:%zd tcp-read:%zd serial-write:%zd\n", maxToSerial, tcp_got, serial_sent); } } - #endif +#endif // determine maximum output size "fair TCP use" // client.availableForWrite() returns 0 when !client.connected() diff --git a/libraries/ESP8266WiFi/examples/udp/udp.ino b/libraries/ESP8266WiFi/examples/udp/udp.ino index 3fcf97a6a1..5fa06239b2 100644 --- a/libraries/ESP8266WiFi/examples/udp/udp.ino +++ b/libraries/ESP8266WiFi/examples/udp/udp.ino @@ -19,8 +19,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define PSK "your-password" +#define STASSID "your-ssid" +#define PSK "your-password" #endif unsigned int localPort = 8888; // local port to listen on diff --git a/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino b/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino index 8a6afc2f09..b47496ca13 100644 --- a/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino +++ b/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino @@ -90,13 +90,13 @@ bool loadConfig(String *ssid, String *pass) { ssid->trim(); pass->trim(); - #ifdef SERIAL_VERBOSE +#ifdef SERIAL_VERBOSE Serial.println("----- file content -----"); Serial.println(content); Serial.println("----- file content -----"); Serial.println("ssid: " + *ssid); Serial.println("psk: " + *pass); - #endif +#endif return true; } // loadConfig diff --git a/libraries/Ethernet/examples/udpntpclient_pedantic/UdpNtpClient_Pedantic.ino b/libraries/Ethernet/examples/udpntpclient_pedantic/UdpNtpClient_Pedantic.ino index 68cf816f9f..d386895d1c 100644 --- a/libraries/Ethernet/examples/udpntpclient_pedantic/UdpNtpClient_Pedantic.ino +++ b/libraries/Ethernet/examples/udpntpclient_pedantic/UdpNtpClient_Pedantic.ino @@ -69,7 +69,7 @@ void loop() { if (Udp.parsePacket()) { // We've received a packet, read the data from it Udp.read((byte *)&packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer - #if 0 // just for debugging +#if 0 // just for debugging Serial.println(ENDIAN_SWAP_16(packetBuffer.rootdelay_main), HEX); Serial.println(ENDIAN_SWAP_16(packetBuffer.rootdelay_fraction), HEX); Serial.println(ENDIAN_SWAP_16(packetBuffer.rootdispersion_main), HEX); @@ -82,7 +82,7 @@ void loop() { Serial.println(ENDIAN_SWAP_32(packetBuffer.receivetimestamp_fraction), HEX); Serial.println(ENDIAN_SWAP_32(packetBuffer.transmittimestamp_main), HEX); Serial.println(ENDIAN_SWAP_32(packetBuffer.transmittimestamp_fraction), HEX); - #endif +#endif Serial.print("Delay "); Serial.print(ENDIAN_SWAP_16(packetBuffer.rootdelay_main)); Serial.print("."); Serial.println(ENDIAN_SWAP_16(packetBuffer.rootdelay_fraction)); Serial.print("Seconds since Jan 1 1900 = "); diff --git a/libraries/esp8266/examples/CallSDKFunctions/CallSDKFunctions.ino b/libraries/esp8266/examples/CallSDKFunctions/CallSDKFunctions.ino index 45908ad0af..77285a31b5 100644 --- a/libraries/esp8266/examples/CallSDKFunctions/CallSDKFunctions.ino +++ b/libraries/esp8266/examples/CallSDKFunctions/CallSDKFunctions.ino @@ -25,9 +25,9 @@ void setup() { void loop() { // Call Espressif SDK functionality - wrapped in ifdef so that it still // compiles on other platforms - #ifdef ESP8266 +#ifdef ESP8266 Serial.print("wifi_station_get_hostname: "); Serial.println(wifi_station_get_hostname()); - #endif +#endif delay(1000); } diff --git a/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino b/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino index 3d959d8ede..ee30a24b85 100644 --- a/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino +++ b/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino @@ -46,7 +46,7 @@ void setup() { Serial.begin(115200); settimeofday_cb(time_is_set); - #if NTP0_OR_LOCAL1 +#if NTP0_OR_LOCAL1 // local ESP.eraseConfig(); @@ -55,14 +55,14 @@ void setup() { timezone tz = { TZ_MN + DST_MN, 0 }; settimeofday(&tv, &tz); - #else // ntp +#else // ntp configTime(TZ_SEC, DST_SEC, "pool.ntp.org"); WiFi.mode(WIFI_STA); WiFi.begin(SSID, SSIDPWD); // don't wait, observe time changing when ntp timestamp is received - #endif // ntp +#endif // ntp } // for testing purpose: diff --git a/tests/examples_restyle.sh b/tests/examples_restyle.sh new file mode 100755 index 0000000000..91117fda28 --- /dev/null +++ b/tests/examples_restyle.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cd $(cd ${0%/*}; pwd) +echo astyle --options=examples_style.conf ../libraries/*/examples/*/*.ino diff --git a/tests/examples_style.conf b/tests/examples_style.conf index 0ca991bf85..f3b77f2cb4 100644 --- a/tests/examples_style.conf +++ b/tests/examples_style.conf @@ -10,7 +10,7 @@ lineend=linux indent=spaces=2 # also indent macros -indent-preprocessor +#indent-preprocessor # indent classes, switches (and cases), comments starting at column 1 indent-classes @@ -36,9 +36,9 @@ attach-extern-c indent-modifiers indent-namespaces indent-labels -indent-preproc-block -indent-preproc-define -indent-preproc-cond +#indent-preproc-block +#indent-preproc-define +#indent-preproc-cond unpad-paren add-braces remove-comment-prefix \ No newline at end of file From 0b849cf6be968517d9e5793cfcc661a33d862b6c Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 02:25:17 +0100 Subject: [PATCH 07/28] fix HTTPClient library --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index a3fbdd9b24..747d3fc5b9 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -27,8 +27,9 @@ #ifdef HTTPCLIENT_1_1_COMPATIBLE #include -#include +#include #endif +#include #include #include @@ -64,12 +65,18 @@ class TLSTraits : public TransportTraits std::unique_ptr create() override { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" return std::unique_ptr(new axTLS::WiFiClientSecure()); +#pragma GCC diagnostic pop } bool verify(WiFiClient& client, const char* host) override { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" auto wcs = static_cast(client); +#pragma GCC diagnostic pop return wcs.verify(_fingerprint.c_str(), host); } From 8ecae222d0f2ea3de45ea716a0515906b3e7bdf9 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 02:54:25 +0100 Subject: [PATCH 08/28] fixes --- .../examples/StreamHttpsClient/StreamHttpsClient.ino | 1 + libraries/ESP8266WebServer/src/ESP8266WebServerSecure.h | 4 +++- .../HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino | 3 +++ libraries/ESP8266WiFi/src/WiFiServerSecure.h | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino b/libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino index 55009349fa..121fd8bd1e 100644 --- a/libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino +++ b/libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino @@ -9,6 +9,7 @@ #include #include +#include #include diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServerSecure.h b/libraries/ESP8266WebServer/src/ESP8266WebServerSecure.h index fa248c1f1f..5258c6cc89 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServerSecure.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServerSecure.h @@ -19,5 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "ESP8266WebServerSecureAxTLS.h" +#include + +//#include "ESP8266WebServerSecureAxTLS.h" #include "ESP8266WebServerSecureBearSSL.h" diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino index 0949bec106..2227f005e5 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino @@ -38,7 +38,10 @@ const int httpsPort = 443; extern const unsigned char caCert[] PROGMEM; extern const unsigned int caCertLen; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" WiFiClientSecure client; +#pragma GCC diagnostic pop void setup() { Serial.begin(115200); diff --git a/libraries/ESP8266WiFi/src/WiFiServerSecure.h b/libraries/ESP8266WiFi/src/WiFiServerSecure.h index 4b88a20916..5167df562d 100644 --- a/libraries/ESP8266WiFi/src/WiFiServerSecure.h +++ b/libraries/ESP8266WiFi/src/WiFiServerSecure.h @@ -17,5 +17,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "WiFiServerSecureAxTLS.h" +#include + +//#include "WiFiServerSecureAxTLS.h" #include "WiFiServerSecureBearSSL.h" From 68f77a5fc57c2c2d7bac62e3cd2eef4e3eda199b Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 02:59:30 +0100 Subject: [PATCH 09/28] common.sh: do not reload arduino when already present (for locally CI testing) --- tests/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common.sh b/tests/common.sh index dbbb070e1a..edcf3d6521 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -104,7 +104,7 @@ function install_ide() local ide_path=$1 local core_path=$2 local debug=$3 - wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz + test -r arduino.tar.xz || wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz tar xf arduino.tar.xz mv arduino-nightly $ide_path cd $ide_path/hardware From f1bb21d090446c82f4246c0f03c52551fbd1cc5b Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 03:07:10 +0100 Subject: [PATCH 10/28] common.sh: do not reload ArduinoJson when already present (for locally CI testing) --- tests/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common.sh b/tests/common.sh index edcf3d6521..1c2f2e4378 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -94,7 +94,7 @@ function install_libraries() pushd $HOME/Arduino/libraries # install ArduinoJson library - wget https://github.com/bblanchon/ArduinoJson/releases/download/v4.6.1/ArduinoJson-v4.6.1.zip && unzip ArduinoJson-v4.6.1.zip + { test -r ArduinoJson-v4.6.1.zip || wget https://github.com/bblanchon/ArduinoJson/releases/download/v4.6.1/ArduinoJson-v4.6.1.zip; } && unzip ArduinoJson-v4.6.1.zip popd } From 797bb37684816494372489ea45f6a0ad38363afe Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 03:15:03 +0100 Subject: [PATCH 11/28] fix --- libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp | 2 +- libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp index 033e575665..09ba1ba5c9 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp @@ -25,7 +25,7 @@ #include #include "WiFiServer.h" #include "WiFiClient.h" -#include "ESP8266WebServerSecure.h" +#include "ESP8266WebServerSecureAxTLS.h" //#define DEBUG_ESP_HTTP_SERVER #ifdef DEBUG_ESP_PORT diff --git a/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp b/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp index 61ae84309d..e50af8c27d 100644 --- a/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp @@ -35,7 +35,7 @@ extern "C" { #include "lwip/tcp.h" #include "lwip/inet.h" #include "include/ClientContext.h" -#include "WiFiServerSecure.h" +#include "WiFiServerSecureAxTLS.h" namespace axTLS { From 9c2c90aac40fd90060f1b066637ae1f7f7045a7e Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 03:33:07 +0100 Subject: [PATCH 12/28] fix --- .../ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino | 1 + .../BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino | 1 + libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino | 1 + .../BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino | 1 + .../ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino | 1 + .../examples/BearSSL_Validation/BearSSL_Validation.ino | 1 + 6 files changed, 6 insertions(+) diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino index 84ad541582..f718ad2050 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino @@ -34,6 +34,7 @@ // Released to the public domain #include +#include #include #include diff --git a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino index 1a24dd658e..071140afc4 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino @@ -5,6 +5,7 @@ // Released to the public domain #include +#include #ifndef STASSID #define STASSID "your-ssid" diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino index 2810d8da3b..9135835bd9 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino @@ -35,6 +35,7 @@ */ #include +#include #include #ifndef STASSID diff --git a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino index 7fa6997878..03eb81520f 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino @@ -63,6 +63,7 @@ */ #include +#include #include #ifndef STASSID diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino index 1de0073465..701f7ecc83 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino @@ -4,6 +4,7 @@ // Released to the public domain #include +#include #include #ifndef STASSID diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino index 781554dd96..0e9c6cec97 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino @@ -5,6 +5,7 @@ // Released to the public domain #include +#include #include #ifndef STASSID From dd0f55f4a52384f017da828c1d6e42ce99f1a0a9 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 04:00:28 +0100 Subject: [PATCH 13/28] fix deprecated example --- .../examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino index 55445a6366..ec67beffb0 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino @@ -54,7 +54,10 @@ void setup() { Serial.println(WiFi.localIP()); // Use WiFiClientSecure class to create TLS connection +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" WiFiClientSecure client; +#pragma GCC diagnostic pop Serial.print("connecting to "); Serial.println(host); if (!client.connect(host, httpsPort)) { From e7ec28a1884737498de68faac0400531ab31dec3 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 24 Nov 2018 04:15:14 +0100 Subject: [PATCH 14/28] fix WiFiHTTPSServer.ino --- .../ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino index cf45c775cc..78fe4c12ee 100644 --- a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino @@ -42,6 +42,7 @@ */ #include +#include #ifndef STASSID #define STASSID "your-ssid" From 70ef54b61a6d4846c4fc3c159f8ba4d5e6b9c7fe Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 25 Nov 2018 16:41:20 +0100 Subject: [PATCH 15/28] reduce footprint --- .../StreamHttpsClient/StreamHttpsClient.ino | 1 - .../src/ESP8266HTTPClient.cpp | 9 +------- .../BearSSL_CertStore/BearSSL_CertStore.ino | 5 ++--- .../BearSSL_MaxFragmentLength.ino | 5 ++--- .../BearSSL_Server/BearSSL_Server.ino | 5 ++--- .../BearSSL_ServerClientCert.ino | 5 ++--- .../BearSSL_Sessions/BearSSL_Sessions.ino | 5 ++--- .../BearSSL_Validation/BearSSL_Validation.ino | 4 ++-- .../examples/HTTPSRequest/HTTPSRequest.ino | 4 ++-- .../HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino | 5 +++-- .../HTTPSRequestCACertAxTLS.ino | 5 +++-- .../examples/NTPClient/NTPClient.ino | 4 ++-- .../examples/WiFiClient/WiFiClient.ino | 4 ++-- .../WiFiClientBasic/WiFiClientBasic.ino | 4 ++-- .../WiFiHTTPSServer/WiFiHTTPSServer.ino | 5 ++--- .../WiFiManualWebServer.ino | 4 ++-- .../WiFiTelnetToSerial/WiFiTelnetToSerial.ino | 6 ++--- libraries/ESP8266WiFi/examples/udp/udp.ino | 4 ++-- libraries/ESP8266WiFi/src/ESP8266WiFi.h | 8 +++---- libraries/ESP8266WiFi/src/WiFiClientSecure.h | 22 ++++++++++++------- .../ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp | 2 +- 21 files changed, 55 insertions(+), 61 deletions(-) diff --git a/libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino b/libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino index 121fd8bd1e..55009349fa 100644 --- a/libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino +++ b/libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino @@ -9,7 +9,6 @@ #include #include -#include #include diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 747d3fc5b9..a3fbdd9b24 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -27,9 +27,8 @@ #ifdef HTTPCLIENT_1_1_COMPATIBLE #include -#include +#include #endif -#include #include #include @@ -65,18 +64,12 @@ class TLSTraits : public TransportTraits std::unique_ptr create() override { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" return std::unique_ptr(new axTLS::WiFiClientSecure()); -#pragma GCC diagnostic pop } bool verify(WiFiClient& client, const char* host) override { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" auto wcs = static_cast(client); -#pragma GCC diagnostic pop return wcs.verify(_fingerprint.c_str(), host); } diff --git a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino index f718ad2050..37c73c67ee 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino @@ -34,17 +34,16 @@ // Released to the public domain #include -#include #include #include #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char *ssid = STASSID; -const char *pass = PSK; +const char *pass = STAPSK; // A single, global CertStore which can be used by all // connections. Needs to stay live the entire time any of diff --git a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino index 071140afc4..19ca6b3f71 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino @@ -5,15 +5,14 @@ // Released to the public domain #include -#include #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char *ssid = STASSID; -const char *pass = PSK; +const char *pass = STAPSK; void fetch(BearSSL::WiFiClientSecure *client) { client->write("GET / HTTP/1.0\r\nHost: tls.mbed.org\r\nUser-Agent: ESP8266\r\n\r\n"); diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino index 9135835bd9..cd1d0bee95 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino @@ -35,16 +35,15 @@ */ #include -#include #include #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char *ssid = STASSID; -const char *pass = PSK; +const char *pass = STAPSK; // The HTTPS server BearSSL::WiFiServerSecure server(443); diff --git a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino index 03eb81520f..a50f115283 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino @@ -63,16 +63,15 @@ */ #include -#include #include #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char *ssid = STASSID; -const char *pass = PSK; +const char *pass = STAPSK; // The server which will require a client cert signed by the trusted CA BearSSL::WiFiServerSecure server(443); diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino index 701f7ecc83..d615497073 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino @@ -4,16 +4,15 @@ // Released to the public domain #include -#include #include #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char *ssid = STASSID; -const char *pass = PSK; +const char *pass = STAPSK; const char * host = "api.github.com"; const uint16_t port = 443; diff --git a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino index 0e9c6cec97..a01ffcb5d9 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino @@ -10,11 +10,11 @@ #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char *ssid = STASSID; -const char *pass = PSK; +const char *pass = STAPSK; const char * host = "api.github.com"; const uint16_t port = 443; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino index 982322b17d..000dbb2a14 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino @@ -21,11 +21,11 @@ #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char* ssid = STASSID; -const char* password = PSK; +const char* password = STAPSK; const char* host = "api.github.com"; const int httpsPort = 443; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino index ec67beffb0..0830491994 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino @@ -16,6 +16,7 @@ This example is in public domain. */ +#define USING_AXTLS #include // force use of AxTLS (BearSSL is now default) @@ -24,11 +25,11 @@ using namespace axTLS; #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char* ssid = STASSID; -const char* password = PSK; +const char* password = STAPSK; const char* host = "api.github.com"; const int httpsPort = 443; diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino index 2227f005e5..2e301972b4 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino @@ -15,6 +15,7 @@ This example is in public domain. */ +#define USING_AXTLS #include #include @@ -24,11 +25,11 @@ using namespace axTLS; #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char* ssid = STASSID; -const char* password = PSK; +const char* password = STAPSK; const char* host = "api.github.com"; const int httpsPort = 443; diff --git a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino index 9193839b52..539e8b17e2 100644 --- a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino +++ b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino @@ -23,11 +23,11 @@ #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif char ssid[] = STASSID; // your network SSID (name) -char pass[] = PSK; // your network password +char pass[] = STAPSK; // your network password unsigned int localPort = 2390; // local port to listen for UDP packets diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index 2977e0cfca..9e333fbcec 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -7,11 +7,11 @@ #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char* ssid = STASSID; -const char* password = PSK; +const char* password = STAPSK; const char* host = "djxmmx.net"; const uint16_t port = 17; diff --git a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino index ebb20d6d4b..e442282e37 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino @@ -9,11 +9,11 @@ #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char* ssid = STASSID; -const char* password = PSK; +const char* password = STAPSK; const char* host = "192.168.1.1"; const uint16_t port = 3000; diff --git a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino index 78fe4c12ee..adb18b4122 100644 --- a/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiHTTPSServer/WiFiHTTPSServer.ino @@ -42,15 +42,14 @@ */ #include -#include #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char* ssid = STASSID; -const char* password = PSK; +const char* password = STAPSK; // The certificate is stored in PMEM static const uint8_t x509[] PROGMEM = { diff --git a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino index bbda306eae..8b22801288 100644 --- a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino @@ -11,11 +11,11 @@ #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif const char* ssid = STASSID; -const char* password = PSK; +const char* password = STAPSK; // Create an instance of the server // specify the port to listen on as an argument diff --git a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino index 61115a4296..8c79a2a53d 100644 --- a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino +++ b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino @@ -20,11 +20,11 @@ */ #include -#include +#include // std::min #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif /* @@ -69,7 +69,7 @@ SoftwareSerial* logger = nullptr; //how many clients should be able to telnet to this ESP8266 #define MAX_SRV_CLIENTS 2 const char* ssid = STASSID; -const char* password = PSK; +const char* password = STAPSK; const int port = 23; diff --git a/libraries/ESP8266WiFi/examples/udp/udp.ino b/libraries/ESP8266WiFi/examples/udp/udp.ino index 5fa06239b2..c413d3cea2 100644 --- a/libraries/ESP8266WiFi/examples/udp/udp.ino +++ b/libraries/ESP8266WiFi/examples/udp/udp.ino @@ -20,7 +20,7 @@ #ifndef STASSID #define STASSID "your-ssid" -#define PSK "your-password" +#define STAPSK "your-password" #endif unsigned int localPort = 8888; // local port to listen on @@ -34,7 +34,7 @@ WiFiUDP Udp; void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); - WiFi.begin(STASSID, PSK); + WiFi.begin(STASSID, STAPSK); while (WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(500); diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.h b/libraries/ESP8266WiFi/src/ESP8266WiFi.h index 117a3e341c..2ff5208a97 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.h @@ -38,10 +38,10 @@ extern "C" { #include "WiFiClient.h" #include "WiFiServer.h" -//#include "WiFiServerSecure.h" -//#include "WiFiClientSecure.h" -//#include "BearSSLHelpers.h" -//#include "CertStoreBearSSL.h" +#include "WiFiServerSecure.h" +#include "WiFiClientSecure.h" +#include "BearSSLHelpers.h" +#include "CertStoreBearSSL.h" #ifdef DEBUG_ESP_WIFI #ifdef DEBUG_ESP_PORT diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.h b/libraries/ESP8266WiFi/src/WiFiClientSecure.h index dbbcae7298..235f7e07f2 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.h @@ -23,18 +23,24 @@ //#include "WiFiClientSecureAxTLS.h" //using namespace axTLS; -#include "WiFiClientSecureBearSSL.h" -using namespace BearSSL; - /********************************** * !! Now BearSSL is the default !! - - While not advised, - Use legacy API without updating with: - + * + * While not advised, + * Use legacy API without updating with: + * +#define USING_AXTLS +#include //#include #include "WiFiClientSecureAxTLS.h" using namespace axTLS; - + * * **********************************/ + +#include "WiFiClientSecureBearSSL.h" + +#ifndef USING_AXTLS +// do not default to BearSSL API ("using" has no "unusing" counterpart) +using namespace BearSSL; +#endif diff --git a/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp b/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp index e50af8c27d..bba0be564a 100644 --- a/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp @@ -30,11 +30,11 @@ extern "C" { #include "ESP8266WiFi.h" #include "WiFiClient.h" #include "WiFiServer.h" -#include "WiFiClientSecureAxTLS.h" #include "lwip/opt.h" #include "lwip/tcp.h" #include "lwip/inet.h" #include "include/ClientContext.h" +#include "WiFiClientSecureAxTLS.h" #include "WiFiServerSecureAxTLS.h" From 003c190564cdb5c17e33b77edbe81c9932f615d3 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 25 Nov 2018 17:39:03 +0100 Subject: [PATCH 16/28] wipfix --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index a3fbdd9b24..5020fb8311 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -27,7 +27,7 @@ #ifdef HTTPCLIENT_1_1_COMPATIBLE #include -#include +#include #endif #include @@ -64,7 +64,10 @@ class TLSTraits : public TransportTraits std::unique_ptr create() override { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" return std::unique_ptr(new axTLS::WiFiClientSecure()); +#pragma GCC diagnostic pop } bool verify(WiFiClient& client, const char* host) override From 49a5d9b2641babbc40fe594257e7f77111a14b28 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 25 Nov 2018 18:04:11 +0100 Subject: [PATCH 17/28] fix led builtin --- .../examples/WiFiManualWebServer/WiFiManualWebServer.ino | 6 +++--- variants/generic/common.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino index 8b22801288..3482393946 100644 --- a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino @@ -25,8 +25,8 @@ void setup() { Serial.begin(115200); // prepare LED - pinMode(BUILTIN_LED, OUTPUT); - digitalWrite(BUILTIN_LED, 0); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, 0); // Connect to WiFi network Serial.println(); @@ -80,7 +80,7 @@ void loop() { } // Set LED according to the request - digitalWrite(BUILTIN_LED, val); + digitalWrite(LED_BUILTIN, val); // read/ignore the rest of the request // do not client.flush(): it is for output only, see below diff --git a/variants/generic/common.h b/variants/generic/common.h index 4b0d4a69ad..4d5ffcf4ab 100644 --- a/variants/generic/common.h +++ b/variants/generic/common.h @@ -76,7 +76,7 @@ static const uint8_t A0 = PIN_A0; #ifdef __cplusplus extern "C" #endif -const int BUILTIN_LED __attribute__((deprecated, weak)) = LED_BUILTIN; +const int BUILTIN_LED __attribute__((deprecated("use LED_BUILTIN"), weak)) = LED_BUILTIN; #endif #endif /* GENERIC_COMMON_H */ From c48d5f414ac1b57c9539acdd9b1974b4d01af789 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 25 Nov 2018 21:52:21 +0100 Subject: [PATCH 18/28] fix example --- .../WiFiManualWebServer.ino | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino index 3482393946..848b6715b7 100644 --- a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino @@ -31,7 +31,7 @@ void setup() { // Connect to WiFi network Serial.println(); Serial.println(); - Serial.print("Connecting to "); + Serial.print(F("Connecting to ")); Serial.println(ssid); WiFi.mode(WIFI_STA); @@ -39,14 +39,14 @@ void setup() { while (WiFi.status() != WL_CONNECTED) { delay(500); - Serial.print("."); + Serial.print(F(".")); } - Serial.println(""); - Serial.println("WiFi connected"); + Serial.println(); + Serial.println(F("WiFi connected")); // Start the server server.begin(); - Serial.println("Server started"); + Serial.println(F("Server started")); // Print the IP address Serial.println(WiFi.localIP()); @@ -58,25 +58,24 @@ void loop() { if (!client) { return; } - Serial.println("new client"); + Serial.println(F("new client")); client.setTimeout(5000); // default is 1000 // Read the first line of the request String req = client.readStringUntil('\r'); - Serial.println("request: "); + Serial.println(F("request: ")); Serial.println(req); // Match the request int val; - if (req.indexOf("/gpio/0") != -1) { + if (req.indexOf(F("/gpio/0")) != -1) { val = 0; - } else if (req.indexOf("/gpio/1") != -1) { + } else if (req.indexOf(F("/gpio/1")) != -1) { val = 1; } else { - Serial.println("invalid request"); - client.stop(); - return; + Serial.println(F("invalid request")); + val = digitalRead(LED_BUILTIN); } // Set LED according to the request @@ -85,21 +84,24 @@ void loop() { // read/ignore the rest of the request // do not client.flush(): it is for output only, see below while (client.available()) - // byte by byte is not very efficient { + // byte by byte is not very efficient client.read(); } // Send the response to the client // it is OK for multiple small client.print/write, // because nagle algorithm will group them into one single packet - // ::print*_P(F("string")) is always usable and saves RAM - client.print_P(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nGPIO is now ")); - client.print_P((val) ? F("high") : F("low")); - client.print_P(F("\n")); + client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nGPIO is now ")); + client.print((val) ? F("high") : F("low")); + client.print(F("

Click here to switch LED GPIO on, or here to switch LED GPIO off.")); // The client will actually be *flushed* then disconnected // when the function returns and 'client' object is destroyed (out-of-scope) // flush = ensure written data are received by the other side - Serial.println("Disconnecting from client"); + Serial.println(F("Disconnecting from client")); } From 119e73d68427cd40476655495efd2e8d431d98a3 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 25 Nov 2018 22:32:26 +0100 Subject: [PATCH 19/28] finished updating APSSID on all examples --- libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino | 9 +++++++-- libraries/ArduinoOTA/examples/OTALeds/OTALeds.ino | 9 +++++++-- .../CaptivePortalAdvanced/CaptivePortalAdvanced.ino | 9 +++++++-- .../examples/Arduino_Wifi_AVRISP/Arduino_Wifi_AVRISP.ino | 9 +++++++-- .../examples/DigestAuthorization/DigestAuthorization.ino | 9 +++++++-- .../SecureBearSSLUpdater/SecureBearSSLUpdater.ino | 9 +++++++-- .../examples/SecureHTTPSUpdater/SecureHTTPSUpdater.ino | 9 +++++++-- .../examples/SecureWebUpdater/SecureWebUpdater.ino | 9 +++++++-- .../examples/WebUpdater/WebUpdater.ino | 9 +++++++-- .../examples/LLMNR_Web_Server/LLMNR_Web_Server.ino | 9 +++++++-- .../ESP8266NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino | 9 +++++++-- libraries/ESP8266SSDP/examples/SSDP/SSDP.ino | 9 +++++++-- .../examples/AdvancedWebServer/AdvancedWebServer.ino | 9 +++++++-- .../ESP8266WebServer/examples/FSBrowser/FSBrowser.ino | 9 +++++++-- .../examples/HelloServer/HelloServer.ino | 9 +++++++-- .../examples/HelloServerBearSSL/HelloServerBearSSL.ino | 9 +++++++-- .../examples/HelloServerSecure/HelloServerSecure.ino | 9 +++++++-- .../examples/HttpAdvancedAuth/HttpAdvancedAuth.ino | 9 +++++++-- .../examples/HttpBasicAuth/HttpBasicAuth.ino | 9 +++++++-- .../examples/SDWebServer/SDWebServer.ino | 9 +++++++-- .../SimpleAuthentication/SimpleAuthentication.ino | 9 +++++++-- .../ESP8266WebServer/examples/WebUpdate/WebUpdate.ino | 9 +++++++-- .../examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino | 2 +- .../examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino | 9 +++++++-- .../examples/mDNS-SD_Extended/mDNS-SD_Extended.ino | 9 +++++++-- .../examples/mDNS_Web_Server/mDNS_Web_Server.ino | 9 +++++++-- libraries/esp8266/examples/I2STransmit/I2STransmit.ino | 9 +++++++-- libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino | 9 +++++++-- libraries/esp8266/examples/interactive/interactive.ino | 9 +++++++-- 29 files changed, 197 insertions(+), 57 deletions(-) diff --git a/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino b/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino index 01935ec9ec..214eb82952 100644 --- a/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino +++ b/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino @@ -3,8 +3,13 @@ #include #include -const char* ssid = ".........."; -const char* password = ".........."; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; void setup() { Serial.begin(115200); diff --git a/libraries/ArduinoOTA/examples/OTALeds/OTALeds.ino b/libraries/ArduinoOTA/examples/OTALeds/OTALeds.ino index 5477012710..7d05074e15 100644 --- a/libraries/ArduinoOTA/examples/OTALeds/OTALeds.ino +++ b/libraries/ArduinoOTA/examples/OTALeds/OTALeds.ino @@ -3,8 +3,13 @@ #include #include -const char* ssid = "..."; -const char* password = "..."; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; const char* host = "OTA-LEDS"; int led_pin = 13; diff --git a/libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino b/libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino index 8c662fd206..0d2251d292 100644 --- a/libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino +++ b/libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino @@ -18,8 +18,13 @@ */ /* Set these to your desired softAP credentials. They are not configurable at runtime */ -const char *softAP_ssid = "ESP_ap"; -const char *softAP_password = "12345678"; +#ifndef APSSID +#define APSSID "ESP_ap" +#define APPSK "12345678" +#endif + +const char *softAP_ssid = APSSID; +const char *softAP_password = APPSK; /* hostname for mDNS. Should work at least on windows. Try http://esp8266.local */ const char *myHostname = "esp8266"; diff --git a/libraries/ESP8266AVRISP/examples/Arduino_Wifi_AVRISP/Arduino_Wifi_AVRISP.ino b/libraries/ESP8266AVRISP/examples/Arduino_Wifi_AVRISP/Arduino_Wifi_AVRISP.ino index e345e30272..71795a71ac 100644 --- a/libraries/ESP8266AVRISP/examples/Arduino_Wifi_AVRISP/Arduino_Wifi_AVRISP.ino +++ b/libraries/ESP8266AVRISP/examples/Arduino_Wifi_AVRISP/Arduino_Wifi_AVRISP.ino @@ -3,9 +3,14 @@ #include #include +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + const char* host = "esp8266-avrisp"; -const char* ssid = "**********"; -const char* pass = "**********"; +const char* ssid = STASSID; +const char* pass = STAPSK; const uint16_t port = 328; const uint8_t reset_pin = 5; diff --git a/libraries/ESP8266HTTPClient/examples/DigestAuthorization/DigestAuthorization.ino b/libraries/ESP8266HTTPClient/examples/DigestAuthorization/DigestAuthorization.ino index 8045620ae2..be91d70503 100644 --- a/libraries/ESP8266HTTPClient/examples/DigestAuthorization/DigestAuthorization.ino +++ b/libraries/ESP8266HTTPClient/examples/DigestAuthorization/DigestAuthorization.ino @@ -11,8 +11,13 @@ #include -const char* ssid = "SSID"; -const char* ssidPassword = "PASSWORD"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* ssidPassword = STAPSK; const char *username = "admin"; const char *password = "admin"; diff --git a/libraries/ESP8266HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino b/libraries/ESP8266HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino index f7ec895e71..be54a1bafe 100644 --- a/libraries/ESP8266HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino +++ b/libraries/ESP8266HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino @@ -19,12 +19,17 @@ #include #include +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + const char* host = "esp8266-webupdate"; const char* update_path = "/firmware"; const char* update_username = "admin"; const char* update_password = "admin"; -const char* ssid = "........"; -const char* password = "........"; +const char* ssid = STASSID; +const char* password = STAPSK; BearSSL::ESP8266WebServerSecure httpServer(443); ESP8266HTTPUpdateServer httpUpdater; diff --git a/libraries/ESP8266HTTPUpdateServer/examples/SecureHTTPSUpdater/SecureHTTPSUpdater.ino b/libraries/ESP8266HTTPUpdateServer/examples/SecureHTTPSUpdater/SecureHTTPSUpdater.ino index 815e9ca965..3e028cf721 100644 --- a/libraries/ESP8266HTTPUpdateServer/examples/SecureHTTPSUpdater/SecureHTTPSUpdater.ino +++ b/libraries/ESP8266HTTPUpdateServer/examples/SecureHTTPSUpdater/SecureHTTPSUpdater.ino @@ -48,12 +48,17 @@ #include #include +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + const char* host = "esp8266-webupdate"; const char* update_path = "/firmware"; const char* update_username = "admin"; const char* update_password = "admin"; -const char* ssid = "........"; -const char* password = "........"; +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServerSecure httpServer(443); ESP8266HTTPUpdateServer httpUpdater; diff --git a/libraries/ESP8266HTTPUpdateServer/examples/SecureWebUpdater/SecureWebUpdater.ino b/libraries/ESP8266HTTPUpdateServer/examples/SecureWebUpdater/SecureWebUpdater.ino index 12ec5b49b8..dc2fd5fdf5 100644 --- a/libraries/ESP8266HTTPUpdateServer/examples/SecureWebUpdater/SecureWebUpdater.ino +++ b/libraries/ESP8266HTTPUpdateServer/examples/SecureWebUpdater/SecureWebUpdater.ino @@ -8,12 +8,17 @@ #include #include +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + const char* host = "esp8266-webupdate"; const char* update_path = "/firmware"; const char* update_username = "admin"; const char* update_password = "admin"; -const char* ssid = "........"; -const char* password = "........"; +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer httpServer(80); ESP8266HTTPUpdateServer httpUpdater; diff --git a/libraries/ESP8266HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino b/libraries/ESP8266HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino index 0857bbe76a..8e5ab2a8f8 100644 --- a/libraries/ESP8266HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino +++ b/libraries/ESP8266HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino @@ -8,9 +8,14 @@ #include #include +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + const char* host = "esp8266-webupdate"; -const char* ssid = "........"; -const char* password = "........"; +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer httpServer(80); ESP8266HTTPUpdateServer httpUpdater; diff --git a/libraries/ESP8266LLMNR/examples/LLMNR_Web_Server/LLMNR_Web_Server.ino b/libraries/ESP8266LLMNR/examples/LLMNR_Web_Server/LLMNR_Web_Server.ino index 3fe2caf23b..b1f4dca186 100644 --- a/libraries/ESP8266LLMNR/examples/LLMNR_Web_Server/LLMNR_Web_Server.ino +++ b/libraries/ESP8266LLMNR/examples/LLMNR_Web_Server/LLMNR_Web_Server.ino @@ -60,8 +60,13 @@ #include #include -const char* ssid = "replace_me"; -const char* password = "replace_me"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer web_server(80); diff --git a/libraries/ESP8266NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino b/libraries/ESP8266NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino index 1d8f255d6a..57f5529850 100755 --- a/libraries/ESP8266NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino +++ b/libraries/ESP8266NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino @@ -2,8 +2,13 @@ #include #include -const char* ssid = "............"; -const char* password = ".............."; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer wwwserver(80); String content; diff --git a/libraries/ESP8266SSDP/examples/SSDP/SSDP.ino b/libraries/ESP8266SSDP/examples/SSDP/SSDP.ino index 0a62248c55..28b0ca977b 100644 --- a/libraries/ESP8266SSDP/examples/SSDP/SSDP.ino +++ b/libraries/ESP8266SSDP/examples/SSDP/SSDP.ino @@ -2,8 +2,13 @@ #include #include -const char* ssid = "************"; -const char* password = "***********"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer HTTP(80); diff --git a/libraries/ESP8266WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino b/libraries/ESP8266WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino index 1315c9a30c..a083666ac3 100644 --- a/libraries/ESP8266WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino +++ b/libraries/ESP8266WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino @@ -33,8 +33,13 @@ #include #include -const char *ssid = "YourSSIDHere"; -const char *password = "YourPSKHere"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char *ssid = STASSID; +const char *password = STAPSK; ESP8266WebServer server(80); diff --git a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino index 66de8988f3..e31acdfd47 100644 --- a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino +++ b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino @@ -30,8 +30,13 @@ #define DBG_OUTPUT_PORT Serial -const char* ssid = "wifi-ssid"; -const char* password = "wifi-password"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; const char* host = "esp8266fs"; ESP8266WebServer server(80); diff --git a/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino b/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino index f0bd12a061..ca5f8890eb 100644 --- a/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino +++ b/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino @@ -3,8 +3,13 @@ #include #include -const char* ssid = "........"; -const char* password = "........"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer server(80); diff --git a/libraries/ESP8266WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino b/libraries/ESP8266WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino index 5ce0a2b44d..e920fb3b69 100644 --- a/libraries/ESP8266WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino +++ b/libraries/ESP8266WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino @@ -14,8 +14,13 @@ #include #include -const char* ssid = "...."; -const char* password = "...."; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; BearSSL::ESP8266WebServerSecure server(443); diff --git a/libraries/ESP8266WebServer/examples/HelloServerSecure/HelloServerSecure.ino b/libraries/ESP8266WebServer/examples/HelloServerSecure/HelloServerSecure.ino index f761dabe49..7dfd0cd5ce 100644 --- a/libraries/ESP8266WebServer/examples/HelloServerSecure/HelloServerSecure.ino +++ b/libraries/ESP8266WebServer/examples/HelloServerSecure/HelloServerSecure.ino @@ -46,8 +46,13 @@ #include #include -const char* ssid = "........"; -const char* password = "........"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServerSecure server(443); diff --git a/libraries/ESP8266WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino b/libraries/ESP8266WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino index 141eb594f9..857048cf0b 100644 --- a/libraries/ESP8266WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino +++ b/libraries/ESP8266WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino @@ -9,8 +9,13 @@ #include #include -const char* ssid = "........"; -const char* password = "........"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer server(80); diff --git a/libraries/ESP8266WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino b/libraries/ESP8266WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino index e8600a480d..7c06637caf 100644 --- a/libraries/ESP8266WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino +++ b/libraries/ESP8266WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino @@ -3,8 +3,13 @@ #include #include -const char* ssid = "........"; -const char* password = "........"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer server(80); diff --git a/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino b/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino index 9428a2882a..1733a912f2 100644 --- a/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino +++ b/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino @@ -36,8 +36,13 @@ #define DBG_OUTPUT_PORT Serial -const char* ssid = "**********"; -const char* password = "**********"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; const char* host = "esp8266sd"; ESP8266WebServer server(80); diff --git a/libraries/ESP8266WebServer/examples/SimpleAuthentication/SimpleAuthentication.ino b/libraries/ESP8266WebServer/examples/SimpleAuthentication/SimpleAuthentication.ino index a3abdac3e2..38e68a2275 100644 --- a/libraries/ESP8266WebServer/examples/SimpleAuthentication/SimpleAuthentication.ino +++ b/libraries/ESP8266WebServer/examples/SimpleAuthentication/SimpleAuthentication.ino @@ -2,8 +2,13 @@ #include #include -const char* ssid = "........"; -const char* password = "........"; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer server(80); diff --git a/libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino b/libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino index ff5204541e..b86ae33f13 100644 --- a/libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino +++ b/libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino @@ -7,9 +7,14 @@ #include #include +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + const char* host = "esp8266-webupdate"; -const char* ssid = "........"; -const char* password = "........"; +const char* ssid = STASSID; +const char* password = STAPSK; ESP8266WebServer server(80); const char* serverIndex = "
"; diff --git a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino index 8c79a2a53d..931afe938a 100644 --- a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino +++ b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino @@ -35,7 +35,7 @@ standard Serial pins RX:GPIO3 and TX:GPIO1 */ -#define SWAP_PINS 1 +#define SWAP_PINS 0 /* SERIAL_LOOPBACK diff --git a/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino b/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino index b47496ca13..2115053dd5 100644 --- a/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino +++ b/libraries/ESP8266mDNS/examples/OTA-mDNS-SPIFFS/OTA-mDNS-SPIFFS.ino @@ -12,6 +12,11 @@ */ +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + // includes #include #include @@ -31,8 +36,8 @@ @brief Default WiFi connection information. @{ */ -const char* ap_default_ssid = "esp8266"; ///< Default SSID. -const char* ap_default_psk = "esp8266esp8266"; ///< Default PSK. +const char* ap_default_ssid = STASSID; ///< Default SSID. +const char* ap_default_psk = STAPSK; ///< Default PSK. /// @} /// Uncomment the next line for verbose output over UART. diff --git a/libraries/ESP8266mDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino b/libraries/ESP8266mDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino index b3f49d2588..80f3efbb60 100644 --- a/libraries/ESP8266mDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino +++ b/libraries/ESP8266mDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino @@ -12,8 +12,13 @@ #include #include -const char* ssid = "..."; -const char* password = "..."; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; char hostString[16] = {0}; void setup() { diff --git a/libraries/ESP8266mDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino b/libraries/ESP8266mDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino index 63562a5245..de46ea31b4 100644 --- a/libraries/ESP8266mDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino +++ b/libraries/ESP8266mDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino @@ -20,8 +20,13 @@ #include #include -const char* ssid = "............"; -const char* password = ".............."; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; // TCP server at port 80 will respond to HTTP requests WiFiServer server(80); diff --git a/libraries/esp8266/examples/I2STransmit/I2STransmit.ino b/libraries/esp8266/examples/I2STransmit/I2STransmit.ino index cdf2cfd0f7..0c7a7eb43c 100644 --- a/libraries/esp8266/examples/I2STransmit/I2STransmit.ino +++ b/libraries/esp8266/examples/I2STransmit/I2STransmit.ino @@ -12,9 +12,14 @@ #include #include +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + // Set your network here -const char *SSID = "...."; -const char *PASS = "...."; +const char *SSID = STASSID; +const char *PASS = STAPSK; WiFiUDP udp; // Set your listener PC's IP here: diff --git a/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino b/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino index ee30a24b85..d7c6b52b4d 100644 --- a/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino +++ b/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino @@ -19,8 +19,13 @@ //////////////////////////////////////////////////////// -#define SSID "open" -#define SSIDPWD "" +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +#define SSID STASSID +#define SSIDPWD STAPSK #define TZ 1 // (utc+) TZ in hours #define DST_MN 60 // use 60mn for summer time in some countries diff --git a/libraries/esp8266/examples/interactive/interactive.ino b/libraries/esp8266/examples/interactive/interactive.ino index dba5332741..8b78738fec 100644 --- a/libraries/esp8266/examples/interactive/interactive.ino +++ b/libraries/esp8266/examples/interactive/interactive.ino @@ -10,8 +10,13 @@ #include "ESP8266WiFi.h" #include "user_interface.h" -const char SSID[] = "open"; -const char PSK[] = ""; +#ifndef STASSID +#define STASSID "your-ssid" +#define STAPSK "your-password" +#endif + +const char SSID[] = STASSID; +const char PSK[] = STAPSK; IPAddress staticip(192, 168, 1, 123); IPAddress gateway(192, 168, 1, 254); From 8a28979ec7355cf6632d3f6500f36ab3dee5355d Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 25 Nov 2018 22:44:19 +0100 Subject: [PATCH 20/28] style --- .../examples/WiFiManualWebServer/WiFiManualWebServer.ino | 3 +-- tests/examples_restyle.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino index 848b6715b7..7360d10640 100644 --- a/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino +++ b/libraries/ESP8266WiFi/examples/WiFiManualWebServer/WiFiManualWebServer.ino @@ -83,8 +83,7 @@ void loop() { // read/ignore the rest of the request // do not client.flush(): it is for output only, see below - while (client.available()) - { + while (client.available()) { // byte by byte is not very efficient client.read(); } diff --git a/tests/examples_restyle.sh b/tests/examples_restyle.sh index 91117fda28..489f419a55 100755 --- a/tests/examples_restyle.sh +++ b/tests/examples_restyle.sh @@ -1,3 +1,3 @@ #!/bin/sh cd $(cd ${0%/*}; pwd) -echo astyle --options=examples_style.conf ../libraries/*/examples/*/*.ino +astyle --options=examples_style.conf ../libraries/*/examples/*/*.ino From b7c4e5571ec41d68b27ec15e26cc59c7c8d8e992 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 27 Nov 2018 23:24:14 +0100 Subject: [PATCH 21/28] restyle examples --- libraries/esp8266/examples/IPv6/IPv6.ino | 10 +++++----- tests/examples_restyle.sh | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/esp8266/examples/IPv6/IPv6.ino b/libraries/esp8266/examples/IPv6/IPv6.ino index fae40460d5..9dbc2788d0 100644 --- a/libraries/esp8266/examples/IPv6/IPv6.ino +++ b/libraries/esp8266/examples/IPv6/IPv6.ino @@ -22,8 +22,8 @@ #include #ifndef STASSID - #define STASSID "your-ssid" - #define STAPSK "your-password" +#define STASSID "your-ssid" +#define STAPSK "your-password" #endif #define FQDN F("www.google.com") // with both IPv4 & IPv6 addresses @@ -101,7 +101,7 @@ void setup() { status(Serial); - #if 0 +#if 0 // legacy loop (still valid with IPv4 only) @@ -110,7 +110,7 @@ void setup() { delay(500); } - #else +#else // Use this loop instead to wait for an IPv6 routable address @@ -131,7 +131,7 @@ void setup() { delay(500); } - #endif +#endif Serial.println(F("connected: ")); diff --git a/tests/examples_restyle.sh b/tests/examples_restyle.sh index 489f419a55..9d56aa41a2 100755 --- a/tests/examples_restyle.sh +++ b/tests/examples_restyle.sh @@ -1,3 +1,3 @@ -#!/bin/sh +#!/bin/bash cd $(cd ${0%/*}; pwd) -astyle --options=examples_style.conf ../libraries/*/examples/*/*.ino +astyle --options=examples_style.conf ../libraries/*/examples/*{,/*}/*.ino From e2ebfab432c7b6b0e2537542b098ea4a15c05109 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 28 Nov 2018 14:36:52 +0100 Subject: [PATCH 22/28] helper to run CI test locally --- tests/run_CI_locally.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tests/run_CI_locally.sh diff --git a/tests/run_CI_locally.sh b/tests/run_CI_locally.sh new file mode 100755 index 0000000000..a241577d20 --- /dev/null +++ b/tests/run_CI_locally.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +# temporary directory + +[ -z "${TMPCI}" ] && TMPCI=/tmp/ci + +################## + +set -e + +TMPDIR=${TMPCI%/*} +CIDIR=${TMPCI##*/} + +mkdir -p ${TMPDIR} + +# set root directory into $ESP +ESP="$(cd ${0%/*}/..; pwd)" + +# clone or update this repository into ${TMPDIR}/${CIDIR} +if test -d ${CIDIR}; then + (cd ${TMPDIR}; git clone ${ESP} ${CIDIR}) +else + (cd ${TMPCI}; git pull) +fi + +cd ${TMPCI} +rm -rf arduino_ide arduino-nightly Arduino/libraries/ArduinoJson +HOME=${TMPCI} TRAVIS_BUILD_DIR=${TMPCI} BUILD_TYPE=build tests/common.sh From ab0b3729ada9eaed6008460b92335aaf39e58a00 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 28 Nov 2018 15:12:48 +0100 Subject: [PATCH 23/28] local CI runner more verbose --- tests/run_CI_locally.sh | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/run_CI_locally.sh b/tests/run_CI_locally.sh index a241577d20..a080f3a3d4 100755 --- a/tests/run_CI_locally.sh +++ b/tests/run_CI_locally.sh @@ -15,14 +15,36 @@ mkdir -p ${TMPDIR} # set root directory into $ESP ESP="$(cd ${0%/*}/..; pwd)" +branch=$(git rev-parse --abbrev-ref HEAD) + +echo "" +echo " -- CI directory: ${TMPCI} --" +echo "" +echo "Ensure your changes are committed in current branch ${branch}" +echo "" +echo "press return to run 'git diff'" +read junk +git diff +echo "press return to run CI, or ^C" +read junk # clone or update this repository into ${TMPDIR}/${CIDIR} -if test -d ${CIDIR}; then - (cd ${TMPDIR}; git clone ${ESP} ${CIDIR}) +if [ -d ${TMPCI} ]; then + echo "" + echo " -- updating CI directory in ${TMPCI} --" + echo "" + (cd ${TMPCI}; git checkout ${branch}; git pull) else - (cd ${TMPCI}; git pull) + echo "" + echo " -- installing CI directory in ${TMPCI} --" + echo "" + (cd ${TMPDIR}; git clone ${ESP} ${CIDIR}) fi cd ${TMPCI} +if [ "$branch" != "$branch" ]; then + echo "branch ${cibranch} in ${TMPCI} not matching branch ${branch} in ${ESP}" + exit 1 +fi rm -rf arduino_ide arduino-nightly Arduino/libraries/ArduinoJson HOME=${TMPCI} TRAVIS_BUILD_DIR=${TMPCI} BUILD_TYPE=build tests/common.sh From 822c38c12432f70e3b64c66a9d8c0d5614b517b3 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 29 Nov 2018 23:17:12 +0100 Subject: [PATCH 24/28] +const --- libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino index 539e8b17e2..1c6acd61aa 100644 --- a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino +++ b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino @@ -26,8 +26,8 @@ #define STAPSK "your-password" #endif -char ssid[] = STASSID; // your network SSID (name) -char pass[] = STAPSK; // your network password +const char ssid[] = STASSID; // your network SSID (name) +const char pass[] = STAPSK; // your network password unsigned int localPort = 2390; // local port to listen for UDP packets From 42dc0b7a12559d003bb308de1d1afa4618f2cd35 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 29 Nov 2018 23:57:53 +0100 Subject: [PATCH 25/28] deprecation deprecation --- .../ESP8266WiFi/src/WiFiClientSecureBearSSL.h | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h index 65baad9e02..9fc018800e 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h @@ -121,48 +121,69 @@ class WiFiClientSecure : public WiFiClient { static bool probeMaxFragmentLength(const char *hostname, uint16_t port, uint16_t len); static bool probeMaxFragmentLength(const String& host, uint16_t port, uint16_t len); - bool setCACert(const uint8_t* pk, size_t size); - bool setCertificate(const uint8_t* pk, size_t size); - bool setPrivateKey(const uint8_t* pk, size_t size); + //////////////////////////////////////////////////// + // AxTLS API deprecated warnings to help upgrading + +#define AXTLS_DEPRECATED + #define xAXTLS_DEPRECATED \ + __attribute__((deprecated( \ + "This is deprecated AxTLS API, " \ + "check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))) + + bool setCACert(const uint8_t* pk, size_t size) AXTLS_DEPRECATED; + bool setCertificate(const uint8_t* pk, size_t size) AXTLS_DEPRECATED; + bool setPrivateKey(const uint8_t* pk, size_t size) AXTLS_DEPRECATED; - bool setCACert_P(PGM_VOID_P pk, size_t size) { return setCACert((const uint8_t *)pk, size); } - bool setCertificate_P(PGM_VOID_P pk, size_t size) { return setCertificate((const uint8_t *)pk, size); } - bool setPrivateKey_P(PGM_VOID_P pk, size_t size) { return setPrivateKey((const uint8_t *)pk, size); } + bool loadCACert(Stream& stream, size_t size) AXTLS_DEPRECATED; + bool loadCertificate(Stream& stream, size_t size) AXTLS_DEPRECATED; + bool loadPrivateKey(Stream& stream, size_t size) AXTLS_DEPRECATED; - bool loadCACert(Stream& stream, size_t size); - bool loadCertificate(Stream& stream, size_t size); - bool loadPrivateKey(Stream& stream, size_t size); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + + bool setCACert_P(PGM_VOID_P pk, size_t size) AXTLS_DEPRECATED { + return setCACert((const uint8_t *)pk, size); + } + + bool setCertificate_P(PGM_VOID_P pk, size_t size) AXTLS_DEPRECATED { + return setCertificate((const uint8_t *)pk, size); + } + + bool setPrivateKey_P(PGM_VOID_P pk, size_t size) AXTLS_DEPRECATED { + return setPrivateKey((const uint8_t *)pk, size); + } template - bool loadCertificate(TFile& file) { + bool loadCertificate(TFile& file) AXTLS_DEPRECATED { return loadCertificate(file, file.size()); } template - bool loadPrivateKey(TFile& file) { + bool loadPrivateKey(TFile& file) AXTLS_DEPRECATED { return loadPrivateKey(file, file.size()); } template - bool loadCACert(TFile& file) { + bool loadCACert(TFile& file) AXTLS_DEPRECATED { return loadCACert(file, file.size()); } - // AxTLS API deprecated warnings to help upgrading +#pragma GCC diagnostic pop - bool verify(const char* fingerprint, const char* domain_name) - __attribute__((deprecated("This is deprecated AxTLS API, check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))) { + bool verify(const char* fingerprint, const char* domain_name) AXTLS_DEPRECATED { (void)fingerprint; (void)domain_name; return connected(); } - bool verifyCertChain(const char* domain_name) - __attribute__((deprecated("This is deprecated AxTLS API, check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))) { + bool verifyCertChain(const char* domain_name) AXTLS_DEPRECATED { (void)domain_name; return connected(); } + // AxTLS API deprecated section end + ///////////////////////////////////// + private: void _clear(); void _clearAuthenticationSettings(); From 3c298e6538315aee4ca19ac80ba003f0523fe22b Mon Sep 17 00:00:00 2001 From: david gauchard Date: Fri, 30 Nov 2018 00:29:10 +0100 Subject: [PATCH 26/28] deprecation --- .../ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp | 9 +++++++++ libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h | 13 ++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp index c1fa3eac18..a4fae44696 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp @@ -1346,7 +1346,10 @@ bool WiFiClientSecure::loadCACert(Stream& stream, size_t size) { uint8_t *dest = _streamLoad(stream, size); bool ret = false; if (dest) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" ret = setCACert(dest, size); +#pragma GCC diagnostic pop } free(dest); return ret; @@ -1356,7 +1359,10 @@ bool WiFiClientSecure::loadCertificate(Stream& stream, size_t size) { uint8_t *dest = _streamLoad(stream, size); bool ret = false; if (dest) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" ret = setCertificate(dest, size); +#pragma GCC diagnostic pop } free(dest); return ret; @@ -1366,7 +1372,10 @@ bool WiFiClientSecure::loadPrivateKey(Stream& stream, size_t size) { uint8_t *dest = _streamLoad(stream, size); bool ret = false; if (dest) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" ret = setPrivateKey(dest, size); +#pragma GCC diagnostic pop } free(dest); return ret; diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h index 9fc018800e..460ba1cc52 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h @@ -124,8 +124,7 @@ class WiFiClientSecure : public WiFiClient { //////////////////////////////////////////////////// // AxTLS API deprecated warnings to help upgrading -#define AXTLS_DEPRECATED - #define xAXTLS_DEPRECATED \ + #define AXTLS_DEPRECATED \ __attribute__((deprecated( \ "This is deprecated AxTLS API, " \ "check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))) @@ -153,23 +152,23 @@ class WiFiClientSecure : public WiFiClient { return setPrivateKey((const uint8_t *)pk, size); } +#pragma GCC diagnostic pop + template - bool loadCertificate(TFile& file) AXTLS_DEPRECATED { + bool loadCertificate(TFile& file) { return loadCertificate(file, file.size()); } template - bool loadPrivateKey(TFile& file) AXTLS_DEPRECATED { + bool loadPrivateKey(TFile& file) { return loadPrivateKey(file, file.size()); } template - bool loadCACert(TFile& file) AXTLS_DEPRECATED { + bool loadCACert(TFile& file) { return loadCACert(file, file.size()); } -#pragma GCC diagnostic pop - bool verify(const char* fingerprint, const char* domain_name) AXTLS_DEPRECATED { (void)fingerprint; (void)domain_name; From 5385a9375938236961a790e71f50f808fdb21676 Mon Sep 17 00:00:00 2001 From: Develo Date: Fri, 30 Nov 2018 00:45:50 -0300 Subject: [PATCH 27/28] Update NTPClient.ino const char[] => const char * --- libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino index 1c6acd61aa..927e78fee9 100644 --- a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino +++ b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino @@ -26,8 +26,8 @@ #define STAPSK "your-password" #endif -const char ssid[] = STASSID; // your network SSID (name) -const char pass[] = STAPSK; // your network password +const char * ssid = STASSID; // your network SSID (name) +const char * pass = STAPSK; // your network password unsigned int localPort = 2390; // local port to listen for UDP packets From cc15e6fab1d23830c65c753a1e20a93643014b80 Mon Sep 17 00:00:00 2001 From: Develo Date: Fri, 30 Nov 2018 00:46:34 -0300 Subject: [PATCH 28/28] Update interactive.ino const char[] => const char * --- libraries/esp8266/examples/interactive/interactive.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/esp8266/examples/interactive/interactive.ino b/libraries/esp8266/examples/interactive/interactive.ino index 8b78738fec..3c21455a29 100644 --- a/libraries/esp8266/examples/interactive/interactive.ino +++ b/libraries/esp8266/examples/interactive/interactive.ino @@ -15,8 +15,8 @@ #define STAPSK "your-password" #endif -const char SSID[] = STASSID; -const char PSK[] = STAPSK; +const char * SSID = STASSID; +const char * PSK = STAPSK; IPAddress staticip(192, 168, 1, 123); IPAddress gateway(192, 168, 1, 254);