Merge branch 'wellenvogel:master' into master

This commit is contained in:
Norbert Walter 2024-09-13 10:00:11 +02:00 committed by GitHub
commit 185bf91a7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 1662 additions and 535 deletions

View File

@ -4,6 +4,7 @@
#include <ArduinoJson.h>
#include <string.h>
#include <MD5Builder.h>
#include <esp_partition.h>
using CfgInit=std::function<void(GwConfigHandler *)>;
static std::vector<CfgInit> cfgInits;
#define CFG_INIT(name,value,mode) \
@ -96,15 +97,36 @@ bool GwConfigHandler::updateValue(String name, String value){
if (i->asString() == value){
return false;
}
LOG_DEBUG(GwLog::LOG,"update config %s=>%s",name.c_str(),i->isSecret()?"***":value.c_str());
prefs->begin(PREF_NAME,false);
prefs->putString(i->getName().c_str(),value);
LOG_DEBUG(GwLog::LOG,"update config %s=>%s, freeEntries=%d",name.c_str(),i->isSecret()?"***":value.c_str(),(int)(prefs->freeEntries()));
prefs->end();
}
return true;
}
bool GwConfigHandler::reset(){
LOG_DEBUG(GwLog::LOG,"reset config");
LOG_DEBUG(GwLog::ERROR,"reset config");
//try to find the nvs partition
//currently we only support the default
bool wiped=false;
const esp_partition_t *nvspart=esp_partition_find_first(ESP_PARTITION_TYPE_DATA,ESP_PARTITION_SUBTYPE_DATA_NVS,"nvs");
if (nvspart != NULL){
LOG_DEBUG(GwLog::ERROR,"wiping nvs partition");
esp_err_t err=esp_partition_erase_range(nvspart,0,nvspart->size);
if (err != ESP_OK){
LOG_DEBUG(GwLog::ERROR,"wiping nvs partition failed: %d",(int)err);
}
else{
wiped=true;
}
}
else{
LOG_DEBUG(GwLog::ERROR,"nvs partition not found");
}
if (wiped){
return true;
}
LOG_DEBUG(GwLog::ERROR,"unable to wipe nvs partition, trying to reset values");
prefs->begin(PREF_NAME,false);
for (int i=0;i<getNumConfig();i++){
prefs->putString(configs[i]->getName().c_str(),configs[i]->getDefault());

View File

@ -1,3 +1,4 @@
#include <esp_wifi.h>
#include "GWWifi.h"
@ -35,7 +36,29 @@ void GwWifi::setup(){
LOG_DEBUG(GwLog::ERROR,"unable to set access point mask %s, falling back to %s",
apMask.c_str(),AP_subnet.toString().c_str());
}
//try to remove any existing config from nvs
//this will avoid issues when updating from framework 6.3.2 to 6.8.1 - see #78
//we do not need the nvs config any way - so we set persistent to false
//unfortunately this will be to late (config from nvs has already been loaded)
//if we update from an older version that has config in the nvs
//so we need to make a dummy init, erase the flash and deinit
wifi_config_t conf_current;
wifi_init_config_t conf=WIFI_INIT_CONFIG_DEFAULT();
esp_err_t err=esp_wifi_init(&conf);
esp_wifi_get_config((wifi_interface_t)WIFI_IF_AP, &conf_current);
LOG_DEBUG(GwLog::DEBUG,"Wifi AP old config before reset ssid=%s, pass=%s, channel=%d",conf_current.ap.ssid,conf_current.ap.password,conf_current.ap.channel);
if (err){
LOG_DEBUG(GwLog::ERROR,"unable to pre-init wifi: %d",(int)err);
}
err=esp_wifi_restore();
if (err){
LOG_DEBUG(GwLog::ERROR,"unable to reset wifi: %d",(int)err);
}
err=esp_wifi_deinit();
WiFi.persistent(false);
WiFi.mode(WIFI_MODE_APSTA); //enable both AP and client
esp_wifi_get_config((wifi_interface_t)WIFI_IF_AP, &conf_current);
LOG_DEBUG(GwLog::DEBUG,"Wifi AP old config after reset ssid=%s, pass=%s, channel=%d",conf_current.ap.ssid,conf_current.ap.password,conf_current.ap.channel);
const char *ssid=config->getConfigItem(config->systemName)->asCString();
if (fixedApPass){
WiFi.softAP(ssid,AP_password);
@ -45,7 +68,7 @@ void GwWifi::setup(){
}
delay(100);
WiFi.softAPConfig(AP_local_ip, AP_gateway, AP_subnet);
LOG_DEBUG(GwLog::LOG,"WifiAP created: ssid=%s,adress=%s",
LOG_DEBUG(GwLog::ERROR,"WifiAP created: ssid=%s,adress=%s",
ssid,
WiFi.softAPIP().toString().c_str()
);

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import {ESPLoader,Transport} from "https://cdn.jsdelivr.net/npm/esptool-js@0.2.1/bundle.js";
import {ESPLoader,Transport} from "https://cdn.jsdelivr.net/npm/esptool-js@0.4.5/bundle.js";
/**
* write all messages to the console
*/
@ -102,10 +102,14 @@ class ESPInstaller{
await this.consoleReader.cancel();
this.consoleReader=undefined;
}
await this.consoleDevice.close();
}catch(e){
console.log(`error cancel serial read ${e}`);
}
try{
await this.consoleDevice.close();
}catch(e){
console.log('error closing console device', this.consoleDevice,e);
}
this.consoleDevice=undefined;
}
if (this.transport){
@ -126,13 +130,17 @@ class ESPInstaller{
}
try {
this.transport = new Transport(device);
this.esploader = new ESPLoader(this.transport, 115200, this.espLoaderTerminal);
let foundChip = await this.esploader.main_fn();
this.esploader = new ESPLoader({
transport:this.transport,
baudrate: 115200,
terminal: this.espLoaderTerminal});
//this.esploader.debugLogging=true;
let foundChip = await this.esploader.main();
if (!foundChip) {
throw new Error("unable to read chip id");
}
this.espLoaderTerminal.writeLine(`chip: ${foundChip}`);
await this.esploader.flash_id();
//await this.esploader.flashId();
this.chipFamily = this.esploader.chip.CHIP_NAME;
this.imageChipId = this.esploader.chip.IMAGE_CHIP_ID;
this.espLoaderTerminal.writeLine(`chipFamily: ${this.chipFamily}`);
@ -198,12 +206,17 @@ class ESPInstaller{
async writeFlash(fileList){
this.checkConnected();
this.espLoaderTerminal.writeLine(`Flashing....`);
await this.esploader.write_flash(
fileList,
"keep",
"keep",
"keep",
false
await this.esploader.writeFlash({
fileArray: fileList,
flashSize: "keep",
flashMode: "keep",
flashFreq: "keep",
eraseAll: false,
compress: true,
/*reportProgress: (fileIndex, written, total)=>{
this.espLoaderTerminal.writeLine(`file ${fileIndex}: ${written}/${total}`);
}*/
}
)
await this.resetTransport();
this.espLoaderTerminal.writeLine(`Done.`);