Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified code/espurna/data/index.all.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.light.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.lightfox.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfbridge.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfm69.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.sensor.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.small.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.thermostat.html.gz
Binary file not shown.
39 changes: 19 additions & 20 deletions code/espurna/libs/URL.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@

#pragma once

struct URL {
String value;
String protocol;
String host;
String path;
uint16_t port;

URL(const char* url) { init(url); }
URL(const String& url) { init(url); }
class URL {
public:
URL(const String&);

void init(String url);
String protocol;
String host;
String path;
uint16_t port;

private:
String buffer;
};

void URL::init(String url) {

this->value = url;
URL::URL(const String& url) : buffer(url) {

// cut the protocol part
int index = url.indexOf("://");
int index = buffer.indexOf("://");
if (index > 0) {
this->protocol = url.substring(0, index);
url.remove(0, (index + 3));
this->protocol = buffer.substring(0, index);
buffer.remove(0, (index + 3));
}

if (this->protocol == "http") {
Expand All @@ -41,17 +40,17 @@ void URL::init(String url) {
// cut the host part
String _host;

index = url.indexOf('/');
index = buffer.indexOf('/');
if (index >= 0) {
_host = url.substring(0, index);
_host = buffer.substring(0, index);
} else {
_host = url;
_host = buffer;
}

// store the remaining part as path
if (index >= 0) {
url.remove(0, index);
this->path = url;
buffer.remove(0, index);
this->path = buffer;
} else {
this->path = "/";
}
Expand Down
76 changes: 76 additions & 0 deletions code/espurna/ota.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*

OTA COMMON FUNCTIONS

*/

#pragma once

#include <Updater.h>

void otaPrintError() {
if (Update.hasError()) {
#if TERMINAL_SUPPORT
Update.printError(terminalSerial());
#elif DEBUG_SERIAL_SUPPORT && defined(DEBUG_PORT)
Update.printError(DEBUG_PORT);
#endif
}
}

bool otaFinalize(size_t size, int reason, bool evenIfRemaining = false) {
if (Update.isRunning() && Update.end(evenIfRemaining)) {
DEBUG_MSG_P(PSTR("[OTA] Success: %7u bytes\n"), size);
deferredReset(500, reason);
return true;
}

otaPrintError();
eepromRotate(true);

return false;
}

// Helper methods from UpdaterClass that need to be called manually for async mode,
// because we are not using Stream interface to feed it data.
bool otaVerifyHeader(uint8_t* data, size_t len) {
if (len < 4) {
return false;
}

// ref: https://github.com/esp8266/Arduino/pull/6820
// accept gzip, let unpacker figure things out later
if (data[0] == 0x1F && data[1] == 0x8B) {
return true;
}

// Check for magic byte with a normal .bin
if (data[0] != 0xE9) {
return false;
}

// Make sure that flash config can be recognized and fit the flash
const auto flash_config = ESP.magicFlashChipSize((data[3] & 0xf0) >> 4);
if (flash_config && (flash_config > ESP.getFlashChipRealSize())) {
return false;
}

return true;
}

void otaProgress(size_t bytes, size_t each = 8192u) {
// Removed to avoid websocket ping back during upgrade (see #1574)
// TODO: implement as separate from debugging message
if (wsConnected()) return;

// Telnet and serial will still output things, but slightly throttled
static size_t last = 0;
if (bytes < last) {
last = 0;
}

if ((bytes > each) && (bytes - each > last)) {
DEBUG_MSG_P(PSTR("[OTA] Progress: %7u bytes\r"), bytes);
last = bytes;
}
}
Loading