3 #include <Adafruit_Sensor.h>
7 #include "serre-semis-config.h"
9 const char* wifi_ssid = WIFI_SSID;
10 const char* wifi_pass = WIFI_PASS;
13 IPAddress influxdb_ip(INFLUXDB_IP);
14 long influxdb_port = INFLUXDB_PORT;
15 unsigned int localPort = 2390;
17 long unsigned poll_int = POLL_INT;
19 String location = LOCATION;
25 DHT_Unified dht(DHTPIN, DHTTYPE);
31 WiFi.begin(WIFI_SSID, WIFI_PASS);
33 while (WiFi.status() != WL_CONNECTED) {
39 dht.temperature().getSensor(&sensor);
40 dht.humidity().getSensor(&sensor);
47 // Check wifi connexion
48 if ( WiFi.status() != WL_CONNECTED ) {
51 WiFi.begin(WIFI_SSID, WIFI_PASS);
52 while (retry < 10 || WiFi.status() != WL_CONNECTED) {
58 if ( WiFi.status() == WL_CONNECTED ) {
59 sensors_event_t event;
61 dht.temperature().getEvent(&event);
62 if (isnan(event.temperature)) {
65 sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
67 dht.humidity().getEvent(&event);
68 if (isnan(event.relative_humidity)) {
71 sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
76 void sendToInfluxDB(String measure, String key, String value) {
77 String line = measure+" "+key+"="+value;
79 Udp.beginPacket(influxdb_ip, influxdb_port);