WIP: working teleinfo

This commit is contained in:
Mathieu Maret 2021-02-18 23:50:54 +01:00
parent 8fed8bedf4
commit 8f471fc0bf
4 changed files with 26 additions and 18 deletions

View File

@ -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"

View File

@ -4,7 +4,8 @@
#ifdef CONFIG_ENABLE_TELEINFO
#include <LibTeleinfo.h>
int TeleinfoSetup();
int TeleinfoProcess();
//int TeleinfoProcess();
int TeleinfoProcess(std::vector<struct mqttInfo> &batchInfo);
#else
typedef struct _ValueList {
} ValueList;
@ -13,7 +14,8 @@ int TeleinfoSetup() {
return -1;
};
int TeleinfoProcess(){
//int TeleinfoProcess(){
int TeleinfoProcess(std::vector<struct mqttInfo> &){
return 0;
};
#endif

View File

@ -8,27 +8,28 @@ void onNewFrame(ValueList *me)
SKETCH_DEBUG_PRINTLN("New Frame available");
}
int TeleinfoSetup() {
int TeleinfoSetup()
{
Serial.begin(1200, SERIAL_7E1);
tinfo.init();
tinfo.attachNewFrame(onNewFrame);
return 0;
}
int TeleinfoProcess() {
int TeleinfoProcess(std::vector<struct mqttInfo> &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<struct mqttInfo> batchInfo;
//std::vector<struct mqttInfo> 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;
}

View File

@ -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();
}
}