From d0ed68aed620d422374ff51ca05d0beaf529ba93 Mon Sep 17 00:00:00 2001 From: bzi Date: Sun, 24 Feb 2019 20:46:39 +0100 Subject: [PATCH] Implement support for sending Arduino I2C sensor values via WiFi --- .../esp_sensor_firmware.ino | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/envisens/esp_sensor_firmware/esp_sensor_firmware.ino b/envisens/esp_sensor_firmware/esp_sensor_firmware.ino index fa2e146..f253046 100644 --- a/envisens/esp_sensor_firmware/esp_sensor_firmware.ino +++ b/envisens/esp_sensor_firmware/esp_sensor_firmware.ino @@ -11,7 +11,7 @@ #include #include #include "DHT.h" -#include "mqtt_credentials.h" +#include "configuration.h" #define TOPIC_BASE "sensor/" sensor_id "/" #define TOPIC_TEMP TOPIC_BASE "temperature" @@ -145,7 +145,7 @@ void loop() { sensor_name[1] = char(data[1]); sensor_name[2] = char(data[2]); sensor_name[3] = char(data[3]); - sensor_name[4] = 0; + sensor_name[4] = '\0'; sensor_union.sensor_b[0] = data[4]; sensor_union.sensor_b[1] = data[5]; @@ -153,11 +153,23 @@ void loop() { sensor_union.sensor_b[3] = data[7]; sensor_value = sensor_union.sensor_float; - Serial.print("Received: "); + Serial.print("Received sensor reading: "); Serial.print(sensor_name); Serial.print(" - "); Serial.println(sensor_value); + if (strcmp(sensor_name, "hmid") == 0){ + hmid = sensor_value; + } else if (strcmp(sensor_name, "temp") == 0){ + temp = sensor_value; + } else if (strcmp(sensor_name, "heat") == 0){ + heat = sensor_value; + } else if (strcmp(sensor_name, "airq") == 0){ + airq = sensor_value; + } else{ + Serial.println("ERR: Sensor could not be identified"); + } + published = false; if (lastSent > FORCE_PERIOD) { Serial.println(F("Forcing a publish of all values"));