OTA NodeMCU

…or if you have esp with OLED integrated, then you can implement something like this:

{ corrected the link! }

This is a @Gunner excellent idea and work though

1 Like

I also have some basic OTA code here…

Hi Gunner I took inspiration from your example and I rewrote the code. You can check if there is any error.

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>  // For OTA w/ ESP8266
#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA
#include <SimpleTimer.h>
SimpleTimer timer;

#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define D5 14
#define D6 12
#define D7 13
#define D8 15

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //nodemcu test
 
char ssid[] = "xxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxx";
char server[] = "192.168.1.63";  // IP for your Local Server
int port = 8080;

//test web http://139.59.206.133/xxxxxxxxxxxxxxxxxxxxxxxxxx/update/V1?value=1
//ifttt Esempio: http://139.59.206.133/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/update/V1
//Method: PUT
//Content Type: application/json
//Body: ["1"]


//INIZIO PROGRAMMAZIONE PER IFTTT GOOGLE
BLYNK_WRITE(V1)
{   
  int value = param.asInt(); // Get value as integer
  
  if (value == 1) //VALORE CHE INTERPRETA
  {
     digitalWrite(D1, LOW); // (D1 NODEMCU) GPIO 5 LOW (......... RELE IN1)
     timer.setTimeout(500L, []() {  // Tempo funzionamento 0.5 secondi
          digitalWrite(D1, HIGH);  // Set  Pin 5 LOW
          Blynk.virtualWrite(V1, HIGH);// Set  Virtual Pin 0 HIGH
           });  // FINE FUNZIONE TIMER GOOGLE

}
}

BLYNK_WRITE(V2)
{   
  int value = param.asInt(); // Get value as integer
  
  if (value == 1) //VALORE CHE INTERPRETA
  {
     digitalWrite(D2, LOW); // (D2 NODEMCU) GPIO 4 LOW (......... RELE IN2)
     timer.setTimeout(500L, []() {  // Tempo funzionamento 0.5 secondi
          digitalWrite(D2, HIGH);  // Set  Pin 4 LOW
          Blynk.virtualWrite(V2, HIGH);// Set  Virtual Pin 2 HIGH
           });  // FINE FUNZIONE TIMER GOOGLE


}
}

BLYNK_WRITE(V3)
{   
  int value = param.asInt(); // Get value as integer
  
  if (value == 1) //VALORE CHE INTERPRETA
  {
     digitalWrite(D3, LOW); // D3 is GPIO 0 (............. RELE IN3)
     timer.setTimeout(500L, []() {  // Tempo funzionamento 0.5 secondi
          digitalWrite(D3, HIGH);  // Set  Pin 0 LOW
          Blynk.virtualWrite(V3, HIGH);// Set  Virtual Pin 3 HIGH
           });  // FINE FUNZIONE TIMER GOOGLE


}
}

BLYNK_WRITE(V4)
{   
  int value = param.asInt(); // Get value as integer
  
  if (value == 1) //VALORE CHE INTERPRETA
  {
     digitalWrite(D4, LOW); // D4 is GPIO 2 (............. RELE IN4)
     timer.setTimeout(500L, []() {  // Tempo funzionamento 0.5 secondi
          digitalWrite(D4, HIGH);  // Set  Pin 2 LOW
          Blynk.virtualWrite(V4, HIGH);// Set  Virtual Pin 4 HIGH
           });  // FINE FUNZIONE TIMER GOOGLE


}
}

BLYNK_WRITE(V5)
{   
  int value = param.asInt(); // Get value as integer
  
  if (value == 1) //VALORE CHE INTERPRETA
  {
     digitalWrite(D5, LOW); // D5 is GPIO 14 (............. RELE IN5)
     timer.setTimeout(500L, []() {  // Tempo funzionamento 0.5 secondi
          digitalWrite(D5, HIGH);  // Set  Pin 14 LOW
          Blynk.virtualWrite(V5, HIGH);// Set  Virtual Pin 5 HIGH
           });  // FINE FUNZIONE TIMER GOOGLE


}
}

BLYNK_WRITE(V6)
{   
  int value = param.asInt(); // Get value as integer
  
  if (value == 1) //VALORE CHE INTERPRETA
  {
     digitalWrite(D6, LOW); // D6 is GPIO 12 (............. RELE IN6)
     timer.setTimeout(500L, []() {  // Tempo funzionamento 0.5 secondi
          digitalWrite(D6, HIGH);  // Set  Pin 12 LOW
          Blynk.virtualWrite(V6, HIGH);// Set  Virtual Pin 6 HIGH
           });  // FINE FUNZIONE TIMER GOOGLE


}
}

BLYNK_WRITE(V7)
{   
  int value = param.asInt(); // Get value as integer
  
  if (value == 1) //VALORE CHE INTERPRETA
  {
     digitalWrite(D7, LOW); // D7 is GPIO 13 (............. RELE IN7)
     timer.setTimeout(500L, []() {  // Tempo funzionamento 0.5 secondi
          digitalWrite(D7, HIGH);  // Set  Pin 13 LOW
          Blynk.virtualWrite(V6, HIGH);// Set  Virtual Pin 7 HIGH
           });  // FINE FUNZIONE TIMER GOOGLE


}
}

BLYNK_WRITE(V8)
{   
  int value = param.asInt(); // Get value as integer
  
  if (value == 1) //VALORE CHE INTERPRETA
  {
     digitalWrite(D8, LOW); // D8 is GPIO 15 (............. RELE IN8)
     timer.setTimeout(500L, []() {  // Tempo funzionamento 0.5 secondi
          digitalWrite(D8, HIGH);  // Set  Pin 15 LOW
          Blynk.virtualWrite(V6, HIGH);// Set  Virtual Pin 8 HIGH
           });  // FINE FUNZIONE TIMER GOOGLE


}
}
//FINE PROGRAMMAZIONE PER IFTTT GOOGLE
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);
  Blynk.connect();;

  ArduinoOTA.setHostname("NodeMCU_LUCI_ZONA_GIORNO");  // For OTA - Use your own device identifying name
  ArduinoOTA.begin();  // For OTA


  pinMode(D1, OUTPUT); //D1 is GPIO 5 (..........RELE' IN1) (RELAY BUTTON)
  digitalWrite(D1, HIGH); // Set GPIO 5 HIGH

  
  pinMode(D2, OUTPUT); //D2 is GPIO 4 (..........RELE' IN2) (RELAY BUTTON)
  digitalWrite(D2, HIGH); // Set GPIO 4 HIGH
  
  pinMode(D3, OUTPUT); //D3 is GPIO 0 (..........RELE' IN3) (RELAY BUTTON)
  digitalWrite(D3, HIGH); // Set GPIO 0 HIGH
 
  
  pinMode(D4, OUTPUT); //D4 is GPIO 2 (..........RELE' IN4) (RELAY BUTTON)
  digitalWrite(D4, HIGH); // Set GPIO 2 HIGH
  
  pinMode(D5, OUTPUT); //D5 is GPIO 14 (..........RELE' IN5) (RELAY BUTTON)
  digitalWrite(D5, HIGH); // Set GPIO 14 HIGH

  pinMode(D6, OUTPUT); //D6 is GPIO 12 (..........RELE' IN6) (RELAY BUTTON)
  digitalWrite(D6, HIGH); // Set GPIO 12 HIGH

  pinMode(D7, OUTPUT); //D7 is GPIO 13 (..........RELE' IN7) (RELAY BUTTON)
  digitalWrite(D7, HIGH); // Set GPIO 13 HIGH

  pinMode(D8, OUTPUT); //D8 is GPIO 15 (..........RELE' IN8) (RELAY BUTTON)
  digitalWrite(D8, HIGH); // Set GPIO 15 HIGH
  
 Blynk.begin(auth, ssid, pass);
  

} 
void loop() {
  timer.run();
  ArduinoOTA.handle();  // For OTA
  Blynk.run();
}

Work, thanks

1 Like

a question in your opinion because when I give power to the circuit the relays to pin D3 and D4 light up for a while and then go off?

Bad choice of pins (GPIO0 and GPIO2).
Read this:

Pete.

1 Like

I need 4 pins to control the relays. which advise me to pin?

Try the green ones first :stuck_out_tongue: (in the chart already provided)

3 Likes

yes, in fact I had really thought of those:

D1 = Pin 5
D2 = Pin 4
D5 = Pin 14
D6 = Pin 12

P.S.: my past projects I chose the pins at random, you never stop to learn …

the problem occurs if I use the code with OTA updates if I use the code without OTA the problem of the relay at the circuit attention does not occur

Why do you think?

IDK. Try putting the OTA stuff at the end of you setup.

inserting the strings of code OTA at the end works as indicated by the table the pins D3 and D4 I had to exclude them

Ciao Eddie, sono italiano come te. Puoi aiutarmi cortesemente per settare bene l’OTA sul NodeMCU?
A me non funziona bene e non so dove sbaglio.
Fammi sapere
Grazie

ciao posso prova ma sono un pò arruginito con il codice ultimamente

A me serve una configurazio definitiva per far funzionare questo benedetto OTA.
Cioè, quando devo aggiornare il codice, nn devo ogni volta andare lì e collegarmi col pc. Mi puoi indicare la giusta configurazione del setup? Hai un codice funzionante così posso vedere? Grazie

il pc lo devi accendere per forza, questa funzione serve solo per aggiornare i dispositivi mediante rete non con il cavo usb, io lo uso perchè il mio dispositivo è chiuso in una cassetta nel muro ed è difficile accederci

si lo so come funziona, però quali sono i settaggi (codice) da fare in sostanza?

WiFi.begin(ssid, pass); //per aggiornamenti OTA
  Blynk.config(auth); //per aggiornamenti OTA
  Blynk.connect();; //per aggiornamenti OTA

  ArduinoOTA.setHostname("NodeMCU_LUCI_ZONA_GIORNO");  // per aggiornamenti OTA (nome identificativo dispositivo)
  ArduinoOTA.begin();  //per aggiornamenti OTA
  
  
 Blynk.begin(auth, ssid, pass);
  

} 
void loop() {
  timer.run();
  ArduinoOTA.handle();  //per aggiornamenti OTA
  Blynk.run();

Ho provato a togliere WiFi.begin(ssid, pass) perchè Blynk.begin già dovrebbe connettersi. L’hostname non lo uso. In questo momento la mia configuazione in setup è questa:

void setup(void) {

  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);

  //WiFi.begin(ssid, pass);
  
  ArduinoOTA.begin();  // For OTA

  ////////////////////////////////
  Serial.begin(9600);
  ina219.begin();
  //Blynk.begin(auth, ssid, pass);

  pinMode(greenLEDD7, OUTPUT);
  pinMode(redLEDD8, OUTPUT);
  pinMode(relayFaretto10WD4, OUTPUT);
  pinMode(relayMadonnaD5, OUTPUT);

  digitalWrite(relayFaretto10WD4, LOW);
  digitalWrite(relayMadonnaD5, LOW);

  // Setup a function to be called every second
  timer.setInterval(1000L, letturaPannelloProva); 
  timer.setInterval(1500L, sendInaValues);  
  timer.setInterval(3000L, controllaConnessione); 
  
}

può andare? E poi ho messo ovviamente la chimata ArduinoOTA.handle() nel loop.
Fammi sapere! Gentilissimo!

riesci ad aiutarmi? Hai un contatto diretto? Grazie