Domotique/WifiControlSensor/Teleinfo.ino

48 lines
1.0 KiB
C++

#ifdef CONFIG_ENABLE_TELEINFO
#include "Teleinfo.h"
#include <LibTeleinfo.h>
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<struct mqttInfo> 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