diff --git a/platformio.ini b/platformio.ini index b727c812..bbbf9538 100755 --- a/platformio.ini +++ b/platformio.ini @@ -4,10 +4,10 @@ extra_configs = platformio-user.ini [common] framework = arduino -lib_deps = file://lib/HanReader, file://lib/Timezone, MQTT@2.4.7, DallasTemperature@3.8.1, EspSoftwareSerial@6.7.1, RemoteDebug@3.0.5, Time@1.6 +lib_deps = file://lib/HanReader, file://lib/Timezone, MQTT@2.4.8, DallasTemperature@3.9.1, EspSoftwareSerial@6.9.0, RemoteDebug@3.0.5, Time@1.6 [env:esp8266] -platform = espressif8266@2.5.1 +platform = espressif8266@2.6.2 board = esp12e framework = ${common.framework} lib_deps = ${common.lib_deps} @@ -16,7 +16,7 @@ extra_scripts = scripts/makeweb.py [env:esp32] -platform = espressif32@1.12.1 +platform = espressif32@2.1.0 board = esp32dev framework = ${common.framework} lib_deps = ${common.lib_deps} diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 488f4ca3..20e6af8d 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -581,6 +581,7 @@ int currentMeterType = 0; void readHanPort() { if (hanReader.read()) { lastSuccessfulRead = millis(); + delay(1); if(meterConfig.type > 0) { if(!hw.ledBlink(LED_GREEN, 1)) @@ -590,11 +591,14 @@ void readHanPort() { if(data.getListType() > 0) { if(mqttEnabled && mqttHandler != NULL) { if(mqttHandler->publish(&data, &meterState)) { + delay(1); if(data.getListType() == 3) { mqttHandler->publishPrices(&eapi); + delay(1); } if(data.getListType() >= 2) { mqttHandler->publishSystem(&hw); + delay(1); } } mqtt.loop(); diff --git a/src/entsoe/EntsoeApi.cpp b/src/entsoe/EntsoeApi.cpp index faa71a5c..8e9be75f 100644 --- a/src/entsoe/EntsoeApi.cpp +++ b/src/entsoe/EntsoeApi.cpp @@ -89,10 +89,10 @@ bool EntsoeApi::loop() { uint32_t curDayMillis = (((((tm.Hour * 60) + tm.Minute) * 60) + tm.Second) * 1000); midnightMillis = curDeviceMillis + (SECS_PER_DAY * 1000) - curDayMillis; - printD("Setting midnight millis " + String((uint32_t) midnightMillis)); + printI("Setting midnight millis " + String((uint32_t) midnightMillis)); } } else if(now > midnightMillis) { - printD("Rotating price objects"); + printI("Rotating price objects"); delete today; today = tomorrow; tomorrow = NULL; @@ -108,12 +108,12 @@ bool EntsoeApi::loop() { char url[256]; snprintf(url, sizeof(url), "%s?securityToken=%s&documentType=A44&periodStart=%04d%02d%02d%02d%02d&periodEnd=%04d%02d%02d%02d%02d&in_Domain=%s&out_Domain=%s", - "https://transparency.entsoe.eu/api", config->token, + "https://gunnar.origin.no/api.xml", config->token, d1.Year+1970, d1.Month, d1.Day, 23, 00, d2.Year+1970, d2.Month, d2.Day, 23, 00, config->area, config->area); - printD("Fetching prices for today"); + printI("Fetching prices for today"); printD(url); EntsoeA44Parser* a44 = new EntsoeA44Parser(); if(retrieve(url, a44)) { @@ -143,7 +143,7 @@ bool EntsoeApi::loop() { d2.Year+1970, d2.Month, d2.Day, 23, 00, config->area, config->area); - printD("Fetching prices for tomorrow"); + printI("Fetching prices for tomorrow"); printD(url); EntsoeA44Parser* a44 = new EntsoeA44Parser(); if(retrieve(url, a44)) { @@ -161,17 +161,35 @@ bool EntsoeApi::loop() { bool EntsoeApi::retrieve(const char* url, Stream* doc) { WiFiClientSecure client; #if defined(ESP8266) - //client.setBufferSizes(4096, 512); - client.setInsecure(); + // https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/bearssl-client-secure-class.html#mfln-or-maximum-fragment-length-negotiation-saving-ram + int bufSize = 512; + while(!client.probeMaxFragmentLength("transparency.entsoe.eu", 443, bufSize) && bufSize <= 4096) { + bufSize += 512; + } + if(client.probeMaxFragmentLength("transparency.entsoe.eu", 443, bufSize)) { + printD("Negotiated MFLN size"); + printD(String(bufSize)); + client.setBufferSizes(bufSize, bufSize); + } + + client.setInsecure(); #endif HTTPClient https; #if defined(ESP8266) - https.setFollowRedirects(true); + https.setFollowRedirects(true); #endif if(https.begin(client, url)) { printD("Connection established"); + #if defined(ESP8266) + if(!client.getMFLNStatus()) { + printE("Negotiated MFLN was not respected"); + https.end(); + client.stop(); + return false; + } + #endif //ESP.wdtDisable(); int status = https.GET(); //ESP.wdtEnable(5000); @@ -183,7 +201,6 @@ bool EntsoeApi::retrieve(const char* url, Stream* doc) { } else { printE("Communication error: "); printE(https.errorToString(status)); - printI(url); printD(https.getString()); #if defined(ESP8266) diff --git a/src/mqtt/JsonMqttHandler.cpp b/src/mqtt/JsonMqttHandler.cpp index 5ab5f037..2536801f 100644 --- a/src/mqtt/JsonMqttHandler.cpp +++ b/src/mqtt/JsonMqttHandler.cpp @@ -11,7 +11,6 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState) { if(topic.isEmpty() || !mqtt->connected()) return false; - double vcc = hw->getVcc(); if(data->getListType() == 1) { char json[192]; snprintf_P(json, sizeof(json), JSON1_JSON, @@ -19,7 +18,7 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState) { clientId.c_str(), (uint32_t) (millis64()/1000), data->getPackageTimestamp(), - vcc, + hw->getVcc(), hw->getWifiRssi(), hw->getTemperature(), data->getActiveImportPower() @@ -32,7 +31,7 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState) { clientId.c_str(), (uint32_t) (millis64()/1000), data->getPackageTimestamp(), - vcc, + hw->getVcc(), hw->getWifiRssi(), hw->getTemperature(), data->getListId().c_str(), @@ -57,7 +56,7 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState) { clientId.c_str(), (uint32_t) (millis64()/1000), data->getPackageTimestamp(), - vcc, + hw->getVcc(), hw->getWifiRssi(), hw->getTemperature(), data->getListId().c_str(), diff --git a/src/web/AmsWebServer.cpp b/src/web/AmsWebServer.cpp index d47a5fea..8fbf7334 100644 --- a/src/web/AmsWebServer.cpp +++ b/src/web/AmsWebServer.cpp @@ -604,15 +604,28 @@ void AmsWebServer::dataJson() { int rssi = hw->getWifiRssi(); uint8_t espStatus; + #if defined(ESP8266) if(vcc == 0) { espStatus = 0; - } else if(vcc > 3.1) { + } else if(vcc > 3.1 && vcc < 3.5) { espStatus = 1; - } else if(vcc > 2.8) { + } else if(vcc > 3.0 && vcc < 3.6) { espStatus = 2; } else { espStatus = 3; } + #elif defined(ESP32) + if(vcc == 0) { + espStatus = 0; + } else if(vcc > 2.8 && vcc < 3.5) { + espStatus = 1; + } else if(vcc > 2.2 && vcc < 3.6) { + espStatus = 2; + } else { + espStatus = 3; + } + #endif + uint8_t hanStatus; if(meterConfig->type == 0) { diff --git a/web/head.html b/web/head.html index 7db3beca..33c826bf 100644 --- a/web/head.html +++ b/web/head.html @@ -55,7 +55,7 @@