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

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