From 8b92484ce6649c0336fc367a504845592ebb42d9 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 19 Aug 2022 16:50:04 +0200 Subject: [PATCH] Update Overkapping.ino Temp + Humidity + Baro implemented --- Overkapping.ino | 76 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/Overkapping.ino b/Overkapping.ino index 99da96f..ebdccf0 100644 --- a/Overkapping.ino +++ b/Overkapping.ino @@ -4,8 +4,16 @@ #include //#include +#include #include #include +#include +#include +#include +#include "Adafruit_Si7021.h" + + +#define idx_temp 2269 #define BUZZER_PIN D8 @@ -20,9 +28,12 @@ const char* mqtt_pwd = "MQTT&Domoticz"; WiFiClient espClient; PubSubClient client(espClient); -#include RCSwitch mySwitch = RCSwitch(); +Adafruit_BMP280 bme; // I2C +Adafruit_Si7021 sensor = Adafruit_Si7021(); + + long lastMsg = 0; char msg[100]; int value = 0; @@ -140,18 +151,33 @@ void setup() { // Transmitter is connected to Arduino Pin #10 - mySwitch.enableTransmit(D4); + mySwitch.enableTransmit(D7); // Optional set protocol (default is 1, will work for most outlets) mySwitch.setProtocol(1); // Optional set pulse length. - mySwitch.setPulseLength(395); //Orgineel op 390 !! + mySwitch.setPulseLength(390); //Orgineel op 390 !! // Optional set number of transmission repetitions. - mySwitch.setRepeatTransmit(2); + mySwitch.setRepeatTransmit(5); Serial.println(F("RF Init done...")); + + if (!bme.begin()) + { + Serial.println("Could not find a valid BMP280 sensor, check wiring!"); + while (1); + } + + if (!sensor.begin()) + { + Serial.println("Did not find Si7021 sensor!"); + while (true); + } + + + } void loop() { @@ -170,18 +196,16 @@ void loop() { } long now = millis(); - if (now - lastMsg > 20000) + if (now - lastMsg > 60000) { + update_temp(); + lastMsg = now; ++value; } } - - - - //MQTT receive void mqtt_callback(char* topic, byte* payload, unsigned int length) { int svalue1, loc, StepperTarget; @@ -265,7 +289,35 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) { mySwitch.send(14944539, 24); //OFF } } - - - +} + + + +void update_temp() +{ + float val_temp; + float val_hum; + float val_baro; + + StaticJsonDocument<200> doc; + // Make our document be an object + JsonObject root = doc.to(); + root["command"] = "udevice"; + root["idx"] = 2269; + root["nvalue"] = 0 ; + //svalue=TEMP;HUM;HUM_STAT;BAR;BAR_FOR + val_temp = sensor.readTemperature(); + val_hum = sensor.readHumidity(); + val_baro = bme.readPressure() / 100; + + root["svalue"] = String(val_temp) + String(";") + String(val_hum) + String(";0;") + String(val_baro) + String(";0"); +// root["svalue"] = "20;60;0;1024;0"; + + serializeJson(root, msg); +#ifdef DEBUG + Serial.println(msg); +#endif + client.publish("domoticz/in", msg); + + }