Hello Blynk users
I am having a LOGICAL doubt, I need to try to “take out the event system” to make it 100% automatic to my system that does not depend on anything.
The idea is to have an IF change between certain “Hours” to change state to a few pins & after those “Hours” only turn them off once.
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>
#include <Wire.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#define DHTPIN 23
#define DHTTYPE DHT11 // DHT 11
char auth[] = "";
#define W5100_CS 10
#define SDCARD_CS 4
BlynkTimer timer;
WidgetTerminal terminal(V73);
WidgetLED ledbomba(V72);
DHT dht(DHTPIN, DHTTYPE);
WidgetRTC rtc;
const int BombaAgua = 30;
const int ReflectorPatio = 32;
const int Presurizadora = 34;
const int SensorPorton = 38;
const int BotonCuarto = 40;
const int ReflectorPorton = 31;
const int ReflectorTerreno = 33;
const int AperturaPorton = 35;
const int LuzCuarto = 37;
int EstadoBombaAgua = LOW;
int EstadoReflectorPatio = LOW;
int EstadoReflectorPorton = LOW;
int EstadoReflectorTerreno = LOW;
int EstadoPresurizadora = LOW;
bool isFirstConnect = true;
int EstadoLuzCuarto, EstadoBotonCuarto, EstadoAperturaPorton, EstadoSensorPorton;
void setup()
{
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH);
Blynk.begin(auth, IPAddress(192, 168, 1, 14), 8080);
pinMode(BombaAgua, OUTPUT);
pinMode(ReflectorPatio, OUTPUT);
pinMode(Presurizadora, OUTPUT);
pinMode(LuzCuarto, OUTPUT);
pinMode(ReflectorPorton, OUTPUT);
pinMode(ReflectorTerreno, OUTPUT);
pinMode(AperturaPorton, OUTPUT);
pinMode(BotonCuarto, INPUT_PULLUP);
pinMode(SensorPorton, INPUT_PULLUP);
dht.begin();
rtc.begin();
setSyncInterval(10 * 60);
terminal.clear();
terminal.println(F("Jarvis Home Iniciado V2"));
terminal.println(F("-------------"));
terminal.println(F("Blynk Version: " BLYNK_VERSION));
terminal.flush();
timer.setInterval(1000L, botonluzcuarto);
//timer.setInterval(10000L, temperaturayhumedad);
timer.setInterval(10000L, checkconnect);
timer.setInterval(1000L, sensorporton);
}
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;
}
}
BLYNK_WRITE(V1) {
EstadoBombaAgua = param.asInt();
digitalWrite(BombaAgua, EstadoBombaAgua);
if (EstadoBombaAgua == 0) {
ledbomba.on();
terminal.println(F("Bomba Encendida"));
terminal.flush();
}
else {
ledbomba.off();
terminal.println(F("Bomba Apagada"));
terminal.flush();
}
}
BLYNK_WRITE(V2) {
EstadoReflectorPatio = param.asInt();
digitalWrite(ReflectorPatio, EstadoReflectorPatio);
}
BLYNK_WRITE(V3) {
EstadoPresurizadora = param.asInt();
digitalWrite(Presurizadora, EstadoPresurizadora);
if (EstadoPresurizadora == 0) {
Blynk.virtualWrite(V103, "Presurizada");
}
else {
Blynk.virtualWrite(V103, "Normal");
}
}
BLYNK_WRITE(V4) {
EstadoLuzCuarto = param.asInt();
digitalWrite(LuzCuarto, EstadoLuzCuarto);
}
BLYNK_WRITE(V5) {
EstadoReflectorPorton = param.asInt();
digitalWrite(ReflectorPorton, EstadoReflectorPorton);
}
BLYNK_WRITE(V6) {
EstadoReflectorTerreno = param.asInt();
digitalWrite(ReflectorTerreno, EstadoReflectorTerreno);
}
BLYNK_WRITE(V7) {
EstadoAperturaPorton = param.asInt();
digitalWrite(AperturaPorton, EstadoAperturaPorton);
}
void botonluzcuarto()
{
if (digitalRead(BotonCuarto) == LOW) {
if (EstadoBotonCuarto != LOW) {
EstadoLuzCuarto = !EstadoLuzCuarto;
digitalWrite(LuzCuarto, EstadoLuzCuarto);
Blynk.virtualWrite(V4, EstadoLuzCuarto);
}
EstadoBotonCuarto = LOW;
} else {
EstadoBotonCuarto = HIGH;
}
}
void temperaturayhumedad()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + "/" + month() + "/" + year();
terminal.println("Error Temperatura Cuarto Kevin: ");
terminal.print(currentTime);
terminal.print(" ");
terminal.print(currentDate);
terminal.println();
terminal.flush();
return;
}
Blynk.virtualWrite(V10, h);
Blynk.virtualWrite(V11, t);
}
void checkconnect()
{
bool result = Blynk.connected();
if (result == false) {
Blynk.connect();
}
}
void sensorporton() {
EstadoSensorPorton = digitalRead(SensorPorton);
if (EstadoSensorPorton == 1)
{
Blynk.virtualWrite(V8, "Abierto");
} else {
Blynk.virtualWrite(V8, "Cerrado");
}
}
But I am having problems in that, like that nothing is executed at all …
Something in my logic goes wrong.
Thank you so much.