3 #include <LibTeleinfo.h>
4 #include <Adafruit_Sensor.h>
7 #include <HardwareSerial.h>
9 #include "garage-config.h"
11 const char* wifi_ssid = WIFI_SSID;
12 const char* wifi_pass = WIFI_PASS;
15 IPAddress influxdb_ip(INFLUXDB_IP);
16 long influxdb_port = INFLUXDB_PORT;
17 unsigned int localPort = 2390;
19 long unsigned poll_int = POLL_INT;
21 String location = LOCATION;
27 DHT_Unified dht(DHTPIN, DHTTYPE);
29 HardwareSerial TinfoSerial(1);
36 TinfoSerial.begin(9600,SERIAL_8N1, 22, 23);
38 WiFi.begin(WIFI_SSID, WIFI_PASS);
40 while (WiFi.status() != WL_CONNECTED) {
46 dht.temperature().getSensor(&sensor);
47 dht.humidity().getSensor(&sensor);
49 tinfo.init(TINFO_MODE_STANDARD);
50 // tinfo.attachNewFrame(NewTinfoFrame);
51 // tinfo.attachUpdatedFrame(NewTinfoFrame);
52 tinfo.attachData(NewTinfoFrame);
60 // Check wifi connexion
61 if ( WiFi.status() != WL_CONNECTED ) {
64 WiFi.begin(WIFI_SSID, WIFI_PASS);
65 while (retry < 10 || WiFi.status() != WL_CONNECTED) {
71 if ( WiFi.status() == WL_CONNECTED ) {
72 Serial.println("DEBUG");
73 sensors_event_t event;
75 dht.temperature().getEvent(&event);
76 if (isnan(event.temperature)) {
79 sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
81 dht.humidity().getEvent(&event);
82 if (isnan(event.relative_humidity)) {
85 sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
87 if ( TinfoSerial.available() ) {
88 Serial.println("DEBUG: process tinfo");
89 tinfo.process(TinfoSerial.read());
94 void sendToInfluxDB(String measure, String key, String value) {
95 String line = measure+" "+key+"="+value;
97 Udp.beginPacket(influxdb_ip, influxdb_port);
102 void NewTinfoFrame(ValueList * me, uint8_t flags)
104 Serial.println("DEBUG NewFrame");
108 Serial.println("DEBUG value");
109 if (me->value && strlen(me->value)) {
110 Serial.println("DEBUG name: "+String(me->name)+",value: "+String(me->value));
111 boolean isNumber = true;
113 char * p = me->value;
115 // check if value is number
116 while (*p && isNumber) {
117 if ( *p < '0' || *p > '9' ) {
123 // this will add "" on not number values
127 // this will remove leading zero on numbers
129 Serial.println("DEBUG influx, name: "+String(me->name)+",value: "+String(atol(me->value)));
130 sendToInfluxDB("teleinfo,city="+city, String(me->name), String(atol(me->value)));