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);
28 TeleInfo teleinfo(&Serial);
34 WiFi.begin(WIFI_SSID, WIFI_PASS);
36 while (WiFi.status() != WL_CONNECTED) {
42 dht.temperature().getSensor(&sensor);
43 dht.humidity().getSensor(&sensor);
50 // Check wifi connexion
51 if ( WiFi.status() != WL_CONNECTED ) {
54 WiFi.begin(WIFI_SSID, WIFI_PASS);
55 while (retry < 10 || WiFi.status() != WL_CONNECTED) {
61 if ( WiFi.status() == WL_CONNECTED ) {
62 sensors_event_t event;
64 dht.temperature().getEvent(&event);
65 if (isnan(event.temperature)) {
68 sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
70 dht.humidity().getEvent(&event);
71 if (isnan(event.relative_humidity)) {
74 sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
78 if(teleinfo.available()){
79 long I1 = teleinfo.getLongVal("IINST1");
80 long I2 = teleinfo.getLongVal("IINST2");
81 long I3 = teleinfo.getLongVal("IINST3");
82 long PAPP = teleinfo.getLongVal("PAPP");
83 long BASE = teleinfo.getLongVal("BASE");
84 sendToInfluxDB("teleinfo,city="+city+",phase=1", "IINST", String(I1));
85 sendToInfluxDB("teleinfo,city="+city+",phase=2", "IINST", String(I2));
86 sendToInfluxDB("teleinfo,city="+city+",phase=3", "IINST", String(I3));
87 sendToInfluxDB("teleinfo,city="+city, "PAPP", String(PAPP));
88 sendToInfluxDB("teleinfo,city="+city, "BASE", String(BASE));
89 teleinfo.resetAvailable();
94 void sendToInfluxDB(String measure, String key, String value) {
95 String line = measure+" "+key+"="+value;
97 Udp.beginPacket(influxdb_ip, influxdb_port);