Add sketch for garage
authorEmmanuel Lacour <elacour@easter-eggs.com>
Wed, 30 Dec 2020 17:30:20 +0000 (18:30 +0100)
committerEmmanuel Lacour <elacour@easter-eggs.com>
Wed, 30 Dec 2020 17:30:20 +0000 (18:30 +0100)
garage/garage-config.h.in [new file with mode: 0644]
garage/garage.ino [new file with mode: 0644]

diff --git a/garage/garage-config.h.in b/garage/garage-config.h.in
new file mode 100644 (file)
index 0000000..4a1402d
--- /dev/null
@@ -0,0 +1,13 @@
+// Enable debug on serial port
+#define DEBUG 1
+// Wifi
+#define WIFI_SSID "XXXXXX"
+#define WIFI_PASS "xxxxxx"
+// InfluxDB
+#define INFLUXDB_IP {w,x,y,z}
+#define INFLUXDB_PORT xxxx
+// Polling interval (ms)
+#define POLL_INT 10000
+// Location informations
+#define CITY "xxxxx"
+#define LOCATION "xxxxx"
diff --git a/garage/garage.ino b/garage/garage.ino
new file mode 100644 (file)
index 0000000..0c11eaa
--- /dev/null
@@ -0,0 +1,69 @@
+#include <WiFi.h>
+#include <WiFiUdp.h>
+#include <TeleInfo.h>
+#include <SimpleDHT.h>
+
+#include "garage-config.h"
+
+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
+long unsigned  poll_int = POLL_INT;
+String city = CITY;
+String location = LOCATION;
+WiFiUDP Udp;
+
+int pinDHT22 = 13;
+SimpleDHT22 dht22(pinDHT22);
+
+TeleInfo teleinfo(&Serial);
+
+void setup() {
+
+  Serial.begin(1200);
+  WiFi.mode(WIFI_STA);
+  WiFi.begin(WIFI_SSID, WIFI_PASS);
+
+  while (WiFi.status() != WL_CONNECTED) {
+    delay(500);
+  }
+}
+
+void loop() {
+  float temperature = 0;
+  float humidity = 0;
+  int err = SimpleDHTErrSuccess;
+  if ((err = dht22.read2(&temperature, &humidity, NULL)) == SimpleDHTErrSuccess) {
+    sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(temperature));
+    sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(humidity));
+  }
+  
+  teleinfo.process();
+  if(teleinfo.available()){
+    long I1 = teleinfo.getLongVal("IINST1");
+    long I2 = teleinfo.getLongVal("IINST2");
+    long I3 = teleinfo.getLongVal("IINST3");
+    long PAPP = teleinfo.getLongVal("PAPP");
+    long BASE = teleinfo.getLongVal("BASE");
+    sendToInfluxDB("teleinfo,city="+city+",phase=1", "IINST", String(I1));
+    sendToInfluxDB("teleinfo,city="+city+",phase=2", "IINST", String(I2));
+    sendToInfluxDB("teleinfo,city="+city+",phase=3", "IINST", String(I3));
+    sendToInfluxDB("teleinfo,city="+city, "PAPP", String(PAPP));
+    sendToInfluxDB("teleinfo,city="+city, "BASE", String(BASE));
+    teleinfo.resetAvailable();
+  }
+  delay(POLL_INT);
+}
+
+void sendToInfluxDB(String measure, String key, String value) {
+  String line = measure+" "+key+"="+value;
+  Udp.begin(localPort);
+  Udp.beginPacket(influxdb_ip, influxdb_port);
+  Udp.print(line);
+  Udp.endPacket();
+}