From 8fed8bedf4c2931afa1807d01678416e1530e81a Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 18 Feb 2021 15:51:49 +0100 Subject: [PATCH] Add missing files --- WifiControlSensor/Teleinfo.h | 19 ++++++++++++++ WifiControlSensor/Teleinfo.ino | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 WifiControlSensor/Teleinfo.h create mode 100644 WifiControlSensor/Teleinfo.ino diff --git a/WifiControlSensor/Teleinfo.h b/WifiControlSensor/Teleinfo.h new file mode 100644 index 0000000..542ae17 --- /dev/null +++ b/WifiControlSensor/Teleinfo.h @@ -0,0 +1,19 @@ +#pragma once +#include "debug_sketch.h" + +#ifdef CONFIG_ENABLE_TELEINFO +#include +int TeleinfoSetup(); +int TeleinfoProcess(); +#else +typedef struct _ValueList { +} ValueList; +int TeleinfoSetup() { + SKETCH_DEBUG_PRINTLN("Teleinfo is disabled at build time"); + return -1; +}; + +int TeleinfoProcess(){ + return 0; +}; +#endif diff --git a/WifiControlSensor/Teleinfo.ino b/WifiControlSensor/Teleinfo.ino new file mode 100644 index 0000000..37e08d1 --- /dev/null +++ b/WifiControlSensor/Teleinfo.ino @@ -0,0 +1,47 @@ +#ifdef CONFIG_ENABLE_TELEINFO +#include "Teleinfo.h" +#include + +TInfo tinfo; +void onNewFrame(ValueList *me) +{ + SKETCH_DEBUG_PRINTLN("New Frame available"); +} + +int TeleinfoSetup() { + Serial.begin(1200, SERIAL_7E1); + + tinfo.init(); + tinfo.attachNewFrame(onNewFrame); + + + return 0; +} + +int TeleinfoProcess() { + 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; + 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}); + } + if (strcmp(me->name, "PAPP") == 0) { + float val = atof(me->value); + batchInfo.push_back({val, TELEINFO_PAPP_FEED_FORMAT, 0, 0}); + } + me = me->next; + } + if (mode == BOOTMODE_NORMAL) + MqttBatchPublish(batchInfo, conf.mqttUser, conf.host); + + return 0; +} +#endif