#include #include #include #include #include #include #include "garage-config.h" // #define TI_DEBUG const char* wifi_ssid = WIFI_SSID; const char* wifi_pass = WIFI_PASS; // Grafana IPAddress influxdb_ip(INFLUXDB_IP); long influxdb_port = INFLUXDB_PORT; unsigned int localPort = 2390; // MilliSeconds unsigned long previousMillis = millis(); long unsigned poll_int = POLL_INT; String city = CITY; String location = LOCATION; WiFiUDP Udp; // Temp // GPIO where the DS18B20 is connected to const int oneWireBus = 19; // Setup a oneWire instance to communicate with any OneWire devices // ROM = 28 C6 C9 81 E3 6E 3C C ROM = 28 31 A7 1D 13 21 1 F6 ROM = 28 15 8E 4B 13 21 1 46 No more addresses. DeviceAddress sensor_heater_out = {0x28, 0x31, 0xA7, 0x1D, 0x13, 0x21, 0x01, 0xF6}; DeviceAddress sensor_serre = {0x28, 0x15, 0x8E, 0x4B, 0x13, 0x21, 0x01, 0x46}; DeviceAddress sensor_heater_in = {0x28, 0xC6, 0xC9, 0x81, 0xE3, 0x6E, 0x3C ,0x0C}; OneWire oneWire(oneWireBus); // Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire); // Uptime timer boolean tick1sec=0;// one for interrupt, don't mess with unsigned long uptime=0; // save value we can use in sketch even if we're interrupted // Used to indicate if we need to send all date or just modified ones boolean fulldata = false; HardwareSerial TinfoSerial(2); TInfo tinfo; String tinfo_SINSTS; String tinfo_SINSTS1; String tinfo_SINSTS2; String tinfo_SINSTS3; String tinfo_IRMS1; String tinfo_IRMS2; String tinfo_IRMS3; String tinfo_URMS1; String tinfo_URMS2; String tinfo_URMS3; String tinfo_EAST; void setup() { Serial.begin(115200); TinfoSerial.begin(9600,SERIAL_7E1,22,23); pinMode(22, INPUT_PULLUP); WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASS); delay(500); while (WiFi.status() != WL_CONNECTED) { WiFi.begin(wifi_ssid, wifi_pass); delay(500); if (WiFi.status() != WL_CONNECTED) { delay(2000); } } sensors.begin(); tinfo.init(TINFO_MODE_STD); tinfo.attachDataStd(DataCallback); } void loop() { if (millis() - previousMillis > POLL_INT) { fulldata = true; previousMillis = millis(); // Reconnect if needed while (WiFi.status() != WL_CONNECTED) { WiFi.begin(WIFI_SSID, WIFI_PASS); delay(500); if (WiFi.status() != WL_CONNECTED) { delay(2000); } } if ( WiFi.status() == WL_CONNECTED ) { Serial.println("DEBUG wifi connected, start temp measure"); sensors.requestTemperatures(); float serre_tempC = sensors.getTempC(sensor_serre); float heater_out_tempC = sensors.getTempC(sensor_heater_out); float heater_in_tempC = sensors.getTempC(sensor_heater_in); if(serre_tempC == DEVICE_DISCONNECTED_C) { // Error } else { sendToInfluxDB("temperature,city="+city+",location=serre-semis", "value", String(serre_tempC)); } if(heater_out_tempC == DEVICE_DISCONNECTED_C) { // Error } else { sendToInfluxDB("temperature,city="+city+",location=heater,direction=out", "value", String(heater_out_tempC)); } if(heater_in_tempC == DEVICE_DISCONNECTED_C) { // Error } else { sendToInfluxDB("temperature,city="+city+",location=heater,direction=in", "value", String(heater_in_tempC)); } sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS", tinfo_SINSTS); sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS1", tinfo_SINSTS1); sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS2", tinfo_SINSTS2); sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS3", tinfo_SINSTS3); sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS1", tinfo_IRMS1); sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS2", tinfo_IRMS2); sendToInfluxDB("teleinfo,city="+city+",location="+location, "IRMS3", tinfo_IRMS3); sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS1", tinfo_URMS1); sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS2", tinfo_URMS2); sendToInfluxDB("teleinfo,city="+city+",location="+location, "URMS3", tinfo_URMS3); sendToInfluxDB("teleinfo,city="+city+",location="+location, "EAST", tinfo_EAST); } } if ( TinfoSerial.available() ) { tinfo.process(TinfoSerial.read()); } } void sendToInfluxDB(String measure, String key, String value) { String line = measure+" "+key+"="+value; Serial.println("Sending to influxdb: "+line); Udp.begin(localPort); Udp.beginPacket(influxdb_ip, influxdb_port); Udp.print(line); Udp.endPacket(); } void DataCallback(char * tilabel, char * tihoro, char * tivalue) { if (strcmp(tilabel, "SINSTS") == 0 ) { tinfo_SINSTS = String(atol(tivalue)); } if (strcmp(tilabel, "SINSTS1") == 0 ) { tinfo_SINSTS1 = String(atol(tivalue)); } if (strcmp(tilabel, "SINSTS2") == 0 ) { tinfo_SINSTS2 = String(atol(tivalue)); } if (strcmp(tilabel, "SINSTS3") == 0 ) { tinfo_SINSTS3 = String(atol(tivalue)); } if (strcmp(tilabel, "IRMS1") == 0 ) { tinfo_IRMS1 = String(atol(tivalue)); } if (strcmp(tilabel, "IRMS2") == 0 ) { tinfo_IRMS2 = String(atol(tivalue)); } if (strcmp(tilabel, "IRMS3") == 0 ) { tinfo_IRMS3 = String(atol(tivalue)); } if (strcmp(tilabel, "URMS1") == 0 ) { tinfo_URMS1 = String(atol(tivalue)); } if (strcmp(tilabel, "URMS2") == 0 ) { tinfo_URMS2 = String(atol(tivalue)); } if (strcmp(tilabel, "URMS3") == 0 ) { tinfo_URMS3 = String(atol(tivalue)); } if (strcmp(tilabel, "EAST") == 0 ) { tinfo_EAST = String(atol(tivalue)); } }