3 #include <LibTeleinfo2Std.h>
5 #include <DallasTemperature.h>
6 #include <HardwareSerial.h>
8 #include "garage-config.h"
12 const char* wifi_ssid = WIFI_SSID;
13 const char* wifi_pass = WIFI_PASS;
16 IPAddress influxdb_ip(INFLUXDB_IP);
17 long influxdb_port = INFLUXDB_PORT;
18 unsigned int localPort = 2390;
20 unsigned long previousMillis = millis();
21 long unsigned poll_int = POLL_INT;
23 String location = LOCATION;
27 // GPIO where the DS18B20 is connected to
28 const int oneWireBus = 19;
29 // Setup a oneWire instance to communicate with any OneWire devices
30 OneWire oneWire(oneWireBus);
31 // Pass our oneWire reference to Dallas Temperature sensor
32 DallasTemperature sensors(&oneWire);
35 boolean tick1sec=0;// one for interrupt, don't mess with
36 unsigned long uptime=0; // save value we can use in sketch even if we're interrupted
38 // Used to indicate if we need to send all date or just modified ones
39 boolean fulldata = false;
41 HardwareSerial TinfoSerial(2);
61 TinfoSerial.begin(9600,SERIAL_7E1,22,23);
62 pinMode(22, INPUT_PULLUP);
65 WiFi.begin(WIFI_SSID, WIFI_PASS);
67 while (WiFi.status() != WL_CONNECTED) {
73 tinfo.init(TINFO_MODE_STD);
74 tinfo.attachDataStd(DataCallback);
80 if (millis() - previousMillis > POLL_INT)
83 previousMillis = millis();
85 // Check wifi connexion
86 if ( WiFi.status() != WL_CONNECTED ) {
89 WiFi.begin(WIFI_SSID, WIFI_PASS);
90 while (retry < 10 || WiFi.status() != WL_CONNECTED) {
96 if ( WiFi.status() == WL_CONNECTED ) {
97 Serial.println("DEBUG wifi connected, start temp measure");
99 sensors.requestTemperatures();
100 float tempC = sensors.getTempCByIndex(0);
102 if(tempC == DEVICE_DISCONNECTED_C)
105 sendToInfluxDB("temperature,city="+city+",location=serre_semis", "value", String(tempC));
108 sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS", tinfo_SINSTS);
109 sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS1", tinfo_SINSTS1);
110 sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS2", tinfo_SINSTS2);
111 sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS3", tinfo_SINSTS3);
112 sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS1", tinfo_IRMS1);
113 sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS2", tinfo_IRMS2);
114 sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS3", tinfo_IRMS3);
115 sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS1", tinfo_URMS1);
116 sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS2", tinfo_URMS2);
117 sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS3", tinfo_URMS3);
118 sendToInfluxDB("teleinfo,city="+city+",location="+location, "EAST", tinfo_EAST);
121 if ( TinfoSerial.available() ) {
122 tinfo.process(TinfoSerial.read());
126 void sendToInfluxDB(String measure, String key, String value) {
127 String line = measure+" "+key+"="+value;
128 Serial.println("Sending to influxdb: "+line);
129 Udp.begin(localPort);
130 Udp.beginPacket(influxdb_ip, influxdb_port);
135 void DataCallback(char * tilabel, char * tihoro, char * tivalue)
137 if (strcmp(tilabel, "SINSTS") == 0 ) {
138 tinfo_SINSTS = String(atol(tivalue));
140 if (strcmp(tilabel, "SINSTS1") == 0 ) {
141 tinfo_SINSTS1 = String(atol(tivalue));
143 if (strcmp(tilabel, "SINSTS2") == 0 ) {
144 tinfo_SINSTS2 = String(atol(tivalue));
146 if (strcmp(tilabel, "SINSTS3") == 0 ) {
147 tinfo_SINSTS3 = String(atol(tivalue));
149 if (strcmp(tilabel, "IRMS1") == 0 ) {
150 tinfo_IRMS1 = String(atol(tivalue));
152 if (strcmp(tilabel, "IRMS2") == 0 ) {
153 tinfo_IRMS2 = String(atol(tivalue));
155 if (strcmp(tilabel, "IRMS3") == 0 ) {
156 tinfo_IRMS3 = String(atol(tivalue));
158 if (strcmp(tilabel, "URMS1") == 0 ) {
159 tinfo_URMS1 = String(atol(tivalue));
161 if (strcmp(tilabel, "URMS2") == 0 ) {
162 tinfo_URMS2 = String(atol(tivalue));
164 if (strcmp(tilabel, "URMS3") == 0 ) {
165 tinfo_URMS3 = String(atol(tivalue));
167 if (strcmp(tilabel, "EAST") == 0 ) {
168 tinfo_EAST = String(atol(tivalue));