Implement support for sending Arduino I2C sensor values via WiFi

This commit is contained in:
bzi 2019-02-24 20:46:39 +01:00
parent d5e0be2f94
commit d0ed68aed6

View File

@ -11,7 +11,7 @@
#include <Wire.h> #include <Wire.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include "DHT.h" #include "DHT.h"
#include "mqtt_credentials.h" #include "configuration.h"
#define TOPIC_BASE "sensor/" sensor_id "/" #define TOPIC_BASE "sensor/" sensor_id "/"
#define TOPIC_TEMP TOPIC_BASE "temperature" #define TOPIC_TEMP TOPIC_BASE "temperature"
@ -145,7 +145,7 @@ void loop() {
sensor_name[1] = char(data[1]); sensor_name[1] = char(data[1]);
sensor_name[2] = char(data[2]); sensor_name[2] = char(data[2]);
sensor_name[3] = char(data[3]); 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[0] = data[4];
sensor_union.sensor_b[1] = data[5]; sensor_union.sensor_b[1] = data[5];
@ -153,11 +153,23 @@ void loop() {
sensor_union.sensor_b[3] = data[7]; sensor_union.sensor_b[3] = data[7];
sensor_value = sensor_union.sensor_float; sensor_value = sensor_union.sensor_float;
Serial.print("Received: "); Serial.print("Received sensor reading: ");
Serial.print(sensor_name); Serial.print(sensor_name);
Serial.print(" - "); Serial.print(" - ");
Serial.println(sensor_value); 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; published = false;
if (lastSent > FORCE_PERIOD) { if (lastSent > FORCE_PERIOD) {
Serial.println(F("Forcing a publish of all values")); Serial.println(F("Forcing a publish of all values"));