Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/http update wi fi client parameter #4980

Merged
merged 49 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ff2858a
Function added to detect baudrate
Jul 29, 2018
588d03b
Two begin() methods added to pass WiFiClient
Jul 29, 2018
5d95871
Two begin() methods added to pass WiFiClient, updated examples
Jul 29, 2018
481d080
Merge branch 'feature/HTTPClient_WiFiClient_parameter' into feature/H…
Jul 29, 2018
f9ae2c4
Two begin() methods added to pass WiFiClient, updated examples
Jul 29, 2018
7b134cb
update() functions and updateSpiffs() function added to pass a WiFiCl…
Jul 29, 2018
d0d7466
Merge branch 'master' into feature/HTTPClient_WiFiClient_parameter
Aug 3, 2018
ac3dbc2
Merge branch 'master' into feature/HTTPUpdate_WiFiClient_parameter
Aug 3, 2018
96636f2
Merge branch 'master' into feature/HTTPClient_WiFiClient_parameter
Aug 3, 2018
02637d2
Merge branch 'master' into feature/HTTPUpdate_WiFiClient_parameter
Aug 3, 2018
5aff343
Merge branch 'master' into feature/HTTPClient_WiFiClient_parameter
Aug 20, 2018
d4db72d
add basicHttpsClient example, ensured in the backward compatible func…
Aug 20, 2018
2807373
Merge branch 'master' into feature/HTTPClient_WiFiClient_parameter
Aug 20, 2018
815fb0f
Adding #pragma's to suppress Travis Build warning for use of deprecat…
Aug 21, 2018
2047402
Adding #pragma's to suppress Travis Build warning for use of deprecat…
Aug 21, 2018
5ff9728
Adding #pragma's to suppress Travis Build warning for use of deprecat…
Aug 21, 2018
11ea32a
Adding #pragma's to suppress Travis Build warning for use of deprecat…
Aug 21, 2018
cfd977c
revert accidentally changed files ESP8266httpUpdate.h and .cpp to ori…
Aug 21, 2018
dc20696
Adding #pragma's to ESP8266httpUpdate.cpp to ignore use of deprecated…
Aug 21, 2018
156b506
Work in progress
Aug 21, 2018
5a16a6a
Work in progress
Aug 22, 2018
29e7754
Allocate BearSSL::WiFiClientSecure dynamically in StreamHttpsClient.ino
Aug 22, 2018
47e0e38
Merge branch 'feature/HTTPClient_WiFiClient_parameter' into feature/H…
Aug 22, 2018
6fe03e3
Added one \n
Aug 22, 2018
fba638c
Bugfix in getStream() and getStreamPtr()
Aug 22, 2018
f4c0129
Merge branch 'feature/HTTPClient_WiFiClient_parameter' into feature/H…
Aug 22, 2018
4fb6236
Updated examples httpUpdate.ino and httpUpdateSecure.ino
Aug 22, 2018
7c19eb2
Indentation to pass Travis and removed comment
Aug 22, 2018
af95fc0
Added #pragma's around calls to deprecated functions from deprecated …
Aug 23, 2018
ae41ad7
Moving httpUpdateSPIFFS.ino to new API
Aug 23, 2018
fd795c1
Merge branch 'master' into feature/HTTPUpdate_WiFiClient_parameter
d-a-v Sep 19, 2018
43741de
Merge branch 'master' into feature/HTTPUpdate_WiFiClient_parameter
devyte Sep 22, 2018
577c2cf
Merge branch 'master' into feature/HTTPUpdate_WiFiClient_parameter
d-a-v Sep 28, 2018
9c6515c
Merge branch 'master' into feature/HTTPUpdate_WiFiClient_parameter
Oct 2, 2018
208a25c
Merge branch 'master' into feature/HTTPUpdate_WiFiClient_parameter
earlephilhower Oct 3, 2018
1593266
Exit writeSteam() on received bytes in stead of timeout and add visua…
Oct 5, 2018
18cb311
Merge branch 'feature/HTTPUpdate_WiFiClient_parameter' of https://git…
Oct 5, 2018
d1eab93
Removed unnecessary references to _tcpDeprecated and unnecessary #ifdefs
Oct 5, 2018
fc3517c
Make LED status optional
Oct 5, 2018
284e3c6
Make LED feedback optional
Oct 5, 2018
fbe28fd
Merge branch 'feature/Updater/flashLED' into feature/HTTPUpdate_WiFiC…
Oct 5, 2018
bc897d5
Give optional feedback (provided by additional feature on Update clas…
Oct 5, 2018
8eeaa01
Removing extraneous debug comment
Oct 5, 2018
2e7c7a9
Updated the examples with setLedPin() including an explanation of the…
Oct 5, 2018
b3571bc
Remove trailing space causing CI to fail.
earlephilhower Oct 5, 2018
5126cfa
Remove trailing space causing CI to fail.
earlephilhower Oct 5, 2018
7ce28bd
Remove trailing space causing CI to fail.
earlephilhower Oct 5, 2018
e5c253f
Merge branch 'master' into feature/HTTPUpdate_WiFiClient_parameter
d-a-v Oct 5, 2018
5a20da5
Fix ::connect() to work for legacy API
earlephilhower Oct 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,26 @@ void UpdaterClass::_reset() {
_currentAddress = 0;
_size = 0;
_command = U_FLASH;

if(_ledPin != -1) {
digitalWrite(_ledPin, _ledStateRestore);
}
}

bool UpdaterClass::begin(size_t size, int command) {
bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
if(_size > 0){
#ifdef DEBUG_UPDATER
DEBUG_UPDATER.println(F("[begin] already running"));
#endif
return false;
}

_ledPin = ledPin;
_ledOn = ledOn;
if(_ledPin != -1) {
_ledStateRestore = digitalRead(_ledPin);
}

/* Check boot mode; if boot mode is 1 (UART download mode),
we will not be able to reset into normal mode once update is done.
Fail early to avoid frustration.
Expand Down Expand Up @@ -360,18 +370,32 @@ size_t UpdaterClass::writeStream(Stream &data) {
return 0;
}

if(_ledPin != -1) {
pinMode(_ledPin, OUTPUT);
}

while(remaining()) {
toRead = data.readBytes(_buffer + _bufferLen, (_bufferSize - _bufferLen));
if(_ledPin != -1) {
digitalWrite(LED_BUILTIN, _ledOn); // Switch LED on
}
size_t bytesToRead = _bufferSize - _bufferLen;
if(bytesToRead > remaining()) {
bytesToRead = remaining();
}
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
if(toRead == 0) { //Timeout
delay(100);
toRead = data.readBytes(_buffer + _bufferLen, (_bufferSize - _bufferLen));
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
if(toRead == 0) { //Timeout
_currentAddress = (_startAddress + _size);
_setError(UPDATE_ERROR_STREAM);
_reset();
return written;
}
}
if(_ledPin != -1) {
digitalWrite(LED_BUILTIN, _ledOn == HIGH ? LOW : HIGH); // Switch LED off
}
_bufferLen += toRead;
if((_bufferLen == remaining() || _bufferLen == _bufferSize) && !_writeBuffer())
return written;
Expand Down
6 changes: 5 additions & 1 deletion cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 command = U_FLASH);
bool begin(size_t size, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW);

/*
Run Updater from asynchronous callbacs
Expand Down Expand Up @@ -162,6 +162,10 @@ class UpdaterClass {

String _target_md5;
MD5Builder _md5;

int _ledPin;
uint8_t _ledOn;
int _ledStateRestore;
};

extern UpdaterClass Update;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial
#include <WiFiClient.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {

USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
Serial.begin(115200);
// Serial.setDebugOutput(true);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
Serial.println();
Serial.println();
Serial.println();

for (uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
Serial.printf("[SETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}

Expand All @@ -40,46 +40,47 @@ void loop() {
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {

WiFiClient client;

HTTPClient http;

USE_SERIAL.print("[HTTP] begin...\n");
Serial.print("[HTTP] begin...\n");
// configure traged server and url


http.begin("http://user:password@192.168.1.12/test.html");
http.begin(client, "http://guest:guest@jigsaw.w3.org/HTTP/Basic/");

/*
// or
http.begin("http://192.168.1.12/test.html");
http.setAuthorization("user", "password");
http.begin(client, "http://jigsaw.w3.org/HTTP/Basic/");
http.setAuthorization("guest", "guest");

// or
http.begin("http://192.168.1.12/test.html");
http.setAuthorization("dXNlcjpwYXN3b3Jk");
http.begin(client, "http://jigsaw.w3.org/HTTP/Basic/");
http.setAuthorization("Z3Vlc3Q6Z3Vlc3Q=");
*/


USE_SERIAL.print("[HTTP] GET...\n");
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();

// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
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);
Serial.println(payload);
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
}

delay(10000);
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial
#include <WiFiClient.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {

USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
Serial.begin(115200);
// Serial.setDebugOutput(true);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
Serial.println();
Serial.println();
Serial.println();

for (uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
Serial.printf("[SETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}

Expand All @@ -40,34 +40,37 @@ void loop() {
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {

WiFiClient client;

HTTPClient http;

USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
//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
Serial.print("[HTTP] begin...\n");
if (http.begin(client, "http://jigsaw.w3.org/HTTP/connection.html")) { // HTTP


USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();

// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
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);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
Serial.printf("[HTTP} Unable to connect\n");
}

http.end();
}

delay(10000);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
BasicHTTPSClient.ino

Created on: 20.08.2018

*/

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#include <WiFiClientSecureBearSSL.h>
// Fingerprint for demo URL, expires on June 2, 2019, needs to be updated well before this date
const uint8_t fingerprint[20] = {0x5A, 0xCF, 0xFE, 0xF0, 0xF1, 0xA6, 0xF4, 0x5F, 0xD2, 0x11, 0x11, 0xC6, 0x1D, 0x2F, 0x0E, 0xBC, 0x39, 0x8D, 0x50, 0xE0};

ESP8266WiFiMulti WiFiMulti;

void setup() {

Serial.begin(115200);
// Serial.setDebugOutput(true);

Serial.println();
Serial.println();
Serial.println();

for (uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}

WiFi.mode(WIFI_STA);
WiFiMulti.addAP("SSID", "PASSWORD");
}

void loop() {
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {

BearSSL::WiFiClientSecure client;
client.setFingerprint(fingerprint);

HTTPClient https;

Serial.print("[HTTPS] begin...\n");
if (https.begin(client, "https://jigsaw.w3.org/HTTP/connection.html")) { // HTTPS


Serial.print("[HTTPS] GET...\n");
// start connection and send HTTP header
int httpCode = https.GET();

// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);

// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}

https.end();
} else {
Serial.printf("[HTTPS] Unable to connect\n");
}
}

delay(10000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#include <ESP8266HTTPClient.h>

const char* ssid = "........";
const char* ssidPassword = "........";
const char* ssid = "SSID";
const char* ssidPassword = "PASSWORD";

const char *username = "admin";
const char *password = "admin";
Expand Down Expand Up @@ -76,7 +76,7 @@ String getDigestAuth(String& authReq, const String& username, const String& pass
}

void setup() {
Serial.begin(9600);
Serial.begin(115200);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, ssidPassword);
Expand All @@ -95,10 +95,12 @@ void setup() {
void loop() {
HTTPClient http;

WiFiClient client;

Serial.print("[HTTP] begin...\n");

// configure traged server and url
http.begin(String(server) + String(uri));
http.begin(client, String(server) + String(uri));


const char *keys[] = {"WWW-Authenticate"};
Expand All @@ -115,7 +117,7 @@ void loop() {
String authorization = getDigestAuth(authReq, String(username), String(password), String(uri), 1);

http.end();
http.begin(String(server) + String(uri));
http.begin(client, String(server) + String(uri));

http.addHeader("Authorization", authorization);

Expand Down
Loading