3 #include <LibTeleinfo2Std.h>
4 #include <Adafruit_Sensor.h>
7 #include <HardwareSerial.h>
9 #include "garage-config.h"
13 const char* wifi_ssid = WIFI_SSID;
14 const char* wifi_pass = WIFI_PASS;
17 IPAddress influxdb_ip(INFLUXDB_IP);
18 long influxdb_port = INFLUXDB_PORT;
19 unsigned int localPort = 2390;
21 unsigned long previousMillis = millis();
22 long unsigned poll_int = POLL_INT;
24 String location = LOCATION;
30 DHT_Unified dht(DHTPIN, DHTTYPE);
33 boolean tick1sec=0;// one for interrupt, don't mess with
34 unsigned long uptime=0; // save value we can use in sketch even if we're interrupted
36 // Used to indicate if we need to send all date or just modified ones
37 boolean fulldata = false;
39 HardwareSerial TinfoSerial(2);
59 TinfoSerial.begin(9600,SERIAL_7E1,22,23);
60 pinMode(22, INPUT_PULLUP);
63 WiFi.begin(WIFI_SSID, WIFI_PASS);
65 while (WiFi.status() != WL_CONNECTED) {
71 dht.temperature().getSensor(&sensor);
72 dht.humidity().getSensor(&sensor);
74 tinfo.init(TINFO_MODE_STD);
75 tinfo.attachDataStd(DataCallback);
81 if (millis() - previousMillis > POLL_INT)
84 previousMillis = millis();
86 // Check wifi connexion
87 if ( WiFi.status() != WL_CONNECTED ) {
90 WiFi.begin(WIFI_SSID, WIFI_PASS);
91 while (retry < 10 || WiFi.status() != WL_CONNECTED) {
97 if ( WiFi.status() == WL_CONNECTED ) {
98 Serial.println("DEBUG wifi connected, start temp measure");
99 sensors_event_t event;
101 dht.temperature().getEvent(&event);
102 if (isnan(event.temperature)) {
105 sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
107 dht.humidity().getEvent(&event);
108 if (isnan(event.relative_humidity)) {
111 sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
113 sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS", tinfo_SINSTS);
114 sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS1", tinfo_SINSTS1);
115 sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS2", tinfo_SINSTS2);
116 sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS3", tinfo_SINSTS3);
117 sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS1", tinfo_IRMS1);
118 sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS2", tinfo_IRMS2);
119 sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS3", tinfo_IRMS3);
120 sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS1", tinfo_URMS1);
121 sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS2", tinfo_URMS2);
122 sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS3", tinfo_URMS3);
123 sendToInfluxDB("teleinfo,city="+city+",location="+location, "EAST", tinfo_EAST);
126 if ( TinfoSerial.available() ) {
127 tinfo.process(TinfoSerial.read());
131 void sendToInfluxDB(String measure, String key, String value) {
132 String line = measure+" "+key+"="+value;
133 Serial.println("Sending to influxdb: "+line);
134 Udp.begin(localPort);
135 Udp.beginPacket(influxdb_ip, influxdb_port);
140 void DataCallback(char * tilabel, char * tihoro, char * tivalue)
142 if (strcmp(tilabel, "SINSTS") == 0 ) {
143 tinfo_SINSTS = String(atol(tivalue));
145 if (strcmp(tilabel, "SINSTS1") == 0 ) {
146 tinfo_SINSTS1 = String(atol(tivalue));
148 if (strcmp(tilabel, "SINSTS2") == 0 ) {
149 tinfo_SINSTS2 = String(atol(tivalue));
151 if (strcmp(tilabel, "SINSTS3") == 0 ) {
152 tinfo_SINSTS3 = String(atol(tivalue));
154 if (strcmp(tilabel, "IRMS1") == 0 ) {
155 tinfo_IRMS1 = String(atol(tivalue));
157 if (strcmp(tilabel, "IRMS2") == 0 ) {
158 tinfo_IRMS2 = String(atol(tivalue));
160 if (strcmp(tilabel, "IRMS3") == 0 ) {
161 tinfo_IRMS3 = String(atol(tivalue));
163 if (strcmp(tilabel, "URMS1") == 0 ) {
164 tinfo_URMS1 = String(atol(tivalue));
166 if (strcmp(tilabel, "URMS2") == 0 ) {
167 tinfo_URMS2 = String(atol(tivalue));
169 if (strcmp(tilabel, "URMS3") == 0 ) {
170 tinfo_URMS3 = String(atol(tivalue));
172 if (strcmp(tilabel, "EAST") == 0 ) {
173 tinfo_EAST = String(atol(tivalue));