ESP is not responding after adding wifimanager

thank you PeteKnight
one last question

i have succeeded with this code to change the status of blynk button in the mobile app as per the actual lamp status even if the physical (push button) in wall is turned on or off, it reflect the status on mobile button.
but i have one problem with this code, that it is only working with physical push button but i need to modify it to be applicable with physical normal switch, you can find below the wiring and the code (wiring for nodemcu with 4 lamps but i used esp32 no problem with that, and i modified the code for one lamp to be simple here)
i am so much frustrated to complete my project to change the code from using push button to switch as it really so much important to me maybe it is something simple but u know am not so good in this coding issue,
in addition that i used IFTTT + Web-hooks with Google home, but when i say voice command it turn on the lamp but the status is not reflected on the mobile blynk app, so is there is any way to Request the latest state from the server for the output pin if it is high or low and then reflect it on the app button?
or change the mobile button status with the actual lamp status when using google home with any other method if applicable.

#define BLYNK_PRINT Serial            
#include <ESPmDNS.h> 
#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

BlynkTimer timer;

void checkPhysicalButton();
int relay1State = LOW;
int pushButton1State = HIGH;

#define AUTH "****"   
#define WIFI_SSID "Ayman33"                 
#define WIFI_PASS "braveheart333"                 
#define SERVER "blynk-cloud.com "             
#define PORT 8080

#define RELAY_PIN_1      22   
#define PUSH_BUTTON_1    34   
#define VPIN_BUTTON_1    V12 

#define OTA_HOSTNAME "Maadi Home"

BLYNK_CONNECTED() {

  // Request the latest state from the server
  Blynk.syncVirtual(VPIN_BUTTON_1);
  
  // Alternatively, you could override server state using:
 // Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
}

// When App button is pushed - switch the state

BLYNK_WRITE(VPIN_BUTTON_1) {
  relay1State = param.asInt();
  digitalWrite(RELAY_PIN_1, relay1State);
}

void checkPhysicalButton()
{
  if (digitalRead(PUSH_BUTTON_1) == LOW) {
    // pushButton1State is used to avoid sequential toggles
    if (pushButton1State != LOW) {

      // Toggle Relay state
      relay1State = !relay1State;
      digitalWrite(RELAY_PIN_1, relay1State);

      // Update Button Widget
      Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
    }
    pushButton1State = LOW;
  } else {
    pushButton1State = HIGH;
  }
}

void setup()
{

  Serial.begin(115200);
  Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS,"blynk-cloud.com", 8080);
  ArduinoOTA.setHostname(OTA_HOSTNAME);  
  ArduinoOTA.begin();  

  pinMode(RELAY_PIN_1, OUTPUT);
  pinMode(PUSH_BUTTON_1, INPUT_PULLUP);
  digitalWrite(RELAY_PIN_1, relay1State);

  // Setup a function to be called every 100 ms
  timer.setInterval(500L, checkPhysicalButton);
}

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

There are several ways to approach the issue of using rocker switches rather than pushbutton switches. One way is to use interrupts that are set to CHANGE, the other is to use a variable to hold the last known value of the switch and compare the new result of polling the switch to this to work-out if the switch state has changed.
Of course this assumes that you don’t have any mains wiring connected to your switch.

Yes, this can be done with the Blynk API, but I’m not sure how you plan to use that data.
The Google Home/IFTTT recipe you have at the moment presumably changes the state of VPIN_BUTTON_1 and it’s the BLYNK_WRITE(VPIN_BUTTON_1) function where the problem lies. You need to have something like this in that function:

Using the ESP32 will be fine, provided you choose appropriate GPIOs to connect the switches and relays, but this wiring won’t work on an ESP8266 as you’re using inappropriate pins.

Pete.

Dear PeteKnight
i have really solved all the above issues and installed the system in my home and working properly now thanks to god and thanks to you too, one issue is that i have already 1 sonoff 3 gang touch switch already installed in my house which control some lighting, and i want to control this switch from my blynk app (not from ewelink app) to control all home lights from one place, so i found 2 options:

1- re flash the sonoff switch with firmware or my own software to be able to use with my blynk (which is not recommended to me as i do not want to play with the device original software)

2- create IFTTT applet triger (will be webhook event with URL link) and action (ewelink switch channel “on” status) and another applet with same configuration for “off” status, then here comes the issue, i want to add a button in blynk app (normal button with virtual pin or webpage button or webhook widget do not know) and when i switch this button on mobile blynk app, then it open the webhook URL “on” status (1st applet) so turning on my sonoff light switch, and when i switch this button back again then it opens the other webhook URL “off” status so turning off my sonoff.

so is this possible and if yes which button to choose, and what should i do with the sketch to achieve it, in other words can i make a virtual pin if it is set to HIGH by blynk mobile app then to open a certain URL (1st applet), and if it is set to LOW then open another URL (2nd applet)

I have reflashed the regular sonoff and it is great! My particular one had a esp8266, (Research your device) so I can load anything that works on an 8266. I would encourage you to get familiar with OTA first (if you aren’t) because it is a pain to hook it up to a TTL converter ever time. (I soldered DuPont jumpers into my sonoff)

As far as which GPIO is which there is typically a lot of info in Google. Sonoffs have been popular…

I’ve never used Sonoff devices with the standard ewelink software, do I don’t know what’s possible via IFTTT, but presumably it’s possible to do what you’re suggesting.
If your’e using the Android version of the app then I guess that Eventor actions triggered by buttons in the app are one way to achieve the Blynk side of things, but once again I’ve never used Eventor because it’s not available in iOS (and also because I use Blynk with Node-Red and MQTT so I’d handle this in a much neater way within Node-Red).

If I were in your situation I’d re-flash the light switch with Blynk code.
The code will be simplified version of your existing code, as there are only three switches and relays. Details of which GPIOs the switches and relays use in the Sonoff 3-gang are available on the internet.

One thing I would do first though - I’d change your code so that it normally if there is no internet connection or if the Blynk server is down. This means moving away from Blynk.begin to Blynk.config and Blynk.connect.

I think that this topic has drifted so far off of it’s original purpose that if you have additional questions regarding your projects you should start a new specific topic focused on just one question.

Pete.