3 #include <LibTeleinfo.h>
4 #include <Adafruit_Sensor.h>
8 #include "garage-config.h"
10 const char* wifi_ssid = WIFI_SSID;
11 const char* wifi_pass = WIFI_PASS;
14 IPAddress influxdb_ip(INFLUXDB_IP);
15 long influxdb_port = INFLUXDB_PORT;
16 unsigned int localPort = 2390;
18 long unsigned poll_int = POLL_INT;
20 String location = LOCATION;
26 DHT_Unified dht(DHTPIN, DHTTYPE);
34 WiFi.begin(WIFI_SSID, WIFI_PASS);
36 while (WiFi.status() != WL_CONNECTED) {
42 dht.temperature().getSensor(&sensor);
43 dht.humidity().getSensor(&sensor);
45 tinfo.init(TINFO_MODE_STANDARD);
46 tinfo.attachNewFrame(NewTinfoFrame);
54 // Check wifi connexion
55 if ( WiFi.status() != WL_CONNECTED ) {
58 WiFi.begin(WIFI_SSID, WIFI_PASS);
59 while (retry < 10 || WiFi.status() != WL_CONNECTED) {
65 if ( WiFi.status() == WL_CONNECTED ) {
66 sensors_event_t event;
68 dht.temperature().getEvent(&event);
69 if (isnan(event.temperature)) {
72 sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
74 dht.humidity().getEvent(&event);
75 if (isnan(event.relative_humidity)) {
78 sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
80 if ( Serial.available() ) {
81 tinfo.process(Serial.read());
86 void sendToInfluxDB(String measure, String key, String value) {
87 String line = measure+" "+key+"="+value;
89 Udp.beginPacket(influxdb_ip, influxdb_port);
94 void NewTinfoFrame(ValueList * me)
96 Serial.print("DEBUG NewFrame");
100 Serial.print("DEBUG value");
101 if (me->value && strlen(me->value)) {
102 Serial.print("DEBUG name: "+String(me->name)+",value: "+String(me->value));
103 boolean isNumber = true;
105 char * p = me->value;
107 // check if value is number
108 while (*p && isNumber) {
109 if ( *p < '0' || *p > '9' ) {
115 // this will add "" on not number values
119 // this will remove leading zero on numbers
121 Serial.print("DEBUG influx, name: "+String(me->name)+",value: "+String(atol(me->value)));
122 sendToInfluxDB("teleinfo,city="+city, String(me->name), String(atol(me->value)));