ESP32 - Wifi Connection

Hello.
I'm programming an ESP32 module using the Arduino IDE, as I'm building a model of an automated house.

I would like to know if there is any way to program the ESP32 to start with all the LEDs on "in case the module does not find or is unable to establish a connection to the Wifi network".

#define BLYNK_TEMPLATE_ID "fsdfdsfsdfsdfsdfsd"
#define BLYNK_TEMPLATE_NAME "fsdfsdfsdfsd"
#define BLYNK_AUTH_TOKEN "fsdfsdfsdfsdfsdfsdfsd"

#define BLYNK_PRINT Serial

#include "WiFi.h"
#include "WiFiClient.h"
#include "BlynkSimpleEsp32.h"

char auth[] = BLYNK_AUTH_TOKEN; 

char ssid[] = "aaaaa";
char pass [] = "bbbbb";

int led0 = 13;
int led1 = 12;
int led2 = 14;
int led3 = 27;

BLYNK_WRITE (V0) {
  int value = param.asInt();
  digitalWrite (led0, value);
}
BLYNK_WRITE (V1) {
  int value = param.asInt();
  digitalWrite (led1, value);
}
BLYNK_WRITE (V2) {
  int value = param.asInt();
  digitalWrite (led2, value);
}
BLYNK_WRITE (V3) {
  int value = param.asInt();
  digitalWrite (led3, value);
}



void setup() {
  Serial.begin (115200);
  Blynk.begin(auth, ssid, pass);
 pinMode (led0, OUTPUT);
 pinMode (led1, OUTPUT);
 pinMode (led2, OUTPUT);
 pinMode (led3, OUTPUT);
}

void loop() {
   Blynk.run();
}

Thank you very much in advance!!

Assuming the LEDs are wired to ground (i.e. come on when the output pin is HIGH), replace setup() with the following:

void setup() {
  pinMode (led0, OUTPUT);
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
  digitalWrite(led0, HIGH);
  digitalWrite(led1, HIGH);
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);
  Serial.begin (115200);
  Blynk.begin(auth, ssid, pass);
}

If the LEDs are wired to 3.3V, replace the HIGH with LOW in the initializing digitalWrite calls.

Wow, it's simpler than I imagined! :astonished:

So, in case of no internet, I can use them as normal light bulbs using a switch!

Thanks a lot for the help!! :sweat_smile: :sweat_smile:

You're quite welcome. Now that your question has been answered, please take a moment to mark the topic as solved by clicking the :ballot_box_with_check: Solution button at the bottom of the reply that answered your question, as shown in How to get the best out of this forum.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.