• Hello my friends. Please note I’m handled this project of SMART HOME. I’m looking for control all relays also over alexa’s voice commands and for now, I didn’t find any solution for this.
I ask you kindly to help me with an amend or complement of IDE code to implement this new functions, whit no spoil current OTA, Clock and Blynk functions
• Actually hardware conections and comunicattion/interaction between Blynk <-> hardware are working perfectly.
Details :
• NodeMcu (ESP8266) + Relay 16 Channels + Amazon Echo-Dot with Alexa.
• Wi-Fi communication type over NodeMcu.
• Smartphone OS (iOS or Android)
• Blynk server
• Blynk Library version 0.6.0
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>
#include <ESP8266WiFi.h>
#include <TimeLib.h>
#include <NTPClient.h>
#include <WidgetRTC.h>
#include <WiFiUdp.h>
#define LUZSALA 16 //DEFINE A NAME FOR PIN D0
#define TOMADASALA 5 //DEFINE A NAME FOR PIN D1
#define LUZQUARTOS 4 //DEFINE A NAME FOR PINO D2
#define TOMADASUITE 0 //DEFINE A NAME FOR PIN D3
#define TOMADAQUARTO 2 //DEFINE A NAME FOR PINO D4
#define LUZCOZINHA 14 //DEFINE A NAME FOR PIN D5
#define TOMADACOZINHA 13 //DEFINE A NAME FOR PIN D7
#define BLYNK_PRINT Serial
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org"); //DECLARE THE GLOBAL TIME SERVER
BlynkTimer timer;
WidgetRTC rtc;
WidgetTerminal terminal(V0); //DEFINE BLYNK VIRTUAL PIN V1 TO TERMINAL DISPLAY USED ON APP
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //BLYNK AUTHORIZATION TOKEN
char ssid[] = "xxxxxxxxxxxxxxxxx"; //SET LOCAL WI-FI SSID (service set identifier)
char pass[] = "xxxxxxxxxxx"; //SET LOCAL WI-FI PASSWORD
String displaycurrenttimepluswifi; //VARIABLE TYPE STRING TO SHOWS IN DISPLAY TERMINAL AT BLYNK APP
int wifisignal, manual, hora, minuto; //VARIABLES TYPE STRING TO STORE CURRENT TIME, WI-FI SIGNAL, MANUAL/AUTOMATIC MODE, HOUR AND MINUTE
//*****************************************************************************************************************************************************************************************
void setup(){
pinMode(LUZSALA, OUTPUT); //DEFINE PIN AS OUTPUT
pinMode(TOMADASALA, OUTPUT); //DEFINE PIN AS OUTPUT
pinMode(TOMADAQUARTO, OUTPUT); //DEFINE PIN AS OUTPUT
pinMode(TOMADASUITE, OUTPUT); //DEFINE PIN AS OUTPUT
pinMode(LUZQUARTOS, OUTPUT); //DEFINE PIN AS OUTPUT
pinMode(LUZCOZINHA, OUTPUT); //DEFINE PIN AS OUTPUT
pinMode(TOMADACOZINHA, OUTPUT); //DEFINE PIN AS OUTPUT
Serial.begin(115200);
Blynk.begin(auth, ssid, pass); //CALL/START CONECTION WITH BLYNK SERVER
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80); //CALL/START CONECTION WITH BLYNK SERVER
Blynk.syncAll(); //SINCRONIZATION WITH BLYNK SERVER
//************************************************************************************************
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else { // U_SPIFFS
type = "filesystem";
}
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) {
Serial.println("Auth Failed");
} else if (error == OTA_BEGIN_ERROR) {
Serial.println("Begin Failed");
} else if (error == OTA_CONNECT_ERROR) {
Serial.println("Connect Failed");
} else if (error == OTA_RECEIVE_ERROR) {
Serial.println("Receive Failed");
} else if (error == OTA_END_ERROR) {
Serial.println("End Failed");
}
});
ArduinoOTA.begin(); //SINCRONIZATION WITH BLYNK SERVER
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
ModoAutomatico(); //CALL FUNCTION TO SET MANUAL E/OU AUTOMATIC MODE OVER APP (function in a secundary sketch)
//************************************************************************************************
int mytimeout = millis() / 1000;
while (Blynk.connect() == false) { //TRY TO CONECT TO SERVER FOR 10 SECONDS
if((millis() / 1000) > mytimeout + 8){ //TRY LOCAL SERVER IF NOT CONECT WITHIN 9 SECONDS
break;
}
}
//************************************************************************************************
timer.setInterval(1000L, clockvalue); //UPDATE EVERY 1s VALUE FOR TIME (function in a secundary sketch)
timer.setInterval(5000L, sendWifi); //UPDATE EVERY 5s WI-FI SIGNAL
timer.setInterval(1800000L, ModoAutomatico); //CHECK EVERY 30m IF IT IS STIL IN AUTOMATIC MODE (function in a secundary sketch)
rtc.begin(); //CALL/START CLOCK PROPETIES
timeClient.begin(); //CALL/START CLOCK PROPETIES
timeClient.setTimeOffset(-3600*3); //SET CLOCK WITH TIME ZONE (Bazil)
acende_tudo(); //CALL FUNCTION TO TURN ON ALL SWITCHES OR RELAYS OR LIGHTS BULB (function in a secundary sketch)
}
//*****************************************************************************************************************************************************************************************
void sendWifi() { //FUNCTION TO GET WI-FI SIGNAL INFO
wifisignal = map(WiFi.RSSI(), -105, -40, 0, 100);
}
//*****************************************************************************************************************************************************************************************
void loop(){
ArduinoOTA.handle(); //CALL OTA FUNCTION TO UPLOAD SKETCHES FROM ARDUINO-IDE TO THE BOARD (NodeMcu) OVER WI-FI
Blynk.run(); //CALL BLYNK APPLICATION
timer.run(); //CALL TIMER FUNCTION
}
Thanks in advance
Best regards[date=2021-05-01 timezone=“America/Sao_Paulo”]