From 8f471fc0bf148f2e60001ca9609b83bbdbc87f99 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 18 Feb 2021 23:50:54 +0100 Subject: [PATCH] WIP: working teleinfo --- WifiControlSensor/MQTT.h | 1 + WifiControlSensor/Teleinfo.h | 6 ++++-- WifiControlSensor/Teleinfo.ino | 25 +++++++++++++++---------- WifiControlSensor/WifiControlSensor.ino | 12 ++++++------ 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/WifiControlSensor/MQTT.h b/WifiControlSensor/MQTT.h index 18c9856..ff56b21 100644 --- a/WifiControlSensor/MQTT.h +++ b/WifiControlSensor/MQTT.h @@ -20,6 +20,7 @@ #define BME680_IAQ_ACC_FEED_FORMAT "/feeds/%s/%s/bme680/iaqAcc" #define TELEINFO_IINST_FEED_FORMAT "/feeds/%s/%s/teleinfo/iinst" #define TELEINFO_PAPP_FEED_FORMAT "/feeds/%s/%s/teleinfo/papp" +#define TELEINFO_BASE_FEED_FORMAT "/feeds/%s/%s/teleinfo/base" #ifndef CONFIG_DISABLE_MQTT #include "Adafruit_MQTT.h" diff --git a/WifiControlSensor/Teleinfo.h b/WifiControlSensor/Teleinfo.h index 542ae17..3931f23 100644 --- a/WifiControlSensor/Teleinfo.h +++ b/WifiControlSensor/Teleinfo.h @@ -4,7 +4,8 @@ #ifdef CONFIG_ENABLE_TELEINFO #include int TeleinfoSetup(); -int TeleinfoProcess(); +//int TeleinfoProcess(); +int TeleinfoProcess(std::vector &batchInfo); #else typedef struct _ValueList { } ValueList; @@ -13,7 +14,8 @@ int TeleinfoSetup() { return -1; }; -int TeleinfoProcess(){ +//int TeleinfoProcess(){ +int TeleinfoProcess(std::vector &){ return 0; }; #endif diff --git a/WifiControlSensor/Teleinfo.ino b/WifiControlSensor/Teleinfo.ino index 37e08d1..4a7cf20 100644 --- a/WifiControlSensor/Teleinfo.ino +++ b/WifiControlSensor/Teleinfo.ino @@ -8,27 +8,28 @@ void onNewFrame(ValueList *me) SKETCH_DEBUG_PRINTLN("New Frame available"); } -int TeleinfoSetup() { - Serial.begin(1200, SERIAL_7E1); +int TeleinfoSetup() +{ + Serial.begin(1200, SERIAL_7E1); tinfo.init(); tinfo.attachNewFrame(onNewFrame); - return 0; } -int TeleinfoProcess() { +int TeleinfoProcess(std::vector &batchInfo) +{ int c; while ((c = Serial.read()) >= 0) { - SKETCH_DEBUG_PRINTF("Got char %c\n", (char)c); tinfo.process(c); } - ValueList * me = tinfo.getList(); - std::vector batchInfo; + ValueList *me = tinfo.getList(); + //std::vector batchInfo; + if (me) + me = me->next; while (me) { - SKETCH_DEBUG_PRINTF("info %s\n", me->name); if (strcmp(me->name, "IINST") == 0) { float val = atof(me->value); batchInfo.push_back({val, TELEINFO_IINST_FEED_FORMAT, 0, 0}); @@ -37,10 +38,14 @@ int TeleinfoProcess() { float val = atof(me->value); batchInfo.push_back({val, TELEINFO_PAPP_FEED_FORMAT, 0, 0}); } + if (strcmp(me->name, "BASE") == 0) { + float val = atof(me->value); + batchInfo.push_back({val, TELEINFO_BASE_FEED_FORMAT, 0, 0}); + } me = me->next; } - if (mode == BOOTMODE_NORMAL) - MqttBatchPublish(batchInfo, conf.mqttUser, conf.host); + //if (mode == BOOTMODE_NORMAL) + // MqttBatchPublish(batchInfo, conf.mqttUser, conf.host); return 0; } diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index 7cf7b31..4efb40d 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -230,10 +230,10 @@ void setup() { SKETCH_DEBUG_PRINTLN(); // Get GPIO 3 Status -#if CONFIG_SERIAL_SHOULD_SWAP - SKETCH_DEBUG_PRINTLN("SWAP UART"); - Serial.swap(); //Switch Serial on GPIO 13 & 15 -#endif +//#if CONFIG_SERIAL_SHOULD_SWAP +// SKETCH_DEBUG_PRINTLN("SWAP UART"); +// Serial.swap(); //Switch Serial on GPIO 13 & 15 +//#endif pinMode(CONFIG_SETUP_GPIO, INPUT_PULLUP); int txStatus = digitalRead(CONFIG_SETUP_GPIO); //#if !defined(CONFIG_ENABLE_EXTRA_GPIO) && CONFIG_SERIAL_SHOULD_SWAP @@ -363,11 +363,11 @@ void loop() { batchInfo.push_back({bme680BSECIaq, BME680_IAQ_FEED_FORMAT, 0, 0}); batchInfo.push_back({bme680BSECIaqAcc, BME680_IAQ_ACC_FEED_FORMAT, 0, 0}); } - + TeleinfoProcess(batchInfo); if (mode == BOOTMODE_NORMAL) MqttBatchPublish(batchInfo, conf.mqttUser, conf.host); nbCycle = 0; } - TeleinfoProcess(); + } }