mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Merge branch 'master' into www-basic-auth
This commit is contained in:
commit
0c6e11b4ea
@ -3,27 +3,27 @@ title: Supported Hardware
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
* [Adafruit HUZZAH ESP8266 (ESP\-12)](#adafruit-huzzah-esp8266-esp-12)
|
* [Adafruit HUZZAH ESP8266 (ESP\-12)](#adafruit-huzzah-esp8266-esp-12)
|
||||||
* [NodeMCU 0\.9 <a name="user\-content\-nodemcu\-0\-9"></a>](#nodemcu-09-)
|
* [NodeMCU 0\.9 <a name="user\-content\-nodemcu\-0\-9"></a>](#nodemcu-09-)
|
||||||
* [Pin mapping](#pin-mapping)
|
* [Pin mapping](#pin-mapping)
|
||||||
* [NodeMCU 1\.0](#nodemcu-10)
|
* [NodeMCU 1\.0](#nodemcu-10)
|
||||||
* [Olimex MOD\-WIFI\-ESP8266\-DEV](#olimex-mod-wifi-esp8266-dev)
|
* [Olimex MOD\-WIFI\-ESP8266\-DEV](#olimex-mod-wifi-esp8266-dev)
|
||||||
* [Olimex MOD\-WIFI\-ESP8266](#olimex-mod-wifi-esp8266)
|
* [Olimex MOD\-WIFI\-ESP8266](#olimex-mod-wifi-esp8266)
|
||||||
* [SparkFun ESP8266 Thing](#sparkfun-esp8266-thing)
|
* [SparkFun ESP8266 Thing](#sparkfun-esp8266-thing)
|
||||||
* [SweetPea ESP\-210](#sweetpea-esp-210)
|
* [SweetPea ESP\-210](#sweetpea-esp-210)
|
||||||
* [Generic ESP8266 modules](#generic-esp8266-modules)
|
* [Generic ESP8266 modules](#generic-esp8266-modules)
|
||||||
* [Serial Adapter](#serial-adapter)
|
* [Serial Adapter](#serial-adapter)
|
||||||
* [Minimal Hardware Setup for Bootloading and Usage](#minimal-hardware-setup-for-bootloading-and-usage)
|
* [Minimal Hardware Setup for Bootloading and Usage](#minimal-hardware-setup-for-bootloading-and-usage)
|
||||||
* [ESP to Serial](#esp-to-serial)
|
* [ESP to Serial](#esp-to-serial)
|
||||||
* [Minimal Hardware Setup for Bootloading only](#minimal-hardware-setup-for-bootloading-only)
|
* [Minimal Hardware Setup for Bootloading only](#minimal-hardware-setup-for-bootloading-only)
|
||||||
* [Minimal Hardware Setup for Running only](#minimal-hardware-setup-for-running-only)
|
* [Minimal Hardware Setup for Running only](#minimal-hardware-setup-for-running-only)
|
||||||
* [Minimal](#minimal)
|
* [Minimal](#minimal)
|
||||||
* [Improved Stability](#improved-stability)
|
* [Improved Stability](#improved-stability)
|
||||||
* [Boot Messages and Modes](#boot-messages-and-modes)
|
* [Boot Messages and Modes](#boot-messages-and-modes)
|
||||||
* [rst cause](#rst-cause)
|
* [rst cause](#rst-cause)
|
||||||
* [boot mode](#boot-mode)
|
* [boot mode](#boot-mode)
|
||||||
* [WeMos D1](#wemos-d1)
|
* [WeMos D1](#wemos-d1)
|
||||||
* [WeMos D1 mini](#wemos-d1-mini)
|
* [WeMos D1 mini](#wemos-d1-mini)
|
||||||
|
|
||||||
## Adafruit HUZZAH ESP8266 (ESP-12)
|
## Adafruit HUZZAH ESP8266 (ESP-12)
|
||||||
|
|
||||||
|
@ -13,6 +13,26 @@ title: Change Log
|
|||||||
- Update documentation for NodeMCU and Olimex boards
|
- Update documentation for NodeMCU and Olimex boards
|
||||||
- Disable interrupts inside ESP.getVcc (#567)
|
- Disable interrupts inside ESP.getVcc (#567)
|
||||||
- Erase RTC RAM only if RF mode looks invalid (#619)
|
- Erase RTC RAM only if RF mode looks invalid (#619)
|
||||||
|
- Get pin levels at time of interrupt, rather than the time of calling the handler.
|
||||||
|
- Move interrupt handlers to ram.
|
||||||
|
- Improve debug output on critical errors
|
||||||
|
- Add ArduinoOTA library and docs
|
||||||
|
- Add WeMos D1 & D1 mini boards
|
||||||
|
- Add documentation about boot messages and mode meaning
|
||||||
|
- Disable sleep mode before doing OTA (#1005)
|
||||||
|
- Add the ability to be called back when the device is about to reset
|
||||||
|
- Add "Reset Method" menu
|
||||||
|
- Add MD5 to core
|
||||||
|
- I2C: generate STOP in case of NACK (fix #698, #254)
|
||||||
|
- Add libc time functions
|
||||||
|
- Fix linker script for 512k(no SPIFFS) variant (#966)
|
||||||
|
- I2S optimizations
|
||||||
|
- Support Sketch > Export compiled binary
|
||||||
|
- Update SPIFFS wrapper for 0.3.3
|
||||||
|
- Fix placement of code into RAM, enable gc-sections
|
||||||
|
- Make soft wdt reset more obvious
|
||||||
|
- Force disable IOSWAP for UART0 in HardwareSerial initialization (#744)
|
||||||
|
- Add IPAddress::toString()
|
||||||
|
|
||||||
|
|
||||||
### Libraries
|
### Libraries
|
||||||
@ -23,6 +43,30 @@ title: Change Log
|
|||||||
- ESP8266mDNS: allow to work on SoftAP interface
|
- ESP8266mDNS: allow to work on SoftAP interface
|
||||||
- EEPROM: round requested size to 4 bytes (#659)
|
- EEPROM: round requested size to 4 bytes (#659)
|
||||||
- Add ESP8266AVRISP library
|
- Add ESP8266AVRISP library
|
||||||
|
- Add ESP8266HTTPUpdate library
|
||||||
|
- Add HTTPClient library
|
||||||
|
- Add WiFiClientSecure
|
||||||
|
- ESP8266WiFi library: add persistent option, fix #1054
|
||||||
|
- Make RequestHandler handle uploads
|
||||||
|
- Add Digest Authentication to OTA and espota.py
|
||||||
|
- Don't close UDP pcbs when WiFi connection drops (#969)
|
||||||
|
- Add espsoftwareserial library
|
||||||
|
- Add HTTP Updater library
|
||||||
|
- Add Ethernet library for W5100
|
||||||
|
- Add SPIFFS WebServer Example
|
||||||
|
- add dnsIP() to ESP8266WiFi class
|
||||||
|
- OTA support encapsulated to ArduinoOTA class
|
||||||
|
- Add gdb stub library
|
||||||
|
- Extracted the WebUpdate example into a library.
|
||||||
|
- Fix to Servo allowing write() to be called before attach()
|
||||||
|
- ESP9266WiFi: add function `begin` without any parameters and add `psk` function to return current PSK form sdk config
|
||||||
|
- Fix a crash due to abort() called from TCP error callback (#428)
|
||||||
|
- Adding support for OPTIONS requests to ESP8266WebServer
|
||||||
|
- Add HTTPS request sample (#43)
|
||||||
|
- Fix _useClientMode & _useApMode in SDK auto connect mode (#754)
|
||||||
|
- Add ESP8266WebServer::sendContent_P with 'size_t size' argument for binary content
|
||||||
|
- Fix bug in WiFiClient::write_P when content was binary
|
||||||
|
- Add WiFiClient::write_P to be used with PROGMEM
|
||||||
|
|
||||||
### Tools
|
### Tools
|
||||||
|
|
||||||
|
@ -3,25 +3,25 @@ title: File System
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
* [Flash layout](#flash-layout)
|
* [Flash layout](#flash-layout)
|
||||||
* [Uploading files to file system](#uploading-files-to-file-system)
|
* [Uploading files to file system](#uploading-files-to-file-system)
|
||||||
* [File system object (SPIFFS)](#file-system-object-spiffs)
|
* [File system object (SPIFFS)](#file-system-object-spiffs)
|
||||||
* [begin](#begin)
|
* [begin](#begin)
|
||||||
* [format](#format)
|
* [format](#format)
|
||||||
* [open](#open)
|
* [open](#open)
|
||||||
* [exists](#exists)
|
* [exists](#exists)
|
||||||
* [openDir](#opendir)
|
* [openDir](#opendir)
|
||||||
* [remove](#remove)
|
* [remove](#remove)
|
||||||
* [rename](#rename)
|
* [rename](#rename)
|
||||||
* [info](#info)
|
* [info](#info)
|
||||||
* [Filesystem information structure](#filesystem-information-structure)
|
* [Filesystem information structure](#filesystem-information-structure)
|
||||||
* [Directory object (Dir)](#directory-object-dir)
|
* [Directory object (Dir)](#directory-object-dir)
|
||||||
* [File object](#file-object)
|
* [File object](#file-object)
|
||||||
* [seek](#seek)
|
* [seek](#seek)
|
||||||
* [position](#position)
|
* [position](#position)
|
||||||
* [size](#size)
|
* [size](#size)
|
||||||
* [name](#name)
|
* [name](#name)
|
||||||
* [close](#close)
|
* [close](#close)
|
||||||
|
|
||||||
|
|
||||||
## Flash layout
|
## Flash layout
|
||||||
@ -127,9 +127,7 @@ Returns *true* if a file with given path exists, *false* otherwise.
|
|||||||
SPIFFS.openDir(path)
|
SPIFFS.openDir(path)
|
||||||
```
|
```
|
||||||
|
|
||||||
Opens a directory given its absolute path. Returns a *Dir* object. To check if
|
Opens a directory given its absolute path. Returns a *Dir* object.
|
||||||
directory was opened successfully, use the boolean operator, similar to opening
|
|
||||||
a file.
|
|
||||||
|
|
||||||
### remove
|
### remove
|
||||||
|
|
||||||
|
@ -3,19 +3,19 @@ title: Libraries
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
* [WiFi(ESP8266WiFi library)](#wifiesp8266wifi-library)
|
* [WiFi(ESP8266WiFi library)](#wifiesp8266wifi-library)
|
||||||
* [Ticker](#ticker)
|
* [Ticker](#ticker)
|
||||||
* [EEPROM](#eeprom)
|
* [EEPROM](#eeprom)
|
||||||
* [I2C (Wire library)](#i2c-wire-library)
|
* [I2C (Wire library)](#i2c-wire-library)
|
||||||
* [SPI](#spi)
|
* [SPI](#spi)
|
||||||
* [SoftwareSerial](#softwareserial)
|
* [SoftwareSerial](#softwareserial)
|
||||||
* [ESP\-specific APIs](#esp-specific-apis)
|
* [ESP\-specific APIs](#esp-specific-apis)
|
||||||
* [OneWire](#onewire)
|
* [OneWire](#onewire)
|
||||||
* [mDNS and DNS\-SD responder (ESP8266mDNS library)](#mdns-and-dns-sd-responder-esp8266mdns-library)
|
* [mDNS and DNS\-SD responder (ESP8266mDNS library)](#mdns-and-dns-sd-responder-esp8266mdns-library)
|
||||||
* [SSDP responder (ESP8266SSDP)](#ssdp-responder-esp8266ssdp)
|
* [SSDP responder (ESP8266SSDP)](#ssdp-responder-esp8266ssdp)
|
||||||
* [DNS server (DNSServer library)](#dns-server-dnsserver-library)
|
* [DNS server (DNSServer library)](#dns-server-dnsserver-library)
|
||||||
* [Servo](#servo)
|
* [Servo](#servo)
|
||||||
* [Other libraries (not included with the IDE)](#other-libraries-not-included-with-the-ide)
|
* [Other libraries (not included with the IDE)](#other-libraries-not-included-with-the-ide)
|
||||||
|
|
||||||
## WiFi(ESP8266WiFi library)
|
## WiFi(ESP8266WiFi library)
|
||||||
|
|
||||||
|
@ -3,29 +3,29 @@ title: OTA Update
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
* [Introduction](#introduction)
|
* [Introduction](#introduction)
|
||||||
* [Security](#security)
|
* [Security](#security)
|
||||||
* [Safety](#safety)
|
* [Safety](#safety)
|
||||||
* [Basic Requirements](#basic-requirements)
|
* [Basic Requirements](#basic-requirements)
|
||||||
* [Arduino IDE](#arduino-ide)
|
* [Arduino IDE](#arduino-ide)
|
||||||
* [Requirements](#requirements)
|
* [Requirements](#requirements)
|
||||||
* [Application Example](#application-example)
|
* [Application Example](#application-example)
|
||||||
* [Classic OTA](#classic-ota)
|
* [Classic OTA](#classic-ota)
|
||||||
* [ArduinoOTA](#arduinoota)
|
* [ArduinoOTA](#arduinoota)
|
||||||
* [Web Browser](#web-browser)
|
* [Web Browser](#web-browser)
|
||||||
* [Requirements](#requirements-1)
|
* [Requirements](#requirements-1)
|
||||||
* [Implementation Overview](#implementation-overview)
|
* [Implementation Overview](#implementation-overview)
|
||||||
* [Application Example](#application-example-1)
|
* [Application Example](#application-example-1)
|
||||||
* [HTTP Server](#http-server)
|
* [HTTP Server](#http-server)
|
||||||
* [Requirements](#requirements-2)
|
* [Requirements](#requirements-2)
|
||||||
* [Arduino code](#arduino-code)
|
* [Arduino code](#arduino-code)
|
||||||
* [Simple updater](#simple-updater)
|
* [Simple updater](#simple-updater)
|
||||||
* [Advanced updater](#advanced-updater)
|
* [Advanced updater](#advanced-updater)
|
||||||
* [Server request handling](#server-request-handling)
|
* [Server request handling](#server-request-handling)
|
||||||
* [Simple updater](#simple-updater-1)
|
* [Simple updater](#simple-updater-1)
|
||||||
* [Advanced updater](#advanced-updater-1)
|
* [Advanced updater](#advanced-updater-1)
|
||||||
* [Stream Interface](#stream-interface)
|
* [Stream Interface](#stream-interface)
|
||||||
* [Updater class](#updater-class)
|
* [Updater class](#updater-class)
|
||||||
|
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
@ -121,8 +121,9 @@ Instructions below demonstrate how to configure both [Classic OTA](#classic-ota-
|
|||||||
2. Now prepare the sketch and configuration for the upload over a serial port.
|
2. Now prepare the sketch and configuration for the upload over a serial port.
|
||||||
- Start Arduino IDE and load sketch DNS_SD_Arduino_OTA.ino available under File > Examples > ESP8266mDNS
|
- Start Arduino IDE and load sketch DNS_SD_Arduino_OTA.ino available under File > Examples > ESP8266mDNS
|
||||||

|

|
||||||
|
|
||||||
**Note:** This sketch is available only for 1.6.5-947-g39819f0 (of July 23, 2015) and 1.6.5-1160-gef26c5f (of Sep 30, 2015) versions of platform packages installed in Arduino IDE using https://github.com/esp8266/Arduino#installing-with-boards-manager. It was removed in [#980](https://github.com/esp8266/Arduino/pull/980) from GitHub repository.
|
**Note:** This sketch is available only for 1.6.5-947-g39819f0 (of July 23, 2015) and 1.6.5-1160-gef26c5f (of Sep 30, 2015) versions of platform packages installed in Arduino IDE using https://github.com/esp8266/Arduino#installing-with-boards-manager. It was removed in [#980](https://github.com/esp8266/Arduino/pull/980) from GitHub repository.
|
||||||
- Update ssid and pass in the sketch so the module can join your Wi-Fi network
|
- Update SSID and password in the sketch so the module can join your Wi-Fi network
|
||||||

|

|
||||||
- Configure upload parameters as below (you may need to adjust configuration if you are using a different module):
|
- Configure upload parameters as below (you may need to adjust configuration if you are using a different module):
|
||||||

|

|
||||||
@ -133,7 +134,7 @@ Instructions below demonstrate how to configure both [Classic OTA](#classic-ota-
|
|||||||
|
|
||||||
4. Only if module is connected to network, after a couple of seconds, the esp8266-ota port will show up in Arduino IDE:
|
4. Only if module is connected to network, after a couple of seconds, the esp8266-ota port will show up in Arduino IDE:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
5. Now get ready for your first OTA upload by changing configuration settings as follows:
|
5. Now get ready for your first OTA upload by changing configuration settings as follows:
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ Instructions below demonstrate how to configure both [Classic OTA](#classic-ota-
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
**Note** To be able to upload your sketch over and over again using OTA, you need to embed OTA routines inside. Please use DNS_SD_Arduino_OTA.ino as an example.
|
**Note:** To be able to upload your sketch over and over again using OTA, you need to embed OTA routines inside. Please use DNS_SD_Arduino_OTA.ino as an example.
|
||||||
|
|
||||||
|
|
||||||
#### ArduinoOTA
|
#### ArduinoOTA
|
||||||
@ -217,15 +218,21 @@ You can use another module if it meets “Flash chip size is 2x the size of the
|
|||||||
- Start Arduino IDE and load sketch WebUpdater.ino available under File > Examples > ESP8266HTTPUpdateServer.
|
- Start Arduino IDE and load sketch WebUpdater.ino available under File > Examples > ESP8266HTTPUpdateServer.
|
||||||
- Update ssid and pass in the sketch so the module can join your Wi-Fi network.
|
- Update ssid and pass in the sketch so the module can join your Wi-Fi network.
|
||||||
- Open File > Preferences, look for “Show verbose output during:” and check out “compilation” option.
|
- Open File > Preferences, look for “Show verbose output during:” and check out “compilation” option.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
**Note:** This setting will be required in step 5 below. You can uncheck this setting afterwards.
|
**Note:** This setting will be required in step 5 below. You can uncheck this setting afterwards.
|
||||||
|
|
||||||
3. Upload sketch (Ctrl+U). Once done open Serial Monitor (Ctrl+Shift+M) and check if you see the following message displayed, that contains url for OTA update.
|
3. Upload sketch (Ctrl+U). Once done open Serial Monitor (Ctrl+Shift+M) and check if you see the following message displayed, that contains url for OTA update.
|
||||||
|
|
||||||

|

|
||||||
**Note:** Such message will be shown only after module successfully joins network and is ready for an OTA upload:
|
|
||||||
|
**Note:** Such message will be shown only after module successfully joins network and is ready for an OTA upload.
|
||||||
|
|
||||||
4. Now open web browser and enter the url provided on Serial Monitor, i.e. http://esp8266-webupdate.local/update. Once entered, browser should display a form like below that has been served by your module. The form invites you to choose a file for update.
|
4. Now open web browser and enter the url provided on Serial Monitor, i.e. http://esp8266-webupdate.local/update. Once entered, browser should display a form like below that has been served by your module. The form invites you to choose a file for update.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
**Note:** If entering “http://esp8266-webupdate.local/update” does not work, try replacing “esp8266-webupdate” with module’s IP address. For example, if your module IP is “192.168.1.100” then url should be “http://192.168.1.100/update”. This workaround is useful in case the host software installed in step 2 does not work. If still nothing works and there are no clues on Serial Monitor, try to diagnose issue by opening provided url in Google Chrome, pressing F12 and checking contents of “Console” and “Network” tabs. Chrome provides some advanced logging on these tabs.
|
**Note:** If entering “http://esp8266-webupdate.local/update” does not work, try replacing “esp8266-webupdate” with module’s IP address. For example, if your module IP is “192.168.1.100” then url should be “http://192.168.1.100/update”. This workaround is useful in case the host software installed in step 2 does not work. If still nothing works and there are no clues on Serial Monitor, try to diagnose issue by opening provided url in Google Chrome, pressing F12 and checking contents of “Console” and “Network” tabs. Chrome provides some advanced logging on these tabs.
|
||||||
|
|
||||||
|
|
||||||
@ -241,7 +248,7 @@ You can use another module if it meets “Flash chip size is 2x the size of the
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Just after reboot you should see exactly the same message “HTTPUpdateServer ready! Open http:// esp8266-webupdate.local /update in your browser” like in step 3. This is because module has been loaded again with the same code – first using serial port, and then using OTA.
|
Just after reboot you should see exactly the same message “HTTPUpdateServer ready! Open http:// esp8266-webupdate.local /update in your browser” like in step 3. This is because module has been loaded again with the same code – first using serial port, and then using OTA.
|
||||||
|
|
||||||
Once you are comfortable with this procedure go ahead and modify WebUpdater.ino sketch to print some additional messages, compile it, locate new binary file and upload it using web browser to see entered changes on a Serial Monitor.
|
Once you are comfortable with this procedure go ahead and modify WebUpdater.ino sketch to print some additional messages, compile it, locate new binary file and upload it using web browser to see entered changes on a Serial Monitor.
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@ title: Reference
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
* [Table of Contents](#table-of-contents)
|
* [Table of Contents](#table-of-contents)
|
||||||
* [Digital IO](#digital-io)
|
* [Digital IO](#digital-io)
|
||||||
* [Analog input](#analog-input)
|
* [Analog input](#analog-input)
|
||||||
* [Analog output](#analog-output)
|
* [Analog output](#analog-output)
|
||||||
* [Timing and delays](#timing-and-delays)
|
* [Timing and delays](#timing-and-delays)
|
||||||
* [Serial](#serial)
|
* [Serial](#serial)
|
||||||
* [Progmem](#progmem)
|
* [Progmem](#progmem)
|
||||||
|
|
||||||
## Digital IO
|
## Digital IO
|
||||||
|
|
||||||
|
@ -1,68 +1,68 @@
|
|||||||
/**
|
/**
|
||||||
* BasicHttpClient.ino
|
* BasicHTTPClient.ino
|
||||||
*
|
*
|
||||||
* Created on: 24.05.2015
|
* Created on: 24.05.2015
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WiFiMulti.h>
|
#include <ESP8266WiFiMulti.h>
|
||||||
|
|
||||||
#include <ESP8266httpClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
#define USE_SERIAL Serial
|
#define USE_SERIAL Serial
|
||||||
|
|
||||||
ESP8266WiFiMulti WiFiMulti;
|
ESP8266WiFiMulti WiFiMulti;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
USE_SERIAL.begin(115200);
|
USE_SERIAL.begin(115200);
|
||||||
// USE_SERIAL.setDebugOutput(true);
|
// USE_SERIAL.setDebugOutput(true);
|
||||||
|
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
|
|
||||||
for(uint8_t t = 4; t > 0; t--) {
|
for(uint8_t t = 4; t > 0; t--) {
|
||||||
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
||||||
USE_SERIAL.flush();
|
USE_SERIAL.flush();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiMulti.addAP("SSID", "PASSWORD");
|
WiFiMulti.addAP("SSID", "PASSWORD");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// wait for WiFi connection
|
// wait for WiFi connection
|
||||||
if((WiFiMulti.run() == WL_CONNECTED)) {
|
if((WiFiMulti.run() == WL_CONNECTED)) {
|
||||||
|
|
||||||
httpClient http;
|
HTTPClient http;
|
||||||
|
|
||||||
USE_SERIAL.print("[HTTP] begin...\n");
|
USE_SERIAL.print("[HTTP] begin...\n");
|
||||||
// configure traged server and url
|
// 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", 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("192.168.1.12", 80, "/test.html"); //HTTP
|
||||||
|
|
||||||
USE_SERIAL.print("[HTTP] GET...\n");
|
USE_SERIAL.print("[HTTP] GET...\n");
|
||||||
// start connection and send HTTP header
|
// start connection and send HTTP header
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
if(httpCode) {
|
if(httpCode) {
|
||||||
// HTTP header has been send and Server response header has been handled
|
// HTTP header has been send and Server response header has been handled
|
||||||
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
|
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
|
||||||
|
|
||||||
// file found at server
|
// file found at server
|
||||||
if(httpCode == 200) {
|
if(httpCode == 200) {
|
||||||
String payload = http.getString();
|
String payload = http.getString();
|
||||||
USE_SERIAL.println(payload);
|
USE_SERIAL.println(payload);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
|
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(10000);
|
delay(10000);
|
||||||
}
|
}
|
||||||
|
|
@ -1,65 +1,65 @@
|
|||||||
/**
|
/**
|
||||||
* reuseConnection.ino
|
* reuseConnection.ino
|
||||||
*
|
*
|
||||||
* Created on: 22.11.2015
|
* Created on: 22.11.2015
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WiFiMulti.h>
|
#include <ESP8266WiFiMulti.h>
|
||||||
|
|
||||||
#include <ESP8266httpClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
#define USE_SERIAL Serial
|
#define USE_SERIAL Serial
|
||||||
|
|
||||||
ESP8266WiFiMulti WiFiMulti;
|
ESP8266WiFiMulti WiFiMulti;
|
||||||
|
|
||||||
httpClient http;
|
HTTPClient http;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
USE_SERIAL.begin(115200);
|
USE_SERIAL.begin(115200);
|
||||||
// USE_SERIAL.setDebugOutput(true);
|
// USE_SERIAL.setDebugOutput(true);
|
||||||
|
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
|
|
||||||
for(uint8_t t = 4; t > 0; t--) {
|
for(uint8_t t = 4; t > 0; t--) {
|
||||||
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
||||||
USE_SERIAL.flush();
|
USE_SERIAL.flush();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiMulti.addAP("SSID", "PASSWORD");
|
WiFiMulti.addAP("SSID", "PASSWORD");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// wait for WiFi connection
|
// wait for WiFi connection
|
||||||
if((WiFiMulti.run() == WL_CONNECTED)) {
|
if((WiFiMulti.run() == WL_CONNECTED)) {
|
||||||
|
|
||||||
http.begin("192.168.1.12", 80, "/test.html");
|
http.begin("192.168.1.12", 80, "/test.html");
|
||||||
|
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
if(httpCode) {
|
if(httpCode) {
|
||||||
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
|
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
|
||||||
|
|
||||||
// file found at server
|
// file found at server
|
||||||
if(httpCode == 200) {
|
if(httpCode == 200) {
|
||||||
http.writeToStream(&USE_SERIAL);
|
http.writeToStream(&USE_SERIAL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
|
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,98 +1,98 @@
|
|||||||
/**
|
/**
|
||||||
* StreamHttpClient.ino
|
* StreamHTTPClient.ino
|
||||||
*
|
*
|
||||||
* Created on: 24.05.2015
|
* Created on: 24.05.2015
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WiFiMulti.h>
|
#include <ESP8266WiFiMulti.h>
|
||||||
|
|
||||||
#include <ESP8266httpClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
#define USE_SERIAL Serial
|
#define USE_SERIAL Serial
|
||||||
|
|
||||||
ESP8266WiFiMulti WiFiMulti;
|
ESP8266WiFiMulti WiFiMulti;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
USE_SERIAL.begin(115200);
|
USE_SERIAL.begin(115200);
|
||||||
// USE_SERIAL.setDebugOutput(true);
|
// USE_SERIAL.setDebugOutput(true);
|
||||||
|
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
|
|
||||||
for(uint8_t t = 4; t > 0; t--) {
|
for(uint8_t t = 4; t > 0; t--) {
|
||||||
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
||||||
USE_SERIAL.flush();
|
USE_SERIAL.flush();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiMulti.addAP("SSID", "PASSWORD");
|
WiFiMulti.addAP("SSID", "PASSWORD");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// wait for WiFi connection
|
// wait for WiFi connection
|
||||||
if((WiFiMulti.run() == WL_CONNECTED)) {
|
if((WiFiMulti.run() == WL_CONNECTED)) {
|
||||||
|
|
||||||
httpClient http;
|
HTTPClient http;
|
||||||
|
|
||||||
USE_SERIAL.print("[HTTP] begin...\n");
|
USE_SERIAL.print("[HTTP] begin...\n");
|
||||||
// configure traged server and url
|
// configure traged server and url
|
||||||
http.begin("192.168.1.12", 80, "/test.html");
|
http.begin("192.168.1.12", 80, "/test.html");
|
||||||
|
|
||||||
USE_SERIAL.print("[HTTP] GET...\n");
|
USE_SERIAL.print("[HTTP] GET...\n");
|
||||||
// start connection and send HTTP header
|
// start connection and send HTTP header
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
if(httpCode) {
|
if(httpCode) {
|
||||||
// HTTP header has been send and Server response header has been handled
|
// HTTP header has been send and Server response header has been handled
|
||||||
|
|
||||||
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
|
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
|
||||||
|
|
||||||
// file found at server
|
// file found at server
|
||||||
if(httpCode == 200) {
|
if(httpCode == 200) {
|
||||||
|
|
||||||
// get lenght of document (is -1 when Server sends no Content-Length header)
|
// get lenght of document (is -1 when Server sends no Content-Length header)
|
||||||
int len = http.getSize();
|
int len = http.getSize();
|
||||||
|
|
||||||
// create buffer for read
|
// create buffer for read
|
||||||
uint8_t buff[128] = { 0 };
|
uint8_t buff[128] = { 0 };
|
||||||
|
|
||||||
// get tcp stream
|
// get tcp stream
|
||||||
WiFiClient * stream = http.getStreamPtr();
|
WiFiClient * stream = http.getStreamPtr();
|
||||||
|
|
||||||
// read all data from server
|
// read all data from server
|
||||||
while(http.connected() && (len > 0 || len == -1)) {
|
while(http.connected() && (len > 0 || len == -1)) {
|
||||||
// get available data size
|
// get available data size
|
||||||
size_t size = stream->available();
|
size_t size = stream->available();
|
||||||
|
|
||||||
if(size) {
|
if(size) {
|
||||||
// read up to 128 byte
|
// read up to 128 byte
|
||||||
int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
|
int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
|
||||||
|
|
||||||
// write it to Serial
|
// write it to Serial
|
||||||
USE_SERIAL.write(buff, c);
|
USE_SERIAL.write(buff, c);
|
||||||
|
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
len -= c;
|
len -= c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
USE_SERIAL.print("[HTTP] connection closed or file end.\n");
|
USE_SERIAL.print("[HTTP] connection closed or file end.\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
|
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(10000);
|
delay(10000);
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,9 @@
|
|||||||
name=ESP8266httpClient
|
name=ESP8266HTTPClient
|
||||||
version=1.0
|
version=1.0
|
||||||
author=Markus Sattler
|
author=Markus Sattler
|
||||||
maintainer=Markus Sattler
|
maintainer=Markus Sattler
|
||||||
sentence=http Client for ESP8266
|
sentence=http Client for ESP8266
|
||||||
paragraph=
|
paragraph=
|
||||||
category=Communication
|
category=Communication
|
||||||
url=https://github.com/Links2004/Arduino/tree/libraries/ESP8266httpClient
|
url=https://github.com/Links2004/Arduino/tree/libraries/ESP8266HTTPClient
|
||||||
architectures=esp8266
|
architectures=esp8266
|
File diff suppressed because it is too large
Load Diff
@ -1,129 +1,129 @@
|
|||||||
/**
|
/**
|
||||||
* ESP8266httpClient.h
|
* ESP8266HTTPClient.h
|
||||||
*
|
*
|
||||||
* Created on: 02.11.2015
|
* Created on: 02.11.2015
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||||
* This file is part of the ESP8266httpClient for Arduino.
|
* This file is part of the ESP8266HTTPClient for Arduino.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
* License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
* 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,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ESP8266HTTPCLIENT_H_
|
#ifndef ESP8266HTTPClient_H_
|
||||||
#define ESP8266HTTPCLIENT_H_
|
#define ESP8266HTTPClient_H_
|
||||||
|
|
||||||
//#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
|
//#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
|
||||||
|
|
||||||
#ifndef DEBUG_HTTPCLIENT
|
#ifndef DEBUG_HTTPCLIENT
|
||||||
#define DEBUG_HTTPCLIENT(...)
|
#define DEBUG_HTTPCLIENT(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HTTPCLIENT_TCP_TIMEOUT (1000)
|
#define HTTPCLIENT_TCP_TIMEOUT (1000)
|
||||||
|
|
||||||
/// HTTP client errors
|
/// HTTP client errors
|
||||||
#define HTTPC_ERROR_CONNECTION_REFUSED (-1)
|
#define HTTPC_ERROR_CONNECTION_REFUSED (-1)
|
||||||
#define HTTPC_ERROR_SEND_HEADER_FAILED (-2)
|
#define HTTPC_ERROR_SEND_HEADER_FAILED (-2)
|
||||||
#define HTTPC_ERROR_SEND_PAYLOAD_FAILED (-3)
|
#define HTTPC_ERROR_SEND_PAYLOAD_FAILED (-3)
|
||||||
#define HTTPC_ERROR_NOT_CONNECTED (-4)
|
#define HTTPC_ERROR_NOT_CONNECTED (-4)
|
||||||
#define HTTPC_ERROR_CONNECTION_LOST (-5)
|
#define HTTPC_ERROR_CONNECTION_LOST (-5)
|
||||||
#define HTTPC_ERROR_NO_STREAM (-6)
|
#define HTTPC_ERROR_NO_STREAM (-6)
|
||||||
#define HTTPC_ERROR_NO_HTTP_SERVER (-7)
|
#define HTTPC_ERROR_NO_HTTP_SERVER (-7)
|
||||||
|
|
||||||
|
|
||||||
class httpClient {
|
class HTTPClient {
|
||||||
public:
|
public:
|
||||||
httpClient();
|
HTTPClient();
|
||||||
~httpClient();
|
~HTTPClient();
|
||||||
|
|
||||||
void begin(const char *url, const char * httpsFingerprint = "");
|
void begin(const char *url, const char * httpsFingerprint = "");
|
||||||
void begin(String url, String httpsFingerprint = "");
|
void begin(String url, String httpsFingerprint = "");
|
||||||
|
|
||||||
void begin(const char *host, uint16_t port, const char * url = "/", bool https = false, const char * httpsFingerprint = "");
|
void begin(const char *host, uint16_t port, const char * url = "/", bool https = false, const char * httpsFingerprint = "");
|
||||||
void begin(String host, uint16_t port, String url = "/", bool https = false, String httpsFingerprint = "");
|
void begin(String host, uint16_t port, String url = "/", bool https = false, String httpsFingerprint = "");
|
||||||
|
|
||||||
void end(void);
|
void end(void);
|
||||||
|
|
||||||
bool connected(void);
|
bool connected(void);
|
||||||
|
|
||||||
void setReuse(bool reuse); /// keep-alive
|
void setReuse(bool reuse); /// keep-alive
|
||||||
void setUserAgent(const char * userAgent);
|
void setUserAgent(const char * userAgent);
|
||||||
|
|
||||||
/// request handling
|
/// request handling
|
||||||
int GET();
|
int GET();
|
||||||
int POST(uint8_t * payload, size_t size);
|
int POST(uint8_t * payload, size_t size);
|
||||||
int POST(String payload);
|
int POST(String payload);
|
||||||
int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0);
|
int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0);
|
||||||
int sendRequest(const char * type, Stream * stream, size_t size = 0);
|
int sendRequest(const char * type, Stream * stream, size_t size = 0);
|
||||||
|
|
||||||
void addHeader(const String& name, const String& value, bool first = false);
|
void addHeader(const String& name, const String& value, bool first = false);
|
||||||
|
|
||||||
/// Response handling
|
/// Response handling
|
||||||
void collectHeaders(const char* headerKeys[], const size_t headerKeysCount);
|
void collectHeaders(const char* headerKeys[], const size_t headerKeysCount);
|
||||||
String header(const char* name); // get request header value by name
|
String header(const char* name); // get request header value by name
|
||||||
String header(size_t i); // get request header value by number
|
String header(size_t i); // get request header value by number
|
||||||
String headerName(size_t i); // get request header name by number
|
String headerName(size_t i); // get request header name by number
|
||||||
int headers(); // get header count
|
int headers(); // get header count
|
||||||
bool hasHeader(const char* name); // check if header exists
|
bool hasHeader(const char* name); // check if header exists
|
||||||
|
|
||||||
|
|
||||||
int getSize(void);
|
int getSize(void);
|
||||||
|
|
||||||
WiFiClient & getStream(void) __attribute__ ((deprecated)) ;
|
WiFiClient & getStream(void) __attribute__ ((deprecated)) ;
|
||||||
WiFiClient * getStreamPtr(void);
|
WiFiClient * getStreamPtr(void);
|
||||||
int writeToStream(Stream * stream);
|
int writeToStream(Stream * stream);
|
||||||
String getString(void);
|
String getString(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
struct RequestArgument {
|
struct RequestArgument {
|
||||||
String key;
|
String key;
|
||||||
String value;
|
String value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
WiFiClient * _tcp;
|
WiFiClient * _tcp;
|
||||||
WiFiClientSecure * _tcps;
|
WiFiClientSecure * _tcps;
|
||||||
|
|
||||||
/// request handling
|
/// request handling
|
||||||
String _host;
|
String _host;
|
||||||
uint16_t _port;
|
uint16_t _port;
|
||||||
bool _reuse;
|
bool _reuse;
|
||||||
|
|
||||||
|
|
||||||
String _url;
|
String _url;
|
||||||
bool _https;
|
bool _https;
|
||||||
String _httpsFingerprint;
|
String _httpsFingerprint;
|
||||||
|
|
||||||
String _Headers;
|
String _Headers;
|
||||||
String _userAgent;
|
String _userAgent;
|
||||||
|
|
||||||
/// Response handling
|
/// Response handling
|
||||||
RequestArgument* _currentHeaders;
|
RequestArgument* _currentHeaders;
|
||||||
size_t _headerKeysCount;
|
size_t _headerKeysCount;
|
||||||
|
|
||||||
int _returnCode;
|
int _returnCode;
|
||||||
int _size;
|
int _size;
|
||||||
bool _canReuse;
|
bool _canReuse;
|
||||||
|
|
||||||
bool connect(void);
|
bool connect(void);
|
||||||
bool sendHeader(const char * type);
|
bool sendHeader(const char * type);
|
||||||
int handleHeaderResponse();
|
int handleHeaderResponse();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* ESP8266HTTPCLIENT_H_ */
|
#endif /* ESP8266HTTPClient_H_ */
|
@ -397,19 +397,28 @@ void ESP8266WebServer::onNotFound(THandlerFunction fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WebServer::_handleRequest() {
|
void ESP8266WebServer::_handleRequest() {
|
||||||
|
bool handled = false;
|
||||||
if (!_currentHandler){
|
if (!_currentHandler){
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DEBUG_OUTPUT.println("request handler not found");
|
DEBUG_OUTPUT.println("request handler not found");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
handled = _currentHandler->handle(*this, _currentMethod, _currentUri);
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (!handled) {
|
||||||
|
DEBUG_OUTPUT.println("request handler failed to handle request");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!handled) {
|
||||||
if(_notFoundHandler) {
|
if(_notFoundHandler) {
|
||||||
_notFoundHandler();
|
_notFoundHandler();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
send(404, "text/plain", String("Not found: ") + _currentUri);
|
send(404, "text/plain", String("Not found: ") + _currentUri);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
_currentHandler->handle(*this, _currentMethod, _currentUri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t maxWait = HTTP_MAX_CLOSE_WAIT;
|
uint16_t maxWait = HTTP_MAX_CLOSE_WAIT;
|
||||||
|
@ -60,7 +60,7 @@ public:
|
|||||||
{
|
{
|
||||||
_isFile = fs.exists(path);
|
_isFile = fs.exists(path);
|
||||||
DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header);
|
DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header);
|
||||||
_baseUriLength = _uri.length();
|
_baseUriLength = _uri.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canHandle(HTTPMethod requestMethod, String requestUri) override {
|
bool canHandle(HTTPMethod requestMethod, String requestUri) override {
|
||||||
@ -75,26 +75,27 @@ public:
|
|||||||
|
|
||||||
bool handle(ESP8266WebServer& server, HTTPMethod requestMethod, String requestUri) override {
|
bool handle(ESP8266WebServer& server, HTTPMethod requestMethod, String requestUri) override {
|
||||||
if (!canHandle(requestMethod, requestUri))
|
if (!canHandle(requestMethod, requestUri))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str());
|
DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str());
|
||||||
|
|
||||||
String path(_path);
|
String path(_path);
|
||||||
|
|
||||||
if(path.endsWith("/")) path += "index.htm";
|
if (!_isFile) {
|
||||||
|
// Base URI doesn't point to a file.
|
||||||
|
// If a directory is requested, look for index file.
|
||||||
|
if (requestUri.endsWith("/")) requestUri += "index.htm";
|
||||||
|
|
||||||
if (!_isFile) {
|
// Append whatever follows this URI in request to get the file path.
|
||||||
// Base URI doesn't point to a file. Append whatever follows this
|
path += requestUri.substring(_baseUriLength);
|
||||||
// URI in request to get the file path.
|
|
||||||
path += requestUri.substring(_baseUriLength);
|
|
||||||
}
|
}
|
||||||
DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile);
|
DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile);
|
||||||
|
|
||||||
String contentType = getContentType(path);
|
String contentType = getContentType(path);
|
||||||
|
|
||||||
// look for gz file, only if the original specified path is not a gz. So part only works to send gzip via content encoding when a non compressed is asked for
|
// look for gz file, only if the original specified path is not a gz. So part only works to send gzip via content encoding when a non compressed is asked for
|
||||||
// if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc...
|
// if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc...
|
||||||
if (!path.endsWith(".gz") && !SPIFFS.exists(path)) {
|
if (!path.endsWith(".gz") && !SPIFFS.exists(path)) {
|
||||||
String pathWithGz = path + ".gz";
|
String pathWithGz = path + ".gz";
|
||||||
if(SPIFFS.exists(pathWithGz))
|
if(SPIFFS.exists(pathWithGz))
|
||||||
path += ".gz";
|
path += ".gz";
|
||||||
@ -104,9 +105,9 @@ public:
|
|||||||
if (!f)
|
if (!f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (_cache_header.length() != 0)
|
if (_cache_header.length() != 0)
|
||||||
server.sendHeader("Cache-Control", _cache_header);
|
server.sendHeader("Cache-Control", _cache_header);
|
||||||
|
|
||||||
server.streamFile(f, contentType);
|
server.streamFile(f, contentType);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -133,7 +134,7 @@ protected:
|
|||||||
FS _fs;
|
FS _fs;
|
||||||
String _uri;
|
String _uri;
|
||||||
String _path;
|
String _path;
|
||||||
String _cache_header;
|
String _cache_header;
|
||||||
bool _isFile;
|
bool _isFile;
|
||||||
size_t _baseUriLength;
|
size_t _baseUriLength;
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WiFiMulti.h>
|
#include <ESP8266WiFiMulti.h>
|
||||||
|
|
||||||
#include <ESP8266httpClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
#include <ESP8266httpUpdate.h>
|
#include <ESP8266httpUpdate.h>
|
||||||
|
|
||||||
#define USE_SERIAL Serial
|
#define USE_SERIAL Serial
|
||||||
|
@ -41,7 +41,7 @@ ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void) {
|
|||||||
* @return t_httpUpdate_return
|
* @return t_httpUpdate_return
|
||||||
*/
|
*/
|
||||||
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * url, const char * current_version, const char * httpsFingerprint) {
|
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * url, const char * current_version, const char * httpsFingerprint) {
|
||||||
httpClient http;
|
HTTPClient http;
|
||||||
http.begin(url, httpsFingerprint);
|
http.begin(url, httpsFingerprint);
|
||||||
return handleUpdate(&http, current_version);
|
return handleUpdate(&http, current_version);
|
||||||
}
|
}
|
||||||
@ -56,24 +56,24 @@ t_httpUpdate_return ESP8266HTTPUpdate::update(const char * url, const char * cur
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port, const char * url, const char * current_version, bool https, const char * httpsFingerprint) {
|
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port, const char * url, const char * current_version, bool https, const char * httpsFingerprint) {
|
||||||
httpClient http;
|
HTTPClient http;
|
||||||
http.begin(host, port, url, https, httpsFingerprint);
|
http.begin(host, port, url, https, httpsFingerprint);
|
||||||
return handleUpdate(&http, current_version);
|
return handleUpdate(&http, current_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_httpUpdate_return ESP8266HTTPUpdate::update(String host, uint16_t port, String url, String current_version, bool https, String httpsFingerprint) {
|
t_httpUpdate_return ESP8266HTTPUpdate::update(String host, uint16_t port, String url, String current_version, bool https, String httpsFingerprint) {
|
||||||
httpClient http;
|
HTTPClient http;
|
||||||
http.begin(host, port, url, https, httpsFingerprint);
|
http.begin(host, port, url, https, httpsFingerprint);
|
||||||
return handleUpdate(&http, current_version.c_str());
|
return handleUpdate(&http, current_version.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param http httpClient *
|
* @param http HTTPClient *
|
||||||
* @param current_version const char *
|
* @param current_version const char *
|
||||||
* @return t_httpUpdate_return
|
* @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) {
|
||||||
|
|
||||||
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
|
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <ESP8266httpClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
//#define DEBUG_HTTP_UPDATE(...) Serial1.printf( __VA_ARGS__ )
|
//#define DEBUG_HTTP_UPDATE(...) Serial1.printf( __VA_ARGS__ )
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class ESP8266HTTPUpdate {
|
|||||||
t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = "");
|
t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = "");
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
t_httpUpdate_return handleUpdate(httpClient * http, const char * current_version);
|
t_httpUpdate_return handleUpdate(HTTPClient * http, const char * current_version);
|
||||||
bool runUpdate(Stream& in, uint32_t size, String md5);
|
bool runUpdate(Stream& in, uint32_t size, String md5);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user