mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-13 13:01:55 +03:00
Add WiFiClient parameter to HTTPClient (#4980)
Make HTTPClient take a WiFiClient parameter, allowing you to pass in a simple HTTP WiFiClient or a BearSSL or axTLS WiFiClientSecure with any desired verification options. Deprecate the older, TLSTraits methods. Add basic HttpsClient example. Add optional LED feedback to the Update class
This commit is contained in:
committed by
Earle F. Philhower, III
parent
9bc8ea1b58
commit
13f374666d
@ -35,9 +35,13 @@ 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"));
|
||||
@ -45,6 +49,12 @@ bool UpdaterClass::begin(size_t size, int command) {
|
||||
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.
|
||||
@ -360,11 +370,22 @@ 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);
|
||||
@ -372,6 +393,9 @@ size_t UpdaterClass::writeStream(Stream &data) {
|
||||
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;
|
||||
|
@ -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
|
||||
@ -162,6 +162,10 @@ class UpdaterClass {
|
||||
|
||||
String _target_md5;
|
||||
MD5Builder _md5;
|
||||
|
||||
int _ledPin;
|
||||
uint8_t _ledOn;
|
||||
int _ledStateRestore;
|
||||
};
|
||||
|
||||
extern UpdaterClass Update;
|
||||
|
Reference in New Issue
Block a user