mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-29 21:27:33 +00:00
Reclaiming some heap space
This commit is contained in:
@@ -510,6 +510,7 @@ bool AmsConfiguration::getEnergyAccountingConfig(EnergyAccountingConfig& config)
|
||||
if(config.thresholds[9] != 255) {
|
||||
clearEnergyAccountingConfig(config);
|
||||
}
|
||||
if(config.hours > 5) config.hours = 5;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -549,6 +550,7 @@ void AmsConfiguration::clearEnergyAccountingConfig(EnergyAccountingConfig& confi
|
||||
config.thresholds[7] = 100;
|
||||
config.thresholds[8] = 150;
|
||||
config.thresholds[9] = 255;
|
||||
config.hours = 3;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::isEnergyAccountingChanged() {
|
||||
|
||||
@@ -307,7 +307,7 @@ void setup() {
|
||||
}
|
||||
|
||||
debugI(" flashing");
|
||||
File firmwareFile = LittleFS.open(FILE_FIRMWARE, "r");
|
||||
File firmwareFile = LittleFS.open(FILE_FIRMWARE, (char*) F("r"));
|
||||
debugD(" firmware size: %d", firmwareFile.size());
|
||||
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
debugD(" available: %d", maxSketchSpace);
|
||||
@@ -358,7 +358,7 @@ void setup() {
|
||||
|
||||
NtpConfig ntp;
|
||||
if(config.getNtpConfig(ntp)) {
|
||||
configTime(ntp.offset*10, ntp.summerOffset*10, ntp.enable ? strlen(ntp.server) > 0 ? ntp.server : "pool.ntp.org" : ""); // Add NTP server by default if none is configured
|
||||
configTime(ntp.offset*10, ntp.summerOffset*10, ntp.enable ? strlen(ntp.server) > 0 ? ntp.server : (char*) F("pool.ntp.org") : (char*) F("")); // Add NTP server by default if none is configured
|
||||
sntp_servermode_dhcp(ntp.enable && ntp.dhcp ? 1 : 0);
|
||||
ntpEnabled = ntp.enable;
|
||||
TimeChangeRule std = {"STD", Last, Sun, Oct, 3, ntp.offset / 6};
|
||||
@@ -473,7 +473,7 @@ void loop() {
|
||||
if(strlen(wifi.hostname) > 0 && wifi.mdns) {
|
||||
debugD("mDNS is enabled, using host: %s", wifi.hostname);
|
||||
if(MDNS.begin(wifi.hostname)) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
MDNS.addService(F("http"), F("tcp"), 80);
|
||||
} else {
|
||||
debugE("Failed to set up mDNS!");
|
||||
}
|
||||
@@ -607,7 +607,7 @@ void loop() {
|
||||
}
|
||||
|
||||
void setupHanPort(uint8_t pin, uint32_t baud, uint8_t parityOrdinal, bool invert) {
|
||||
if(Debug.isActive(RemoteDebug::INFO)) Debug.printf("(setupHanPort) Setting up HAN on pin %d with baud %d and parity %d\n", pin, baud, parityOrdinal);
|
||||
if(Debug.isActive(RemoteDebug::INFO)) Debug.printf((char*) F("(setupHanPort) Setting up HAN on pin %d with baud %d and parity %d\n"), pin, baud, parityOrdinal);
|
||||
|
||||
HardwareSerial *hwSerial = NULL;
|
||||
if(pin == 3 || pin == 113) {
|
||||
@@ -658,14 +658,11 @@ void setupHanPort(uint8_t pin, uint32_t baud, uint8_t parityOrdinal, bool invert
|
||||
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
hwSerial->begin(baud, serialConfig, -1, -1, invert);
|
||||
hwSerial->setRxBufferSize(768);
|
||||
uart_set_pin(UART_NUM_1, UART_PIN_NO_CHANGE, pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
#elif defined(ESP32)
|
||||
hwSerial->begin(baud, serialConfig, -1, -1, invert);
|
||||
hwSerial->setRxBufferSize(768);
|
||||
#else
|
||||
hwSerial->begin(baud, serialConfig, SERIAL_FULL, 1, invert);
|
||||
hwSerial->setRxBufferSize(768);
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
@@ -765,14 +762,14 @@ void swapWifiMode() {
|
||||
|
||||
if (mode != WIFI_AP || !config.hasConfig()) {
|
||||
if(Debug.isActive(RemoteDebug::INFO)) debugI("Swapping to AP mode");
|
||||
WiFi.softAP("AMS2MQTT");
|
||||
WiFi.softAP((char*) F("AMS2MQTT"));
|
||||
WiFi.mode(WIFI_AP);
|
||||
|
||||
if(dnsServer == NULL) {
|
||||
dnsServer = new DNSServer();
|
||||
}
|
||||
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
dnsServer->start(53, "*", WiFi.softAPIP());
|
||||
dnsServer->start(53, (char*) F("*"), WiFi.softAPIP());
|
||||
} else {
|
||||
if(Debug.isActive(RemoteDebug::INFO)) debugI("Swapping to STA mode");
|
||||
if(dnsServer != NULL) {
|
||||
@@ -978,13 +975,13 @@ void printHanReadError(int pos) {
|
||||
void debugPrint(byte *buffer, int start, int length) {
|
||||
for (int i = start; i < start + length; i++) {
|
||||
if (buffer[i] < 0x10)
|
||||
Debug.print("0");
|
||||
Debug.print(F("0"));
|
||||
Debug.print(buffer[i], HEX);
|
||||
Debug.print(" ");
|
||||
Debug.print(F(" "));
|
||||
if ((i - start + 1) % 16 == 0)
|
||||
Debug.println("");
|
||||
else if ((i - start + 1) % 4 == 0)
|
||||
Debug.print(" ");
|
||||
Debug.print(F(" "));
|
||||
|
||||
yield(); // Let other get some resources too
|
||||
}
|
||||
@@ -1099,7 +1096,7 @@ void WiFi_connect() {
|
||||
if(strlen(wifi.dns2) > 0) {
|
||||
dns2.fromString(wifi.dns2);
|
||||
} else if(dns1.toString().isEmpty()) {
|
||||
dns2.fromString("208.67.220.220"); // Add OpenDNS as second by default if nothing is configured
|
||||
dns2.fromString(F("208.67.220.220")); // Add OpenDNS as second by default if nothing is configured
|
||||
}
|
||||
if(!WiFi.config(ip, gw, sn, dns1, dns2)) {
|
||||
debugE("Static IP configuration is invalid, not using");
|
||||
@@ -1327,7 +1324,7 @@ void MQTT_connect() {
|
||||
|
||||
if(LittleFS.exists(FILE_MQTT_CA)) {
|
||||
debugI("Found MQTT CA file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_CA, "r");
|
||||
file = LittleFS.open(FILE_MQTT_CA, (char*) F("r"));
|
||||
#if defined(ESP8266)
|
||||
BearSSL::X509List *serverTrustedCA = new BearSSL::X509List(file);
|
||||
mqttSecureClient->setTrustAnchors(serverTrustedCA);
|
||||
@@ -1340,12 +1337,12 @@ void MQTT_connect() {
|
||||
if(LittleFS.exists(FILE_MQTT_CERT) && LittleFS.exists(FILE_MQTT_KEY)) {
|
||||
#if defined(ESP8266)
|
||||
debugI("Found MQTT certificate file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_CERT, "r");
|
||||
file = LittleFS.open(FILE_MQTT_CERT, (char*) F("r"));
|
||||
BearSSL::X509List *serverCertList = new BearSSL::X509List(file);
|
||||
file.close();
|
||||
|
||||
debugI("Found MQTT key file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_KEY, "r");
|
||||
file = LittleFS.open(FILE_MQTT_KEY, (char*) F("r"));
|
||||
BearSSL::PrivateKey *serverPrivKey = new BearSSL::PrivateKey(file);
|
||||
file.close();
|
||||
|
||||
@@ -1353,12 +1350,12 @@ void MQTT_connect() {
|
||||
mqttSecureClient->setClientRSACert(serverCertList, serverPrivKey);
|
||||
#elif defined(ESP32)
|
||||
debugI("Found MQTT certificate file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_CERT, "r");
|
||||
file = LittleFS.open(FILE_MQTT_CERT, (char*) F("r"));
|
||||
mqttSecureClient->loadCertificate(file, file.size());
|
||||
file.close();
|
||||
|
||||
debugI("Found MQTT key file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_KEY, "r");
|
||||
file = LittleFS.open(FILE_MQTT_KEY, (char*) F("r"));
|
||||
mqttSecureClient->loadPrivateKey(file, file.size());
|
||||
file.close();
|
||||
#endif
|
||||
@@ -1424,7 +1421,7 @@ void configFileParse() {
|
||||
return;
|
||||
}
|
||||
|
||||
File file = LittleFS.open(FILE_CFG, "r");
|
||||
File file = LittleFS.open(FILE_CFG, (char*) F("r"));
|
||||
|
||||
bool lSys = false;
|
||||
bool lWiFi = false;
|
||||
@@ -1454,198 +1451,198 @@ void configFileParse() {
|
||||
char* buf = (char*) commonBuffer;
|
||||
memset(buf, 0, 1024);
|
||||
while((size = file.readBytesUntil('\n', buf, 1024)) > 0) {
|
||||
if(strncmp(buf, "boardType ", 10) == 0) {
|
||||
if(strncmp(buf, (char*) F("boardType "), 10) == 0) {
|
||||
if(!lSys) { config.getSystemConfig(sys); lSys = true; };
|
||||
sys.boardType = String(buf+10).toInt();
|
||||
} else if(strncmp(buf, "ssid ", 5) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("ssid "), 5) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
memcpy(wifi.ssid, buf+5, size-5);
|
||||
} else if(strncmp(buf, "psk ", 4) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("psk "), 4) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
memcpy(wifi.psk, buf+4, size-4);
|
||||
} else if(strncmp(buf, "ip ", 3) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("ip "), 3) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
memcpy(wifi.ip, buf+3, size-3);
|
||||
} else if(strncmp(buf, "gateway ", 8) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gateway "), 8) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
memcpy(wifi.gateway, buf+8, size-8);
|
||||
} else if(strncmp(buf, "subnet ", 7) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("subnet "), 7) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
memcpy(wifi.subnet, buf+7, size-7);
|
||||
} else if(strncmp(buf, "dns1 ", 5) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("dns1 "), 5) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
memcpy(wifi.dns1, buf+5, size-5);
|
||||
} else if(strncmp(buf, "dns2 ", 5) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("dns2 "), 5) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
memcpy(wifi.dns2, buf+5, size-5);
|
||||
} else if(strncmp(buf, "hostname ", 9) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("hostname "), 9) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
memcpy(wifi.hostname, buf+9, size-9);
|
||||
} else if(strncmp(buf, "mdns ", 5) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mdns "), 5) == 0) {
|
||||
if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; };
|
||||
wifi.mdns = String(buf+5).toInt() == 1;;
|
||||
} else if(strncmp(buf, "mqttHost ", 9) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mqttHost "), 9) == 0) {
|
||||
if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; };
|
||||
memcpy(mqtt.host, buf+9, size-9);
|
||||
} else if(strncmp(buf, "mqttPort ", 9) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mqttPort "), 9) == 0) {
|
||||
if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; };
|
||||
mqtt.port = String(buf+9).toInt();
|
||||
} else if(strncmp(buf, "mqttClientId ", 13) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mqttClientId "), 13) == 0) {
|
||||
if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; };
|
||||
memcpy(mqtt.clientId, buf+13, size-13);
|
||||
} else if(strncmp(buf, "mqttPublishTopic ", 17) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mqttPublishTopic "), 17) == 0) {
|
||||
if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; };
|
||||
memcpy(mqtt.publishTopic, buf+17, size-17);
|
||||
} else if(strncmp(buf, "mqttUsername ", 13) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mqttUsername "), 13) == 0) {
|
||||
if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; };
|
||||
memcpy(mqtt.username, buf+13, size-13);
|
||||
} else if(strncmp(buf, "mqttPassword ", 13) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mqttPassword "), 13) == 0) {
|
||||
if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; };
|
||||
memcpy(mqtt.password, buf+13, size-13);
|
||||
} else if(strncmp(buf, "mqttPayloadFormat ", 18) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mqttPayloadFormat "), 18) == 0) {
|
||||
if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; };
|
||||
mqtt.payloadFormat = String(buf+18).toInt();
|
||||
} else if(strncmp(buf, "mqttSsl ", 8) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("mqttSsl "), 8) == 0) {
|
||||
if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; };
|
||||
mqtt.ssl = String(buf+8).toInt() == 1;;
|
||||
} else if(strncmp(buf, "webSecurity ", 12) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("webSecurity "), 12) == 0) {
|
||||
if(!lWeb) { config.getWebConfig(web); lWeb = true; };
|
||||
web.security = String(buf+12).toInt();
|
||||
} else if(strncmp(buf, "webUsername ", 12) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("webUsername "), 12) == 0) {
|
||||
if(!lWeb) { config.getWebConfig(web); lWeb = true; };
|
||||
memcpy(web.username, buf+12, size-12);
|
||||
} else if(strncmp(buf, "webPassword ", 12) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("webPassword "), 12) == 0) {
|
||||
if(!lWeb) { config.getWebConfig(web); lWeb = true; };
|
||||
memcpy(web.username, buf+12, size-12);
|
||||
} else if(strncmp(buf, "meterBaud ", 10) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("meterBaud "), 10) == 0) {
|
||||
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
|
||||
meter.baud = String(buf+10).toInt();
|
||||
} else if(strncmp(buf, "meterParity ", 12) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("meterParity "), 12) == 0) {
|
||||
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
|
||||
if(strncmp(buf+12, "7N1", 3) == 0) meter.parity = 2;
|
||||
if(strncmp(buf+12, "8N1", 3) == 0) meter.parity = 3;
|
||||
if(strncmp(buf+12, "7E1", 3) == 0) meter.parity = 10;
|
||||
if(strncmp(buf+12, "8E1", 3) == 0) meter.parity = 11;
|
||||
} else if(strncmp(buf, "meterInvert ", 12) == 0) {
|
||||
if(strncmp(buf+12, (char*) F("7N1"), 3) == 0) meter.parity = 2;
|
||||
if(strncmp(buf+12, (char*) F("8N1"), 3) == 0) meter.parity = 3;
|
||||
if(strncmp(buf+12, (char*) F("7E1"), 3) == 0) meter.parity = 10;
|
||||
if(strncmp(buf+12, (char*) F("8E1"), 3) == 0) meter.parity = 11;
|
||||
} else if(strncmp(buf, (char*) F("meterInvert "), 12) == 0) {
|
||||
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
|
||||
meter.invert = String(buf+12).toInt() == 1;;
|
||||
} else if(strncmp(buf, "meterDistributionSystem ", 24) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("meterDistributionSystem "), 24) == 0) {
|
||||
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
|
||||
meter.distributionSystem = String(buf+24).toInt();
|
||||
} else if(strncmp(buf, "meterMainFuse ", 14) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("meterMainFuse "), 14) == 0) {
|
||||
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
|
||||
meter.mainFuse = String(buf+14).toInt();
|
||||
} else if(strncmp(buf, "meterProductionCapacity ", 24) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("meterProductionCapacity "), 24) == 0) {
|
||||
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
|
||||
meter.productionCapacity = String(buf+24).toInt();
|
||||
} else if(strncmp(buf, "meterEncryptionKey ", 19) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("meterEncryptionKey "), 19) == 0) {
|
||||
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
|
||||
fromHex(meter.encryptionKey, String(buf+19), 16);
|
||||
} else if(strncmp(buf, "meterAuthenticationKey ", 23) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("meterAuthenticationKey "), 23) == 0) {
|
||||
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
|
||||
fromHex(meter.authenticationKey, String(buf+19), 16);
|
||||
} else if(strncmp(buf, "gpioHanPin ", 11) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioHanPin "), 11) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.hanPin = String(buf+11).toInt();
|
||||
} else if(strncmp(buf, "gpioApPin ", 10) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioApPin "), 10) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.apPin = String(buf+10).toInt();
|
||||
} else if(strncmp(buf, "gpioLedPin ", 11) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioLedPin "), 11) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.ledPin = String(buf+11).toInt();
|
||||
} else if(strncmp(buf, "gpioLedInverted ", 16) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioLedInverted "), 16) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.ledInverted = String(buf+16).toInt() == 1;
|
||||
} else if(strncmp(buf, "gpioLedPinRed ", 14) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioLedPinRed "), 14) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.ledPinRed = String(buf+14).toInt();
|
||||
} else if(strncmp(buf, "gpioLedPinGreen ", 16) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioLedPinGreen "), 16) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.ledPinGreen = String(buf+16).toInt();
|
||||
} else if(strncmp(buf, "gpioLedPinBlue ", 15) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioLedPinBlue "), 15) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.ledPinBlue = String(buf+15).toInt();
|
||||
} else if(strncmp(buf, "gpioLedRgbInverted ", 19) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioLedRgbInverted "), 19) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.ledRgbInverted = String(buf+19).toInt() == 1;
|
||||
} else if(strncmp(buf, "gpioTempSensorPin ", 18) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioTempSensorPin "), 18) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.tempSensorPin = String(buf+18).toInt();
|
||||
} else if(strncmp(buf, "gpioTempAnalogSensorPin ", 24) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioTempAnalogSensorPin "), 24) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.tempAnalogSensorPin = String(buf+24).toInt();
|
||||
} else if(strncmp(buf, "gpioVccPin ", 11) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioVccPin "), 11) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.vccPin = String(buf+11).toInt();
|
||||
} else if(strncmp(buf, "gpioVccOffset ", 14) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioVccOffset "), 14) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.vccOffset = String(buf+14).toDouble() * 100;
|
||||
} else if(strncmp(buf, "gpioVccMultiplier ", 18) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioVccMultiplier "), 18) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.vccMultiplier = String(buf+18).toDouble() * 1000;
|
||||
} else if(strncmp(buf, "gpioVccBootLimit ", 17) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioVccBootLimit "), 17) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.vccBootLimit = String(buf+17).toDouble() * 10;
|
||||
} else if(strncmp(buf, "gpioVccResistorGnd ", 19) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioVccResistorGnd "), 19) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.vccResistorGnd = String(buf+19).toInt();
|
||||
} else if(strncmp(buf, "gpioVccResistorVcc ", 19) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("gpioVccResistorVcc "), 19) == 0) {
|
||||
if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; };
|
||||
gpio.vccResistorVcc = String(buf+19).toInt();
|
||||
} else if(strncmp(buf, "domoticzElidx ", 14) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("domoticzElidx "), 14) == 0) {
|
||||
if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; };
|
||||
domo.elidx = String(buf+14).toInt();
|
||||
} else if(strncmp(buf, "domoticzVl1idx ", 15) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("domoticzVl1idx "), 15) == 0) {
|
||||
if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; };
|
||||
domo.vl1idx = String(buf+15).toInt();
|
||||
} else if(strncmp(buf, "domoticzVl2idx ", 15) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("domoticzVl2idx "), 15) == 0) {
|
||||
if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; };
|
||||
domo.vl2idx = String(buf+15).toInt();
|
||||
} else if(strncmp(buf, "domoticzVl3idx ", 15) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("domoticzVl3idx "), 15) == 0) {
|
||||
if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; };
|
||||
domo.vl3idx = String(buf+15).toInt();
|
||||
} else if(strncmp(buf, "domoticzCl1idx ", 15) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("domoticzCl1idx "), 15) == 0) {
|
||||
if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; };
|
||||
domo.cl1idx = String(buf+15).toInt();
|
||||
} else if(strncmp(buf, "ntpEnable ", 10) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("ntpEnable "), 10) == 0) {
|
||||
if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; };
|
||||
ntp.enable = String(buf+10).toInt() == 1;
|
||||
} else if(strncmp(buf, "ntpDhcp ", 8) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("ntpDhcp "), 8) == 0) {
|
||||
if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; };
|
||||
ntp.dhcp = String(buf+8).toInt() == 1;
|
||||
} else if(strncmp(buf, "ntpOffset ", 10) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("ntpOffset "), 10) == 0) {
|
||||
if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; };
|
||||
ntp.offset = String(buf+10).toInt() / 10;
|
||||
} else if(strncmp(buf, "ntpSummerOffset ", 16) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("ntpSummerOffset "), 16) == 0) {
|
||||
if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; };
|
||||
ntp.summerOffset = String(buf+16).toInt() / 10;
|
||||
} else if(strncmp(buf, "ntpServer ", 10) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("ntpServer "), 10) == 0) {
|
||||
if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; };
|
||||
memcpy(ntp.server, buf+10, size-10);
|
||||
} else if(strncmp(buf, "entsoeToken ", 12) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("entsoeToken "), 12) == 0) {
|
||||
if(!lEntsoe) { config.getEntsoeConfig(entsoe); lEntsoe = true; };
|
||||
memcpy(entsoe.token, buf+12, size-12);
|
||||
} else if(strncmp(buf, "entsoeArea ", 11) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("entsoeArea "), 11) == 0) {
|
||||
if(!lEntsoe) { config.getEntsoeConfig(entsoe); lEntsoe = true; };
|
||||
memcpy(entsoe.area, buf+11, size-11);
|
||||
} else if(strncmp(buf, "entsoeCurrency ", 15) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("entsoeCurrency "), 15) == 0) {
|
||||
if(!lEntsoe) { config.getEntsoeConfig(entsoe); lEntsoe = true; };
|
||||
memcpy(entsoe.currency, buf+15, size-15);
|
||||
} else if(strncmp(buf, "entsoeMultiplier ", 17) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("entsoeMultiplier "), 17) == 0) {
|
||||
if(!lEntsoe) { config.getEntsoeConfig(entsoe); lEntsoe = true; };
|
||||
entsoe.multiplier = String(buf+17).toDouble() * 1000;
|
||||
} else if(strncmp(buf, "thresholds ", 11) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("thresholds "), 11) == 0) {
|
||||
if(!lEac) { config.getEnergyAccountingConfig(eac); lEac = true; };
|
||||
int i = 0;
|
||||
char * pch = strtok (buf+11," ");
|
||||
char * pch = strtok (buf+11,(char*) F(" "));
|
||||
while (pch != NULL) {
|
||||
eac.thresholds[i++] = String(pch).toInt();
|
||||
pch = strtok (NULL, " ");
|
||||
pch = strtok (NULL, (char*) F(" "));
|
||||
}
|
||||
} else if(strncmp(buf, "dayplot ", 8) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("dayplot "), 8) == 0) {
|
||||
int i = 0;
|
||||
DayDataPoints day = { 4 }; // Use a version we know the multiplier of the data points
|
||||
char * pch = strtok (buf+8," ");
|
||||
char * pch = strtok (buf+8,(char*) F(" "));
|
||||
while (pch != NULL) {
|
||||
int64_t val = String(pch).toInt();
|
||||
if(i == 1) {
|
||||
@@ -1660,15 +1657,15 @@ void configFileParse() {
|
||||
day.hExport[i-28] = val / 10;
|
||||
}
|
||||
|
||||
pch = strtok (NULL, " ");
|
||||
pch = strtok (NULL, (char*) F(" "));
|
||||
i++;
|
||||
}
|
||||
ds.setDayData(day);
|
||||
sDs = true;
|
||||
} else if(strncmp(buf, "monthplot ", 10) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("monthplot "), 10) == 0) {
|
||||
int i = 0;
|
||||
MonthDataPoints month = { 5 }; // Use a version we know the multiplier of the data points
|
||||
char * pch = strtok (buf+10," ");
|
||||
char * pch = strtok (buf+10,(char*) F(" "));
|
||||
while (pch != NULL) {
|
||||
int64_t val = String(pch).toInt();
|
||||
if(i == 1) {
|
||||
@@ -1683,12 +1680,12 @@ void configFileParse() {
|
||||
month.dExport[i-35] = val / 10;
|
||||
}
|
||||
|
||||
pch = strtok (NULL, " ");
|
||||
pch = strtok (NULL, (char*) F(" "));
|
||||
i++;
|
||||
}
|
||||
ds.setMonthData(month);
|
||||
sDs = true;
|
||||
} else if(strncmp(buf, "energyaccounting ", 17) == 0) {
|
||||
} else if(strncmp(buf, (char*) F("energyaccounting "), 17) == 0) {
|
||||
uint8_t i = 0;
|
||||
EnergyAccountingData ead = { 4, 0,
|
||||
0, 0, 0,
|
||||
@@ -1698,7 +1695,7 @@ void configFileParse() {
|
||||
0, 0, // Peak 4
|
||||
0, 0 // Peak 5
|
||||
};
|
||||
char * pch = strtok (buf+17," ");
|
||||
char * pch = strtok (buf+17,(char*) F(" "));
|
||||
while (pch != NULL) {
|
||||
if(i == 0) {
|
||||
// Ignore version
|
||||
@@ -1729,7 +1726,7 @@ void configFileParse() {
|
||||
ead.peaks[hour/2].value = val * 100;
|
||||
}
|
||||
}
|
||||
pch = strtok (NULL, " ");
|
||||
pch = strtok (NULL, (char*) F(" "));
|
||||
i++;
|
||||
}
|
||||
ea.setData(ead);
|
||||
|
||||
@@ -237,7 +237,7 @@ float EnergyAccounting::getMonthMax() {
|
||||
uint32_t maxHour = 0.0;
|
||||
bool included[5] = { false, false, false, false, false };
|
||||
|
||||
while(count < config->hours && count <= 5) {
|
||||
while(count < config->hours && count < 5) {
|
||||
uint8_t maxIdx = 0;
|
||||
uint16_t maxVal = 0;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
@@ -265,7 +265,7 @@ float EnergyAccounting::getPeak(uint8_t num) {
|
||||
uint8_t count = 0;
|
||||
bool included[5] = { false, false, false, false, false };
|
||||
|
||||
while(count < config->hours && count <= 5) {
|
||||
while(count < config->hours && count < 5) {
|
||||
uint8_t maxIdx = 0;
|
||||
uint16_t maxVal = 0;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
|
||||
@@ -92,7 +92,9 @@ bool RawMqttHandler::publish(AmsData* data, AmsData* meterState, EnergyAccountin
|
||||
}
|
||||
mqtt->publish(topic + "/realtime/import/hour", String(ea->getUseThisHour(), 3));
|
||||
mqtt->publish(topic + "/realtime/import/day", String(ea->getUseToday(), 2));
|
||||
for(uint8_t i = 1; i <= ea->getConfig()->hours; i++) {
|
||||
uint8_t peakCount = ea->getConfig()->hours;
|
||||
if(peakCount > 5) peakCount = 5;
|
||||
for(uint8_t i = 1; i <= peakCount; i++) {
|
||||
mqtt->publish(topic + "/realtime/import/peak/" + String(i, 10), String(ea->getPeak(i), 10), true, 0);
|
||||
}
|
||||
mqtt->publish(topic + "/realtime/import/threshold", String(ea->getCurrentThreshold(), 10), true, 0);
|
||||
|
||||
@@ -2,6 +2,7 @@ static const char HEADER_CACHE_CONTROL[] PROGMEM = "Cache-Control";
|
||||
static const char HEADER_PRAGMA[] PROGMEM = "Pragma";
|
||||
static const char HEADER_EXPIRES[] PROGMEM = "Expires";
|
||||
static const char HEADER_AUTHENTICATE[] PROGMEM = "WWW-Authenticate";
|
||||
static const char HEADER_LOCATION[] PROGMEM = "Location";
|
||||
|
||||
static const char CACHE_CONTROL_NO_CACHE[] PROGMEM = "no-cache, no-store, must-revalidate";
|
||||
static const char CACHE_1HR[] PROGMEM = "public, max-age=3600";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user