From cff6c02d575c9e40cc5acae4f4a427e315855dd5 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Fri, 22 May 2020 22:26:31 +0200 Subject: [PATCH] Some cleanup and changes. Trying to get self-update to work, no luck --- src/AmsToMqttBridge.ino | 7 +++++-- src/web/AmsWebServer.cpp | 22 ++++++++++------------ web/application.js | 13 +++++++++++++ web/configmqtt.html | 2 +- web/configsystem.html | 2 +- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index a67480ba..c4afe2c1 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -142,8 +142,9 @@ void setup() { hw.setVccMultiplier(config.getVccMultiplier()); hw.ledBlink(LED_INTERNAL, 1); hw.ledBlink(LED_RED, 1); - hw.ledBlink(LED_GREEN, 1); hw.ledBlink(LED_YELLOW, 1); + hw.ledBlink(LED_GREEN, 1); + hw.ledBlink(LED_BLUE, 1); if(config.getHanPin() == 3) { if(config.getMeterType() == 3) { @@ -214,8 +215,9 @@ void setup() { i++; } - if(Debug.isActive(RemoteDebug::INFO)) debugI(" flashing"); + debugI(" flashing"); File firmwareFile = SPIFFS.open(FILE_FIRMWARE, "r"); + debugD(" firmware size: %d", firmwareFile.size()); uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; if (!Update.begin(maxSketchSpace, U_FLASH)) { if(Debug.isActive(RemoteDebug::ERROR)) { @@ -239,6 +241,7 @@ void setup() { debugI("Firmware update complete, restarting"); Serial.flush(); } + delay(250); #if defined(ESP8266) ESP.reset(); #elif defined(ESP32) diff --git a/src/web/AmsWebServer.cpp b/src/web/AmsWebServer.cpp index 5dd753cb..3b8d047f 100644 --- a/src/web/AmsWebServer.cpp +++ b/src/web/AmsWebServer.cpp @@ -757,12 +757,6 @@ void AmsWebServer::handleSave() { if(!config->isDebugTelnet()) { debugger->stop(); } - - hw->setLed(config->getLedPin(), config->isLedInverted()); - hw->setLedRgb(config->getLedPinRed(), config->getLedPinGreen(), config->getLedPinBlue(), config->isLedRgbInverted()); - hw->setTempSensorPin(config->getTempSensorPin()); - hw->setVccPin(config->getVccPin()); - hw->setVccMultiplier(config->getVccMultiplier()); } printI("Saving configuration now..."); @@ -948,17 +942,18 @@ void AmsWebServer::firmwareDownload() { String versionStripped = version.substring(1); printI("Downloading firmware..."); WiFiClientSecure client; - //client.setFingerprint(githubFingerprint); #if defined(ESP8266) - client.setInsecure(); client.setBufferSizes(512, 512); + client.setInsecure(); #endif + String url = "https://github.com/gskjold/AmsToMqttBridge/releases/download/" + version + "/ams2mqtt-esp12e-" + versionStripped + ".bin"; HTTPClient https; - String url = "https://github.com/gskjold/AmsToMqttBridge/releases/download/" + version + "/ams2mqtt-d1mini-" + versionStripped + ".bin"; -/* The following does not work... Maybe someone will make it work in the future? +#if defined(ESP8266) https.setFollowRedirects(true); +#endif if(https.begin(client, url)) { + https.addHeader("Referer", "https://github.com/gskjold/AmsToMqttBridge/releases"); printD("HTTP client setup successful"); int status = https.GET(); if(status == HTTP_CODE_OK) { @@ -966,7 +961,8 @@ void AmsWebServer::firmwareDownload() { if(SPIFFS.begin()) { printI("Downloading firmware to SPIFFS"); file = SPIFFS.open(FILE_FIRMWARE, "w"); - https.writeToStream(&file); + // The following does not work... Maybe someone will make it work in the future? It seems to be disconnected at this point. + int len = https.writeToStream(&file); file.close(); SPIFFS.end(); performRestart = true; @@ -987,13 +983,15 @@ void AmsWebServer::firmwareDownload() { } } else { printE("Unable to configure HTTP client"); +#if defined(ESP8266) char buf[256]; client.getLastSSLError(buf,256); printE(buf); +#endif server.sendHeader("Location","/"); server.send(303); } - */ + https.end(); } else { printI("No firmware version specified..."); server.sendHeader("Location","/"); diff --git a/web/application.js b/web/application.js index f5197463..4cbf4133 100644 --- a/web/application.js +++ b/web/application.js @@ -40,6 +40,19 @@ $(function() { } }); + $('#mqttSsl').on('change', function() { + var port = $('#mqttPort'); + if($(this).is(':checked')) { + if(port.val() == 1883) { + port.val(8883); + } + } else { + if(port.val() == 8883) { + port.val(1883); + } + } + }); + $('#mqttEnable').trigger('change'); $('#mqttPayloadFormat').trigger('change'); diff --git a/web/configmqtt.html b/web/configmqtt.html index 1d8eb7c1..00308b23 100644 --- a/web/configmqtt.html +++ b/web/configmqtt.html @@ -16,7 +16,7 @@
Port
- +
diff --git a/web/configsystem.html b/web/configsystem.html index b926e308..cc59f71e 100644 --- a/web/configsystem.html +++ b/web/configsystem.html @@ -1,4 +1,4 @@ -
!!WARNING!!
Do not change anything here unless you know exactly what you are doing! Changing things here coulds cause the device to stop responding
+
!!WARNING!!
Do not change anything here unless you know exactly what you are doing! Changing things here could cause the device to stop responding