Domotique/WifiControlSensor/Teleinfo.ino

78 lines
1.5 KiB
Arduino
Raw Normal View History

2021-02-18 15:51:49 +01:00
#ifdef CONFIG_ENABLE_TELEINFO
#include "Teleinfo.h"
#include <LibTeleinfo.h>
2022-09-10 21:53:06 +02:00
#define TELESerial Serial
2021-02-18 15:51:49 +01:00
TInfo tinfo;
2021-02-18 23:50:54 +01:00
int TeleinfoSetup()
{
2022-09-10 21:53:06 +02:00
TELESerial.begin(1200, SERIAL_7E1);
2021-02-18 15:51:49 +01:00
tinfo.init();
return 0;
}
2023-03-27 21:01:20 +02:00
int TeleinfoRetrieve(float &iinst, float &papp, float &base){
2021-02-18 15:51:49 +01:00
int c;
2022-09-10 21:53:06 +02:00
while ((c = TELESerial.read()) >= 0) {
2021-02-18 15:51:49 +01:00
tinfo.process(c);
}
2021-02-18 23:50:54 +01:00
ValueList *me = tinfo.getList();
if (me)
me = me->next;
2021-02-18 15:51:49 +01:00
while (me) {
if (strcmp(me->name, "IINST") == 0) {
2023-03-27 21:01:20 +02:00
iinst = atof(me->value);
2021-02-18 15:51:49 +01:00
}
if (strcmp(me->name, "PAPP") == 0) {
2023-03-27 21:01:20 +02:00
papp = atof(me->value);
2021-02-18 15:51:49 +01:00
}
2021-02-18 23:50:54 +01:00
if (strcmp(me->name, "BASE") == 0) {
2023-03-27 21:01:20 +02:00
float tmp = atof(me->value);
if(tmp != 0){
base = tmp;
}
2021-02-18 23:50:54 +01:00
}
2021-02-18 15:51:49 +01:00
me = me->next;
}
2022-09-10 21:53:06 +02:00
return 0;
}
2023-03-27 21:01:20 +02:00
int TeleinfoRetrieve(float &iinst, float &papp, float &base,
2022-09-24 22:43:15 +02:00
std::vector<struct mqttInfo> &batchInfo)
2022-09-10 21:53:06 +02:00
{
int c;
while ((c = TELESerial.read()) >= 0) {
tinfo.process(c);
}
ValueList *me = tinfo.getList();
if (me)
me = me->next;
while (me) {
if (strcmp(me->name, "IINST") == 0) {
iinst = atof(me->value);
2022-09-24 22:43:15 +02:00
batchInfo.push_back({iinst, TELEINFO_IINST_FEED_FORMAT, 0, 0});
2022-09-10 21:53:06 +02:00
}
if (strcmp(me->name, "PAPP") == 0) {
papp = atof(me->value);
2022-09-24 22:43:15 +02:00
batchInfo.push_back({papp, TELEINFO_PAPP_FEED_FORMAT, 0, 0});
2022-09-10 21:53:06 +02:00
}
if (strcmp(me->name, "BASE") == 0) {
2023-03-27 21:01:20 +02:00
float tmp = atof(me->value);
if(tmp != 0){
base = tmp;
batchInfo.push_back({base, TELEINFO_BASE_FEED_FORMAT, 0, 0});
}
2022-09-10 21:53:06 +02:00
}
me = me->next;
}
2021-02-18 15:51:49 +01:00
return 0;
}
#endif