Update Overkapping.ino
Temp + Humidity + Baro implemented
This commit is contained in:
parent
0d04297a29
commit
8b92484ce6
@ -4,8 +4,16 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
//#include <ESP8266HTTPClient.h>
|
||||
#include <Wire.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <RCSwitch.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BMP280.h>
|
||||
#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.h>
|
||||
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<JsonObject>();
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user