Some changes after testing

This commit is contained in:
Gunnar Skjold 2021-01-18 20:32:51 +01:00
parent 33070af111
commit f15cf5d75e
7 changed files with 55 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -55,7 +55,7 @@
</head>
<body class="bg-light">
<main role="main" class="container">
<header class="navbar navbar-expand navbar-dark flex-column flex-lg-row rounded mt-2 mb-3" style="background-color: var(--purple);">
<header class="navbar navbar-expand navbar-dark flex-column flex-lg-row rounded shadow mt-2 mb-3" style="background-color: var(--purple);">
<a href="/" class="">
<h6 class="navbar-brand">AMS reader <small id="swVersion" data-url="https://api.github.com/repos/gskjold/AmsToMqttBridge/releases">${version}</small></h6>
</a>

View File

@ -1,8 +1,8 @@
{
"id" : "%s",
"name" : "%s",
"up" : %d,
"t" : %d,
"up" : %lu,
"t" : %lu,
"vcc" : %.3f,
"rssi": %d,
"temp": %.2f,
@ -24,6 +24,6 @@
"tPO" : %.1f,
"tQI" : %.1f,
"tQO" : %.1f,
"rtc" : %d
"rtc" : %lu
}
}