void loop() {
delay(POLL_INT);
- sensors_event_t event;
-
- dht.temperature().getEvent(&event);
- if (isnan(event.temperature)) {
- #if defined(DEBUG)
- Serial.println("DHT 22 temperature error");
- #endif
- } else {
- #if defined(DEBUG)
- Serial.println("Temperature: "+String(event.temperature));
- #endif
- sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
- double water_dist = distanceSensor.measureDistanceCm(event.temperature);
- #if defined(DEBUG)
- Serial.println("Distance: "+String(water_dist));
- #endif
- sendToInfluxDB("water_well,city="+city+",location="+location, "distance", String(water_dist));
+ // Check wifi connexion
+ if ( WiFi.status() != WL_CONNECTED ) {
+ int retry = 0;
+ WiFi.mode(WIFI_STA);
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
+ while (retry < 10 || WiFi.status() != WL_CONNECTED) {
+ retry++;
+ delay(500);
+ }
}
- dht.humidity().getEvent(&event);
- if (isnan(event.relative_humidity)) {
- #if defined(DEBUG)
- Serial.println("DHT 22 humidity error");
- #endif
- } else {
- #if defined(DEBUG)
- Serial.println("Humidity: "+String(event.relative_humidity));
- #endif
- sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
+
+ if ( WiFi.status() != WL_CONNECTED ) {
+ sensors_event_t event;
+
+ dht.temperature().getEvent(&event);
+ if (isnan(event.temperature)) {
+ #if defined(DEBUG)
+ Serial.println("DHT 22 temperature error");
+ #endif
+ } else {
+ #if defined(DEBUG)
+ Serial.println("Temperature: "+String(event.temperature));
+ #endif
+ sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+ double water_dist = distanceSensor.measureDistanceCm(event.temperature);
+ #if defined(DEBUG)
+ Serial.println("Distance: "+String(water_dist));
+ #endif
+ sendToInfluxDB("water_well,city="+city+",location="+location, "distance", String(water_dist));
+ }
+ dht.humidity().getEvent(&event);
+ if (isnan(event.relative_humidity)) {
+ #if defined(DEBUG)
+ Serial.println("DHT 22 humidity error");
+ #endif
+ } else {
+ #if defined(DEBUG)
+ Serial.println("Humidity: "+String(event.relative_humidity));
+ #endif
+ sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
+ }
}
}
void loop() {
delay(POLL_INT);
- sensors_event_t event;
-
- dht.temperature().getEvent(&event);
- if (isnan(event.temperature)) {
- // Error
- } else {
- sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+ // Check wifi connexion
+ if ( WiFi.status() != WL_CONNECTED ) {
+ int retry = 0;
+ WiFi.mode(WIFI_STA);
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
+ while (retry < 10 || WiFi.status() != WL_CONNECTED) {
+ retry++;
+ delay(500);
+ }
}
- dht.humidity().getEvent(&event);
- if (isnan(event.relative_humidity)) {
- // Error
- } else {
- sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_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();
+
+ if ( WiFi.status() == WL_CONNECTED ) {
+ sensors_event_t event;
+
+ dht.temperature().getEvent(&event);
+ if (isnan(event.temperature)) {
+ // Error
+ } else {
+ sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+ }
+ dht.humidity().getEvent(&event);
+ if (isnan(event.relative_humidity)) {
+ // Error
+ } else {
+ sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_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();
+ }
}
}
void loop() {
delay(POLL_INT);
- sensors_event_t event;
-
- dht.temperature().getEvent(&event);
- if (isnan(event.temperature)) {
- // Error
- } else {
- sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+ // Check wifi connexion
+ if ( WiFi.status() != WL_CONNECTED ) {
+ int retry = 0;
+ WiFi.mode(WIFI_STA);
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
+ while (retry < 10 || WiFi.status() != WL_CONNECTED) {
+ retry++;
+ delay(500);
+ }
}
- dht.humidity().getEvent(&event);
- if (isnan(event.relative_humidity)) {
- // Error
- } else {
- sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
+
+ if ( WiFi.status() == WL_CONNECTED ) {
+ sensors_event_t event;
+
+ dht.temperature().getEvent(&event);
+ if (isnan(event.temperature)) {
+ // Error
+ } else {
+ sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+ }
+ dht.humidity().getEvent(&event);
+ if (isnan(event.relative_humidity)) {
+ // Error
+ } else {
+ sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
+ }
}
-
}
void sendToInfluxDB(String measure, String key, String value) {
void loop() {
delay(POLL_INT);
- sensors_event_t event;
-
- dht.temperature().getEvent(&event);
- if (isnan(event.temperature)) {
- // Error
- } else {
- sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+ // Check wifi connexion
+ if ( WiFi.status() != WL_CONNECTED ) {
+ int retry = 0;
+ WiFi.mode(WIFI_STA);
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
+ while (retry < 10 || WiFi.status() != WL_CONNECTED) {
+ retry++;
+ delay(500);
+ }
}
- dht.humidity().getEvent(&event);
- if (isnan(event.relative_humidity)) {
- // Error
- } else {
- sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
+
+ if ( WiFi.status() == WL_CONNECTED ) {
+ sensors_event_t event;
+
+ dht.temperature().getEvent(&event);
+ if (isnan(event.temperature)) {
+ // Error
+ } else {
+ sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+ }
+ dht.humidity().getEvent(&event);
+ if (isnan(event.relative_humidity)) {
+ // Error
+ } else {
+ sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
+ }
}
-
}
void sendToInfluxDB(String measure, String key, String value) {
Serial.println("Please upgrade the firmware");
}
+ Serial.print("Attempting to connect to SSID: ");
+ Serial.println(wifi_ssid);
+ // Connect to WPA/WPA2 network
+ WiFi.begin(wifi_ssid, wifi_pass);
+
// attempt to connect to Wifi network:
- while (wifi_status != WL_CONNECTED) {
- Serial.print("Attempting to connect to SSID: ");
- Serial.println(wifi_ssid);
- // Connect to WPA/WPA2 network
- wifi_status = WiFi.begin(wifi_ssid, wifi_pass);
-
- // wait 10 seconds for connection:
- delay(10000);
+ while (WiFi.status() != WL_CONNECTED) {
+ delay(500);
}
Serial.println("Connected to wifi");
*/
void loop(void)
{
-
- String temp_influx_line;
- String rain_influx_line;
- float rainfall_1min(0);
- float tempC(0);
+ delay(POLL_INT);
- // Get rainfall height
- rainfall_1min = rainfall_ticks * rain_incr;
- rainfall_ticks = 0;
- Serial.print("Rain mm/m2: ");
- Serial.println(rainfall_1min);
- Serial.println("Sending rain height to influxdb...");
- rain_influx_line = String("rain,city="+city+"location="+location+" value=" + String(rainfall_1min, 2));
- udp.beginPacket(influxdb_host, influxdb_port);
- udp.print(rain_influx_line);
- udp.endPacket();
-
- // Temperature
- tempC = get_temperature();
- // Check if reading was successful
- if(tempC != DEVICE_DISCONNECTED_C)
- {
- Serial.print("Temperature for the device 1 (index 0) is: ");
- Serial.println(tempC);
- temp_influx_line = String("temperature,city="+city+",location="+location+" value=" + String(tempC, 2));
- // send the packet
- Serial.println("Sending UDP packet...");
- udp.beginPacket(influxdb_host, influxdb_port);
- udp.print(temp_influx_line);
- udp.endPacket();
- }
- else
- {
- Serial.println("Error: Could not read temperature data");
+ // Check wifi connexion
+ if ( WiFi.status() != WL_CONNECTED ) {
+ int retry = 0;
+ WiFi.begin(wifi_ssid, wifi_pass);
+ while (retry < 10 || WiFi.status() != WL_CONNECTED) {
+ retry++;
+ delay(500);
+ }
+ }
+
+ if ( WiFi.status() != WL_CONNECTED ) {
+ String temp_influx_line;
+ String rain_influx_line;
+ float rainfall_1min(0);
+ float tempC(0);
+
+ // Get rainfall height
+ rainfall_1min = rainfall_ticks * rain_incr;
+ rainfall_ticks = 0;
+ Serial.print("Rain mm/m2: ");
+ Serial.println(rainfall_1min);
+ Serial.println("Sending rain height to influxdb...");
+ rain_influx_line = String("rain,city="+city+"location="+location+" value=" + String(rainfall_1min, 2));
+ udp.beginPacket(influxdb_host, influxdb_port);
+ udp.print(rain_influx_line);
+ udp.endPacket();
+
+ // Temperature
+ tempC = get_temperature();
+ // Check if reading was successful
+ if(tempC != DEVICE_DISCONNECTED_C)
+ {
+ Serial.print("Temperature for the device 1 (index 0) is: ");
+ Serial.println(tempC);
+ temp_influx_line = String("temperature,city="+city+",location="+location+" value=" + String(tempC, 2));
+ // send the packet
+ Serial.println("Sending UDP packet...");
+ udp.beginPacket(influxdb_host, influxdb_port);
+ udp.print(temp_influx_line);
+ udp.endPacket();
+ }
+ else
+ {
+ Serial.println("Error: Could not read temperature data");
+ }
}
- delay(POLL_INT);
}