1 // Board ESP8266 - NodeMCU 1.0 (ESP-12E module)
3 #include <ESP8266WiFi.h>
5 #include <Adafruit_Sensor.h>
9 #include "grande-chambre-config.h"
11 const char* wifi_ssid = WIFI_SSID;
12 const char* wifi_pass = WIFI_PASS;
15 IPAddress influxdb_ip(INFLUXDB_IP);
16 long influxdb_port = INFLUXDB_PORT;
17 unsigned int localPort = 2390;
19 long unsigned poll_int = POLL_INT;
21 String location = LOCATION;
28 DHT_Unified dht(DHTPIN, DHTTYPE);
33 // Not for esp8266 WiFi.mode(WIFI_STA);
34 WiFi.begin(WIFI_SSID, WIFI_PASS);
35 while (WiFi.status() != WL_CONNECTED) {
41 dht.temperature().getSensor(&sensor);
42 dht.humidity().getSensor(&sensor);
48 // Check wifi connexion
49 if ( WiFi.status() != WL_CONNECTED ) {
51 // Not for esp8266 WiFi.mode(WIFI_STA);
52 WiFi.begin(WIFI_SSID, WIFI_PASS);
53 while (retry < 10 || WiFi.status() != WL_CONNECTED) {
59 if ( WiFi.status() == WL_CONNECTED ) {
60 sensors_event_t event;
62 dht.temperature().getEvent(&event);
63 if (isnan(event.temperature)) {
66 sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
68 dht.humidity().getEvent(&event);
69 if (isnan(event.relative_humidity)) {
72 sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
77 void sendToInfluxDB(String measure, String key, String value) {
78 String line = measure+" "+key+"="+value;
80 Udp.beginPacket(influxdb_ip, influxdb_port);