From 14b70e9328e78c94ba0c0042766a11854ac389de Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 4 Dec 2015 19:02:46 +0300 Subject: [PATCH 01/41] Allow setting client side TLS key and certificate --- .../examples/HTTPSRequest/HTTPSRequest.ino | 4 +- .../ESP8266WiFi/src/WiFiClientSecure.cpp | 74 ++++++++++++++++++ libraries/ESP8266WiFi/src/WiFiClientSecure.h | 16 ++++ tools/sdk/lib/libaxtls.a | Bin 556130 -> 554486 bytes 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino index 975fe13ef..6d10d5115 100644 --- a/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino +++ b/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino @@ -4,7 +4,7 @@ * This example demonstrates how to use * WiFiClientSecure class to access HTTPS API. * We fetch and display the status of - * esp8266/Arduino project continous integration + * esp8266/Arduino project continuous integration * build. * * Created by Ivan Grokhotkov, 2015. @@ -54,7 +54,7 @@ void setup() { Serial.println("certificate doesn't match"); } - String url = "/repos/esp8266/Arduino/commits/esp8266/status"; + String url = "/repos/esp8266/Arduino/commits/master/status"; Serial.print("requesting URL: "); Serial.println(url); diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp index 6d4365221..247701acd 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp @@ -50,6 +50,17 @@ extern "C" #define SSL_DEBUG_OPTS 0 #endif +uint8_t* default_private_key = 0; +uint32_t default_private_key_len = 0; +static bool default_private_key_dynamic = false; +// +uint8_t* default_certificate = 0; +uint32_t default_certificate_len = 0; +static bool default_certificate_dynamic = false; + +static void clear_private_key(); +static void clear_certificate(); + class SSLContext { public: @@ -70,6 +81,9 @@ public: if (_ssl_ctx_refcnt == 0) { ssl_ctx_free(_ssl_ctx); } + + clear_private_key(); + clear_certificate(); } void ref() { @@ -337,6 +351,66 @@ bool WiFiClientSecure::verify(const char* fp, const char* url) { return true; } +void WiFiClientSecure::setCertificate(const uint8_t* cert_data, size_t size) { + clear_certificate(); + default_certificate = (uint8_t*) cert_data; + default_certificate_len = size; +} + +void WiFiClientSecure::setPrivateKey(const uint8_t* pk, size_t size) { + clear_private_key(); + default_private_key = (uint8_t*) pk; + default_private_key_len = size; +} + +bool WiFiClientSecure::loadCertificate(Stream& stream, size_t size) { + clear_certificate(); + default_certificate = new uint8_t[size]; + if (!default_certificate) { + return false; + } + if (stream.readBytes(default_certificate, size) != size) { + delete[] default_certificate; + return false; + } + default_certificate_dynamic = true; + default_certificate_len = size; + return true; +} + +bool WiFiClientSecure::loadPrivateKey(Stream& stream, size_t size) { + clear_private_key(); + default_private_key = new uint8_t[size]; + if (!default_private_key) { + return false; + } + if (stream.readBytes(default_private_key, size) != size) { + delete[] default_private_key; + return false; + } + default_private_key_dynamic = true; + default_private_key_len = size; + return true; +} + +static void clear_private_key() { + if (default_private_key && default_private_key_dynamic) { + delete[] default_private_key; + default_private_key_dynamic = false; + } + default_private_key = 0; + default_private_key_len = 0; +} + +static void clear_certificate() { + if (default_certificate && default_certificate_dynamic) { + delete[] default_certificate; + default_certificate_dynamic = false; + } + default_certificate = 0; + default_certificate_len = 0; +} + extern "C" int ax_port_read(int fd, uint8_t* buffer, size_t count) { ClientContext* _client = reinterpret_cast(fd); if (_client->state() != ESTABLISHED && !_client->getSize()) { diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.h b/libraries/ESP8266WiFi/src/WiFiClientSecure.h index 8ce11f939..07b111e1a 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.h +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.h @@ -48,6 +48,22 @@ public: int peek() override; void stop() override; + void setCertificate(const uint8_t* cert_data, size_t size); + void setPrivateKey(const uint8_t* pk, size_t size); + + bool loadCertificate(Stream& stream, size_t size); + bool loadPrivateKey(Stream& stream, size_t size); + + template + bool loadCertificate(TFile& file) { + return loadCertificate(file, file.size()); + } + + template + bool loadPrivateKey(TFile& file) { + return loadPrivateKey(file, file.size()); + } + protected: int _connectSSL(); diff --git a/tools/sdk/lib/libaxtls.a b/tools/sdk/lib/libaxtls.a index b74d97cc434d721102ac4874ea72865d8ff219f8..9e29c802bd67ed9c543db86b405a38974432558f 100644 GIT binary patch delta 19157 zcmc(nd3Y5?+V-o?>9d3+7?O}3IAkM)K*BD2Kz0?79Rw0&N0xvQ0nvks!YB#|Qs6{_ zh>FT63K~=fmvJ8k(LrBy6wtwq0mWr}9YuNXyU)|4^B@1!d~Hs!U5EBv%Gy4e+g(R@o>b2NM<4xvsXX|^=gRY;{FjyMYn!Uj1wMT7 zL+by+_wF~M!rZtukg>bkmll#i*}XO{>mK1-c5SKKwMB26DDm}cN*kPVLtGk)^sOG$}m>KCV}%BT$Xw$4|o~$3d{#=Y$X}*Z8?79cc*hs}}^7($As1 zHZ+ENz3xzk^L7Kh$ZXAXS|d1^=d{r)&98Y*4uY(FCujWqjg?v-uT+s9<-5UA#Th8| zuh4e5+Hn86!#Aqp<`6%HxGyI9mMK+S2JOG0{gP(RWJGi(Tz^Mc*IG*0#VcdRT#zt&7Z@0;fgVkTj*f z^=df2RJAw?(+cxQfitmL6lqfvS^Eh8_j;r%ZHH0X46(E?V38>(bS~G=nrjN3iyIt) z++q&oBXv&~I&*#5E77`JF%gj27i9=muQWYcI+^ioe(^-aPp6s5EuBIi!auZh zT1J>NtC5>C;O7)VW@p{LXiybzceB6S(&?@5H>t%=Pv57F&B$Uj<9@TP*lDL5nfHpF z7A)$wVyB=$!<~3y1mh$*NivO(3PgVmGe)U7L+&zdX%}e#L3mwW?qRiHq6PR zYu-*Z2TPoe(GT?=%(<2;@so*!yHl0w`wlIh)^C%)Mzi!Y`a^Jw8W^37RjJ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`RUB<)KD0A1--Hip(`6Csi^B?jpr}CvdM~-k0xJ%(W#9 i{=g7t4`qxn9?g2$XpA|F<_Jn{-;_^~)y~sdjsG86CDa)J From 8cec66b23ba3b78e9abec9cd918b1b9cced5266c Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Fri, 4 Dec 2015 18:16:05 +0100 Subject: [PATCH 02/41] add a simple TCP example --- .../examples/WiFiClientMin/WiFiClientMin.ino | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino diff --git a/libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino b/libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino new file mode 100644 index 000000000..9386362ff --- /dev/null +++ b/libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino @@ -0,0 +1,68 @@ +/* + * This sketch sends a message to a TCP server + * + */ + +#include +#include + +ESP8266WiFiMulti WiFiMulti; + +void setup() { + Serial.begin(115200); + delay(10); + + // We start by connecting to a WiFi network + WiFiMulti.addAP("SSID", "passpasspass"); + + Serial.println(); + Serial.println(); + Serial.print("Wait for WiFi... "); + + while(WiFiMulti.run() != WL_CONNECTED) { + Serial.print("."); + delay(500); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + + delay(500); +} + + +void loop() { + const uint16_t port = 80; + const char * host = "192.168.1.1"; // ip or dns + + + + Serial.print("connecting to "); + Serial.println(host); + + // Use WiFiClient class to create TCP connections + WiFiClient client; + + if (!client.connect(host, port)) { + Serial.println("connection failed"); + Serial.println("wait 5 sec..."); + delay(5000); + return; + } + + // This will send the request to the server + client.print("Send this data to server"); + + //read back one line from server + String line = client.readStringUntil('\r'); + client.println(line); + + Serial.println("closing connection"); + client.stop(); + + Serial.println("wait 5 sec..."); + delay(5000); +} + From 34571a0e9d2bfa69aa855c9b283cb7bc4abf0515 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Fri, 4 Dec 2015 18:20:40 +0100 Subject: [PATCH 03/41] typo --- .../examples/WiFiClientMin/WiFiClientMin.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino b/libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino index 9386362ff..accb37bf8 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino @@ -37,8 +37,8 @@ void loop() { const uint16_t port = 80; const char * host = "192.168.1.1"; // ip or dns - - + + Serial.print("connecting to "); Serial.println(host); @@ -47,8 +47,8 @@ void loop() { if (!client.connect(host, port)) { Serial.println("connection failed"); - Serial.println("wait 5 sec..."); - delay(5000); + Serial.println("wait 5 sec..."); + delay(5000); return; } @@ -61,8 +61,8 @@ void loop() { Serial.println("closing connection"); client.stop(); - + Serial.println("wait 5 sec..."); - delay(5000); + delay(5000); } From cedce24bf39171d2d74eab2d6aead61108a88530 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Fri, 4 Dec 2015 19:07:51 +0100 Subject: [PATCH 04/41] rename to WiFiClientBasic --- .../WiFiClientMin.ino => WiFiClientBasic/WiFiClientBasic.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libraries/ESP8266WiFi/examples/{WiFiClientMin/WiFiClientMin.ino => WiFiClientBasic/WiFiClientBasic.ino} (100%) diff --git a/libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino b/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino similarity index 100% rename from libraries/ESP8266WiFi/examples/WiFiClientMin/WiFiClientMin.ino rename to libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino From e3137a0b559aeda228718fde4f46c0ff70786610 Mon Sep 17 00:00:00 2001 From: Rodrigo Mendez Date: Fri, 4 Dec 2015 18:24:08 -0600 Subject: [PATCH 05/41] added ESPino to supported boards --- boards.txt | 85 ++++++++++++++++++++++++++++++++++ variants/espino/pins_arduino.h | 73 +++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 variants/espino/pins_arduino.h diff --git a/boards.txt b/boards.txt index 8ed16f539..5b8505dd2 100644 --- a/boards.txt +++ b/boards.txt @@ -691,3 +691,88 @@ d1_mini.menu.FlashSize.4M1M.build.spiffs_start=0x300000 d1_mini.menu.FlashSize.4M1M.build.spiffs_end=0x3FB000 d1_mini.menu.FlashSize.4M1M.build.spiffs_blocksize=8192 d1_mini.menu.FlashSize.4M1M.build.spiffs_pagesize=256 + + +############################################################## +espino.name=ESPino + +espino.upload.tool=esptool +espino.upload.speed=115200 +espino.upload.resetmethod=ck +espino.upload.maximum_size=434160 +espino.upload.maximum_data_size=81920 +espino.upload.wait_for_upload_port=true +espino.serial.disableDTR=true +espino.serial.disableRTS=true + +espino.build.mcu=esp8266 +espino.build.f_cpu=80000000L +espino.build.board=ESP8266_ESP12 +espino.build.core=esp8266 +espino.build.variant=generic +espino.build.flash_mode=qio +espino.build.flash_size=4M +espino.build.flash_freq=40 +espino.build.spiffs_pagesize=256 + +espino.menu.UploadTool.esptool=Serial +espino.menu.UploadTool.esptool.upload.tool=esptool +espino.menu.UploadTool.esptool.upload.verbose=-vv +espino.menu.UploadTool.espota=OTA +espino.menu.UploadTool.espota.upload.tool=espota + +espino.menu.CpuFrequency.80=80 MHz +espino.menu.CpuFrequency.80.build.f_cpu=80000000L +espino.menu.CpuFrequency.160=160 MHz +espino.menu.CpuFrequency.160.build.f_cpu=160000000L + +espino.menu.FlashFreq.40=40MHz +espino.menu.FlashFreq.40.build.flash_freq=40 +espino.menu.FlashFreq.80=80MHz +espino.menu.FlashFreq.80.build.flash_freq=80 + +espino.menu.FlashMode.dio=DIO +espino.menu.FlashMode.dio.build.flash_mode=dio +espino.menu.FlashMode.qio=QIO +espino.menu.FlashMode.qio.build.flash_mode=qio + +espino.menu.UploadSpeed.115200=115200 +espino.menu.UploadSpeed.115200.upload.speed=115200 +espino.menu.UploadSpeed.9600=9600 +espino.menu.UploadSpeed.9600.upload.speed=9600 +espino.menu.UploadSpeed.57600=57600 +espino.menu.UploadSpeed.57600.upload.speed=57600 +espino.menu.UploadSpeed.256000.windows=256000 +espino.menu.UploadSpeed.256000.upload.speed=256000 +espino.menu.UploadSpeed.230400.linux=230400 +espino.menu.UploadSpeed.230400.macosx=230400 +espino.menu.UploadSpeed.230400.upload.speed=230400 +espino.menu.UploadSpeed.460800.linux=460800 +espino.menu.UploadSpeed.460800.macosx=460800 +espino.menu.UploadSpeed.460800.upload.speed=460800 +espino.menu.UploadSpeed.512000.windows=512000 +espino.menu.UploadSpeed.512000.upload.speed=512000 +espino.menu.UploadSpeed.921600=921600 +espino.menu.UploadSpeed.921600.upload.speed=921600 + +espino.menu.FlashSize.4M1M=4M (1M SPIFFS) +espino.menu.FlashSize.4M1M.build.flash_size=4M +espino.menu.FlashSize.4M1M.build.flash_ld=eagle.flash.4m1m.ld +espino.menu.FlashSize.4M1M.build.spiffs_start=0x300000 +espino.menu.FlashSize.4M1M.build.spiffs_end=0x3FB000 +espino.menu.FlashSize.4M1M.build.spiffs_blocksize=8192 +espino.menu.FlashSize.4M1M.build.spiffs_pagesize=256 +espino.menu.FlashSize.4M1M.upload.maximum_size=1044464 + +espino.menu.FlashSize.4M3M=4M (3M SPIFFS) +espino.menu.FlashSize.4M3M.build.flash_size=4M +espino.menu.FlashSize.4M3M.build.flash_ld=eagle.flash.4m.ld +espino.menu.FlashSize.4M3M.build.spiffs_start=0x100000 +espino.menu.FlashSize.4M3M.build.spiffs_end=0x3FB000 +espino.menu.FlashSize.4M3M.build.spiffs_blocksize=8192 +espino.menu.FlashSize.4M3M.upload.maximum_size=1044464 + +espino.menu.ResetMethod.ck=ck +espino.menu.ResetMethod.ck.upload.resetmethod=ck +espino.menu.ResetMethod.nodemcu=nodemcu +espino.menu.ResetMethod.nodemcu.upload.resetmethod=nodemcu diff --git a/variants/espino/pins_arduino.h b/variants/espino/pins_arduino.h new file mode 100644 index 000000000..2efad2db3 --- /dev/null +++ b/variants/espino/pins_arduino.h @@ -0,0 +1,73 @@ +/* + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2007 David A. Mellis + Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2015. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ +*/ + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#define EXTERNAL_NUM_INTERRUPTS 16 +#define NUM_DIGITAL_PINS 17 +#define NUM_ANALOG_INPUTS 1 + +#define analogInputToDigitalPin(p) ((p > 0)?NOT_A_PIN:0) +#define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)?p:NOT_A_PIN) +#define digitalPinHasPWM(p) (((p) < NUM_DIGITAL_PINS)?p:NOT_A_PIN) + +static const uint8_t SDA = 4; +static const uint8_t SCL = 5; + +static const uint8_t SS = 15; +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; + +static const uint8_t BUILTIN_LED = 2; +static const uint8_t BUILTIN_LEDR = 2; +static const uint8_t BUILTIN_LEDG = 4; +static const uint8_t BUILTIN_LEDB = 5; +static const uint8_t BUILTIN_BUTTON = 0; + +static const uint8_t A0 = 17; + +// These serial port names are intended to allow libraries and architecture-neutral +// sketches to automatically default to the correct port name for a particular type +// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, +// the first hardware serial port whose RX/TX pins are not dedicated to another use. +// +// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor +// +// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial +// +// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library +// +// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. +// +// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX +// pins are NOT connected to anything by default. +#define SERIAL_PORT_MONITOR Serial +#define SERIAL_PORT_USBVIRTUAL Serial +#define SERIAL_PORT_HARDWARE Serial +#define SERIAL_PORT_HARDWARE_OPEN Serial + +#endif /* Pins_Arduino_h */ From d076012cc8b0a8d3c0917795ff56bad9205c526d Mon Sep 17 00:00:00 2001 From: Rodrigo Mendez Date: Fri, 4 Dec 2015 18:40:21 -0600 Subject: [PATCH 06/41] variant and maxium_size for ESPino board wasn't correct, fixed --- boards.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boards.txt b/boards.txt index 5b8505dd2..b24d084de 100644 --- a/boards.txt +++ b/boards.txt @@ -699,7 +699,7 @@ espino.name=ESPino espino.upload.tool=esptool espino.upload.speed=115200 espino.upload.resetmethod=ck -espino.upload.maximum_size=434160 +espino.upload.maximum_size=1044464 espino.upload.maximum_data_size=81920 espino.upload.wait_for_upload_port=true espino.serial.disableDTR=true @@ -709,7 +709,7 @@ espino.build.mcu=esp8266 espino.build.f_cpu=80000000L espino.build.board=ESP8266_ESP12 espino.build.core=esp8266 -espino.build.variant=generic +espino.build.variant=espino espino.build.flash_mode=qio espino.build.flash_size=4M espino.build.flash_freq=40 From ac0264767ae932e57c95f6a233689863f455c641 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 5 Dec 2015 13:04:24 +0100 Subject: [PATCH 07/41] #1151 SPI definition correction - SPILADDR --- cores/esp8266/esp8266_peri.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/esp8266_peri.h b/cores/esp8266/esp8266_peri.h index 64c1f30b5..4fd057009 100644 --- a/cores/esp8266/esp8266_peri.h +++ b/cores/esp8266/esp8266_peri.h @@ -494,7 +494,7 @@ extern uint8_t esp8266_gpioToFn[16]; //SPI Phase Length Locations #define SPILCOMMAND 28 //4 bit in SPIxU2 default 7 (8bit) -#define SPILADDR 16 //6 bit in SPIxU1 default:23 (24bit) +#define SPILADDR 26 //6 bit in SPIxU1 default:23 (24bit) #define SPILDUMMY 0 //8 bit in SPIxU1 default:0 (0 cycles) #define SPILMISO 8 //9 bit in SPIxU1 default:0 (1bit) #define SPILMOSI 17 //9 bit in SPIxU1 default:0 (1bit) From f7bbea407e484771ca6ab9813990d20ccbb17f23 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sat, 5 Dec 2015 16:29:37 +0300 Subject: [PATCH 08/41] Fix failure when trying to open empty file (#1126) --- cores/esp8266/spiffs_api.cpp | 11 +++++++++++ tests/FSWrapper/FSWrapper.ino | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index 978e2ea0d..f1689cbfe 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -410,6 +410,17 @@ protected: FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode) { int mode = getSpiffsMode(openMode, accessMode); int fd = SPIFFS_open(&_fs, path, mode, 0); + if (fd < 0 && _fs.err_code == SPIFFS_ERR_DELETED && (openMode & OM_CREATE)) { + DEBUGV("SPIFFSImpl::open: fd=%d path=`%s` openMode=%d accessMode=%d err=%d, trying to remove\r\n", + fd, path, openMode, accessMode, _fs.err_code); + auto rc = SPIFFS_remove(&_fs, path); + if (rc != SPIFFS_OK) { + DEBUGV("SPIFFSImpl::open: SPIFFS_ERR_DELETED, but failed to remove path=`%s` openMode=%d accessMode=%d err=%d\r\n", + path, openMode, accessMode, _fs.err_code); + return FileImplPtr(); + } + fd = SPIFFS_open(&_fs, path, mode, 0); + } if (fd < 0) { DEBUGV("SPIFFSImpl::open: fd=%d path=`%s` openMode=%d accessMode=%d err=%d\r\n", fd, path, openMode, accessMode, _fs.err_code); diff --git a/tests/FSWrapper/FSWrapper.ino b/tests/FSWrapper/FSWrapper.ino index b152093d5..099065f4f 100644 --- a/tests/FSWrapper/FSWrapper.ino +++ b/tests/FSWrapper/FSWrapper.ino @@ -139,7 +139,15 @@ void setup() { fail("some files left after format"); } } - + { + File tmp = SPIFFS.open("/tmp.txt", "w"); + } + { + File tmp = SPIFFS.open("/tmp.txt", "w"); + if (!tmp) { + fail("failed to re-open empty file"); + } + } Serial.println("success"); } From 68a406274af6dbcbecf5aaeae5c97654aee35b14 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 5 Dec 2015 17:16:53 +0100 Subject: [PATCH 09/41] add parameter name to h for better reading --- cores/esp8266/Updater.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/Updater.h b/cores/esp8266/Updater.h index b9f1b3d06..a25cb081b 100644 --- a/cores/esp8266/Updater.h +++ b/cores/esp8266/Updater.h @@ -26,7 +26,7 @@ class UpdaterClass { Call this to check the space needed for the update Will return false if there is not enough space */ - bool begin(size_t size, int = U_FLASH); + bool begin(size_t size, int command = U_FLASH); /* Writes a buffer to the flash and increments the address From 02366bb9352f0ac6a7ae4a394ab17f8a66a18240 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 5 Dec 2015 17:17:24 +0100 Subject: [PATCH 10/41] add example makefile.init file for eclipse --- doc/eclipse/makefile.init | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 doc/eclipse/makefile.init diff --git a/doc/eclipse/makefile.init b/doc/eclipse/makefile.init new file mode 100644 index 000000000..f8e6d9daa --- /dev/null +++ b/doc/eclipse/makefile.init @@ -0,0 +1,39 @@ +vecho := @echo +Q := @ + +PROJECT_NAME=project_name + +OTA_IP=192.168.254.100 +OTA_PORT=8266 + +SERIAL_PORT=COM3 +SERIAL_BAUD=230400 + +ARDUINO_BASE = D:/Coding/avr/Programme/arduino-nightly +ESP8266_BASE = $(ARDUINO_BASE)/hardware/esp8266com/esp8266 +ESP8266_TOOLS = $(ESP8266_BASE)/tools +XTENSA_TOOLS_ROOT = $(ESP8266_TOOLS)/xtensa-lx106-elf/bin + +PYTHON_BIN = python +ESPTOOL_PY_BIN = $(ESP8266_TOOLS)/esptool.py +ESPOTA_PY_BIN = $(ESP8266_TOOLS)/espota.py +ESPTOOL_BIN = $(ESP8266_TOOLS)/esptool/esptool.exe + +ota: + $(vecho) ota... + $(PYTHON_BIN) $(ESPOTA_PY_BIN) -i $(OTA_IP) -p $(OTA_PORT) --auth= -f ./$(PROJECT_NAME).bin + +ota_spiffs: + $(vecho) ota spiffs... + $(PYTHON_BIN) $(ESPOTA_PY_BIN) -i $(OTA_IP) -p $(OTA_PORT) --auth= -s -f ./$(PROJECT_NAME)_spiffs.bin + +erase_flash: + $(vecho) "Erase Flash" + $(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(ESPPORT) -b $(SERIAL_BAUD) erase_flash + +dumpmem: + $(vecho) "Read Flash need some time..." + $(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(ESPPORT) -b $(ESPBAUD) read_flash 0 4194304 dump.bin + +objdump: + "$(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump" -S $(PROJECT_NAME).elf > $(PROJECT_NAME).dobj From d06b9105d56470a6fb3749600d543406247ba046 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 5 Dec 2015 17:22:28 +0100 Subject: [PATCH 11/41] fix C&P... --- doc/eclipse/makefile.init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/eclipse/makefile.init b/doc/eclipse/makefile.init index f8e6d9daa..76438d62c 100644 --- a/doc/eclipse/makefile.init +++ b/doc/eclipse/makefile.init @@ -29,11 +29,11 @@ ota_spiffs: erase_flash: $(vecho) "Erase Flash" - $(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(ESPPORT) -b $(SERIAL_BAUD) erase_flash + $(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(SERIAL_PORT) -b $(SERIAL_BAUD) erase_flash dumpmem: $(vecho) "Read Flash need some time..." - $(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(ESPPORT) -b $(ESPBAUD) read_flash 0 4194304 dump.bin + $(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(SERIAL_PORT) -b $(SERIAL_BAUD) read_flash 0 4194304 dump.bin objdump: "$(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump" -S $(PROJECT_NAME).elf > $(PROJECT_NAME).dobj From ecce35d24058e3a6b77a86f845c732f2592b5540 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 5 Dec 2015 20:33:08 +0100 Subject: [PATCH 12/41] allow SPIFFS --- .../src/ESP8266httpUpdate.cpp | 61 ++++++++++++++++--- .../ESP8266httpUpdate/src/ESP8266httpUpdate.h | 6 +- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index 39ba0555c..8907df24a 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -23,9 +23,10 @@ * */ - #include "ESP8266httpUpdate.h" +extern "C" uint32_t _SPIFFS_start; +extern "C" uint32_t _SPIFFS_end; ESP8266HTTPUpdate::ESP8266HTTPUpdate(void) { } @@ -46,6 +47,19 @@ t_httpUpdate_return ESP8266HTTPUpdate::update(const char * url, const char * cur return handleUpdate(&http, current_version); } +/** + * + * @param url const char * + * @param current_version const char * + * @param httpsFingerprint const char * + * @return t_httpUpdate_return + */ +t_httpUpdate_return ESP8266HTTPUpdate::updateSpiffs(const char * url, const char * current_version, const char * httpsFingerprint) { + HTTPClient http; + http.begin(url, httpsFingerprint); + return handleUpdate(&http, current_version, false, true); +} + /** * * @param host const char * @@ -73,7 +87,7 @@ t_httpUpdate_return ESP8266HTTPUpdate::update(String host, uint16_t port, String * @param current_version const char * * @return t_httpUpdate_return */ -t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const char * current_version) { +t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const char * current_version, bool reboot, bool spiffs) { t_httpUpdate_return ret = HTTP_UPDATE_FAILED; @@ -85,6 +99,12 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha http->addHeader("x-ESP8266-chip-size", String(ESP.getFlashChipRealSize())); http->addHeader("x-ESP8266-sdk-version", ESP.getSdkVersion()); + if(spiffs) { + http->addHeader("x-ESP8266-mode", "spiffs"); + } else { + http->addHeader("x-ESP8266-mode", "sketch"); + } + if(current_version && current_version[0] != 0x00) { http->addHeader("x-ESP8266-version", current_version); } @@ -119,9 +139,20 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha switch(code) { case 200: ///< OK (Start Update) if(len > 0) { - if(len > ESP.getFreeSketchSpace()) { + bool startUpdate = false; + if(spiffs) { + size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start); + if(len > (int) spiffsSize) { + DEBUG_HTTP_UPDATE("[httpUpdate] spiffsSize to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len); + } + } else { + if(len > (int) ESP.getFreeSketchSpace()) { + DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len); + } + } + + if(!startUpdate) { ret = HTTP_UPDATE_FAILED; - DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len); } else { WiFiClient * tcp = http->getStreamPtr(); @@ -131,11 +162,25 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha delay(100); - if(runUpdate(*tcp, len, http->header("x-MD5"))) { + int command; + + if(spiffs) { + command = U_SPIFFS; + DEBUG_HTTP_UPDATE("[httpUpdate] runUpdate spiffs...\n"); + } else { + command = U_FLASH; + DEBUG_HTTP_UPDATE("[httpUpdate] runUpdate flash...\n"); + } + + if(runUpdate(*tcp, len, http->header("x-MD5"), command)) { ret = HTTP_UPDATE_OK; DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n"); http->end(); - ESP.restart(); + + if(reboot) { + ESP.restart(); + } + } else { ret = HTTP_UPDATE_FAILED; DEBUG_HTTP_UPDATE("[httpUpdate] Update failed\n"); @@ -171,9 +216,9 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha * @param md5 String * @return true if Update ok */ -bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5) { +bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command) { - if(!Update.begin(size)) { + if(!Update.begin(size, command)) { DEBUG_HTTP_UPDATE("[httpUpdate] Update.begin failed!\n"); return false; } diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h index a494695ff..f9a4d8030 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h @@ -53,9 +53,11 @@ class ESP8266HTTPUpdate { t_httpUpdate_return update(const char * host, uint16_t port, const char * url = "/", const char * current_version = "", bool https = false, const char * httpsFingerprint = ""); t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = ""); + t_httpUpdate_return updateSpiffs(const char * url, const char * current_version, const char * httpsFingerprint); + protected: - t_httpUpdate_return handleUpdate(HTTPClient * http, const char * current_version); - bool runUpdate(Stream& in, uint32_t size, String md5); + t_httpUpdate_return handleUpdate(HTTPClient * http, const char * current_version, bool reboot = true, bool spiffs = false); + bool runUpdate(Stream& in, uint32_t size, String md5, int command = U_FLASH); }; extern ESP8266HTTPUpdate ESPhttpUpdate; From 95d53c37c381536cb9e87a0516082b1f5c2f26ba Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 5 Dec 2015 20:47:58 +0100 Subject: [PATCH 13/41] add httpUpdateSPIFFS.ino example --- .../httpUpdateSPIFFS/httpUpdateSPIFFS.ino | 65 +++++++++++++++++++ .../src/ESP8266httpUpdate.cpp | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino diff --git a/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino b/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino new file mode 100644 index 000000000..3d746af6c --- /dev/null +++ b/libraries/ESP8266httpUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino @@ -0,0 +1,65 @@ +/** + * httpUpdateSPIFFS.ino + * + * Created on: 05.12.2015 + * + */ + +#include + +#include +#include + +#include +#include + +#define USE_SERIAL Serial + +ESP8266WiFiMulti WiFiMulti; + +void setup() { + + USE_SERIAL.begin(115200); + // USE_SERIAL.setDebugOutput(true); + + USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); + + for(uint8_t t = 4; t > 0; t--) { + USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); + USE_SERIAL.flush(); + delay(1000); + } + + WiFiMulti.addAP("SSID", "PASSWORD"); + +} + +void loop() { + // wait for WiFi connection + if((WiFiMulti.run() == WL_CONNECTED)) { + + USE_SERIAL.println("Update SPIFFS..."); + t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs("https://server/spiffs.bin"); + if(ret == HTTP_UPDATE_OK) { + USE_SERIAL.println("Update sketch..."); + ret = ESPhttpUpdate.update("https://server/file.bin"); + + switch(ret) { + case HTTP_UPDATE_FAILED: + USE_SERIAL.println("HTTP_UPDATE_FAILD"); + break; + + case HTTP_UPDATE_NO_UPDATES: + USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES"); + break; + + case HTTP_UPDATE_OK: + USE_SERIAL.println("HTTP_UPDATE_OK"); + break; + } + } + } +} + diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index 8907df24a..52a094c69 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -143,7 +143,7 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha if(spiffs) { size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start); if(len > (int) spiffsSize) { - DEBUG_HTTP_UPDATE("[httpUpdate] spiffsSize to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len); + DEBUG_HTTP_UPDATE("[httpUpdate] spiffsSize to low (%d) needed: %d\n", spiffsSize, len); } } else { if(len > (int) ESP.getFreeSketchSpace()) { From d8e3c766a33041158af3f97499742ee4eb522e0c Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sun, 6 Dec 2015 11:07:25 +0100 Subject: [PATCH 14/41] ESP8266HTTPUpdate - improve error displaying --- .../ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index 52a094c69..92b047b30 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -24,6 +24,7 @@ */ #include "ESP8266httpUpdate.h" +#include extern "C" uint32_t _SPIFFS_start; extern "C" uint32_t _SPIFFS_end; @@ -218,8 +219,12 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha */ bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command) { + StreamString error; + if(!Update.begin(size, command)) { - DEBUG_HTTP_UPDATE("[httpUpdate] Update.begin failed!\n"); + Update.printError(error); + error.trim(); // remove line ending + DEBUG_HTTP_UPDATE("[httpUpdate] Update.begin failed! (%s)\n", error.c_str()); return false; } @@ -228,12 +233,16 @@ bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int com } if(Update.writeStream(in) != size) { - DEBUG_HTTP_UPDATE("[httpUpdate] Update.writeStream failed!\n"); + Update.printError(error); + error.trim(); // remove line ending + DEBUG_HTTP_UPDATE("[httpUpdate] Update.writeStream failed! (%s)\n", error.c_str()); return false; } if(!Update.end()) { - DEBUG_HTTP_UPDATE("[httpUpdate] Update.end failed!\n"); + Update.printError(error); + error.trim(); // remove line ending + DEBUG_HTTP_UPDATE("[httpUpdate] Update.end failed! (%s)\n", error.c_str()); return false; } From 6fa70bda011419520c1484ab7f861114a827e45a Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Sun, 6 Dec 2015 09:42:51 -0500 Subject: [PATCH 15/41] replace delay with while loop in WiFiClient.ino --- libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index 7ffc78acd..8ed67168a 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -71,7 +71,13 @@ void loop() { client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); - delay(10); + while (client.available() == 0) { + if (timeout - millis() < 0) { + Serial.println(">>> Client Timeout !"); + client.stop(); + return; + } + } // Read all the lines of the reply from server and print them to Serial while(client.available()){ From e166e85f739758a258567b2f49834b05dd8dbd16 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Sun, 6 Dec 2015 09:47:00 -0500 Subject: [PATCH 16/41] oupps ! I forgot to set the timout value --- libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index 8ed67168a..eb7c02eff 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -71,6 +71,7 @@ void loop() { client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); + int timeout = millis() + 5000; while (client.available() == 0) { if (timeout - millis() < 0) { Serial.println(">>> Client Timeout !"); From 3d1fbc60ab5c96294a6c68ea6bb9f292cb11aead Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 6 Dec 2015 20:22:54 +0300 Subject: [PATCH 17/41] Replace chain of UDP pbufs with a single pbuf before sending (#1009) Packets up to 1492 bytes may be sent this way. Also reduced pbuf_unit_size to 128 bytes. --- .../ESP8266WiFi/src/include/UdpContext.h | 58 ++++++++----------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/libraries/ESP8266WiFi/src/include/UdpContext.h b/libraries/ESP8266WiFi/src/include/UdpContext.h index d9347fd34..708007036 100644 --- a/libraries/ESP8266WiFi/src/include/UdpContext.h +++ b/libraries/ESP8266WiFi/src/include/UdpContext.h @@ -1,9 +1,9 @@ -/* +/* UdpContext.h - UDP connection handling on top of lwIP Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -206,10 +206,10 @@ public: size_t max_size = _rx_buf->len - _rx_buf_offset; size = (size < max_size) ? size : max_size; DEBUGV(":urd %d, %d, %d\r\n", size, _rx_buf->len, _rx_buf_offset); - - os_memcpy(dst, reinterpret_cast(_rx_buf->payload) + _rx_buf_offset, size); + + memcpy(dst, reinterpret_cast(_rx_buf->payload) + _rx_buf_offset, size); _consume(size); - + return size; } @@ -236,7 +236,7 @@ public: { _reserve(_tx_buf_offset + size); } - + size_t left_to_copy = size; while(left_to_copy) { @@ -249,7 +249,7 @@ public: continue; } size_t will_copy = (left_to_copy < free_cur) ? left_to_copy : free_cur; - os_memcpy(reinterpret_cast(_tx_buf_cur->payload) + used_cur, data, will_copy); + memcpy(reinterpret_cast(_tx_buf_cur->payload) + used_cur, data, will_copy); _tx_buf_offset += will_copy; left_to_copy -= will_copy; data += will_copy; @@ -259,18 +259,20 @@ public: void send(ip_addr_t* addr = 0, uint16_t port = 0) { - size_t orig_size = _tx_buf_head->tot_len; - size_t data_size = _tx_buf_offset; - size_t size_adjustment = orig_size - data_size; - for (pbuf* p = _tx_buf_head; p; p = p->next) - { - p->tot_len -= size_adjustment; - if (!p->next) - { - p->len = p->tot_len; - } + pbuf* tx_copy = pbuf_alloc(PBUF_TRANSPORT, data_size, PBUF_RAM); + uint8_t* dst = reinterpret_cast(tx_copy->payload); + for (pbuf* p = _tx_buf_head; p; p = p->next) { + size_t will_copy = (data_size < p->len) ? data_size : p->len; + memcpy(dst, p->payload, will_copy); + dst += will_copy; + data_size -= will_copy; } + pbuf_free(_tx_buf_head); + _tx_buf_head = 0; + _tx_buf_cur = 0; + _tx_buf_offset = 0; + if (!addr) { addr = &_dest_addr; @@ -282,30 +284,16 @@ public: _pcb->ttl = _multicast_ttl; } - udp_sendto(_pcb, _tx_buf_head, addr, port); - + udp_sendto(_pcb, tx_copy, addr, port); _pcb->ttl = old_ttl; - - for (pbuf* p = _tx_buf_head; p; p = p->next) - { - p->tot_len += size_adjustment; - if (!p->next) - { - p->len = p->tot_len; - } - } - - pbuf_free(_tx_buf_head); - _tx_buf_head = 0; - _tx_buf_cur = 0; - _tx_buf_offset = 0; + pbuf_free(tx_copy); } private: void _reserve(size_t size) { - const size_t pbuf_unit_size = 512; + const size_t pbuf_unit_size = 128; if (!_tx_buf_head) { _tx_buf_head = pbuf_alloc(PBUF_TRANSPORT, pbuf_unit_size, PBUF_RAM); @@ -357,7 +345,7 @@ private: } - static void _s_recv(void *arg, + static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, ip_addr_t *addr, u16_t port) { From c6c7d2475059fff19f7127b0a4aba082c7ca7200 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 6 Dec 2015 20:39:54 +0300 Subject: [PATCH 18/41] Add __throw_logic_error (#1136) --- cores/esp8266/abi.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cores/esp8266/abi.cpp b/cores/esp8266/abi.cpp index b38f16453..ff865d9ca 100644 --- a/cores/esp8266/abi.cpp +++ b/cores/esp8266/abi.cpp @@ -68,6 +68,10 @@ void __throw_length_error(char const*) { void __throw_bad_alloc() { panic(); } + +void __throw_logic_error(const char* str) { + panic(); +} } // TODO: rebuild windows toolchain to make this unnecessary: From ee314f2cdc1890997516338491aeea4e4510ef71 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 6 Dec 2015 20:54:35 +0300 Subject: [PATCH 19/41] fix portInput(Output, Mode)Register definitions to return pointers (#1110) --- cores/esp8266/Arduino.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 7e06e0058..10c6ebd44 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -219,14 +219,12 @@ void loop(void); void yield(void); void optimistic_yield(uint32_t interval_us); -// Get the bit location within the hardware port of the given virtual pin. -// This comes from the pins_*.c file for the active board configuration. #define digitalPinToPort(pin) (0) #define digitalPinToBitMask(pin) (1UL << (pin)) #define digitalPinToTimer(pin) (0) -#define portOutputRegister(port) ((volatile uint32_t*) GPO) -#define portInputRegister(port) ((volatile uint32_t*) GPI) -#define portModeRegister(port) ((volatile uint32_t*) GPE) +#define portOutputRegister(port) ((volatile uint32_t*) &GPO) +#define portInputRegister(port) ((volatile uint32_t*) &GPI) +#define portModeRegister(port) ((volatile uint32_t*) &GPE) #define NOT_A_PIN -1 #define NOT_A_PORT -1 From cc0a8ead55ce756103ff47146cdbd499cd1a2d77 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Sun, 6 Dec 2015 21:03:05 -0800 Subject: [PATCH 20/41] Always arm the "TX FIFO Empty" interrupt after we write into _tx_buffer. This avoids a race where the interrupt handler detects an empty _tx_buffer just before we write data into it. Note that commit d6f62943d4b511e7d5fe6147096c8979890416f5 works around this race when data is continually added to _tx_buffer in the hung state. We revert that change here as the race should no longer occur. Testing performed: - set UART_CONF1.txfifo_empty_thrhd=0x70 (which exacerbates the issue) - generate a ~240 byte burst of data, sent in back-to-back Serial1.write(, 4) calls, optionally followed by a Serial1.flush() Test results: - before this change, observe occasional unsent data and hang in flush() (if used). - after this change, data is sent as expected. --- cores/esp8266/HardwareSerial.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 2e93f8aee..78108bee7 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -617,18 +617,15 @@ size_t HardwareSerial::write(uint8_t c) { size_t room = uart_get_tx_fifo_room(_uart); if(room > 0 && _tx_buffer->empty()) { uart_transmit_char(_uart, c); - if(room < 10) { - uart_arm_tx_interrupt(_uart); - } return 1; } while(_tx_buffer->room() == 0) { yield(); - uart_arm_tx_interrupt(_uart); } _tx_buffer->write(c); + uart_arm_tx_interrupt(_uart); return 1; } From 7133a6c1f99b74986586c56a9a2ab7013cdc7cb9 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Mon, 7 Dec 2015 00:23:46 -0800 Subject: [PATCH 21/41] Ensure that we never write an out of bounds value (_bufend) to _begin or _end, even temporarily. Testing: - Boot tested, ran basic serial I/O code Notes: - Before this change, there are instruction like "s32i.n , , <_begin>" in the disassembled output, followed by an overwrite if turns out to be _bufend. After this change, there is only one store instruction to <_begin> per function. --- cores/esp8266/cbuf.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/cbuf.h b/cores/esp8266/cbuf.h index fee98a94b..ce3ac5c64 100644 --- a/cores/esp8266/cbuf.h +++ b/cores/esp8266/cbuf.h @@ -62,7 +62,7 @@ class cbuf { if(getSize() == 0) return -1; char result = *_begin; - if(++_begin == _bufend) _begin = _buf; + _begin = wrap_if_bufend(_begin + 1); return static_cast(result); } @@ -78,8 +78,7 @@ class cbuf { dst += top_size; } memcpy(dst, _begin, size_to_read); - _begin += size_to_read; - if(_begin == _bufend) _begin = _buf; + _begin = wrap_if_bufend(_begin + size_to_read); return size_read; } @@ -87,7 +86,7 @@ class cbuf { if(room() == 0) return 0; *_end = c; - if(++_end == _bufend) _end = _buf; + _end = wrap_if_bufend(_end + 1); return 1; } @@ -103,8 +102,7 @@ class cbuf { src += top_size; } memcpy(_end, src, size_to_write); - _end += size_to_write; - if(_end == _bufend) _end = _buf; + _end = wrap_if_bufend(_end + size_to_write); return size_written; } @@ -114,6 +112,10 @@ class cbuf { } private: + inline char* wrap_if_bufend(char* ptr) { + return (ptr == _bufend) ? _buf : ptr; + } + size_t _size; char* _buf; char* _bufend; From d8417c2855b685e31d1d5796c5a89e5a70d49e84 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Mon, 7 Dec 2015 00:31:46 -0800 Subject: [PATCH 22/41] Remove a check in room() for (_begin == _end). It's covered by the (_end >= _begin) case. --- cores/esp8266/cbuf.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/cores/esp8266/cbuf.h b/cores/esp8266/cbuf.h index ce3ac5c64..087e7200b 100644 --- a/cores/esp8266/cbuf.h +++ b/cores/esp8266/cbuf.h @@ -42,9 +42,6 @@ class cbuf { if(_end >= _begin) { return _size - (_end - _begin) - 1; } - if(_begin == _end) { - return _size; - } return _begin - _end - 1; } From dd89de4dad042a427c7e7399d6bb2a1a1b5cc537 Mon Sep 17 00:00:00 2001 From: Jens Hauke Date: Mon, 7 Dec 2015 18:01:15 +0100 Subject: [PATCH 23/41] Make pgm_read_byte() and pgm_read_word() usable from c files. The two defines used reinterpret_cast<> which is only available when compiling with c++. Now using plain old c casts instead. --- cores/esp8266/pgmspace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/pgmspace.h b/cores/esp8266/pgmspace.h index 4ee599557..c9e83fa05 100644 --- a/cores/esp8266/pgmspace.h +++ b/cores/esp8266/pgmspace.h @@ -78,7 +78,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut (__extension__({ \ PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \ ptrdiff_t __offset = ((uint32_t)__local & 0x00000003); /* byte aligned mask */ \ - const uint32_t* __addr32 = reinterpret_cast(reinterpret_cast(__local)-__offset); \ + const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local)-__offset); \ uint8_t __result = ((*__addr32) >> (__offset * 8)); \ __result; \ })) @@ -87,7 +87,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut (__extension__({ \ PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \ ptrdiff_t __offset = ((uint32_t)__local & 0x00000002); /* word aligned mask */ \ - const uint32_t* __addr32 = reinterpret_cast(reinterpret_cast(__local) - __offset); \ + const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local) - __offset); \ uint16_t __result = ((*__addr32) >> (__offset * 8)); \ __result; \ })) From 8847d7ab1af8e4572b4a2afe5fcc0443cf22b338 Mon Sep 17 00:00:00 2001 From: Rodrigo Mendez Date: Mon, 7 Dec 2015 17:35:30 -0600 Subject: [PATCH 24/41] added ESPino to dox/boards.md and package_esp8266com_index.template.json. removed flash speed selection --- boards.txt | 5 ----- doc/boards.md | 9 +++++++++ package/package_esp8266com_index.template.json | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/boards.txt b/boards.txt index b24d084de..248622f74 100644 --- a/boards.txt +++ b/boards.txt @@ -726,11 +726,6 @@ espino.menu.CpuFrequency.80.build.f_cpu=80000000L espino.menu.CpuFrequency.160=160 MHz espino.menu.CpuFrequency.160.build.f_cpu=160000000L -espino.menu.FlashFreq.40=40MHz -espino.menu.FlashFreq.40.build.flash_freq=40 -espino.menu.FlashFreq.80=80MHz -espino.menu.FlashFreq.80.build.flash_freq=80 - espino.menu.FlashMode.dio=DIO espino.menu.FlashMode.dio.build.flash_mode=dio espino.menu.FlashMode.qio=QIO diff --git a/doc/boards.md b/doc/boards.md index e92c4c591..578ea319d 100644 --- a/doc/boards.md +++ b/doc/boards.md @@ -11,6 +11,7 @@ title: Supported Hardware * [Olimex MOD\-WIFI\-ESP8266](#olimex-mod-wifi-esp8266) * [SparkFun ESP8266 Thing](#sparkfun-esp8266-thing) * [SweetPea ESP\-210](#sweetpea-esp-210) + * [ESPino](#espino) * [Generic ESP8266 modules](#generic-esp8266-modules) * [Serial Adapter](#serial-adapter) * [Minimal Hardware Setup for Bootloading and Usage](#minimal-hardware-setup-for-bootloading-and-usage) @@ -91,6 +92,14 @@ Product page: https://www.sparkfun.com/products/13231 *TODO: add notes* +## ESPino + +ESPino integrates the ESP-12 module with a 3.3v regulator, CP2104 USB-Serial bridge and a micro USB connector for easy programming. It is designed for fitting in a breadboard and has an RGB Led and two buttons for easy prototyping. + +For more information about the hardware, pinout diagram and programming procedures, please see the [datasheet](https://github.com/makerlabmx/ESPino-tools/raw/master/Docs/ESPino-Datasheet-EN.pdf). + +Product page: http://www.espino.io/en + ## Generic ESP8266 modules These modules come in different form factors and pinouts. See the page at ESP8266 community wiki for more info: diff --git a/package/package_esp8266com_index.template.json b/package/package_esp8266com_index.template.json index ee1042450..d070d4809 100644 --- a/package/package_esp8266com_index.template.json +++ b/package/package_esp8266com_index.template.json @@ -43,11 +43,14 @@ { "name": "SweetPea ESP-210" }, - { + { "name": "WeMos D1" }, - { + { "name": "WeMos D1 mini" + }, + { + "name": "ESPino" } ], "toolsDependencies": [ From a3c3c934bcfae34dc4cac04f010dda7bc6bd44b2 Mon Sep 17 00:00:00 2001 From: tzapu Date: Tue, 8 Dec 2015 08:49:40 +0200 Subject: [PATCH 25/41] Update libraries.md Added link to WiFiManager --- doc/libraries.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/libraries.md b/doc/libraries.md index 314b1aa51..894143815 100644 --- a/doc/libraries.md +++ b/doc/libraries.md @@ -152,3 +152,4 @@ Libraries that don't rely on low-level access to AVR registers should work well. - [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB. - [ST7735](https://github.com/nzmichaelh/Adafruit-ST7735-Library) - Adafruit's ST7735 library modified to be compatible with ESP8266. Just make sure to modify the pins in the examples as they are still AVR specific. - [UTFT-ESP8266](https://github.com/gnulabis/UTFT-ESP8266) - UTFT display library with support for ESP8266. Only serial interface (SPI) displays are supported for now (no 8-bit parallel mode, etc). Also includes support for the hardware SPI controller of the ESP8266. +- [WiFiManager](https://github.com/tzapu/WiFiManager) - WiFi Connection manager with web captive portal. If it can't connect, it starts AP mode and a configuration portal so you can choose and enter WiFi credentials. From 02e22b38cb17697d43f347478d63530c72b61e7d Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Tue, 8 Dec 2015 11:33:15 +0100 Subject: [PATCH 26/41] add define RANDOM_REG32 ESP8266_DREG(0x20E44) --- cores/esp8266/esp8266_peri.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cores/esp8266/esp8266_peri.h b/cores/esp8266/esp8266_peri.h index 4fd057009..e7aab1f03 100644 --- a/cores/esp8266/esp8266_peri.h +++ b/cores/esp8266/esp8266_peri.h @@ -834,4 +834,10 @@ extern uint8_t esp8266_gpioToFn[16]; #define I2STXCMM (0x7) //I2S_TX_CHAN_MOD #define I2STXCM (0) //I2S_TX_CHAN_MOD_S +/** + Random Number Generator 32bit + http://esp8266-re.foogod.com/wiki/Random_Number_Generator +**/ +#define RANDOM_REG32 ESP8266_DREG(0x20E44) + #endif From 22af40af184b28c64b31031a6b0a0edd407c80a7 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Tue, 8 Dec 2015 11:35:14 +0100 Subject: [PATCH 27/41] add note about Adafruit_ILI9341 --- doc/libraries.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/libraries.md b/doc/libraries.md index 314b1aa51..756293ef7 100644 --- a/doc/libraries.md +++ b/doc/libraries.md @@ -140,14 +140,15 @@ While many RC servo motors will accept the 3.3V IO data pin from a ESP8266, most Libraries that don't rely on low-level access to AVR registers should work well. Here are a few libraries that were verified to work: +- [Adafruit_ILI9341](https://github.com/Links2004/Adafruit_ILI9341) - Port of the Adafruit ILI9341 for the ESP8266 - [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets) - WebSocket Server and Client compatible with ESP8266 (RFC6455) -- [aREST](https://github.com/marcoschwartz/aREST) REST API handler library. +- [aREST](https://github.com/marcoschwartz/aREST) - REST API handler library. - [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)). - [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git) - [DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library) - Arduino library for the DHT11/DHT22 temperature and humidity sensors. Download latest v1.1.1 library and no changes are necessary. Older versions should initialize DHT as follows: `DHT dht(DHTPIN, DHTTYPE, 15)` - [NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) - Adafruit's NeoPixel library, now with support for the ESP8266 (use version 1.0.2 or higher from Arduino's library manager). - [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with ESP8266. Use the "NeoPixelAnimator" branch for ESP8266 to get HSL color support and more. -- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy. +- [PubSubClient](https://github.com/Imroy/pubsubclient) - MQTT library by @Imroy. - [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with ESP8266. - [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB. - [ST7735](https://github.com/nzmichaelh/Adafruit-ST7735-Library) - Adafruit's ST7735 library modified to be compatible with ESP8266. Just make sure to modify the pins in the examples as they are still AVR specific. From 5cd42a0316b528fca61482ef41b6d75431e8f399 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 9 Dec 2015 09:23:47 +0300 Subject: [PATCH 28/41] WiFiClientSecure: don't trash certificate and private key on stop() --- libraries/ESP8266WiFi/src/WiFiClientSecure.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp index 247701acd..997fe5ccb 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp @@ -53,7 +53,7 @@ extern "C" uint8_t* default_private_key = 0; uint32_t default_private_key_len = 0; static bool default_private_key_dynamic = false; -// +static int s_pk_refcnt = 0; uint8_t* default_certificate = 0; uint32_t default_certificate_len = 0; static bool default_certificate_dynamic = false; @@ -81,9 +81,6 @@ public: if (_ssl_ctx_refcnt == 0) { ssl_ctx_free(_ssl_ctx); } - - clear_private_key(); - clear_certificate(); } void ref() { @@ -186,12 +183,17 @@ int SSLContext::_ssl_ctx_refcnt = 0; WiFiClientSecure::WiFiClientSecure() { + ++s_pk_refcnt; } WiFiClientSecure::~WiFiClientSecure() { if (_ssl) { _ssl->unref(); } + if (--s_pk_refcnt == 0) { + clear_private_key(); + clear_certificate(); + } } WiFiClientSecure::WiFiClientSecure(const WiFiClientSecure& other) From 8b161ecf16e4ef0250fa0e1164c4c746c2685034 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 12:47:23 +0100 Subject: [PATCH 29/41] add http codes as enum t_http_codes --- .../ESP8266HTTPClient/src/ESP8266HTTPClient.h | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index 2d1312a29..46c3de415 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -42,6 +42,71 @@ #define HTTPC_ERROR_NO_STREAM (-6) #define HTTPC_ERROR_NO_HTTP_SERVER (-7) +/// HTTP codes see RFC7231 +typedef enum { + HTTP_CODE_CONTINUE = 100, + HTTP_CODE_SWITCHING_PROTOCOLS = 101, + HTTP_CODE_PROCESSING = 102, + HTTP_CODE_OK = 200, + HTTP_CODE_CREATED = 201, + HTTP_CODE_ACCEPTED = 202, + HTTP_CODE_NON_AUTHORITATIVE_INFORMATION = 203, + HTTP_CODE_NO_CONTENT = 204, + HTTP_CODE_RESET_CONTENT = 205, + HTTP_CODE_PARTIAL_CONTENT = 206, + HTTP_CODE_MULTI_STATUS = 207, + HTTP_CODE_ALREADY_REPORTED = 208, + HTTP_CODE_IM_USED = 226, + HTTP_CODE_MULTIPLE_CHOICES = 300, + HTTP_CODE_MOVED_PERMANENTLY = 301, + HTTP_CODE_FOUND = 302, + HTTP_CODE_SEE_OTHER = 303, + HTTP_CODE_NOT_MODIFIED = 304, + HTTP_CODE_USE_PROXY = 305, + HTTP_CODE_TEMPORARY_REDIRECT = 307, + HTTP_CODE_PERMANENT_REDIRECT = 308, + HTTP_CODE_BAD_REQUEST = 400, + HTTP_CODE_UNAUTHORIZED = 401, + HTTP_CODE_PAYMENT_REQUIRED = 402, + HTTP_CODE_FORBIDDEN = 403, + HTTP_CODE_NOT_FOUND = 404, + HTTP_CODE_METHOD_NOT_ALLOWED = 405, + HTTP_CODE_NOT_ACCEPTABLE = 406, + HTTP_CODE_PROXY_AUTHENTICATION_REQUIRED = 407, + HTTP_CODE_REQUEST_TIMEOUT = 408, + HTTP_CODE_CONFLICT = 409, + HTTP_CODE_GONE = 410, + HTTP_CODE_LENGTH_REQUIRED = 411, + HTTP_CODE_PRECONDITION_FAILED = 412, + HTTP_CODE_PAYLOAD_TOO_LARGE = 413, + HTTP_CODE_URI_TOO_LONG = 414, + HTTP_CODE_UNSUPPORTED_MEDIA_TYPE = 415, + HTTP_CODE_RANGE_NOT_SATISFIABLE = 416, + HTTP_CODE_EXPECTATION_FAILED = 417, + HTTP_CODE_MISDIRECTED_REQUEST = 421, + HTTP_CODE_UNPROCESSABLE_ENTITY = 422, + HTTP_CODE_LOCKED = 423, + HTTP_CODE_FAILED_DEPENDENCY = 424, + HTTP_CODE_UNASSIGNED = 425, + HTTP_CODE_UPGRADE_REQUIRED = 426, + HTTP_CODE_UNASSIGNED = 427, + HTTP_CODE_PRECONDITION_REQUIRED = 428, + HTTP_CODE_TOO_MANY_REQUESTS = 429, + HTTP_CODE_UNASSIGNED = 430, + HTTP_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, + HTTP_CODE_INTERNAL_SERVER_ERROR = 500, + HTTP_CODE_NOT_IMPLEMENTED = 501, + HTTP_CODE_BAD_GATEWAY = 502, + HTTP_CODE_SERVICE_UNAVAILABLE = 503, + HTTP_CODE_GATEWAY_TIMEOUT = 504, + HTTP_CODE_HTTP_VERSION_NOT_SUPPORTED = 505, + HTTP_CODE_VARIANT_ALSO_NEGOTIATES = 506, + HTTP_CODE_INSUFFICIENT_STORAGE = 507, + HTTP_CODE_LOOP_DETECTED = 508, + HTTP_CODE_UNASSIGNED = 509, + HTTP_CODE_NOT_EXTENDED = 510, + HTTP_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511 +} t_http_codes; class HTTPClient { public: From e15c745e6f27ccf8cf8d2bcd3e42cb03857c8447 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 12:50:55 +0100 Subject: [PATCH 30/41] remove some HTTP_CODE_UNASSIGNED --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index 46c3de415..a455192ed 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -87,12 +87,9 @@ typedef enum { HTTP_CODE_UNPROCESSABLE_ENTITY = 422, HTTP_CODE_LOCKED = 423, HTTP_CODE_FAILED_DEPENDENCY = 424, - HTTP_CODE_UNASSIGNED = 425, HTTP_CODE_UPGRADE_REQUIRED = 426, - HTTP_CODE_UNASSIGNED = 427, HTTP_CODE_PRECONDITION_REQUIRED = 428, HTTP_CODE_TOO_MANY_REQUESTS = 429, - HTTP_CODE_UNASSIGNED = 430, HTTP_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, HTTP_CODE_INTERNAL_SERVER_ERROR = 500, HTTP_CODE_NOT_IMPLEMENTED = 501, @@ -103,7 +100,6 @@ typedef enum { HTTP_CODE_VARIANT_ALSO_NEGOTIATES = 506, HTTP_CODE_INSUFFICIENT_STORAGE = 507, HTTP_CODE_LOOP_DETECTED = 508, - HTTP_CODE_UNASSIGNED = 509, HTTP_CODE_NOT_EXTENDED = 510, HTTP_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511 } t_http_codes; From 1dabac60a925b0b548b78e49489cdac6ed5fd391 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 12:56:49 +0100 Subject: [PATCH 31/41] rework HTTPclient examples --- .../examples/BasicHttpClient/BasicHttpClient.ino | 10 +++++++--- .../examples/ReuseConnection/ReuseConnection.ino | 11 ++++++++--- .../examples/StreamHttpClient/StreamHttpClient.ino | 11 +++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino b/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino index 3c722556b..8e2b5d2f4 100644 --- a/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino +++ b/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino @@ -43,24 +43,28 @@ void loop() { USE_SERIAL.print("[HTTP] begin...\n"); // configure traged server and url - //http.begin("192.168.1.12", 443, "/test.html", true, "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS - http.begin("192.168.1.12", 80, "/test.html"); //HTTP + //http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS + http.begin("http://192.168.1.12/test.html"); //HTTP USE_SERIAL.print("[HTTP] GET...\n"); // start connection and send HTTP header int httpCode = http.GET(); + + // httpCode will be negative on error if(httpCode) { // HTTP header has been send and Server response header has been handled USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); // file found at server - if(httpCode == 200) { + if(httpCode == HTTP_CODE_OK) { String payload = http.getString(); USE_SERIAL.println(payload); } } else { USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n"); } + + http.end(); } delay(10000); diff --git a/libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino b/libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino index e725a1f76..36c189cb3 100644 --- a/libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino +++ b/libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino @@ -36,26 +36,31 @@ void setup() { WiFiMulti.addAP("SSID", "PASSWORD"); - + // allow reuse (if server supports it) + http.setReuse(true); } void loop() { // wait for WiFi connection if((WiFiMulti.run() == WL_CONNECTED)) { - http.begin("192.168.1.12", 80, "/test.html"); + http.begin("http://192.168.1.12/test.html"); + //http.begin("192.168.1.12", 80, "/test.html"); int httpCode = http.GET(); if(httpCode) { USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); // file found at server - if(httpCode == 200) { + if(httpCode == HTTP_CODE_OK) { http.writeToStream(&USE_SERIAL); } } else { USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n"); } + + http.end(); + } delay(1000); diff --git a/libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino b/libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino index 442fa6547..7f6c37872 100644 --- a/libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino +++ b/libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino @@ -42,19 +42,20 @@ void loop() { HTTPClient http; USE_SERIAL.print("[HTTP] begin...\n"); - // configure traged server and url - http.begin("192.168.1.12", 80, "/test.html"); + + // configure server and url + http.begin("http://192.168.1.12/test.html"); + //http.begin("192.168.1.12", 80, "/test.html"); USE_SERIAL.print("[HTTP] GET...\n"); // start connection and send HTTP header int httpCode = http.GET(); if(httpCode) { // HTTP header has been send and Server response header has been handled - USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); // file found at server - if(httpCode == 200) { + if(httpCode == HTTP_CODE_OK) { // get lenght of document (is -1 when Server sends no Content-Length header) int len = http.getSize(); @@ -91,6 +92,8 @@ void loop() { } else { USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n"); } + + http.end(); } delay(10000); From b1e3d2256a3f891909dacaa229551ba79151cae5 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 13:01:08 +0100 Subject: [PATCH 32/41] add errorToString function --- .../BasicHttpClient/BasicHttpClient.ino | 2 +- .../ReuseConnection/ReuseConnection.ino | 2 +- .../StreamHttpClient/StreamHttpClient.ino | 2 +- .../src/ESP8266HTTPClient.cpp | 27 +++++++++++++++++++ .../ESP8266HTTPClient/src/ESP8266HTTPClient.h | 2 ++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino b/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino index 8e2b5d2f4..d3a5fbc7d 100644 --- a/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino +++ b/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino @@ -61,7 +61,7 @@ void loop() { USE_SERIAL.println(payload); } } else { - USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n"); + USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); diff --git a/libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino b/libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino index 36c189cb3..35babdc33 100644 --- a/libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino +++ b/libraries/ESP8266HTTPClient/examples/ReuseConnection/ReuseConnection.ino @@ -56,7 +56,7 @@ void loop() { http.writeToStream(&USE_SERIAL); } } else { - USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n"); + USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); diff --git a/libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino b/libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino index 7f6c37872..2e7f4487d 100644 --- a/libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino +++ b/libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino @@ -90,7 +90,7 @@ void loop() { } } else { - USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n"); + USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 37b71dbc1..5561c62ae 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -454,6 +454,33 @@ String HTTPClient::getString(void) { return sstring; } +/** + * converts error code to String + * @param error int + * @return String + */ +String HTTPClient::errorToString(int error) { + switch(error) { + case HTTPC_ERROR_CONNECTION_REFUSED: + return String("connection refused"); + case HTTPC_ERROR_SEND_HEADER_FAILED: + return String("send header failed"); + case HTTPC_ERROR_SEND_PAYLOAD_FAILED: + return String("send payload failed"); + case HTTPC_ERROR_NOT_CONNECTED: + return String("not connected"); + case HTTPC_ERROR_CONNECTION_LOST: + return String("connection lost"); + case HTTPC_ERROR_NO_STREAM: + return String("no stream"); + case HTTPC_ERROR_NO_HTTP_SERVER: + return String("no HTTP server"); + default: + return String(); + } +} + + /** * adds Header to the request * @param name diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index a455192ed..5d3fc51bc 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -147,6 +147,8 @@ class HTTPClient { int writeToStream(Stream * stream); String getString(void); + String errorToString(int error); + protected: struct RequestArgument { From 62f38bfef3681209933c88702ed3ad26db911cb6 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 13:51:39 +0100 Subject: [PATCH 33/41] add base64 class --- cores/esp8266/base64.cpp | 63 ++++++++++++++++++++++++++++++++++++++++ cores/esp8266/base64.h | 36 +++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 cores/esp8266/base64.cpp create mode 100644 cores/esp8266/base64.h diff --git a/cores/esp8266/base64.cpp b/cores/esp8266/base64.cpp new file mode 100644 index 000000000..11deb0af0 --- /dev/null +++ b/cores/esp8266/base64.cpp @@ -0,0 +1,63 @@ +/** + * base64.cpp + * + * Created on: 09.12.2015 + * + * Copyright (c) 2015 Markus Sattler. All rights reserved. + * This file is part of the ESP8266 core for Arduino. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "Arduino.h" +extern "C" { +#include "libb64/cdecode.h" +#include "libb64/cencode.h" +} +#include "base64.h" + +/** + * convert input data to base64 + * @param data uint8_t * + * @param length size_t + * @return String + */ +String base64::encode(uint8_t * data, size_t length) { + // base64 needs more size then the source data + size_t size = ((length * 1.6f) + 1); + char * buffer = (char *) malloc(size); + if(buffer) { + base64_encodestate _state; + base64_init_encodestate(&_state); + int len = base64_encode_block((const char *) &data[0], length, &buffer[0], &_state); + len = base64_encode_blockend((buffer + len), &_state); + + String base64 = String(buffer); + free(buffer); + return base64; + } + return String("-FAIL-"); +} + +/** + * convert input data to base64 + * @param text String + * @return String + */ +String base64::encode(String text) { + return base64::encode((uint8_t *) text.c_str(), text.length()); +} + diff --git a/cores/esp8266/base64.h b/cores/esp8266/base64.h new file mode 100644 index 000000000..39be2d397 --- /dev/null +++ b/cores/esp8266/base64.h @@ -0,0 +1,36 @@ +/** + * base64.h + * + * Created on: 09.12.2015 + * + * Copyright (c) 2015 Markus Sattler. All rights reserved. + * This file is part of the ESP8266 core for Arduino. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef CORE_BASE64_H_ +#define CORE_BASE64_H_ + +class base64 { + public: + static String encode(uint8_t * data, size_t length); + static String encode(String text); + private: +}; + + +#endif /* CORE_BASE64_H_ */ From a9ce1b4f2ebb774d69aab6573bd474d5d704ff4e Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 13:51:55 +0100 Subject: [PATCH 34/41] add Authorization support for HTTP client --- cores/esp8266/core_esp8266_features.h | 1 + .../src/ESP8266HTTPClient.cpp | 26 +++++++++++++++++-- .../ESP8266HTTPClient/src/ESP8266HTTPClient.h | 4 ++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/core_esp8266_features.h b/cores/esp8266/core_esp8266_features.h index bafcd3aee..ae5d58539 100644 --- a/cores/esp8266/core_esp8266_features.h +++ b/cores/esp8266/core_esp8266_features.h @@ -26,6 +26,7 @@ #define CORE_HAS_LIBB64 +#define CORE_HAS_BASE64_CLASS #endif diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 5561c62ae..357aebda3 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -26,9 +26,11 @@ #include #include #include +#include #include "ESP8266HTTPClient.h" + /** * constractor */ @@ -219,6 +221,20 @@ void HTTPClient::setUserAgent(const char * userAgent) { _userAgent = userAgent; } +/** + * set the Authorizatio for the http request + * @param user const char * + * @param password const char * + */ +void HTTPClient::setAuthorization(const char * user, const char * password) { + if(user && password) { + String auth = user; + auth += ":"; + auth += password; + _base64Authorization = base64::encode(auth); + } +} + /** * send a GET request * @return http code @@ -490,7 +506,7 @@ String HTTPClient::errorToString(int error) { void HTTPClient::addHeader(const String& name, const String& value, bool first) { // not allow set of Header handled by code - if(!name.equalsIgnoreCase("Connection") && !name.equalsIgnoreCase("User-Agent") && !name.equalsIgnoreCase("Host")) { + if(!name.equalsIgnoreCase("Connection") && !name.equalsIgnoreCase("User-Agent") && !name.equalsIgnoreCase("Host") && !(_base64Authorization.length() && name.equalsIgnoreCase("Authorization"))) { String headerLine = name; headerLine += ": "; headerLine += value; @@ -622,7 +638,13 @@ bool HTTPClient::sendHeader(const char * type) { } else { header += "close"; } - header += "\r\n" + _Headers + "\r\n"; + header += "\r\n"; + + if(_base64Authorization.length()) { + header += "Authorization: Basic " + _base64Authorization + "\r\n"; + } + + header += _Headers + "\r\n"; return (_tcp->write(header.c_str(), header.length()) == header.length()); } diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index 5d3fc51bc..f6c4bba6a 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -25,7 +25,7 @@ #ifndef ESP8266HTTPClient_H_ #define ESP8266HTTPClient_H_ -//#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ ) +#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ ) #ifndef DEBUG_HTTPCLIENT #define DEBUG_HTTPCLIENT(...) @@ -121,6 +121,7 @@ class HTTPClient { void setReuse(bool reuse); /// keep-alive void setUserAgent(const char * userAgent); + void setAuthorization(const char * user, const char * password); /// request handling int GET(); @@ -172,6 +173,7 @@ class HTTPClient { String _Headers; String _userAgent; + String _base64Authorization; /// Response handling RequestArgument* _currentHeaders; From 85341ff25a0a144a3095b8a6f20fdd07f825fdf4 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 14:19:28 +0100 Subject: [PATCH 35/41] HTTPClient phasing username + password from url --- .../src/ESP8266HTTPClient.cpp | 42 +++++++++++++------ .../ESP8266HTTPClient/src/ESP8266HTTPClient.h | 3 +- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 357aebda3..6a8d010e1 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -102,27 +102,34 @@ void HTTPClient::begin(String url, String httpsFingerprint) { String protocol; // check for : (http: or https: int index = url.indexOf(':'); - int index2; + //int index2; bool hasPort = false; if(index) { protocol = url.substring(0, index); url.remove(0, (index + 3)); // remove http:// or https:// - index = url.indexOf(':'); - index2 = url.indexOf('/'); + index = url.indexOf('/'); + String host = url.substring(0, index); + url.remove(0, index); // remove host part - if(index >= 0 && ((index2 >= 0 && index < index2) || index2 == 0)) { // do we have a port? - _host = url.substring(0, index); // hostname - url.remove(0, (index + 1)); // remove hostname + : + // get Authorization + index = host.indexOf('@'); + if(index >= 0) { + // auth info + String auth = host.substring(0, index); + host.remove(0, index +1); // remove auth part including @ + _base64Authorization = base64::encode(auth); + } - index = url.indexOf('/'); - _port = url.substring(0, index).toInt(); // get port - url.remove(0, index); // remove port + // get port + index = host.indexOf(':'); + if(index >= 0) { + _host = host.substring(0, index); // hostname + host.remove(0, (index + 1)); // remove hostname + : + _port = host.toInt(); // get port hasPort = true; } else { - index = index2; - _host = url.substring(0, index); - url.remove(0, index); // remove hostname + _host = host; } _url = url; @@ -141,6 +148,7 @@ void HTTPClient::begin(String url, String httpsFingerprint) { DEBUG_HTTPCLIENT("[HTTP-Client][begin] protocol: %s unknown?!\n", protocol.c_str()); return; } + } DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s https: %d httpsFingerprint: %s\n", _host.c_str(), _port, _url.c_str(), _https, _httpsFingerprint.c_str()); @@ -235,6 +243,16 @@ void HTTPClient::setAuthorization(const char * user, const char * password) { } } +/** + * set the Authorizatio for the http request + * @param auth const char * base64 + */ +void HTTPClient::setAuthorization(const char * auth) { + if(auth) { + _base64Authorization = auth; + } +} + /** * send a GET request * @return http code diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index f6c4bba6a..2bf6d0565 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -25,7 +25,7 @@ #ifndef ESP8266HTTPClient_H_ #define ESP8266HTTPClient_H_ -#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ ) +//#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ ) #ifndef DEBUG_HTTPCLIENT #define DEBUG_HTTPCLIENT(...) @@ -122,6 +122,7 @@ class HTTPClient { void setReuse(bool reuse); /// keep-alive void setUserAgent(const char * userAgent); void setAuthorization(const char * user, const char * password); + void setAuthorization(const char * auth); /// request handling int GET(); From 0a4da83243bdbcc30cd36639765ca966d7aeb268 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 14:19:49 +0100 Subject: [PATCH 36/41] HTTPClient add Authorization example --- .../examples/Authorization/Authorization.ino | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 libraries/ESP8266HTTPClient/examples/Authorization/Authorization.ino diff --git a/libraries/ESP8266HTTPClient/examples/Authorization/Authorization.ino b/libraries/ESP8266HTTPClient/examples/Authorization/Authorization.ino new file mode 100644 index 000000000..79a4c3fdf --- /dev/null +++ b/libraries/ESP8266HTTPClient/examples/Authorization/Authorization.ino @@ -0,0 +1,84 @@ +/** + * Authorization.ino + * + * Created on: 09.12.2015 + * + */ + +#include + +#include +#include + +#include + +#define USE_SERIAL Serial + +ESP8266WiFiMulti WiFiMulti; + +void setup() { + + USE_SERIAL.begin(115200); + // USE_SERIAL.setDebugOutput(true); + + USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); + + for(uint8_t t = 4; t > 0; t--) { + USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); + USE_SERIAL.flush(); + delay(1000); + } + + WiFiMulti.addAP("SSID", "PASSWORD"); + +} + +void loop() { + // wait for WiFi connection + if((WiFiMulti.run() == WL_CONNECTED)) { + + HTTPClient http; + + USE_SERIAL.print("[HTTP] begin...\n"); + // configure traged server and url + + + http.begin("http://user:password@192.168.1.12/test.html"); + + /* + // or + http.begin("http://192.168.1.12/test.html"); + http.setAuthorization("user", "password"); + + // or + http.begin("http://192.168.1.12/test.html"); + http.setAuthorization("dXNlcjpwYXN3b3Jk"); + */ + + + USE_SERIAL.print("[HTTP] GET...\n"); + // start connection and send HTTP header + int httpCode = http.GET(); + + // httpCode will be negative on error + if(httpCode) { + // HTTP header has been send and Server response header has been handled + USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); + + // file found at server + if(httpCode == HTTP_CODE_OK) { + String payload = http.getString(); + USE_SERIAL.println(payload); + } + } else { + USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); + } + + http.end(); + } + + delay(10000); +} + From b1ea7b602e3b731f7b9e5f666aabfe7d5e743d41 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 16:27:04 +0100 Subject: [PATCH 37/41] httpUpdate Improve error handling --- .../ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index 92b047b30..763efea4b 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -120,6 +120,12 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha int code = http->GET(); int len = http->getSize(); + if(code <= 0) { + DEBUG_HTTP_UPDATE("[httpUpdate] HTTP error: %s\n", http->errorToString(code).c_str()); + http->end(); + return HTTP_UPDATE_FAILED; + } + DEBUG_HTTP_UPDATE("[httpUpdate] Header read fin.\n"); DEBUG_HTTP_UPDATE("[httpUpdate] Server header:\n"); DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code); @@ -138,7 +144,7 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha } switch(code) { - case 200: ///< OK (Start Update) + case HTTP_CODE_OK: ///< OK (Start Update) if(len > 0) { bool startUpdate = false; if(spiffs) { @@ -192,19 +198,18 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha DEBUG_HTTP_UPDATE("[httpUpdate] Content-Length is 0 or not set by Server?!\n"); } break; - case 304: + case HTTP_CODE_NOT_MODIFIED: ///< Not Modified (No updates) ret = HTTP_UPDATE_NO_UPDATES; break; - case 403: - ///< Forbidden - // todo handle login default: ret = HTTP_UPDATE_FAILED; - DEBUG_HTTP_UPDATE("[httpUpdate] Code is (%d)\n", code); + DEBUG_HTTP_UPDATE("[httpUpdate] HTTP Code is (%d)\n", code); + //http->writeToStream(&Serial1); break; } + http->end(); return ret; From 95089b75b909da9828f81047d90162a272b548dd Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 9 Dec 2015 19:56:14 +0100 Subject: [PATCH 38/41] fix startUpdate always false --- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index 763efea4b..785258de9 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -146,15 +146,17 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha switch(code) { case HTTP_CODE_OK: ///< OK (Start Update) if(len > 0) { - bool startUpdate = false; + bool startUpdate = true; if(spiffs) { size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start); if(len > (int) spiffsSize) { DEBUG_HTTP_UPDATE("[httpUpdate] spiffsSize to low (%d) needed: %d\n", spiffsSize, len); + startUpdate = false; } } else { if(len > (int) ESP.getFreeSketchSpace()) { DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len); + startUpdate = false; } } From a7609bce35ee36cd02b5026df4fff1a7dca5079b Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Wed, 9 Dec 2015 22:17:50 -0800 Subject: [PATCH 39/41] Remove double include of cbuf.h. --- libraries/ESP8266WiFi/src/WiFiClientSecure.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp index 997fe5ccb..f141a0909 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp @@ -29,7 +29,6 @@ extern "C" } #include #include "debug.h" -#include "cbuf.h" #include "ESP8266WiFi.h" #include "WiFiClientSecure.h" #include "WiFiClient.h" From 55afeba174ae00b4ca1ea0bcc104642bea92e683 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Thu, 10 Dec 2015 12:00:28 +0100 Subject: [PATCH 40/41] see #1167 add close and stop as alias --- libraries/ESP8266WebServer/src/ESP8266WebServer.cpp | 9 +++++++++ libraries/ESP8266WebServer/src/ESP8266WebServer.h | 3 +++ libraries/ESP8266WiFi/src/WiFiServer.cpp | 10 ++++++++++ libraries/ESP8266WiFi/src/WiFiServer.h | 2 ++ 4 files changed, 24 insertions(+) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index cecc8eabc..a2c8a9866 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -71,6 +71,7 @@ ESP8266WebServer::~ESP8266WebServer() { delete handler; handler = next; } + close(); } void ESP8266WebServer::begin() { @@ -173,6 +174,14 @@ void ESP8266WebServer::handleClient() { _handleRequest(); } +void ESP8266WebServer::close() { + _server.close(); +} + +void ESP8266WebServer::stop() { + close(); +} + void ESP8266WebServer::sendHeader(const String& name, const String& value, bool first) { String headerLine = name; headerLine += ": "; diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index 40172e92a..e9ea8f1a1 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -66,6 +66,9 @@ public: void begin(); void handleClient(); + void close(); + void stop(); + bool authenticate(const char * username, const char * password); void requestAuthentication(); diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index 5de2d4ac7..462e7d7de 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -121,6 +121,16 @@ uint8_t WiFiServer::status() { return _pcb->state; } +void WiFiServer::close() { + if (!_pcb) { + return; + } + tcp_close(_pcb); +} + +void WiFiServer::stop() { + close(); +} size_t WiFiServer::write(uint8_t b) { return write(&b, 1); diff --git a/libraries/ESP8266WiFi/src/WiFiServer.h b/libraries/ESP8266WiFi/src/WiFiServer.h index 263bcbcdf..424a2331d 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.h +++ b/libraries/ESP8266WiFi/src/WiFiServer.h @@ -54,6 +54,8 @@ public: virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buf, size_t size); uint8_t status(); + void close(); + void stop(); using Print::write; From fdadadc7875386b749ee23728bc6abc31accc259 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Thu, 10 Dec 2015 12:03:53 +0100 Subject: [PATCH 41/41] add default values for updateSpiffs --- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h index f9a4d8030..d3fe4ca19 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h @@ -53,7 +53,7 @@ class ESP8266HTTPUpdate { t_httpUpdate_return update(const char * host, uint16_t port, const char * url = "/", const char * current_version = "", bool https = false, const char * httpsFingerprint = ""); t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = ""); - t_httpUpdate_return updateSpiffs(const char * url, const char * current_version, const char * httpsFingerprint); + t_httpUpdate_return updateSpiffs(const char * url, const char * current_version = "", const char * httpsFingerprint = ""); protected: t_httpUpdate_return handleUpdate(HTTPClient * http, const char * current_version, bool reboot = true, bool spiffs = false);