Skip to content

Commit

Permalink
Merge branch 'master' into asl-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
GregAscolab committed Sep 5, 2024
2 parents 067d9fd + 8a1e732 commit 77fe5d3
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 53 deletions.
2 changes: 1 addition & 1 deletion built-in-webpages/setup/build_setup/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
If you want customize **/setup** webpage (headers, logo etc etc):
* edit the source files as your needs (setup.htm, app.js, style.css)
* open a terminal in *build* folder and run `npm i` to install all nodejs modules needed
* run `node minimize.js`
* run `node minify.js`
* overwrite the content of *setup_htm.h* in src folder with the new generated file
3 changes: 2 additions & 1 deletion examples/customHTML/thingsboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ function createNewDevice() {
var token = $(TB_DEVICE_TOKEN);
token.focus();
token.value = obj.credentialsValue;
openModalMessage('Write device attributes', 'Device provisioned correctly.<br>Do you want to set client attributes on ThingsBoard server?', setDeviceClientAttribute);
options[token.id] = token.value; // Manual update, because, it doesn't fire "change" event...
openModal('Write device attributes', 'Device provisioned correctly.<br>Do you want to set client attributes on ThingsBoard server?', setDeviceClientAttribute);
});
}

Expand Down
9 changes: 6 additions & 3 deletions examples/remoteOTA/data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,19 @@ <h1>ESP FS WebServer - Remote OTA update</h1>
function checkNewFirmware () {
document.getElementById('check-fw').setAttribute('aria-busy', true);
document.getElementById('current-fw').setAttribute('aria-busy', true);
const url = 'https://corsproxy.io/?' + encodeURIComponent(firmware_info);

fetch(url)
console.log(firmware_info);
fetch(firmware_info)
.then(response => response.json())
.then(obj => {
if (compareVersion(obj.version, actual_version) === 1) {
// Prompt the user for confirmation
if (confirm(`Firmware version ${obj.version} available.\n Are you sure you want to proceed with firmware update?`)) {
updateFirmware(obj);
}
else {
document.getElementById('check-fw').setAttribute('aria-busy', false);
document.getElementById('current-fw').setAttribute('aria-busy', false);
}
}
else {
alert("No new version available");
Expand Down
Binary file modified examples/remoteOTA/fw-esp32/firmware.bin
Binary file not shown.
Binary file modified examples/remoteOTA/fw-esp8266/firmware.bin
Binary file not shown.
41 changes: 22 additions & 19 deletions examples/remoteOTA/remoteOTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ uint8_t ledPin = LED_BUILTIN;
bool apMode = false;

#ifdef ESP8266
String fimwareInfo = "https://github.com/cotestatnt/async-esp-fs-webserver/raw/main/examples/remoteOTA/version-esp8266.json";
String fimwareInfo = "https://raw.githubusercontent.com/cotestatnt/async-esp-fs-webserver/master/examples/remoteOTA/version-esp8266.json";
#elif defined(ESP32)
String fimwareInfo = "https://github.com/cotestatnt/async-esp-fs-webserver/raw/main/examples/remoteOTA/version-esp32.json";
String fimwareInfo = "https://raw.githubusercontent.com/cotestatnt/async-esp-fs-webserver/master/examples/remoteOTA/version-esp32.json";
#endif

char fw_version[10] = {"0.0.0"};
Expand All @@ -41,7 +41,16 @@ void doUpdate(const char* url, const char* version) {
#define UPDATER ESPhttpUpdate
#elif defined(ESP32)
#define UPDATER httpUpdate
esp_task_wdt_init(30, 1);
#if ESP_ARDUINO_VERSION_MAJOR > 2
esp_task_wdt_config_t twdt_config = {
.timeout_ms = 15*1000,
.idle_core_mask = (1 << portNUM_PROCESSORS) - 1, // Bitmask of all cores
.trigger_panic = false,
};
ESP_ERROR_CHECK(esp_task_wdt_reconfigure(&twdt_config));
#else
ESP_ERROR_CHECK(esp_task_wdt_init(15, 0));
#endif
#endif

// onProgress handling is missing with ESP32 library
Expand Down Expand Up @@ -174,40 +183,34 @@ void setup(){
EEPROM.begin(128);

// Try to connect to flash stored SSID, start AP if fails after timeout
IPAddress myIP = server.startWiFi(30000, "ESP_AP", "123456789" );
(void) myIP; // return value is not used
// WiFi.persistent(true);
// WiFi.begin("PuccosNET", "Tole76tnt");
// uint32_t beginTime = millis();
// while (WiFi.status() != WL_CONNECTED && millis() - beginTime < 30000) {
// delay(500);
// Serial.print(".");
// }
IPAddress myIP = server.startWiFi(15000, "ESP_AP", "123456789" );

// FILESYSTEM INIT
startFilesystem();

// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();

/*
* Getting FS info (total and free bytes) is strictly related to
* filesystem library used (LittleFS, FFat, SPIFFS etc etc) and ESP framework
*/
#ifdef ESP32
server.setFsInfoCallback([](fsInfo_t* fsInfo) {
fsInfo->fsName = "LittleFS";
fsInfo->totalBytes = LittleFS.totalBytes();
fsInfo->usedBytes = LittleFS.usedBytes();
fsInfo->fsName = "LittleFS";
fsInfo->totalBytes = LittleFS.totalBytes();
fsInfo->usedBytes = LittleFS.usedBytes();
});
#endif

// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();

// Add custom handlers to webserver
server.on("/led", HTTP_GET, handleLed);
server.on("/firmware_update", HTTP_GET, handleUpdate);

// Add handler as lambda function (just to show a different method)
server.on("/version", HTTP_GET, [](AsyncWebServerRequest *request) {
server.getOptionValue("New firmware JSON", fimwareInfo);

EEPROM.get(0, fw_version);
if (fw_version[0] == 0xFF) // Still not stored in EEPROM (first run)
strcpy(fw_version, "0.0.0");
Expand Down Expand Up @@ -237,5 +240,5 @@ void setup(){

/////////////////////////////////// LOOP ///////////////////////////////////////
void loop() {

delay(10);
}
2 changes: 1 addition & 1 deletion examples/remoteOTA/version-esp32.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0.1",
"raw_url": "https://github.com/cotestatnt/async-esp-fs-webserver/raw/main/examples/remoteOTA/fw-esp32/firmware.bin"
"raw_url": "https://github.com/cotestatnt/async-esp-fs-webserver/raw/master/examples/remoteOTA/fw-esp32/firmware.bin"
}
2 changes: 1 addition & 1 deletion examples/remoteOTA/version-esp8266.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0.1",
"raw_url": "https://github.com/cotestatnt/async-esp-fs-webserver/raw/main/examples/remoteOTA/fw-esp8266/firmware.bin"
"raw_url": "https://github.com/cotestatnt/async-esp-fs-webserver/raw/master/examples/remoteOTA/fw-esp8266/firmware.bin"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AsyncEspFsWebserver
version=1.0.5
version=1.0.7
author=Tolentino Cotesta <[email protected]>
maintainer=Tolentino Cotesta <[email protected]>
sentence=ESPAsyncWebserver with steroids
Expand Down
7 changes: 3 additions & 4 deletions src/AsyncFsWebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ bool AsyncFsWebServer::startCaptivePortal(const char* ssid, const char* pass, co
void AsyncFsWebServer::handleWebSocket(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t * data, size_t len) {
switch (type) {
case WS_EVT_CONNECT:
client->printf("{\"Websocket connected\": true, \"clients\": %u}", client->id());
client->printf("{\"Websocket connected\": true, \"clients\": %lu}", client->id());
break;
case WS_EVT_DISCONNECT:
client->printf("{\"Websocket connected\": false, \"clients\": 0}");
Expand All @@ -165,7 +165,7 @@ void AsyncFsWebServer::handleWebSocket(AsyncWebSocket * server, AsyncWebSocketCl
String msg = "";
if(info->final && info->index == 0 && info->len == len){
//the whole message is in a single frame and we got all of it's data
Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len);
Serial.printf("ws[%s][%lu] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len);
if (info->opcode == WS_TEXT){
for(size_t i=0; i < info->len; i++) {
msg += (char) data[i];
Expand Down Expand Up @@ -676,7 +676,7 @@ IPAddress AsyncFsWebServer::startWiFi(uint32_t timeout, CallbackF fn, bool skipA
if (!m_apSSID.length()) {
char _ssid[21];
#ifdef ESP8266
snprintf(ssid, sizeof(ssid), "ESP-%dX", ESP.getChipId());
snprintf(_ssid, sizeof(_ssid), "ESP-%dX", ESP.getChipId());
#elif defined(ESP32)
snprintf(_ssid, sizeof(_ssid), "ESP-%llX", ESP.getEfuseMac());
#endif
Expand Down Expand Up @@ -886,7 +886,6 @@ void AsyncFsWebServer::handleFsStatus(AsyncWebServerRequest *request)
getFsInfo(&info);
}
String json;
json.reserve(128);
json = "{\"type\":\"";
json += info.fsName;
json += "\", \"isOk\":";
Expand Down
22 changes: 8 additions & 14 deletions src/ESPAsyncWebServer/src/AsyncWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@
*/
#include "Arduino.h"
#include "AsyncWebSocket.h"

#include "../../SerialLog.h"
#include <libb64/cencode.h>

// #ifndef ESP8266
// #include "mbedtls/sha1.h"
// #else
// #include <Hash.h>
// #endif

#ifdef ESP8266
#include "mbedtls/sha1.h"
#include <Hash.h>
#else
#if ESP_ARDUINO_VERSION_MAJOR > 2
#include "SHA1Builder.h"
#else
#include <Hash.h>
#include "mbedtls/sha1.h"
#endif
#endif

Expand Down Expand Up @@ -629,7 +623,7 @@ void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage *dataMessage){
return;
}
if(_messageQueue.length() >= WS_MAX_QUEUED_MESSAGES){
log_e("ERROR: Too many messages queued");
log_error("ERROR: Too many messages queued");
// Serial.printf("%u Q3\n", _clientId);
delete dataMessage;
} else {
Expand Down Expand Up @@ -776,7 +770,7 @@ void AsyncWebSocketClient::_onData(void *pbuf, size_t plen){
} else if(_pinfo.opcode < 8){//continuation or text/binary frame
_server->_handleEvent(this, WS_EVT_DATA, (void *)&_pinfo, data, datalen);
if (_pinfo.final) _pinfo.num = 0;
else _pinfo.num += 1;
else _pinfo.num += 1;
}
} else {
//os_printf("frame error: len: %u, index: %llu, total: %llu\n", datalen, _pinfo.index, _pinfo.len);
Expand Down Expand Up @@ -1272,14 +1266,14 @@ void AsyncWebSocket::handleRequest(AsyncWebServerRequest *request){
if((_username.length() && _password.length()) && !request->authenticate(_username.c_str(), _password.c_str())){
return request->requestAuthentication();
}
//////////////////////////////////////////
//////////////////////////////////////////
if(_handshakeHandler != nullptr){
if(!_handshakeHandler(request)){
request->send(401);
return;
}
}
//////////////////////////////////////////
//////////////////////////////////////////
AsyncWebHeader* version = request->getHeader(WS_STR_VERSION);
if(version->value().toInt() != 13){
AsyncWebServerResponse *response = request->beginResponse(400);
Expand Down Expand Up @@ -1367,7 +1361,7 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
sha1.calculate();
sha1.getBytes(hash);
#else

(String&)key += WS_STR_UUID;
mbedtls_sha1_context ctx;
mbedtls_sha1_init(&ctx);
Expand Down
6 changes: 3 additions & 3 deletions src/SerialLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ extern "C"
{
#endif

#define __FILE_NAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define _LOG_FORMAT(letter, format) "\n["#letter"][%s:%u] %s():\t" format, __FILE_NAME__, __LINE__, __FUNCTION__
#define __SOURCE_FILE_NAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define _LOG_FORMAT(letter, format) "\n["#letter"][%s:%u] %s():\t" format, __SOURCE_FILE_NAME__, __LINE__, __FUNCTION__

#if LOG_LEVEL == 0
#define log_error(format, ...)
#define log_error(format, ...)
#define log_info(format, ...)
#define log_debug(format, ...)
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "AsyncFsWebServer.h"
const char* AsyncFsWebServer::getVersion() {
return "1.0.5";
return "1.0.7";
}
4 changes: 0 additions & 4 deletions src/version.cpp

This file was deleted.

0 comments on commit 77fe5d3

Please sign in to comment.