X-Git-Url: http://git.home-dn.net/?p=manu%2Farduino-maison.git;a=blobdiff_plain;f=salon%2Fsalon.ino;fp=salon%2Fsalon.ino;h=fb7d51f90d3cabe67595a4f31baaa640c74f0ebd;hp=0000000000000000000000000000000000000000;hb=1ff1ba48715f214ad940fd403fdf6c8982c6870c;hpb=87bd5c6e89ec49eff96705f846729275901e9f8e diff --git a/salon/salon.ino b/salon/salon.ino new file mode 100644 index 0000000..fb7d51f --- /dev/null +++ b/salon/salon.ino @@ -0,0 +1,52 @@ +#include +#include +#include + +#include "salon-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); + +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)); + } + + 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(); +}