Some cleanup and changes. Trying to get self-update to work, no luck

This commit is contained in:
Gunnar Skjold
2020-05-22 22:26:31 +02:00
parent 0c92f7401c
commit cff6c02d57
5 changed files with 30 additions and 16 deletions

View File

@@ -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)

View File

@@ -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","/");

View File

@@ -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');

View File

@@ -16,7 +16,7 @@
<div class="input-group-prepend">
<span class="input-group-text">Port</span>
</div>
<input type="number" class="form-control mqtt-config" name="mqttPort" value="${config.mqttPort}" min="1024" max="65535" placeholder="1883"/>
<input id="mqttPort" type="number" class="form-control mqtt-config" name="mqttPort" value="${config.mqttPort}" min="1024" max="65535" placeholder="1883"/>
</div>
</div>
<div class="col-xl-3 col-lg-4 col-md-6 col-sm-8">

View File

@@ -1,4 +1,4 @@
<div class="alert alert-warning">!!WARNING!!<br/>Do not change anything here unless you know exactly what you are doing! Changing things here coulds cause the device to stop responding</div>
<div class="alert alert-warning">!!WARNING!!<br/>Do not change anything here unless you know exactly what you are doing! Changing things here could cause the device to stop responding</div>
<form method="post" action="/save">
<input type="hidden" name="sysConfig" value="true"/>
<div class="my-3 p-3 bg-white rounded shadow">