Well after thinking about it I decided to learn node-red and work together with blynk to make an all-in-1 dashboard as I always wanted and thus continue using BLYNK as a backend.
I have a query I did something basic to start learning.
Create a topic with mqtt “casa/habitaciones/cuartokevin/luz” inside node-red, that topic I send to the write event of node iot.
Then i use MQTTX for make pub to that topic node-red recive all its ok but
In the blynk dashboard and the mobile app the “PIN” is updated but does not do the typical blynk function:
BLYNK_WRITE (V0) {
livingstatus = param.asInt ();
digitalWrite (luzliving, estaoluzliving);
Blynk.virtualWrite (V50, luzlivingstate);
}
For the relay to activate.
I don’t know what I’m doing wrong or that is where I started with the left foot, I saw many videos where they used the arduino to create the SUBs, I don’t know if that’s the case? or as if someone could give me a BASIC example, that’s where I start.
In screens if any can see “Switch Luz Living” updated, but i think blynk code from arduino dont digitalwrite to relay.
Arduino Code:
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME "Living"
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <RCSwitch.h>
AsyncWebServer server(80);
RCSwitch ReceptorRF = RCSwitch();
IPAddress local_IP(192, 168, 1, 228);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";
char pass[] = "";
const int timbre = D7;
const int btntimbre = D8;
const int btnluzliving = D13;
const int luzliving = D6;
const int luzgarage = D4;
int estadotimbre = LOW;
int estadobtntimbre = LOW;
int estadobtnluzliving = LOW;
int estadoluzliving = LOW;
int estadoluzgarage = LOW;
BlynkTimer timer;
void CheckBotonTimbre();
void CheckBotonLuzLiving();
BLYNK_CONNECTED() {
Blynk.syncAll();
}
BLYNK_WRITE(V0) {
estadoluzliving = param.asInt();
digitalWrite(luzliving, estadoluzliving);
Blynk.virtualWrite(V50, estadoluzliving);
}
BLYNK_WRITE(V1) {
estadoluzgarage = param.asInt();
digitalWrite(luzgarage, estadoluzgarage);
}
BLYNK_WRITE(V2) {
estadotimbre = param.asInt();
digitalWrite(timbre, estadotimbre);
}
void CheckBotonTimbre()
{
if (digitalRead(btntimbre) == LOW) {
if (estadobtntimbre != LOW) {
estadotimbre = !estadotimbre;
SonarTimbre();
Blynk.logEvent("tocarontimbre");
}
estadobtntimbre = LOW;
} else {
estadobtntimbre = HIGH;
}
}
void CheckBotonLuzLiving()
{
if (digitalRead(btnluzliving) == LOW) {
if (estadobtnluzliving != LOW) {
estadoluzliving = !estadoluzliving;
digitalWrite(luzliving, estadoluzliving);
Blynk.virtualWrite(V0, estadoluzliving);
}
estadobtnluzliving = LOW;
} else {
estadobtnluzliving = HIGH;
}
}
void SonarTimbre()
{
digitalWrite(timbre, LOW);
Blynk.virtualWrite(V2, LOW);
timer.setTimeout(500L, ApagarTimbre);
}
void ApagarTimbre()
{
digitalWrite(timbre, HIGH);
Blynk.virtualWrite(V2, HIGH);
}
void setup()
{
// Debug console
Serial.begin(115200);
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi: ");
Serial.println(ssid);
Serial.print("Direccion IP: ");
Serial.println(WiFi.localIP());
server.begin();
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/plain", "Hola, EscuderoKevin.net Devs Home Automation V1.2 - Wemos Living");
});
AsyncElegantOTA.begin(&server);
Blynk.config(auth);
pinMode(luzliving, OUTPUT);
pinMode(luzgarage, OUTPUT);
pinMode(timbre, OUTPUT);
pinMode(btntimbre, INPUT_PULLUP);
pinMode(btnluzliving, INPUT_PULLUP);
timer.setInterval(100L, CheckBotonTimbre);
timer.setInterval(200L, CheckBotonLuzLiving);
digitalWrite(timbre, HIGH);
}
void loop()
{
Blynk.run();
timer.run();
}