1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Merge remote-tracking branch 'esp8266/master' into www-basic-auth

This commit is contained in:
Me No Dev 2015-11-30 15:00:50 +02:00
commit 4ca084e628
18 changed files with 1221 additions and 1148 deletions

View File

@ -23,12 +23,12 @@ If you find this ESP8266 board manager useful, please consider supporting it wit
##### Stable version ![](http://arduino.esp8266.com/stable/badge.svg) ##### Stable version ![](http://arduino.esp8266.com/stable/badge.svg)
Boards manager link: `http://arduino.esp8266.com/stable/package_esp8266com_index.json` Boards manager link: `http://arduino.esp8266.com/stable/package_esp8266com_index.json`
Documentation: [Reference](http://arduino.esp8266.com/stable/doc/reference.html) Documentation: [http://esp8266.github.io/Arduino/versions/2.0.0/](http://esp8266.github.io/Arduino/versions/2.0.0/)
##### Staging version ![](http://arduino.esp8266.com/staging/badge.svg) ##### Staging version ![](http://arduino.esp8266.com/staging/badge.svg)
Boards manager link: `http://arduino.esp8266.com/staging/package_esp8266com_index.json` Boards manager link: `http://arduino.esp8266.com/staging/package_esp8266com_index.json`
Documentation: [Reference](http://arduino.esp8266.com/staging/doc/reference.html) Documentation: [http://esp8266.github.io/Arduino/versions/2.0.0-rc2/](http://esp8266.github.io/Arduino/versions/2.0.0-rc2/)
### Using git version [![Linux build status](https://travis-ci.org/esp8266/Arduino.svg)](https://travis-ci.org/esp8266/Arduino) ### Using git version [![Linux build status](https://travis-ci.org/esp8266/Arduino.svg)](https://travis-ci.org/esp8266/Arduino)
@ -51,9 +51,11 @@ python get.py
Documentation for latest development version: Documentation for latest development version:
- [Reference](doc/reference.md) - [Reference](doc/reference.md)
- [Libraries](doc/libraries.md)
- [File system](doc/filesystem.md)
- [OTA update](doc/ota_updates/ota_updates.md)
- [Supported boards](doc/boards.md) - [Supported boards](doc/boards.md)
- [Change log](doc/changes.md) - [Change log](doc/changes.md)
- [OTA Update](doc/ota_updates/ota_updates.md)
### Issues and support ### ### Issues and support ###

View File

@ -2,7 +2,19 @@
title: Change Log title: Change Log
--- ---
*Current release* ## Current version
### Core
### Libraries
### Tools
---
## 2.0.0
November 30, 2015
Package link: `http://arduino.esp8266.com/versions/2.0.0/package_esp8266com_index.json`.
### Core ### Core
@ -13,6 +25,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 +55,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()
- ESP8266WiFi: 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

View File

@ -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

View File

@ -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
![OTA sketch selection](ota-ide-sketch-selection.png) ![OTA sketch selection](ota-ide-sketch-selection.png)
**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
![ssid and pass entry](ota-ide-ssid-pass-entry.png) ![ssid and pass entry](ota-ide-ssid-pass-entry.png)
- 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):
![configuration of serial upload](ota-ide-serial-upload-configuration.png) ![configuration of serial upload](ota-ide-serial-upload-configuration.png)
@ -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:
![selection og OTA port](ota-ide-ota-port-selection.png) ![selection of OTA port](ota-ide-ota-port-selection.png)
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-
![OTA upload complete](ota-ide-ota-upload-complete.png) ![OTA upload complete](ota-ide-ota-upload-complete.png)
**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.
![Preferences - enablig verbose output during compilation](ota-web-show-verbose-compilation.png) ![Preferences - enablig verbose output during compilation](ota-web-show-verbose-compilation.png)
**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.
![Serial Monitor - after first load using serial](ota-web-serial-monitor-ready.png) ![Serial Monitor - after first load using serial](ota-web-serial-monitor-ready.png)
**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.
![OTA update form in web browser](ota-web-browser-form.png) ![OTA update form in web browser](ota-web-browser-form.png)
**Note:** If entering “http://esp8266-webupdate.local/update” does not work, try replacing “esp8266-webupdate” with modules 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 modules 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
![Serial Monitor - after OTA update](ota-web-serial-monitor-reboot.png) ![Serial Monitor - after OTA update](ota-web-serial-monitor-reboot.png)
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.

View File

@ -1,5 +1,5 @@
/** /**
* BasicHttpClient.ino * BasicHTTPClient.ino
* *
* Created on: 24.05.2015 * Created on: 24.05.2015
* *
@ -10,7 +10,7 @@
#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
@ -39,7 +39,7 @@ 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

View File

@ -11,13 +11,13 @@
#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() {

View File

@ -1,5 +1,5 @@
/** /**
* StreamHttpClient.ino * StreamHTTPClient.ino
* *
* Created on: 24.05.2015 * Created on: 24.05.2015
* *
@ -10,7 +10,7 @@
#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
@ -39,7 +39,7 @@ 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

View File

@ -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

View File

@ -1,10 +1,10 @@
/** /**
* ESP8266httpClient.cpp * ESP8266HTTPClient.cpp
* *
* 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
@ -27,12 +27,12 @@
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
#include <StreamString.h> #include <StreamString.h>
#include "ESP8266httpClient.h" #include "ESP8266HTTPClient.h"
/** /**
* constractor * constractor
*/ */
httpClient::httpClient() { HTTPClient::HTTPClient() {
_tcp = NULL; _tcp = NULL;
_tcps = NULL; _tcps = NULL;
@ -41,7 +41,7 @@ httpClient::httpClient() {
_reuse = false; _reuse = false;
_https = false; _https = false;
_userAgent = "ESP8266httpClient"; _userAgent = "ESP8266HTTPClient";
_headerKeysCount = 0; _headerKeysCount = 0;
_currentHeaders = NULL; _currentHeaders = NULL;
@ -55,7 +55,7 @@ httpClient::httpClient() {
/** /**
* deconstractor * deconstractor
*/ */
httpClient::~httpClient() { HTTPClient::~HTTPClient() {
if(_tcps) { if(_tcps) {
_tcps->stop(); _tcps->stop();
@ -78,7 +78,7 @@ httpClient::~httpClient() {
* @param url const char * * @param url const char *
* @param httpsFingerprint const char * * @param httpsFingerprint const char *
*/ */
void httpClient::begin(const char *url, const char * httpsFingerprint) { void HTTPClient::begin(const char *url, const char * httpsFingerprint) {
begin(String(url), String(httpsFingerprint)); begin(String(url), String(httpsFingerprint));
} }
@ -87,7 +87,7 @@ void httpClient::begin(const char *url, const char * httpsFingerprint) {
* @param url String * @param url String
* @param httpsFingerprint String * @param httpsFingerprint String
*/ */
void httpClient::begin(String url, String httpsFingerprint) { void HTTPClient::begin(String url, String httpsFingerprint) {
DEBUG_HTTPCLIENT("[HTTP-Client][begin] url: %s\n", url.c_str()); DEBUG_HTTPCLIENT("[HTTP-Client][begin] url: %s\n", url.c_str());
@ -153,7 +153,7 @@ void httpClient::begin(String url, String httpsFingerprint) {
* @param https bool * @param https bool
* @param httpsFingerprint const char * * @param httpsFingerprint const char *
*/ */
void httpClient::begin(const char *host, uint16_t port, const char * url, bool https, const char * httpsFingerprint) { void HTTPClient::begin(const char *host, uint16_t port, const char * url, bool https, const char * httpsFingerprint) {
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port:%d url: %s https: %d httpsFingerprint: %s\n", host, port, url, https, httpsFingerprint); DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port:%d url: %s https: %d httpsFingerprint: %s\n", host, port, url, https, httpsFingerprint);
@ -170,7 +170,7 @@ void httpClient::begin(const char *host, uint16_t port, const char * url, bool h
} }
void httpClient::begin(String host, uint16_t port, String url, bool https, String httpsFingerprint) { void HTTPClient::begin(String host, uint16_t port, String url, bool https, String httpsFingerprint) {
begin(host.c_str(), port, url.c_str(), https, httpsFingerprint.c_str()); begin(host.c_str(), port, url.c_str(), https, httpsFingerprint.c_str());
} }
@ -178,7 +178,7 @@ void httpClient::begin(String host, uint16_t port, String url, bool https, Strin
* end * end
* called after the payload is handled * called after the payload is handled
*/ */
void httpClient::end(void) { void HTTPClient::end(void) {
if(connected()) { if(connected()) {
if(_reuse && _canReuse) { if(_reuse && _canReuse) {
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n"); DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n");
@ -195,7 +195,7 @@ void httpClient::end(void) {
* connected * connected
* @return connected status * @return connected status
*/ */
bool httpClient::connected() { bool HTTPClient::connected() {
if(_tcp) { if(_tcp) {
return (_tcp->connected() || (_tcp->available() > 0)); return (_tcp->connected() || (_tcp->available() > 0));
} }
@ -207,7 +207,7 @@ bool httpClient::connected() {
* keep-alive * keep-alive
* @param reuse bool * @param reuse bool
*/ */
void httpClient::setReuse(bool reuse) { void HTTPClient::setReuse(bool reuse) {
_reuse = reuse; _reuse = reuse;
} }
@ -215,7 +215,7 @@ void httpClient::setReuse(bool reuse) {
* set User Agent * set User Agent
* @param userAgent const char * * @param userAgent const char *
*/ */
void httpClient::setUserAgent(const char * userAgent) { void HTTPClient::setUserAgent(const char * userAgent) {
_userAgent = userAgent; _userAgent = userAgent;
} }
@ -223,7 +223,7 @@ void httpClient::setUserAgent(const char * userAgent) {
* send a GET request * send a GET request
* @return http code * @return http code
*/ */
int httpClient::GET() { int HTTPClient::GET() {
return sendRequest("GET"); return sendRequest("GET");
} }
@ -233,11 +233,11 @@ int httpClient::GET() {
* @param size size_t * @param size size_t
* @return http code * @return http code
*/ */
int httpClient::POST(uint8_t * payload, size_t size) { int HTTPClient::POST(uint8_t * payload, size_t size) {
return sendRequest("POST", payload, size); return sendRequest("POST", payload, size);
} }
int httpClient::POST(String payload) { int HTTPClient::POST(String payload) {
return POST((uint8_t *) payload.c_str(), payload.length()); return POST((uint8_t *) payload.c_str(), payload.length());
} }
@ -248,7 +248,7 @@ int httpClient::POST(String payload) {
* @param size size_t size for the message body if 0 not send * @param size size_t size for the message body if 0 not send
* @return -1 if no info or > 0 when Content-Length is set by server * @return -1 if no info or > 0 when Content-Length is set by server
*/ */
int httpClient::sendRequest(const char * type, uint8_t * payload, size_t size) { int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) {
// connect to server // connect to server
if(!connect()) { if(!connect()) {
return HTTPC_ERROR_CONNECTION_REFUSED; return HTTPC_ERROR_CONNECTION_REFUSED;
@ -281,7 +281,7 @@ int httpClient::sendRequest(const char * type, uint8_t * payload, size_t size) {
* @param size size_t size for the message body if 0 not Content-Length is send * @param size size_t size for the message body if 0 not Content-Length is send
* @return -1 if no info or > 0 when Content-Length is set by server * @return -1 if no info or > 0 when Content-Length is set by server
*/ */
int httpClient::sendRequest(const char * type, Stream * stream, size_t size) { int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
if(!stream) { if(!stream) {
return HTTPC_ERROR_NO_STREAM; return HTTPC_ERROR_NO_STREAM;
@ -349,7 +349,7 @@ int httpClient::sendRequest(const char * type, Stream * stream, size_t size) {
* size of message body / payload * size of message body / payload
* @return -1 if no info or > 0 when Content-Length is set by server * @return -1 if no info or > 0 when Content-Length is set by server
*/ */
int httpClient::getSize(void) { int HTTPClient::getSize(void) {
return _size; return _size;
} }
@ -358,7 +358,7 @@ int httpClient::getSize(void) {
* returns the stream of the tcp connection * returns the stream of the tcp connection
* @return WiFiClient * @return WiFiClient
*/ */
WiFiClient & httpClient::getStream(void) { WiFiClient & HTTPClient::getStream(void) {
if(connected()) { if(connected()) {
return *_tcp; return *_tcp;
} }
@ -372,7 +372,7 @@ WiFiClient & httpClient::getStream(void) {
* returns the stream of the tcp connection * returns the stream of the tcp connection
* @return WiFiClient * * @return WiFiClient *
*/ */
WiFiClient * httpClient::getStreamPtr(void) { WiFiClient * HTTPClient::getStreamPtr(void) {
if(connected()) { if(connected()) {
return _tcp; return _tcp;
} }
@ -386,7 +386,7 @@ WiFiClient * httpClient::getStreamPtr(void) {
* @param stream Stream * * @param stream Stream *
* @return bytes written ( negative values are error codes ) * @return bytes written ( negative values are error codes )
*/ */
int httpClient::writeToStream(Stream * stream) { int HTTPClient::writeToStream(Stream * stream) {
if(!stream) { if(!stream) {
return HTTPC_ERROR_NO_STREAM; return HTTPC_ERROR_NO_STREAM;
@ -439,7 +439,7 @@ int httpClient::writeToStream(Stream * stream) {
* return all payload as String (may need lot of ram or trigger out of memory!) * return all payload as String (may need lot of ram or trigger out of memory!)
* @return String * @return String
*/ */
String httpClient::getString(void) { String HTTPClient::getString(void) {
StreamString sstring; StreamString sstring;
if(_size) { if(_size) {
@ -460,7 +460,7 @@ String httpClient::getString(void) {
* @param value * @param value
* @param first * @param first
*/ */
void httpClient::addHeader(const String& name, const String& value, bool first) { void HTTPClient::addHeader(const String& name, const String& value, bool first) {
// not allow set of Header handled by code // 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")) {
@ -478,7 +478,7 @@ void httpClient::addHeader(const String& name, const String& value, bool first)
} }
void httpClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) { void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) {
_headerKeysCount = headerKeysCount; _headerKeysCount = headerKeysCount;
if(_currentHeaders) if(_currentHeaders)
delete[] _currentHeaders; delete[] _currentHeaders;
@ -488,7 +488,7 @@ void httpClient::collectHeaders(const char* headerKeys[], const size_t headerKey
} }
} }
String httpClient::header(const char* name) { String HTTPClient::header(const char* name) {
for(size_t i = 0; i < _headerKeysCount; ++i) { for(size_t i = 0; i < _headerKeysCount; ++i) {
if(_currentHeaders[i].key == name) if(_currentHeaders[i].key == name)
return _currentHeaders[i].value; return _currentHeaders[i].value;
@ -496,23 +496,23 @@ String httpClient::header(const char* name) {
return String(); return String();
} }
String httpClient::header(size_t i) { String HTTPClient::header(size_t i) {
if(i < _headerKeysCount) if(i < _headerKeysCount)
return _currentHeaders[i].value; return _currentHeaders[i].value;
return String(); return String();
} }
String httpClient::headerName(size_t i) { String HTTPClient::headerName(size_t i) {
if(i < _headerKeysCount) if(i < _headerKeysCount)
return _currentHeaders[i].key; return _currentHeaders[i].key;
return String(); return String();
} }
int httpClient::headers() { int HTTPClient::headers() {
return _headerKeysCount; return _headerKeysCount;
} }
bool httpClient::hasHeader(const char* name) { bool HTTPClient::hasHeader(const char* name) {
for(size_t i = 0; i < _headerKeysCount; ++i) { for(size_t i = 0; i < _headerKeysCount; ++i) {
if((_currentHeaders[i].key == name) && (_currentHeaders[i].value.length() > 0)) if((_currentHeaders[i].key == name) && (_currentHeaders[i].value.length() > 0))
return true; return true;
@ -524,7 +524,7 @@ bool httpClient::hasHeader(const char* name) {
* init TCP connection and handle ssl verify if needed * init TCP connection and handle ssl verify if needed
* @return true if connection is ok * @return true if connection is ok
*/ */
bool httpClient::connect(void) { bool HTTPClient::connect(void) {
if(connected()) { if(connected()) {
DEBUG_HTTPCLIENT("[HTTP-Client] connect. already connected, try reuse!\n"); DEBUG_HTTPCLIENT("[HTTP-Client] connect. already connected, try reuse!\n");
@ -580,7 +580,7 @@ bool httpClient::connect(void) {
* @param type (GET, POST, ...) * @param type (GET, POST, ...)
* @return status * @return status
*/ */
bool httpClient::sendHeader(const char * type) { bool HTTPClient::sendHeader(const char * type) {
if(!connected()) { if(!connected()) {
return false; return false;
} }
@ -604,7 +604,7 @@ bool httpClient::sendHeader(const char * type) {
* reads the response from the server * reads the response from the server
* @return int http code * @return int http code
*/ */
int httpClient::handleHeaderResponse() { int HTTPClient::handleHeaderResponse() {
if(!connected()) { if(!connected()) {
return HTTPC_ERROR_NOT_CONNECTED; return HTTPC_ERROR_NOT_CONNECTED;

View File

@ -1,10 +1,10 @@
/** /**
* 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
@ -22,8 +22,8 @@
* *
*/ */
#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__ )
@ -43,10 +43,10 @@
#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 = "");
@ -126,4 +126,4 @@ class httpClient {
#endif /* ESP8266HTTPCLIENT_H_ */ #endif /* ESP8266HTTPClient_H_ */

View File

@ -405,19 +405,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;

View File

@ -81,11 +81,12 @@ public:
String path(_path); String path(_path);
if(path.endsWith("/")) path += "index.htm";
if (!_isFile) { if (!_isFile) {
// Base URI doesn't point to a file. Append whatever follows this // Base URI doesn't point to a file.
// URI in request to get the file path. // If a directory is requested, look for index file.
if (requestUri.endsWith("/")) requestUri += "index.htm";
// Append whatever follows this URI in request to get the file path.
path += requestUri.substring(_baseUriLength); 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);
@ -94,9 +95,9 @@ public:
// 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") && !_fs.exists(path)) {
String pathWithGz = path + ".gz"; String pathWithGz = path + ".gz";
if(SPIFFS.exists(pathWithGz)) if(_fs.exists(pathWithGz))
path += ".gz"; path += ".gz";
} }

View File

@ -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

View File

@ -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;

View File

@ -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);
}; };