2021-02-18 15:51:49 +01:00
|
|
|
#ifdef CONFIG_ENABLE_TELEINFO
|
|
|
|
#include "Teleinfo.h"
|
|
|
|
#include <LibTeleinfo.h>
|
|
|
|
|
|
|
|
TInfo tinfo;
|
|
|
|
void onNewFrame(ValueList *me)
|
|
|
|
{
|
|
|
|
SKETCH_DEBUG_PRINTLN("New Frame available");
|
|
|
|
}
|
|
|
|
|
2021-02-18 23:50:54 +01:00
|
|
|
int TeleinfoSetup()
|
|
|
|
{
|
|
|
|
Serial.begin(1200, SERIAL_7E1);
|
2021-02-18 15:51:49 +01:00
|
|
|
|
|
|
|
tinfo.init();
|
|
|
|
tinfo.attachNewFrame(onNewFrame);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-18 23:50:54 +01:00
|
|
|
int TeleinfoProcess(std::vector<struct mqttInfo> &batchInfo)
|
|
|
|
{
|
2021-02-18 15:51:49 +01:00
|
|
|
int c;
|
|
|
|
|
|
|
|
while ((c = Serial.read()) >= 0) {
|
|
|
|
tinfo.process(c);
|
|
|
|
}
|
2021-02-18 23:50:54 +01:00
|
|
|
ValueList *me = tinfo.getList();
|
|
|
|
//std::vector<struct mqttInfo> batchInfo;
|
|
|
|
if (me)
|
|
|
|
me = me->next;
|
2021-02-18 15:51:49 +01:00
|
|
|
while (me) {
|
|
|
|
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});
|
|
|
|
}
|
2021-02-18 23:50:54 +01:00
|
|
|
if (strcmp(me->name, "BASE") == 0) {
|
|
|
|
float val = atof(me->value);
|
|
|
|
batchInfo.push_back({val, TELEINFO_BASE_FEED_FORMAT, 0, 0});
|
|
|
|
}
|
2021-02-18 15:51:49 +01:00
|
|
|
me = me->next;
|
|
|
|
}
|
2021-02-18 23:50:54 +01:00
|
|
|
//if (mode == BOOTMODE_NORMAL)
|
|
|
|
// MqttBatchPublish(batchInfo, conf.mqttUser, conf.host);
|
2021-02-18 15:51:49 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|