Wifimanager + blynk +wemos connection problem

I! i use wemos d1 mini pro and i try to make connection with blynk and wifimanager with the option for new user start always at the same place (use always the same step by step method for first configuration).

i have 2 problem i can’t resolve . the first it is the connection, when i start the code all as good for setup the wifi to connect and the blynk ‘‘auth’’ too. when it restart and connect to blynk succesfully , it send me notification to my email (all is ok for now).

the problem is

after this the code/blynk/wifi don’t work more time, it stop working and when i try to send me notification with the normal condition , they don’t work more long time(aproxymativly 2 min) and i have try many thing but i can found and fix the problem.

i’m not very experimented with arduino expression c++ but i learn speedly (when is teach good XD) . i need help please and i don’t found the fix of my problem …

the normal fonction i want is: ( 1 ) first boot = wifi open , when connect to it then redirect to 192.168.4.1 for add all information need(ssid/pass/ blynk authentification).
( 2 ) : receive one time email for show is really connected and goodly synchronized with blynk.

( 3 ): can store and save the wifi ssid pass and blynk auth and restart with this same identification if try is fail restart with first boot option and delete all setting before

( 4 ) finally the wemos can as connected for very long time(physical reset with button only (not be reset if is possible)

P.S. when i take code with manual enter the ssid and the password and the blynk autentification, all work good but i can use this methode if the user change wifi setting i can go at there home each time is need to change… i really want use wifimanager and blynk connection at the same time and the same place ( 192.168.4.1)
the oled can deleted if is in conflic
if my english is poor i’m very sorry i speak french normaly


#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// SCL GPIO5
// SDA GPIO4
#define OLED_RESET 0  // GPIO0
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16




#include <FS.h>                   
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          
//#include <SimpleTimer.h>
#include <ArduinoJson.h>          


#define BLYNK_PRINT Serial    
//#define BLYNK_DEBUG



char server[15] = "45.55.96.146" ;
char port[6] = "80";
char auth[34]; //= "JDyxKH28IZu5NO8d48GuUbhwQMzNPEEC";
int  niveau;
const int  eau =4 ;
int  debordement = 4;  //D2
int sent;
const int level = 0;    // D3
int buttonState = 0;
int fin ;
const int finish = 16;  // D0
int done = 16;

bool shouldSaveConfig = false;
void check(){
if (buttonState == LOW) {
    sent = LOW;}
 if (sent == HIGH) {
    done  = HIGH;}

     }   

void saveConfigCallback () {
 Serial.println("Should save config");
 shouldSaveConfig = true;
}


void setup() {

  {Serial.begin(9600);

 // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 64x48)
 // init done

 display.display();
 delay(2000);

 // Clear the buffer.
 display.clearDisplay();

 // text display tests
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35,16);
 display.println("demmarage");
 display.display();
 delay(100);
 display.clearDisplay();
}
 
 // put your setup code here, to run once:
 Serial.begin(115200);
 Serial.println();
pinMode(finish, INPUT);
 pinMode(level, INPUT);
 pinMode(niveau, INPUT);
 //clean FS, for testing
 SPIFFS.format();

 //read configuration from FS json
 Serial.println("mounting FS...");
 display.clearDisplay();
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("FS mounting");
 display.display();
 delay(1000);
 display.startscrollleft(0x00, 0x0F);
 delay(2000);
 display.clearDisplay();
 display.stopscroll();
  display.clearDisplay();
 display.setTextSize(0);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("set wifi&auth");
 display.display();
 delay(1000);
 display.startscrollleft(0x00, 0x0F);
 delay(5000);
 display.clearDisplay();
 display.stopscroll();
 delay(1000);
display.clearDisplay();
 if (SPIFFS.begin()) {
   Serial.println("mounted file system");
   if (SPIFFS.exists("/config.json")) {
     //file exists, reading and loading
     Serial.println("reading config file");
     File configFile = SPIFFS.open("/config.json", "r");
     if (configFile) {
       Serial.println("opened config file");
       size_t size = configFile.size();
       // Allocate a buffer to store contents of the file.
       std::unique_ptr<char[]> buf(new char[size]);

       configFile.readBytes(buf.get(), size);
       DynamicJsonBuffer jsonBuffer;
       JsonObject& json = jsonBuffer.parseObject(buf.get());
       json.printTo(Serial);
       if (json.success()) {
         Serial.println("\nparsed json");

         strcpy(server, json["server"]);
         strcpy(port, json["port"]);
         strcpy(auth, json["auth"]);

       } else {
         Serial.println("failed to load json config");
       }
     }
   }
 } else {
   Serial.println("failed to mount FS");
 }
 //end read



 // The extra parameters to be configured (can be either global or just in the setup)
 // After connecting, parameter.getValue() will get you the configured value
 // id/name placeholder/prompt default length
 WiFiManagerParameter custom_server("server", "server", server, 15);
 WiFiManagerParameter custom_port("port", "port", port, 6);
 WiFiManagerParameter custom_auth("blynk", "blynk token", auth, 34);

 //WiFiManager
 //Local intialization. Once its business is done, there is no need to keep it around
 WiFiManager wifiManager;

 //set config save notify callback
 wifiManager.setSaveConfigCallback(saveConfigCallback);

 //set static ip
 //wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
 
 //add all your parameters here
 wifiManager.addParameter(&custom_server);
 wifiManager.addParameter(&custom_port);
 wifiManager.addParameter(&custom_auth);

 //reset settings - for testing
 //wifiManager.resetSettings();

 //set minimu quality of signal so it ignores AP's under that quality
 //defaults to 8%
 //wifiManager.setMinimumSignalQuality();
 
 //sets timeout until configuration portal gets turned off
 //useful to make it all retry or go to sleep
 //in seconds
 //wifiManager.setTimeout(120);

 //fetches ssid and pass and tries to connect
 //if it does not connect it starts an access point with the specified name
 //here  "AutoConnectAP"
 //and goes into a blocking loop awaiting configuration
 if (!wifiManager.autoConnect("Wifi_Manager", "")) {
   Serial.println("failed to connect and hit timeout");
     display.clearDisplay();
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("reset esp wifi");
 display.display();
 delay(100);
 display.startscrollleft(0x00, 0x0F);
 delay(3000);
 display.stopscroll();
 delay(10);
display.clearDisplay();
   //reset and try again, or maybe put it to deep sleep
   ESP.reset();
   
 }

 //if you get here you have connected to the WiFi
 Serial.println("connected...yeey :)");
 display.clearDisplay();
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("wifi connected");
 display.display();
 delay(100);
 display.startscrollleft(0x00, 0x0F);
 delay(2000);
 display.stopscroll();
 delay(100);
display.clearDisplay();


 //read updated parameters
 strcpy(server, custom_server.getValue());
 strcpy(port, custom_port.getValue());
 strcpy(auth, custom_auth.getValue());

 //save the custom parameters to FS
 if (shouldSaveConfig) {
   Serial.println("saving config");
     display.clearDisplay();
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("saving config");
 display.display();
 delay(1000);
 display.startscrollleft(0x00, 0x0F);
 delay(2000);
 display.stopscroll();
 delay(10);
display.clearDisplay();
   DynamicJsonBuffer jsonBuffer;
   JsonObject& json = jsonBuffer.createObject();
   json["server"] = server;
   json["port"] = port;
   json["auth"] = auth;

   File configFile = SPIFFS.open("/config.json", "w");
   if (!configFile) {
     Serial.println("failed to open config file for writing");

     
   }

   json.printTo(Serial);
   json.printTo(configFile);
   configFile.close();
   //end save
 }

Serial.println("local ip");
Serial.println(WiFi.localIP());

 Blynk.config(auth);
 bool result = Blynk.connect();
Blynk.run();
if (result != true)
{
 Serial.println("BLYNK Connection Fail");
    display.clearDisplay();
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("noBLYNK I reset");
 display.display();
 delay(1000);
 display.startscrollleft(0x00, 0x0F);
 delay(5000);
 display.stopscroll();
 delay(1000);
display.clearDisplay();
 Serial.println(auth);
 wifiManager.resetSettings();
 Serial.println("local ip");
Serial.println(WiFi.localIP());

 Blynk.config(auth);
 bool result = Blynk.connect();
Blynk.run();
if (result != true)
 display.clearDisplay();
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("reset wifi&auth");
 display.display();
 delay(1000);
 display.startscrollleft(0x00, 0x0F);
 delay(3000);
 display.stopscroll();
 delay(1000);
display.clearDisplay();
 ESP.reset();

}
else
{
 Serial.println("BLYNK Connected");
  display.clearDisplay();
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("BLYNK connected");
 display.display();
 delay(1000);
 display.startscrollleft(0x00, 0x0F);
 delay(3000);
display.clearDisplay();
}
//WiFi.mode(WIFI_STA);
}
void notify(){
 if ((buttonState == LOW) && (sent == LOW)) {
 Blynk.email("grr.la@grr.la", " VOTRE APPAREIL  SEMBLE EN PROBLÈME ÉLÉCTIQUE ET EST A VÉRIFIÉ  ", "VOTRE APPAREIL  A BESOIN D'ÊTRE VÉRIFIÉ  Alert MODULE ESP8266  UNE PANNE ÉLÉTRIQUE A ÉTÉ DÉTÉCTÉ  ");
sent = HIGH;
fin = LOW;
 }
if  ((buttonState == HIGH) && (fin == LOW)) {
 Blynk.email("grr.la@grr.la", "VOTRE APPAREIL EST ALIMENTÉ EN ELECTRICITÉ ", "VÉRIFIÉ QUAND MÊME LE BON FONCTIONNEMENT DE VOTRE APPAREIL S.V.P. DÈS QUE POSSIBLE! ");
  fin = HIGH;
 }
if ((debordement == LOW) && (niveau == LOW)) {
 Blynk.email("grr.la@grr.la", " VOTRE POMPE SUBMERSIBLE EST A VÉRIFIÉ  ", "HAUT NIVEAU DÉTÉCTÉ SUR VOTRE POMPE SUBMERSIBLE Alert MODULE ESP8266 ");
niveau = HIGH;
 }
// if ((debordement == HIGH) && (niveau == HIGH)) {
// Blynk.email("grr.la@grr.la", " LE NIVEAU D'EAU DE VOTRE POMPE SUBMERSIBLE SEMBLE RÉTABLE  ", "LE HAUT NIVEAU DÉTÉCTÉ SUR VOTRE POMPE SUBMERSIBLE SEMBLE EST REVENUE A LA NORMAL  VÉRIFIÉ QUAND MÊME LE BON FONCTIONNEMENT DE VOTRE APPAREIL S.V.P. DÈS QUE POSSIBLE! ");
// niveau = LOW;
// }

 
}
void loop() {
 notify();
  buttonState = digitalRead(level); 
  debordement = digitalRead(eau);
{
if (buttonState == HIGH)  {
 sent = LOW;}
  if (sent == HIGH)  {
   display.clearDisplay();
display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("ALARM");
 display.display();
 display.clearDisplay();
   }
   

{
if (debordement == HIGH)  {
 niveau = LOW;}
 if (niveau == HIGH)  {
  display.clearDisplay();
display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(35, 16);
 display.print("HAUT NIVEAU");
 display.display();
   display.clearDisplay();
   }
 
}}}

I don’t really understand what you’re saying, I think some of it is getting lost in translation, but at the moment this line of code:

is deleting all of your saved parameters from SPIFFS memory every time the device boots, so should be commented-out.

If you still have a problem then maybe explain what happens in a step by step way, with screenshots and data from the serial monitor.

Pete.

tank you for this answer! yes effectively this point correct the connection identification ssid pass and auth blynk when is already connected in the past. nice tank you very much , i’m very sorry for my language next time i will use traductor

i have another question/problem. i have 2 model of wemos , one is wemos d1 mini pro and another is wemos d1 mini.
when i configure the setup for blynk connection with the wemos d1 mini pro is work perfectly and when i have lost electricity when it come against the wemos d1 mini pro reconnect succesfull with blynk, the problem is the wemos d1 mini when it restart or after lost electricity it don’t reconnect and reset all parameter wifi and blynk!? have ou ideal why? when is try to mounting fs is fail each time. the code is exactly the same between this to model , i very don’t know why it do this. the wemos d1 mini pro work each time for reconnect and mounting fs. the wemos d1 mini fail each time for reconnect and mounting! anybody have idea why? tank you very much!

The memory maps of the 2 boards are different (Pro is much bigger). You can use exactly the same source (.ino, etc) files, but have to compile 2 different bin files or to directly upload. You can’t use the same bin file if you’re using SPIFFS.

From Tools->Boards

  1. For Wemos D1 Mini, you can try using
  • NodeMCU 1.0
  • Flash 4MB (FS: 1MB OTA: ~1019KB)
  1. For Wemos D1 Mini Pro, you can try using
  • LOLIN (WEMOS) D1 mini Pro
  • Flash 16MB (FS: 14MB OTA: ~1019KB)
1 Like

nice! you are awesome! tank you very much ! very very much !

Here’s some code I pieced together that combines blynk and wifimanager on a Wemos D1 mini pro, and other wifi boards. It saves wifi login and your blynk token through resets and power cycles.
If the code can’t connect to a wifi network, it opens an Access Point (AP) which you can connect to using a device with wifi and a browser. Simply put in the new network name, password, and the token given in your blynk app, then connect to the same wifi as the board.
If the connection is successful, it will store the connection information and should reconnect after resets!

Make sure to read through all the code. You might have to download a few libraries, as well as choose a name and password for the AP.
In addition, it has been translated to use ArduinoJson 6.

#include <FS.h>                   //this needs to be first, or it all crashes and burns...

#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager

#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson

#define BLYNK_PRINT Serial


//define your default values here, if there are different values in config.json, they are overwritten.
char blynk_token[34] = "your-blynk-token";

//flag for saving data
bool shouldSaveConfig = false;

//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}


  void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println();

  //clean FS, for testing
  //SPIFFS.format();

  //read configuration from FS json
  Serial.println("mounting FS...");

  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        //Json Document initialize
        DynamicJsonDocument doc(256);
        auto error = deserializeJson(doc, buf.get());
        serializeJson(doc, Serial);

        if (!error) {
          Serial.println("\nparsed doc");
          strcpy(blynk_token, doc["blynk_token"]);

        } else {
          Serial.print(F("deserializeJson() failed with code "));
          Serial.println(error.c_str());
        }
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
  //end read


  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 34);

  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //add all your parameters here
  wifiManager.addParameter(&custom_blynk_token);


  //reset settings - for testing
  //wifiManager.resetSettings();


  //set minimum quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();
  
  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("AP Connect", "password")) {     //Choose a name and password for the AP to be created
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");

  //read updated parameters
  strcpy(blynk_token, custom_blynk_token.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonDocument doc(256);
    doc["blynk_token"] = blynk_token;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }

    serializeJson(doc, Serial);
    serializeJson(doc, configFile);
    configFile.close();
    //end save
  }

  //configure blynk
  delay(5000);
  Blynk.config(blynk_token);
  bool result = Blynk.connect(180);
  if (result != true) {
    Serial.println("BLYNK Connection Fail");
    //needs testing on whether this line should be commented out:
    //wifiManager.resetSettings();
    ESP.reset();
    delay (5000);
  }
  else  {
    Serial.println("BLYNK Connected");
  }
  
  //Connect to blynk using an already-open internet connection and preset configuration
  if(!Blynk.connect()) {
    Serial.println("Blynk connection timed out.");
    ESP.reset();
    delay (5000);
  }
}

  void loop() {
  // put your main code here, to run repeatedly:
  Blynk.run();
}

@primerIsNerdArt Hi, I’m trying to use your code. I load it on my wemos, it compiles it and records it without problems, but when searching the wifi networks, the AP of the wemos doesn’t appear … can you help me, I want to implement your code in my project.

//#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "gyyR8xzGjenl610qwc6wioY1H12xBQs4";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TORRES";
char pass[] = "19841887";

// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() 
{
  if (isFirstConnect) 
  {
    // Request Blynk server to re-send latest values for all pins
    Blynk.syncAll();
    isFirstConnect = false;
  }
}
bool alarm_mode = false ;
int sensor = 5; //GPIO5 D1 Pin number on which sensor is connected
int buzzer = 15; //GPIO15 D8 Pin number on which buzzer is connected
int alarm_led = 4; //GPIO4 D2 Pin number on which alarm status led is connected
int alarm_led_off = 0; //GPIO0 D3 Pin number on which alarm status led is connected

BlynkTimer timer;

void myTimerEvent(){
   
  if(digitalRead(sensor) == 0){
    Blynk.virtualWrite(V0, "ACTIVADO");
     Blynk.notify("alarma activada");
      delay (1000);
  }
  if(digitalRead(sensor) == 1)
  {
    Blynk.virtualWrite(V0, "DESACTIVADO");
     Blynk.notify("alarma desactivada");
     delay (1000);
    if(alarm_mode == true)
    {digitalWrite(alarm_led, HIGH); 
            
    }
  }
  }
BLYNK_WRITE(V1) {
  switch (param.asInt()) {
    case 1: { // Item 1
      //Serial.println("Item 1 selected");
      alarm_mode = true;
      digitalWrite(alarm_led, HIGH); 
      digitalWrite(alarm_led_off, LOW);
      break;
    }
    case 2: { // Item 2
      //Serial.println("Item 2 selected");
      alarm_mode = false;
      digitalWrite(buzzer, LOW);  
      digitalWrite(alarm_led, LOW);
      digitalWrite(alarm_led_off, HIGH);  
      break;
    }    
  }
}

void setup()
{
  pinMode(sensor, INPUT_PULLUP);
  pinMode(buzzer, OUTPUT);
  pinMode(alarm_led, OUTPUT);
  pinMode(alarm_led_off, OUTPUT);
  
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

What does your serial monitor show?

Pete.

Please edit your post, remove the screenshot, and copy/paste the entire serial monitor output from the device boot-up.

Pete.

try with this, i use it each time i make thing d1 is dht probe all other is in or out(as your choise , it virtualised) reset all parameter connection by d7 and heartbeat d8.
https://pastebin.pl/view/6ae0ecf0
i only accessed this code for one weak

Hi, I’m happy @primerIsNerdArt I was able to incorporate the code of my project and it worked! the only problem I have is that when I turn off the wemos the credentials are not saved and vulve open the AP for the new username and password … can you help me?

#include <FS.h>    
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> 
#include <ArduinoJson.h>    
//define your default values here, if there are different values in config.json, they are overwritten.
char mqtt_server[40];
char mqtt_port[6] = "8080";
char blynk_token[34] = "zUDZm-EtQq9arxeaE1IJZtAjFi_uCI3L";

//flag for saving data
bool shouldSaveConfig = false;

// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() 
{
  if (isFirstConnect) 
  {
    // Request Blynk server to re-send latest values for all pins
    Blynk.syncAll();
    isFirstConnect = false;
  }
}
bool alarm_mode = false ;
bool verificador = false;
int led_placa = 2;
int sensor = 5;
int buzzer = 15;
int alarm_led = 4;
int alarm_led_off = 0;
//int boton = 12;
int indicador = 13;
int ledPin = 14;
int contconexion = 0;
int conteoReactivacion = 0;

BlynkTimer timer;
//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
  }
void myTimerEvent() {
  Serial.println("Tiempo desactivada en seg: " + String(conteoReactivacion));
  if (alarm_mode == false) {
    conteoReactivacion++;
    if (conteoReactivacion >= 600) { //son 30 minutos es 1800 segundos dividido en 3 da 600 segundos por el delay que se le da a V0 de 3000 milisegundos para retrasar el pulso de disparo por 3 segundos
      Blynk.virtualWrite(V1, 1);
      digitalWrite(alarm_led, HIGH);
      digitalWrite(alarm_led_off, LOW);
      alarm_mode = true;
    }
  } else {
    conteoReactivacion = 0;
  }
  if (digitalRead(sensor) == 0) {
    Blynk.virtualWrite(V0, "NORMAL");
    //delay(7000);
  }
  if (digitalRead(sensor) == 1)

  {
    Blynk.virtualWrite(V0, "ALERTA");
    
    if (alarm_mode == true)
      //AUTOR ALEXIS MORA
    {
      Blynk.email("ale24cba@gmail.com", "Historial de Alarmas", "Alarma Disparo");
      Blynk.notify("EME-WIFI EMERGENCIA SAN LORENZO 546");
      digitalWrite(buzzer, HIGH);
      delay(500);
      digitalWrite(buzzer, LOW);
    }
  }
}
BLYNK_WRITE(V1) {
  Serial.println(param.asInt());
  switch (param.asInt()) {
    case 1: {
        alarm_mode = true;
        digitalWrite(alarm_led, HIGH);
        digitalWrite(alarm_led_off, LOW);
        break;
      }
    case 2: {
        alarm_mode = false;
        digitalWrite(buzzer, LOW);
        digitalWrite(alarm_led, LOW);
        digitalWrite(alarm_led_off, HIGH);
        break;
    }    
  }
}

void setup()
{
  pinMode(sensor, INPUT_PULLUP);
  pinMode(buzzer, OUTPUT);
  pinMode(alarm_led, OUTPUT);
  pinMode(alarm_led_off, OUTPUT);
  //pinMode(boton, INPUT);
  pinMode(indicador, OUTPUT);
  pinMode(led_placa, OUTPUT);
  
  // Debug console
  Serial.begin(9600);
 // Blynk.begin(auth, ssid, pass);
  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);

 
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();

  //clean FS, for testing
  //SPIFFS.format();

  //read configuration from FS json
  Serial.println("mounting FS...");

  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          //strcpy(mqtt_server, json["mqtt_server"]);
         //strcpy(mqtt_port, json["mqtt_port"]);
          strcpy(blynk_token, json["blynk_token"]);

        } else {
          Serial.println("failed to load json config");
        }
        configFile.close();
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
  //end read



  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  //WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
  //WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 34);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //set static ip
  //wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
  
  //add all your parameters here
  //wifiManager.addParameter(&custom_mqtt_server);
  //wifiManager.addParameter(&custom_mqtt_port);
  wifiManager.addParameter(&custom_blynk_token);

  //reset settings - for testing
  wifiManager.resetSettings();

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();
  
  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep
  //in seconds
  //wifiManager.setTimeout(120);

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("NanoWifi", "12345678")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");

  //read updated parameters
  //strcpy(mqtt_server, custom_mqtt_server.getValue());
  //strcpy(mqtt_port, custom_mqtt_port.getValue());
  strcpy(blynk_token, custom_blynk_token.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    //json["mqtt_server"] = mqtt_server;
   // json["mqtt_port"] = mqtt_port;
    json["blynk_token"] = blynk_token;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }

    json.printTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

 while (WiFi.status() != WL_CONNECTED) {
       int mytimeout = 5;
       delay(500);
       Serial.print(".");
       if((millis() / 1000) > mytimeout ){ // try for less than 6 seconds to connect to WiFi router
         Serial.println(" ");
          break;
        }
   }

   if(WiFi.status() == WL_CONNECTED){  
    //if you get here you have connected to the WiFi
   Serial.println(" ");
   Serial.println("connected to WiFi!! yay :)");
   Serial.println("IP address: ");
   Serial.println(WiFi.localIP()); 
   digitalWrite(indicador, HIGH);
 
 
  Blynk.config(blynk_token);
  bool result = Blynk.connect();

  if (result != true)
  {
  Serial.println("BLYNK Connection Fail");
  Serial.println(blynk_token);
  //wifiManager.resetSettings(); //BORRA USUARIO Y CONTRASELLA DE WIFI AL APAGARSE
  ESP.reset();
  //delay (5000);
  }
  else
  {
  Serial.println("BLYNK Connected!! Yay again");
  }
 }
 else if (WiFi.status() != WL_CONNECTED){
  Serial.println("WiFi Connection Fail");
 } 

}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Very difficult to diagnose without knowing what flash size settings you used when you uploaded your code, and what the output of your serial monitor says (I can almost guarantee that the serial monitor output will hold the answer).

Pete.

Hello Pet, I am very new to this, I open the serial monitor and nothing appears … what can it be?

Check that you have the correct COM port selected, and the correct baud rate.

Pete.

speed and port are correct Pet … what appears to me is this, everything works fine except when I disconnect the equipment …
⸮H⸮Hv⸮ ⸮⸮H⸮
JH⸮⸮G!G(⸮ 9⸮⸮⸮Hv⸮
J⸮HJ⸮ ⸮⸮p⸮⸮⸮ -⸮⸮)⸮⸮⸮m⸮0D⸮9,⸮8⸮HT⸮⸮⸮

That’s the NodeMCU boot message, being output at a baud rate of 74880.
The sensible approach is to use the same baud rate in your Serial.begin statement in your sketch, so both boot messages and debug data can be seen at the same time.

Pete.

Pet now appears on the serial monitor

pet I can see the information of serial monitor but when copying and pasting I can’t! is incredible!! I only copy the last line of everything copied

CTRL A (or Command A on a Mac) will select all.
CTRL C (or Command C) will copy what has been selected.

Pete.