NODE_MQTT_PIR_TEMP_TIMER.ino
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <BlynkSimpleEsp8266.h>
// #define BLYNK_PRINT Serial // Comment this to disable prints and save space
#include "Settings.h"
#include "mqtt_publish.h"
#include "mqtt_subscribe.h"
#include "wifi_credentials.h"
/*-------------------------------- Setup -------------------------------------*/
void setup() {
WiFi.mode(WIFI_STA);
Serial.begin(115200); // See the connection status in Serial Monitor
Serial.println(F("\n Setup STARTING"));
WiFi.begin(WIFI_SSID, WIFI_PASS);
if(WiFi.status() == 6) Serial.println("\tWiFi not connected yet.");
client.setServer(MQTT_SERVER, 1883);
client.setCallback(callback);
//----------------------------------Blynk------------------------------------
#ifdef LOCAL_SERVER
Blynk.config(AUTH, LOCAL_SERVER ,8080);
#else
Blynk.config(AUTH, Geo_DNS_SERVER);
#endif
while (Blynk.connect() == false) { // Wait until connected
if ((millis() - last_UP_change) > 30000) { // 30s before reset
Serial.println(F("resetting"));
ESP.reset();
}
}
//-----------------------------------OTA--------------------------------------
ArduinoOTA.setHostname(OTA_HOSTNAME);
// ArduinoOTA.setPassword(OTA_PASSWORD); //If you need a Password uncomment this line
ArduinoOTA.begin();
Serial.println(F(" Entering loop"));
timer.setInterval(4000L, Heartbeat); // Heartbeat 4000L
Blynk.syncVirtual(vPIN_ON_OFF_1);
Blynk.syncVirtual(vPIN_ON_OFF_2);
Blynk.syncVirtual(vPIN_ON_OFF_3);
Blynk.syncVirtual(vPIN_PIR_TIMER); // var2
Blynk.syncVirtual(vPIN_NUMERIC_TIMER); // var1
Blynk.syncVirtual(vPIN_NUMERIC_DISTANCE); // var3
Blynk.setProperty(vPIN_HEARTBEAT, "label", String("\xF0\x9F\x92\x93") + " HEARTBEAT");
}
/*----------------------------------Loop--------------------------------------*/
void loop() {
Blynk.run();
if(!Blynk.connected()) {
Serial.println(F("Resetting in loop"));
ESP.restart();
}
timer.run();
if (!client.connected()) {
reconnect();
}
client.loop();
ArduinoOTA.handle();
}
/*============================================================================*/
Settings.h
/*****************************************************************************
*
* Settings.h
*
*****************************************************************************/
BlynkTimer timer;
/*---------------------------Blynk Auth Code----------------------------------*/
#define AUTH "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/*-------------------------Over The Air Hostname------------------------------*/
#define OTA_HOSTNAME "N-MQTT_Bridge" // put here your host name
#define OTA_PASSWORD "blynk" // your password for OTA if needed
/*----------------------------Hardware Pins-----------------------------------*/
/*-NodeMCU#*/
/*-------------------------------Virtual Pins---------------------------------*/
#define vPIN_HEARTBEAT V0
#define vPIN_SR04_DIST V8
#define vPIN_TEMP_UNIT V9
#define vPIN_ALL_TEMP V10
#define vPIN_ON_OFF_1 V21 // ON/OFF POWER 1
#define vPIN_PIR_TIMER V22 // select PIR motion or TIMER
#define vPIN_NUMERIC_TIMER V23 // up to 9999 sec
#define vPIN_AUTO_SR04 V25 // Activate/Desactivate Rule3
#define vPIN_TIMER_START V26 // PB START Timer
#define vPIN_NUMERIC_DISTANCE V27 // up to 300 cm
#define vPIN_ON_OFF_2 V31 // ON/OFF POWER 2 Activated by Sun
#define vPIN_ON_OFF_3 V41 // ON/OFF POWER 3 Turn ON/OFF I2C OLED
/*-----------------------------variables-------------------------------------*/
bool var2 ;
int var1 ;
int var3 ;
int counter = 0;
long int last_UP_change = millis();
int rssi;
float Vcc;
float Distance;
String SUNRISE;
String SUNSET;
/*---------------------------------Heartbeat--------------------------------*/
void Heartbeat() {
Blynk.virtualWrite(vPIN_HEARTBEAT," \xF0\x9F\x92\x96"); //
timer.setTimeout(2000L,[](){Blynk.virtualWrite(vPIN_HEARTBEAT," \xF0\x9F\x92\x97");});
}
/*--------------------------------------------------------------------------*/
mqtt_publish.h
/******************************************************************************
*
* mqtt_publish.h
*
*****************************************************************************/
WiFiClient espClient;
PubSubClient client(espClient);
//----------------------------------------------℃/℉----------------------------------------
BLYNK_WRITE(vPIN_TEMP_UNIT) { // Change Temp. Unit from Celsius ℃ to Fahrenheit ℉
if (param.asInt()) {
client.publish("stairs/cmnd/setoption8","0"); // Celcius ℃
delay(4000);
client.publish("stairs/cmnd/teleperiod", "300"); // to get sensor & state info
Blynk.setProperty(vPIN_TEMP_UNIT,"onLabel" ,String("\xf0\x9f\x8c\xa1") + " Celsius ℃ ");
Blynk.setProperty(vPIN_TEMP_UNIT,"onColor","#FFFFFF"); // White
Blynk.setProperty(vPIN_TEMP_UNIT,"onBackColor","#8a2be2"); // Blue Violet
Blynk.setProperty (vPIN_ALL_TEMP,"color","#8a2be2"); // Blue Violet
} else {
client.publish("stairs/cmnd/setoption8","1"); // Fahrenheit ℉
delay(4000);
client.publish("stairs/cmnd/teleperiod", "300"); // to get sensor & state info immediately
Blynk.setProperty(vPIN_TEMP_UNIT,"offLabel",String("\xf0\x9f\x8c\xa1") + " Fahrenheit ℉ ");
Blynk.setProperty(vPIN_TEMP_UNIT,"offColor","#04C0F8"); // BLYNK_BLUE
Blynk.setProperty(vPIN_TEMP_UNIT,"offBackColor","#04C0F8"); // BLYNK_BLUE
Blynk.setProperty (vPIN_ALL_TEMP,"color","#04C0F8"); // BLYNK_BLUE
}
}
//--------------------------------------------POWER1----(ON/OFF)------------------------------
BLYNK_WRITE(vPIN_ON_OFF_1) { // ON/OFF switch
if (param.asInt()) {
client.publish("stairs/cmnd/POWER1","1");
} else {
client.publish("stairs/cmnd/POWER1","0");
}
}
//---------------------------------------------POWER1----(PIR & Timer)------------------------
BLYNK_WRITE(vPIN_PIR_TIMER) { // PIR/TIMER
if (param.asInt()) {
client.publish("stairs/cmnd/switchmode1","1");
client.publish("stairs/cmnd/var1","30");
client.publish("stairs/cmnd/var2","1");
var1 = 30;
Blynk.setProperty(vPIN_PIR_TIMER,"label"," PIR " );
Blynk.setProperty(vPIN_PIR_TIMER,"onLabel",String("\xF0\x9F\x8F\x83"));
Blynk.setProperty(vPIN_PIR_TIMER,"onColor","#FFFFFF"); // White
Blynk.setProperty(vPIN_PIR_TIMER,"onBackColor","#04C0F8"); // BLYNK_BLUE
Blynk.setProperty(vPIN_NUMERIC_TIMER,"color","#04C0F8"); // BLYNK_BLUE
Blynk.virtualWrite(vPIN_NUMERIC_TIMER,var1);
Blynk.setProperty(vPIN_NUMERIC_TIMER,"label",String("\xE2\x8F\xB3")+" TIMER "+ 30 +String(" S"));
Blynk.setProperty(vPIN_TIMER_START,"label"," " );
Blynk.setProperty(vPIN_TIMER_START,"offLabel"," ");
Blynk.setProperty(vPIN_TIMER_START,"offColor","#FFFFFF"); // White
Blynk.setProperty(vPIN_TIMER_START,"offBackColor","#FFFFFF"); // White
var2 = 1;
} else {
client.publish("stairs/cmnd/switchmode1","0");
client.publish("stairs/cmnd/var1","180");
client.publish("stairs/cmnd/var2","0");
var1 = 180;
Blynk.setProperty(vPIN_PIR_TIMER,"label",String("\xE2\x8F\xB0") + " TIMER");
Blynk.setProperty(vPIN_PIR_TIMER,"offLabel",String("\xE2\x8F\xB0"));
Blynk.setProperty(vPIN_PIR_TIMER,"offColor","#FFFF00"); // YELLOW
Blynk.setProperty(vPIN_PIR_TIMER,"offBackColor","#00FF00"); // GREEN
Blynk.setProperty(vPIN_NUMERIC_TIMER,"color","#23C48E"); // BLYNK_GREEN
Blynk.virtualWrite(vPIN_NUMERIC_TIMER,var1);
Blynk.setProperty(vPIN_NUMERIC_TIMER,"label",String("\xE2\x8F\xB3")+" TIMER "+ 180 +String(" S"));
Blynk.setProperty(vPIN_TIMER_START,"label"," Start PB" );
Blynk.setProperty(vPIN_TIMER_START,"offLabel","Start");
Blynk.setProperty(vPIN_TIMER_START,"offColor","#00FF00"); // GREEN
Blynk.setProperty(vPIN_TIMER_START,"offBackColor","#00FF00"); // GREEN
var2 = 0;
}
char value[4];
dtostrf(var1, 2, 0, value);
client.publish("stairs/cmnd/ruletimer1",value);
BLYNK_WRITE(vPIN_NUMERIC_TIMER);
}
BLYNK_WRITE(vPIN_NUMERIC_TIMER) { // TIMER 0-9999 Sec
int VALUE = param.asInt();
var1 = VALUE;
char value[4];
dtostrf(VALUE, 2, 0, value);
client.publish("stairs/cmnd/var1", value);
client.publish("stairs/cmnd/ruletimer1", value);
Blynk.virtualWrite(vPIN_NUMERIC_TIMER,var1);
Blynk.setProperty(vPIN_NUMERIC_TIMER,"label",String("\xE2\x8F\xB3")+" TIMER "+ var1 +String(" S"));
if (var2 == 1) {
client.publish("stairs/cmnd/POWER1", "ON");
}
}
BLYNK_WRITE(vPIN_TIMER_START) { // PB TIMER Sart
if (param.asInt()) {
if (var2 == 0){
char value[4];
dtostrf(var1, 2, 0, value);
client.publish("stairs/cmnd/ruletimer1",value);
client.publish("stairs/cmnd/POWER1","1");
} else {
client.publish("stairs/cmnd/POWER1","0");
}
}
}
//---------------------------------------------POWER2----(Sun)------------------------------
BLYNK_WRITE(vPIN_ON_OFF_2) { // ON/OFF PORCH Light
if (param.asInt()) {
client.publish("stairs/cmnd/POWER2","1");
} else {
client.publish("stairs/cmnd/POWER2","0");
Blynk.setProperty(vPIN_ON_OFF_2,"offColor","#8a2be2"); // Blue Violet
Blynk.setProperty(vPIN_ON_OFF_2,"offBackColor","#ffff00"); // YELLOW
}
}
//---------------------------------------------POWER3----(I2C OLED)----------------------
BLYNK_WRITE(vPIN_ON_OFF_3) { // ON/OFF I2C OLED
if (param.asInt()) {
client.publish("stairs/cmnd/POWER3","1");
} else {
client.publish("stairs/cmnd/POWER3","0");
}
}
//-----------------------------------------------SR04----------------------------------------
BLYNK_WRITE(vPIN_AUTO_SR04) { // AUTO/Manual
if (param.asInt()) {
client.publish("stairs/cmnd/Rule3","1");
Blynk.setProperty(vPIN_AUTO_SR04, "label",String("\xF0\x9F\x92\xAB") + " AUTO SR04");
} else {
client.publish("stairs/cmnd/Rule3","0");
client.publish("stairs/cmnd/POWER1","0");
Blynk.virtualWrite(vPIN_SR04_DIST,"--.--");
Blynk.setProperty (vPIN_AUTO_SR04, "label",String("\xE2\x9C\x8B") + " MANUAL SR04");
}
}
BLYNK_WRITE(vPIN_NUMERIC_DISTANCE) { //
int VALUE = param.asInt();
var3 = VALUE;
char value[4];
dtostrf(VALUE, 2, 0, value);
client.publish("stairs/cmnd/var3", value);
}
//------------------------------------------------------------------------------------------
mqtt_subscribe.h
/*******************************************************************************
*
* mqtt_subscribe.h
*
******************************************************************************/
#define MQTT_SERVER IPAddress(192,168,xxx,xxx) // Your MQTT Broker IP address
#define MQTT_USERNAME "xxxx" // put here your MQTT username
#define MQTT_PASSWORD "xxxx" // put here your MQTT password
#define InTOPIC_0 "stairs/tele/STATE"
#define InTOPIC_1 "stairs/tele/SENSOR"
#define InTOPIC_2 "stairs/PIR_stairs/state"
#define InTOPIC_3 "stairs/stat/POWER1"
#define InTOPIC_4 "stairs/stat/POWER2"
#define InTOPIC_5 "stairs/stat/POWER3"
#define InTOPIC_6 "stairs/stat/RESULT"
#define InTOPIC_7 "stairs/sunset/state"
#define InTOPIC_8 "stairs/sunrise/state"
#define InTOPIC_9 "stairs/Distance"
void reconnect() { // Loop until we're reconnected
while (!client.connected()) {
Serial.print(" Attempting MQTT connection..."); // Attempt to connect
delay(4000);
if (client.connect("DEVS", MQTT_USERNAME, MQTT_PASSWORD)) {
Serial.println("connected");
counter = 0; // ... and resubscribe
client.subscribe(InTOPIC_0);
client.subscribe(InTOPIC_1);
client.subscribe(InTOPIC_2);
client.subscribe(InTOPIC_3);
client.subscribe(InTOPIC_4);
client.subscribe(InTOPIC_5);
client.subscribe(InTOPIC_6);
client.subscribe(InTOPIC_7);
client.subscribe(InTOPIC_8);
client.subscribe(InTOPIC_9);
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 4 second");
++counter;
if (counter > 20) ESP.restart(); // Wait 4 seconds before retrying
}
}
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
//-------------------------------------------STATE--------------------------------------------
// MQT: stairs/tele/STATE =
// {"Time":"2019-03-18T17:56:18","Uptime":"0T18:23:11","Vcc":3.002,"SleepMode":"Dynamic",
// "Sleep":50,"LoadAvg":19,"POWER1":"ON","POWER2":"OFF","Wifi":{"AP":1,"SSId":"BLYNK",
// "BSSId":"48:F8:B3:84:AB:22","Channel":10,"RSSI":84,"LinkCount":6,"Downtime":"0T00:00:21"}}
if (String(topic) == InTOPIC_0) { // stairs/tele/STATE
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
Vcc = root["Vcc"]; // 3.002
rssi = root["Wifi"]["RSSI"]; // 84
const char* Uptime = root["Uptime"]; // 0T18:23:11
// const char* Time = root["Time"]; // 2019-03-18T17:56:18
// const char* SleepMode = root["SleepMode"];// Dynamic
// int Sleep = root["Sleep"]; // 50
// int LoadAvg = root["LoadAvg"]; // 19
// const char* POWER1 = root["POWER1"]; // ON
// const char* POWER2 = root["POWER2"]; // OFF
// int AP = root["Wifi"]["AP"]; // 1
// const char* SSId = root["Wifi"]["SSId"]; // BLYNK
// const char* BSSId = root["Wifi"]["BSSId"];// 48:F8:B3:84:AB:22
// int Chl = root["Wifi"]["Channel"];// 10
// int LC= root["Wifi"]["LinkCount"];// 6
// const char* DT = root["Wifi"]["Downtime"];// 0T00:00:21
Blynk.setProperty(vPIN_HEARTBEAT, "label",String("\xE2\x8F\xB3")+" "+String(Uptime));
//-------------------------------------------SENSOR-------------------------------------------
//MQT: stairs/tele/SENSOR =
//{"Time":"2019-03-19T13:19:16","Switch1":"OFF","DS18B20-1":{"Id":"000006F242B1","Temperature":21.9},
//"DS18B20-2":{"Id":"000006F2B80A","Temperature":22.0},"DS18B20-3":{"Id":"00000789E508","Temperature":21.9},
//"DS18B20-4":{"Id":"8000001F18D8","Temperature":22.6},"AM2301":{"Temperature":22.0,"Humidity":68.7},
//"ADS1115":[{"A0":-1,"A1":26033,"A2":4851,"A3":4809}],"SR04":{"Distance":40.509},"TempUnit":"C"}
}else if (String(topic) == InTOPIC_1) { // stairs/tele/SENSOR
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
const char* Time = root["Time"]; // 2019-03-19T13:19:16
float DS1_T = root["DS18B20-1"]["Temperature"]; // 21.9
float DS2_T = root["DS18B20-2"]["Temperature"]; // 22.0
float DS3_T = root["DS18B20-3"]["Temperature"]; // 21.9
float DS4_T = root["DS18B20-4"]["Temperature"]; // 22.6
float Temp = root["AM2301"]["Temperature"]; // 22.0
float Hum = root["AM2301"]["Humidity"]; // 68.7
float Dist = root["SR04"]["Distance"]; // 40.509
// const char* Switch1 = root["Switch1"]; // OFF
// const char* DS1_ID = root["DS18B20-1"]["Id"]; // 000006F242B1
// const char* DS2_ID = root["DS18B20-2"]["Id"]; // 000006F2B80A
// const char* DS3_ID = root["DS18B20-3"]["Id"]; // 00000789E508
// const char* DS4_ID = root["DS18B20-4"]["Id"]; // 8000001F18D8
// float ADS_A0 = root["ADS1115"]["A0"]; // -1
// float ADS_A1 = root["ADS1115"]["A1"]; // 26033
// float ADS_A2 = root["ADS1115"]["A2"]; // 4851
// float ADS_A3 = root["ADS1115"]["A3"]; // 4809
// const char* TU = root["TempUnit"];// "C"
Blynk.setProperty(vPIN_TEMP_UNIT, "label",String("\xE2\x8C\x9A")+Time+" "+String("\xF0\x9F\x93\xB6")+" WiFi = "+rssi+" %"+" "+String("\xE2\x9A\xA1")+"Vcc = "+String(Vcc,2)+" V" );
Blynk.virtualWrite(vPIN_ALL_TEMP, (String (DS1_T,1)+" "+String (DS2_T,1)+" "+String (DS3_T,1)+" "+String (Temp,1)+" "+String(Hum,1)+"%"));
Blynk.setProperty (vPIN_ALL_TEMP, "label",String("\xf0\x9f\x8c\xa1")+"DS18B20-1 DS18B20-2 DSPROBE-3 "+String("\xf0\x9f\x8c\xa1")+"AM2302"+" "+String("\xF0\x9F\x92\xA7")+"AM2302");
//--------------------------------------------PIR---------------------------------------------
}else if (String(topic) == InTOPIC_2) { // stairs/PIR_stairs/state = (1/0)
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
if ((char)payload[0] == '1') { // Switch1 on LED if 1 was received as first character
Serial.println("PIR = ON");
Blynk.setProperty(vPIN_PIR_TIMER,"label"," PIR " +String("\xF0\x9F\x94\xB5"));
}
if ((char)payload[0] == '0'){
Serial.println("PIR = OFF");
if (var2==1) {
Blynk.setProperty(vPIN_PIR_TIMER,"label", " PIR ");
Blynk.setProperty(vPIN_PIR_TIMER,"onLabel",String("\xF0\x9F\x8F\x83"));
Blynk.setProperty(vPIN_PIR_TIMER,"onColor","#FFFFFF"); // White
Blynk.setProperty(vPIN_PIR_TIMER,"onBackColor","#04C0F8"); // BLYNK_BLUE
}
if (var2==0) {
Blynk.setProperty(vPIN_PIR_TIMER,"label",String("\xE2\x8F\xB0") + " TIMER ");
Blynk.setProperty(vPIN_PIR_TIMER,"offLabel",String("\xE2\x8F\xB0"));
Blynk.setProperty(vPIN_PIR_TIMER,"offColor","#E0E000"); // dark YELLOW
Blynk.setProperty(vPIN_PIR_TIMER,"offBackColor","#23C48E"); // BLYNK_GREEN
}
}
//---------------------------------------------POWER1-----------------------------------------
}else if (String(topic) == InTOPIC_3) { // stairs/stat/POWER1
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
if ((char)payload[1] == 'N') {
Blynk.virtualWrite(vPIN_ON_OFF_1,1);
Serial.println("POWER1 = ON");
}else{
Blynk.virtualWrite(vPIN_ON_OFF_1,0);
Serial.println("POWER1 = OFF");
}
//---------------------------------------------POWER2-----------------------------------------
}else if (String(topic) == InTOPIC_4) { // stairs/stat/POWER2
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
if ((char)payload[1] == 'N') {
Blynk.virtualWrite(vPIN_ON_OFF_2,1);
Serial.println("POWER2 = ON");
}else{
Blynk.virtualWrite(vPIN_ON_OFF_2,0);
Serial.println("POWER2 = OFF");
}
//---------------------------------------------POWER3-----------------------------------------
}else if (String(topic) == InTOPIC_5) { // stairs/stat/POWER3
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
if ((char)payload[1] == 'N') {
Blynk.virtualWrite(vPIN_ON_OFF_3,1);
Serial.println("POWER3 = ON");
}else{
Blynk.virtualWrite(vPIN_ON_OFF_3,0);
Serial.println("POWER3 = OFF");
}
//--------------------------------------------------------------------------------------------
//09:59:13 MQT: stairs/stat/RESULT = {"T1":20,"T2":0,"T3":0,"T4":0,"T5":0,"T6":0,"T7":0,"T8":0}
//10:01:05 MQT: stairs/stat/RESULT = {"POWER1":"ON"}
//10:01:40 MQT: stairs/stat/RESULT = {"POWER1":"OFF"}
//10:04:11 MQT: stairs/stat/RESULT = {"var1":"20"}
}else if (String(topic) == InTOPIC_6) { //stairs/stat/RESULT
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
int var1 = root["var1"];
int T1 = root["T1"];
const char* POWER1 = root["POWER1"]; // "OFF"
//------------------------------------------------sunset--------------------------------------
}else if (String(topic) == InTOPIC_7) { //stairs/sunset/state
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
int mins = root["Sunset"];
int hours = mins / 60; //convert minutes to hours
mins = mins - (hours * 60); //subtract the coverted minutes to hours in order to display 59 minutes max
String mins_o = ":";
if (mins < 10) { mins_o = ":0";}
SUNSET = hours + mins_o + mins ;
//------------------------------------------------sunrise-------------------------------------
}else if (String(topic) == InTOPIC_8) { //stairs/sunrise/state
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
int mins = root["Sunrise"];
int hours = mins / 60; //convert minutes to hours
mins = mins - (hours * 60); //subtract the coverted minutes to hours in order to display 59 minutes max
String mins_o = ":";
if (mins < 10) { mins_o = ":0";}
SUNRISE = hours + mins_o + mins ;
// every Hour update Sunrise & Sunset [Tasmota => " on Time#Set do publish "]
Blynk.setProperty(vPIN_ON_OFF_2,"label"," [* PORCH LIGHT *] Sunrise @ "+SUNRISE + " "+"Sunset @ "+SUNSET);
Serial.print("SUNRISE @ ");Serial.print(SUNRISE);Serial.print(" ");Serial.print("SUNSET1 @ "); Serial.println(SUNSET);
//-------------------------------------------------SR04---------------------------------------
}else if (String(topic) == InTOPIC_9) { // stairs/Distance
StaticJsonBuffer<450> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char*)payload);
Distance = root["Distance"];
Blynk.virtualWrite(vPIN_SR04_DIST,Distance);
Blynk.setProperty (vPIN_SR04_DIST, "label", "DISTANCE in Cm");
}
}
//--------------------------------------------------------------------------------------------
wifi_credentials.h
/*******************************************************************************
*
* wifi_credentials.h
*
******************************************************************************/
/*******************************************************************************
Local Blynk Server Settings (uncomment to use local server and set address)
*******************************************************************************/
#define WIFI_SSID "xxxx" // ["xxxx" PW = "xxxx" ]
#define WIFI_PASS "xxxx" //Set pass to "" for open networks.
//#define LOCAL_SERVER IPAddress(192, 168,xxx, xxx) //your Local IP Server
#define Geo_DNS_SERVER IPAddress(xxx, xxx, xxx, xxx) //FRANKFURT