diff --git a/Logger.cpp b/Logger.cpp new file mode 100644 index 0000000..af0f957 --- /dev/null +++ b/Logger.cpp @@ -0,0 +1,39 @@ +#include "Logger.h" +#include "Settings.h" + +enum LEVEL +{ + DEBUG = 1, + INFO = 2, + WARN = 3 +}; + +// Create Wifi Connector +Logger::Logger(String name) +{ + _name = name; +} + +void Logger::debug(String msg) +{ + if (LOG_LEVEL <= DEBUG) + { + Serial.println("DEBUG - " + _name + ":" + msg); + } +} + +void Logger::info(String msg) +{ + if (LOG_LEVEL <= INFO) + { + Serial.println("INFO - " + _name + ":" + msg); + } +} + +void Logger::warn(String msg) +{ + if (LOG_LEVEL <= WARN) + { + Serial.println("WARN - " + _name + ":" + msg); + } +} diff --git a/Logger.h b/Logger.h new file mode 100644 index 0000000..3e368f1 --- /dev/null +++ b/Logger.h @@ -0,0 +1,14 @@ +#pragma once +#include + +class Logger +{ +private: + String _name; + +public: + Logger(String name = "Logger"); + void info(String msg); + void debug(String msg); + void warn(String msg); +}; diff --git a/MQTTPublisher.cpp b/MQTTPublisher.cpp index 681f431..fc7cd55 100644 --- a/MQTTPublisher.cpp +++ b/MQTTPublisher.cpp @@ -1,109 +1,111 @@ -#include "MQTTPublisher.h" -#include "Settings.h" - -WiFiClient espClient; -PubSubClient client(espClient); - -MQTTPublisher::MQTTPublisher(bool inDebugMode) -{ - randomSeed(micros()); - debugMode = inDebugMode; -} - -MQTTPublisher::~MQTTPublisher() -{ - client.publish(MQTT_HOSTNAME, "offline"); - client.disconnect(); -} - -bool MQTTPublisher::reconnect() -{ - lastConnectionAttempt = millis(); - - if (debugMode) - { - Serial.println("MQTT) Attempt connection to server: " + String(MQTT_HOST_NAME)); - } - - // Create a random client ID - String clientId = String(MQTT_HOSTNAME) + "-"; - clientId += String(random(0xffff), HEX); - - // Attempt to connect - bool clientConnected; - if (String(MQTT_USER_NAME).length()) - { - Serial.println("MQTT) Connecting with credientials"); - clientConnected = client.connect(clientId.c_str(), MQTT_USER_NAME, MQTT_PASSWORD); - } - else - { - Serial.println("MQTT) Connecting without credentials"); - clientConnected = client.connect(clientId.c_str()); - } - - if (clientConnected) - { - if (debugMode) { - Serial.println("MQTT) connected"); - } - - hasMQTT = true; - - // Once connected, publish an announcement... - client.publish(MQTT_HOSTNAME, "online"); - - return true; - } else { - - if (debugMode) - { - Serial.println("MQTT) failed, rc="); - Serial.println(client.state()); - } - - } - - return false; -} - - -void MQTTPublisher::start() -{ - if (String(MQTT_HOST_NAME).length() == 0 || MQTT_PORT == 0) - { - Serial.println("MQTT) disabled. No hostname or port set."); - return; //not configured - } - - if (debugMode){ - Serial.println("MQTT) enabled. Connecting."); - } - - client.setServer(MQTT_HOST_NAME, MQTT_PORT); - reconnect(); - isStarted = true; -} - -void MQTTPublisher::stop() -{ - isStarted = false; -} - -void MQTTPublisher::handle() -{ - if (!isStarted) - return; - - if (!client.connected() && millis() - lastConnectionAttempt > RECONNECT_TIMEOUT) { - hasMQTT = false; - if (!reconnect()) return; - } -} - -bool MQTTPublisher::publishOnMQTT(String prepend, String topic, String value) -{ - auto retVal = client.publish((prepend.c_str() + topic).c_str(), value.c_str()); - yield(); - return retVal; -} +#include "MQTTPublisher.h" +#include "Settings.h" + +WiFiClient espClient; +PubSubClient client(espClient); + +MQTTPublisher::MQTTPublisher(String clientId) +{ + randomSeed(micros()); + _clientId = clientId; + logger = Logger("MQTTPublisher"); + logger.debug("ClientId:" + _clientId); +} + +MQTTPublisher::~MQTTPublisher() +{ + client.publish(getTopic("status").c_str(), "offline"); + client.disconnect(); +} + +String MQTTPublisher::getTopic(String name) +{ + if (USE_CLIENT_ID) + { + return String(MQTT_PREFIX) + '/' + _clientId + '/' + name; + } + else + { + return String(MQTT_PREFIX) + '/' + name; + } +} + +bool MQTTPublisher::reconnect() +{ + lastConnectionAttempt = millis(); + + logger.debug("Attempt connection to server: " + String(MQTT_HOST_NAME)); + + // Attempt to connect + bool clientConnected; + if (String(MQTT_USER_NAME).length()) + { + logger.info("Connecting with credientials"); + clientConnected = client.connect(_clientId.c_str(), MQTT_USER_NAME, MQTT_PASSWORD); + } + else + { + logger.info("Connecting without credentials"); + clientConnected = client.connect(_clientId.c_str()); + } + + if (clientConnected) + { + logger.debug("connected"); + + hasMQTT = true; + + // Once connected, publish an announcement... + client.publish(getTopic("status").c_str(), "online"); + + return true; + } + else + { + logger.warn("failed, rc=" + client.state()); + } + + return false; +} + +void MQTTPublisher::start() +{ + if (String(MQTT_HOST_NAME).length() == 0 || MQTT_PORT == 0) + { + logger.warn("disabled. No hostname or port set."); + return; //not configured + } + + logger.debug("enabled. Connecting."); + + client.setServer(MQTT_HOST_NAME, MQTT_PORT); + reconnect(); + isStarted = true; +} + +void MQTTPublisher::stop() +{ + isStarted = false; +} + +void MQTTPublisher::handle() +{ + if (!isStarted) + return; + + if (!client.connected() && millis() - lastConnectionAttempt > RECONNECT_TIMEOUT) + { + hasMQTT = false; + if (!reconnect()) + return; + } +} + +bool MQTTPublisher::publishOnMQTT(String topicSuffix, String msg) +{ + String topic = getTopic(topicSuffix); + logger.debug("Publish to '" + topic + "':" + msg); + auto retVal = client.publish(topic.c_str(), msg.c_str()); + yield(); + return retVal; +} diff --git a/MQTTPublisher.h b/MQTTPublisher.h index 3fd8494..7e95d1c 100644 --- a/MQTTPublisher.h +++ b/MQTTPublisher.h @@ -5,6 +5,7 @@ #include #include "PubSubClient.h" #include "WiFiClient.h" +#include "Logger.h" #define RECONNECT_TIMEOUT 15000 @@ -14,20 +15,23 @@ extern bool hasWIFI; class MQTTPublisher { private: - bool debugMode; + Logger logger; + bool _debugMode; + String _clientId; bool isStarted; uint32_t lastConnectionAttempt = 0; // last reconnect uint32_t lastUpdateMqtt; // last data send bool reconnect(); + String getTopic(String name); public: - MQTTPublisher(bool inDebugMode = false); + MQTTPublisher(String clientId = String(ESP.getChipId(), HEX)); ~MQTTPublisher(); void start(); void stop(); void handle(); - bool publishOnMQTT(String prepend, String topic, String value); + bool publishOnMQTT(String topic, String msg); }; diff --git a/README.md b/README.md index 1faa802..b272a19 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,66 @@ # esp8266-dsmr -A ESP8266 based DSMR reader, posting onto MQTT, powered directly from the meter itself, no external power supply needed.. -All units (except power tariff and version) are rounded to 3 decimals. +A ESP8266 based DSMR reader, posting onto MQTT, powered directly from the meter itself, no external power supply needed. The code should work on DSRM v2.2 and higher, only tested on V4.2. ![esp8266-dsmr](https://github.com/bram2202/esp8266-dsmr/blob/master/docs/esp8266-dsmr.jpg "esp8266-dsmr") ## Requirements -* ESP8266 (Wemos/LOLIN D1 mini) +* Arduino IDE / VS code +* ESP8266 board (Wemos/LOLIN D1 mini/ESP01/NodeMCU) * Basic soldering and wiring skills * (For Wemos d1 mini) CH340G driver [[link]](https://wiki.wemos.cc/downloads) -* Arduino IDE -* Hardware package for arduino [[LINK]](https://github.com/esp8266/Arduino) -* MQTT lib. for Arduino [[LINK]](https://pubsubclient.knolleary.net/) +## Library dependencies +- [PubSubClient](https://pubsubclient.knolleary.net) - MQTT client +- [Core for ESP8266](https://github.com/esp8266/Arduino) - Arduino core for ESP8266 WiFi chip ## Supported messages + +### Info +| Name | unit | DSMR code | MQTT topic | +|:---- |:-------|:------ |:------| +| DSMR version | - | 1-3:0.2.8 | /version | +| Status | online, offline | - | /status | + +### Power | Name | unit | DSMR code | MQTT topic | |:---- |:-------|:------ |:------| -| DSMR version | - | 0.2.8 | dsmr/power_consuption | -| power consuption | kW | 1.7.0 | dsmr/power_consuption | -| power prduction | kW | 2.7.0| dsmr/power_production | -| total consuption low | kWh | 1.8.1 | dsmr/total_consuption_low | -| total consuption high | kWh | 1.8.2 | dsmr/total_consuption_high | -| total production low | kWh | 2.8.1 | dsmr/total_production_low | -| total production high | kWh | 2.8.2 | dsmr/total_production_high | -| total gas | m3 | 24.2.1 | dsmr/total_gas | -| power tariff | 1 = low, 2 = high | 96.14.0 | dsmr/power_tariff | +| current power consumption | kW | 1-0:1.7.0 | /power/consumption | +| current power production | kW | 1-0:2.7.0 | /power/production | +| total consumption low | kWh | 1-0:1.8.1 | /power/total_consumption_low | +| total consumption high | kWh | 1-0:1.8.2 | /power/total_consumption_high | +| total production low | kWh | 1-0:2.8.1 | /power/total_production_low | +| total production high | kWh | 1-0:2.8.2 | /power/total_production_high | +| power tariff | 1 = low, 2 = high | 0-0:96.14.0 | /power/power_tariff | +| short power outages | - | 0-0:96.7.21 |/power/short_power_outages | +| long power outages | - | 0-0:96.7.9 |/power/long_power_outages | +| instant current phase 1 | A | 1-0:31.7.0 |/power/phase_1/current | +| instant current phase 2 | A | 1-0:51.7.0 |/power/phase_2/current | +| instant current phase 3 | A | 1-0:71.7.0 |/power/phase_3/current | +| instant usage phase 1 | kW | 1-0:21.7.0 |/power/phase_1/usage | +| instant usage phase 2 | kW | 1-0:41.7.0 |/power/phase_2/usage | +| instant usage phase 3 | kW | 1-0:61.7.0 |/power/phase_3/usage | +| instant delivery phase 1 | kW | 1-0:22.7.0 |/power/phase_1/delivery | +| instant delivery phase 2 | kW | 1-0:42.7.0 |/power/phase_2/delivery | +| instant delivery phase 3 | kW | 1-0:62.7.0 |/power/phase_3/delivery | +| short drops phase 1 | - | 1-0:32.32.0 | /power/phase_1/drops | +| short drops phase 2 | - | 1-0:52.32.0 | /power/phase_2/drops | +| short drops phase 3 | - | 1-0:72.32.0 | /power/phase_3/drops | +| short peaks phase 1 | - | 1-0:32.36.0 | /power/phase_1/peaks | +| short peaks phase 2 | - | 1-0:52.36.0 | /power/phase_2/peaks | +| short peaks phase 3 | - | 1-0:72.36.0 | /power/phase_3/peaks | +| timestamp| - | 0-0:1.0.0 | /power/timestamp | +| device id | - | 0-0:96.1.1 | /power/device | + +### Gas +| Name | unit | DSMR code | MQTT topic | +|:---- |:-------|:------ |:------| +| total gas | m3 | 0-1:24.2.1 | /gas/total | +| timestamp| - | 0-1:24.2.1| /gas/timestamp | +| device id | - | 0-1:96.1.0 | /gas/device | + ## Settings Copy `Settings.example.h` to `Settings.h` and fill in the correct data. @@ -42,8 +75,9 @@ Copy `Settings.example.h` to `Settings.h` and fill in the correct data. | MQTT_USER_NAME| - | MQTT user name | | MQTT_PASSWORD | - | MQTT password | | MQTT_HOSTNAME| ESP-DSMR | MQTT name | -| MQTT_TOPIC | dsmr | MQTT topic prefix | -| DEBUGE_MODE | true | debug mode | +| MQTT_PREFIX | dsmr | MQTT prefix | +| USE_CLIENT_ID | FALSE | Use clientId in prefix | +| LOG_LEVEL | INFO | ( DEBUG / INFO / WARN ) | ## Circuit @@ -83,4 +117,4 @@ Connecting to the DSMR witn a RJ11 in Port 1 (P1), found on most smart meters. - If the level shifter inverter is connected, it's impossible to flash the firmware.
Pin RX is used, disconnect the pin to flash new firmware. - Some DSMR cannot deliver enough power to run the Wemos stably.
-Connect a 5V usb supply to fix this. \ No newline at end of file +Connect a 5V usb supply to fix this. diff --git a/Settings.example.h b/Settings.example.h index 962cc71..b62e9c8 100644 --- a/Settings.example.h +++ b/Settings.example.h @@ -8,22 +8,25 @@ #define WIFI_PASSWORD "" //set the mqqt host name or ip address to your mqqt host. Leave empty to disable mqtt. -#define MQTT_HOST_NAME "" +#define MQTT_HOST_NAME "" //mqtt port for the above host -#define MQTT_PORT 1883 +#define MQTT_PORT 1883 //if authentication is enabled for mqtt, set the username below. Leave empty to disable authentication -#define MQTT_USER_NAME "" +#define MQTT_USER_NAME "" //password for above user -#define MQTT_PASSWORD "" +#define MQTT_PASSWORD "" //publish online status name #define MQTT_HOSTNAME "ESP-DSMR" -//default MQTT topic -#define MQTT_TOPIC "dsmr" +//default MQTT prefix +#define MQTT_PREFIX "dsmr" -//for debugging, print info on serial -#define DEBUGE_MODE true \ No newline at end of file +// Use Client ID in MQTT prefix +#define USE_CLIENT_ID false + +//for debugging, print info on serial (DEBUG, INFO, WARN) +#define LOG_LEVEL INFO diff --git a/WifiConnector.cpp b/WifiConnector.cpp index 3644efd..e787ce0 100644 --- a/WifiConnector.cpp +++ b/WifiConnector.cpp @@ -7,9 +7,9 @@ #include "ESP8266mDNS.h" // Create Wifi Connector -WifiConnector::WifiConnector(bool inDebugMode) +WifiConnector::WifiConnector() { - debugMode = inDebugMode; + logger = Logger("WifiConnector"); tryingReconnect = false; } @@ -17,77 +17,62 @@ WifiConnector::WifiConnector(bool inDebugMode) void WifiConnector::start() { - if (debugMode){ - Serial.println("Wifi) Start "); - } + logger.info("Start"); // Setup Wifi WiFi.mode(WIFI_STA); WiFi.hostname(WIFI_HOSTNAME); - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // This funtion is called from main setup function, // Wait until unit has wifi before continuing - while (WiFi.status() != WL_CONNECTED) { - delay(500); - if (debugMode){ - Serial.print("."); - } + while (WiFi.status() != WL_CONNECTED) + { + delay(500); + logger.debug("."); } // Set wifi bool hasWIFI = true; - if (debugMode) - { - Serial.println("Wifi) Connected!"); - Serial.println("Wifi) IP: "); - Serial.println(WiFi.localIP()); - } - + logger.info("Connected!"); + logger.debug("IP: " + WiFi.localIP()); } // If wifi connection is lost, try to reconnect void WifiConnector::reconnect() { - if (debugMode){ - Serial.println("Wifi) Try to reconnect!"); - } - - // First hit, try to reconnect. - if(!tryingReconnect) + logger.debug("Try to reconnect!"); + + // First hit, try to reconnect. + if (!tryingReconnect) { WiFi.reconnect(); tryingReconnect = true; } - } // handle function called from main loop void WifiConnector::handle() { - + // Check if WIfi is Connected - if(!WiFi.isConnected() && !tryingReconnect){ - - if (debugMode){ - Serial.println("Wifi) Disconnected!"); - } + if (!WiFi.isConnected() && !tryingReconnect) + { + + logger.info("Disconnected!"); // Set bool false and try to reconnect hasWIFI = false; reconnect(); - - }else if (WiFi.isConnected() && !hasWIFI){ // Wifi is Reconnected + } + else if (WiFi.isConnected() && !hasWIFI) + { // Wifi is Reconnected - if (debugMode){ - Serial.println("Wifi) Reconnected!"); - } + logger.info("Reconnected!"); hasWIFI = true; tryingReconnect = false; - } - -} \ No newline at end of file +} diff --git a/WifiConnector.h b/WifiConnector.h index 88bd0b2..6fa6463 100644 --- a/WifiConnector.h +++ b/WifiConnector.h @@ -1,16 +1,17 @@ #pragma once +#include "Logger.h" extern bool hasWIFI; class WifiConnector { private: - bool debugMode; + Logger logger; bool tryingReconnect; public: - WifiConnector(bool inDebugMode = false); + WifiConnector(); void start(); void handle(); void reconnect(); -}; \ No newline at end of file +}; diff --git a/esp8266-dsmr.ino b/esp8266-dsmr.ino index 59425b9..78c4252 100644 --- a/esp8266-dsmr.ino +++ b/esp8266-dsmr.ino @@ -3,130 +3,140 @@ #include #include #include "MQTTPublisher.h" +#include #include "WifiConnector.h" #include "ESP8266mDNS.h" #include "Settings.h" - -MQTTPublisher mqqtPublisher(DEBUGE_MODE); -WifiConnector wifiConnector(DEBUGE_MODE); +#include "Logger.h" + +typedef struct +{ + String name; + String key; // OBIS property key + int start; // start of value in string + int end; // end of value in string + + enum + { + STRING, + FLOAT, + INT + } valueType; + +} Measurement; + +const Measurement measurements[] = { + {"version", "1-3:0.2.8", 10, 12, Measurement::STRING}, + {"power/timestamp", "0-0:1.0.0", 10, 23, Measurement::STRING}, + {"power/device_id", "0-0:96.1.1", 11, 45, Measurement::STRING}, + {"power/consuption", "1-0:1.7.0", 10, 16, Measurement::FLOAT}, + {"power/production", "1-0:2.7.0", 10, 16, Measurement::FLOAT}, + {"power/total_consuption_low", "1-0:1.8.1", 10, 20, Measurement::FLOAT}, + {"power/total_consuption_high", "1-0:1.8.2", 10, 20, Measurement::FLOAT}, + {"power/total_production_low", "1-0:2.8.1", 10, 20, Measurement::FLOAT}, + {"power/total_production_high", "1-0:2.8.2", 10, 20, Measurement::FLOAT}, + {"power/power_tariff", "0-0:96.14.0", 12, 16, Measurement::INT}, + {"power/short_power_outages", "0-0:96.7.21", 12, 17, Measurement::INT}, + {"power/long_power_outages", "0-0:96.7.9", 11, 16, Measurement::INT}, + {"power/phase_1/short_power_drops", "1-0:32.32.0", 12, 17, Measurement::INT}, + {"power/phase_2/short_power_drops", "1-0:52.32.0", 12, 17, Measurement::INT}, + {"power/phase_3/short_power_drops", "1-0:72.32.0", 12, 17, Measurement::INT}, + {"power/phase_1/short_power_peaks", "1-0:32.36.0", 12, 17, Measurement::INT}, + {"power/phase_2/short_power_peaks", "1-0:52.36.0", 12, 17, Measurement::INT}, + {"power/phase_3/short_power_peaks", "1-0:72.36.0", 12, 17, Measurement::INT}, + {"power/phase_1/current", "1-0:31.7.0", 11, 14, Measurement::INT}, + {"power/phase_2/current", "1-0:51.7.0", 11, 14, Measurement::INT}, + {"power/phase_3/current", "1-0:71.7.0", 11, 14, Measurement::INT}, + {"power/phase_1/usage", "1-0:21.7.0", 11, 17, Measurement::FLOAT}, + {"power/phase_2/usage", "1-0:41.7.0", 11, 17, Measurement::FLOAT}, + {"power/phase_3/usage", "1-0:61.7.0", 11, 17, Measurement::FLOAT}, + {"power/phase_1/delivery", "1-0:22.7.0", 11, 17, Measurement::FLOAT}, + {"power/phase_2/delivery", "1-0:42.7.0", 11, 17, Measurement::FLOAT}, + {"power/phase_3/delivery", "1-0:62.7.0", 11, 17, Measurement::FLOAT}, + {"gas/total", "0-1:24.2.1", 26, 35, Measurement::FLOAT}, + {"gas/device_id", "0-1:96.1.0", 11, 45, Measurement::STRING}, + {"gas/timestamp", "0-1:24.2.1", 11, 24, Measurement::STRING}, +}; + +MQTTPublisher mqttPublisher; +WifiConnector wifiConnector; WiFiUDP ntpUDP; String incomingString = ""; bool hasMQTT = false; bool hasWIFI = false; +Logger logger = Logger("App"); -void setup() { +void setup() +{ // Start serial ESP8266 RX port (pin 3) Serial.begin(115200); pinMode(3, FUNCTION_0); - if (DEBUGE_MODE) { - Serial.println("Booting"); - } + logger.info("Booting"); // Setup Wifi + wifiConnector = WifiConnector(); wifiConnector.start(); // Setup MQTT - mqqtPublisher.start(); + mqttPublisher = MQTTPublisher(); + mqttPublisher.start(); + + // Setup OTA + ArduinoOTA.setHostname(WIFI_HOSTNAME); + ArduinoOTA.begin(); } -void loop() { - +void loop() +{ + wifiConnector.handle(); yield(); - mqqtPublisher.handle(); + ArduinoOTA.handle(); + yield(); + mqttPublisher.handle(); yield(); // If serial received, read until newline - if (Serial.available() > 0) { + if (Serial.available() > 0) + { incomingString = Serial.readStringUntil('\n'); - handelString(incomingString); + handleString(incomingString); } } // Regex are not supported, so use indexOf and substring -void handelString(String incomingString) { - - // DSMR version - int found1 = incomingString.indexOf("1-3:0.2.8"); - if (found1 > -1) { - String value1 = incomingString.substring(10, 12); - if (DEBUGE_MODE) - Serial.println("0.2.8= " + value1); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/version", value1); - } - - // Power consuption - int found2 = incomingString.indexOf("1-0:1.7.0"); - if (found2 > -1) { - String value2 = String(incomingString.substring(10, 16).toFloat(), 3); - if (DEBUGE_MODE) - Serial.println("1.7.0= " + value2); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/power_consuption", value2); - } - - // Power production - int found3 = incomingString.indexOf("1-0:2.7.0"); - if (found3 > -1) { - String value3 = String(incomingString.substring(10, 16).toFloat(), 3); - if (DEBUGE_MODE) - Serial.println("2.7.0= " + value3); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/power_production", value3); - } - - // Total consuption low - int found4 = incomingString.indexOf("1-0:1.8.1"); - if (found4 > -1) { - String value4 = String(incomingString.substring(10, 20).toFloat(), 3); - if (DEBUGE_MODE) - Serial.println("1.8.1= " + value4); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/total_consuption_low", value4); +void handleString(String incomingString) +{ + + int i; + int arraySize = sizeof(measurements) / sizeof(measurements[0]); + + for (i = 0; i < arraySize; i++) + { + Measurement measurement = measurements[i]; + String obisKey = measurement.key; + + if (incomingString.indexOf(obisKey) > -1) + { + // found + String value = incomingString.substring(measurement.start, measurement.end); + logger.debug("DEBUG_1 " + obisKey + "=" + value); + + switch (measurement.valueType) + { + case Measurement::FLOAT: + value = String(value.toFloat(), 3); + break; + case Measurement::INT: + value = String(value.toInt()); + break; + default: + break; + } + + mqttPublisher.publishOnMQTT(measurement.name, value); + } } - - // Total consuption high - int found5 = incomingString.indexOf("1-0:1.8.2"); - if (found5 > -1) { - String value5 = String(incomingString.substring(10, 20).toFloat(), 3); - if (DEBUGE_MODE) - Serial.println("1.8.2= " + value5); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/total_consuption_high", value5); - } - - // Total production low - int found6 = incomingString.indexOf("1-0:2.8.1"); - if (found6 > -1) { - String value6 = String(incomingString.substring(10, 20).toFloat(), 3); - if (DEBUGE_MODE) - Serial.println("2.8.1= " + value6); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/total_production_low", value6); - } - - // Total production high - int found7 = incomingString.indexOf("1-0:2.8.2"); - if (found7 > -1) { - String value7 = String(incomingString.substring(10, 20).toFloat(), 3); - if (DEBUGE_MODE) - Serial.println("2.8.2= " + value7); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/total_production_high", value7); - } - - // Total gas - int found8 = incomingString.indexOf("0-1:24.2.1"); - if (found8 > -1) { - String value8 = String(incomingString.substring(26, 35).toFloat(), 3); - if (DEBUGE_MODE) - Serial.println("24.2.1= " + value8); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/total_gas", value8); - } - - // Power tariff (1 low, 2 high) - int found9 = incomingString.indexOf("0-0:96.14.0"); - if (found9 > -1) { - String value9 = String(incomingString.substring(12, 16).toInt()); - if (DEBUGE_MODE) - Serial.println("96.14.0= " + value9); - mqqtPublisher.publishOnMQTT(MQTT_TOPIC, "/power_tariff", value9); - } - }