From: Emmanuel Lacour Date: Fri, 30 Apr 2021 20:44:42 +0000 (+0200) Subject: Switch tinfo to standard mode X-Git-Url: http://git.home-dn.net/?p=manu%2Farduino-maison.git;a=commitdiff_plain;h=c2318af8b65624d7518d9c85ff4cdd245402c7b6 Switch tinfo to standard mode --- diff --git a/garage/garage.ino b/garage/garage.ino index 5128f1f..bb4ecaf 100644 --- a/garage/garage.ino +++ b/garage/garage.ino @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -25,11 +25,11 @@ WiFiUDP Udp; #define DHTTYPE DHT22 DHT_Unified dht(DHTPIN, DHTTYPE); -TeleInfo teleinfo(&Serial); +TInfo tinfo; void setup() { - Serial.begin(1200); + Serial.begin(9600); WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASS); @@ -42,9 +42,13 @@ void setup() { dht.temperature().getSensor(&sensor); dht.humidity().getSensor(&sensor); + tinfo.init(TINFO_MODE_STANDARD); + tinfo.attachNewFrame(NewTinfoFrame); + } void loop() { + delay(POLL_INT); // Check wifi connexion @@ -73,20 +77,8 @@ void loop() { } else { sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity)); } - - teleinfo.process(); - if(teleinfo.available()){ - long I1 = teleinfo.getLongVal("IINST1"); - long I2 = teleinfo.getLongVal("IINST2"); - long I3 = teleinfo.getLongVal("IINST3"); - long PAPP = teleinfo.getLongVal("PAPP"); - long BASE = teleinfo.getLongVal("BASE"); - sendToInfluxDB("teleinfo,city="+city+",phase=1", "IINST", String(I1)); - sendToInfluxDB("teleinfo,city="+city+",phase=2", "IINST", String(I2)); - sendToInfluxDB("teleinfo,city="+city+",phase=3", "IINST", String(I3)); - sendToInfluxDB("teleinfo,city="+city, "PAPP", String(PAPP)); - sendToInfluxDB("teleinfo,city="+city, "BASE", String(BASE)); - teleinfo.resetAvailable(); + if ( Serial.available() ) { + tinfo.process(Serial.read()); } } } @@ -98,3 +90,38 @@ void sendToInfluxDB(String measure, String key, String value) { Udp.print(line); Udp.endPacket(); } + +void NewTinfoFrame(ValueList * me) +{ + Serial.print("DEBUG NewFrame"); + if ( me ) { + while (me->next) { + me = me->next; + Serial.print("DEBUG value"); + if (me->value && strlen(me->value)) { + Serial.print("DEBUG name: "+String(me->name)+",value: "+String(me->value)); + boolean isNumber = true; + uint8_t c; + char * p = me->value; + + // check if value is number + while (*p && isNumber) { + if ( *p < '0' || *p > '9' ) { + isNumber = false; + } + p++; + } + + // this will add "" on not number values + if (!isNumber) { + // FIXME + } + // this will remove leading zero on numbers + else { + Serial.print("DEBUG influx, name: "+String(me->name)+",value: "+String(atol(me->value))); + sendToInfluxDB("teleinfo,city="+city, String(me->name), String(atol(me->value))); + } + } + } + } +} diff --git a/serre-semis/serre-semis-config.h.in b/serre-semis/serre-semis-config.h.in new file mode 100644 index 0000000..4a1402d --- /dev/null +++ b/serre-semis/serre-semis-config.h.in @@ -0,0 +1,13 @@ +// Enable debug on serial port +#define DEBUG 1 +// Wifi +#define WIFI_SSID "XXXXXX" +#define WIFI_PASS "xxxxxx" +// InfluxDB +#define INFLUXDB_IP {w,x,y,z} +#define INFLUXDB_PORT xxxx +// Polling interval (ms) +#define POLL_INT 10000 +// Location informations +#define CITY "xxxxx" +#define LOCATION "xxxxx" diff --git a/serre-semis/serre-semis.h.in b/serre-semis/serre-semis.h.in deleted file mode 100644 index 4a1402d..0000000 --- a/serre-semis/serre-semis.h.in +++ /dev/null @@ -1,13 +0,0 @@ -// Enable debug on serial port -#define DEBUG 1 -// Wifi -#define WIFI_SSID "XXXXXX" -#define WIFI_PASS "xxxxxx" -// InfluxDB -#define INFLUXDB_IP {w,x,y,z} -#define INFLUXDB_PORT xxxx -// Polling interval (ms) -#define POLL_INT 10000 -// Location informations -#define CITY "xxxxx" -#define LOCATION "xxxxx"