ESP is not responding after adding wifimanager

You’re using the same serial port for both debug output and communication with your ESP-01
You can’t do this.

You should use one of the Mega’s other serial ports for connecting your ESP-01

I’d doubt very much if that is the case. Having everything connected into a single centralised board is not normally a good topology.
Also, if you were going to take this approach then an ESP32 or an ESP8266 with a port expander is a much better board to use.

Having said that, I think whole house home automation systems are best based around a Node-Red system using Blynk as a plug-in, but you need to make the right choices for your specific needs.

Pete.

1 Like

you are my hero :smiley: it worked , i flashed the ESP8266 with firmware and connected it again to the arduino mega and changed the serial for the ESP to serial1 and after it is connected to wifi and my relays were working, i plugged off my wifi router and plugged it on again, then the esp is connected automatically.

Last thing, is there is any way to include a hard coding in my sketch to allow the ESP to act as an access point if it is not able to connect the wifi credentials mentioned in the sketch after 3 trials for example, so to allow me to login on the ESP and change it and after i save it rebot automatic (same function of WIFIManager but hard coded)?

and Regarding the nodeMCU, do you think that it is better than the arduino mega which worth having 2 boards nodeMCU connected together (to have more I/O pins) instead of 1 mega for example?

No, the ESP is simply acting as a Wi-Fi modem, not an access point serving-up a web config portal.

No, don’t go down the route of physically connecting two ESPs.
Either use an ESP32 or a port expander on the NodeMCU. The ESP32 is the easier solution.

Pete.

ok thank you bro, since last post it was working good, but now i found the blynk is offline and i had to restart power for my mega board to connect again, now i have same problem as before, i thought it was solved but apparently not yet, do u have any clue why it didn’t connect automatically again? totally depressed for this issue and do not know why it is offline again.

i tried to enhance my sketch as shown below (am afraid that i made the opposite :upside_down_face:), but i sometimes get the below message in serial monitor for example when i change the RGB color from the Blynk app on mobile.

[29394] Buffer overflow

and here is the code

#define BLYNK_PRINT Serial // Enables Serial Monitor

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

char auth[] = "********";
char ssid[] = "Ayman33";
char pass[] = "braveheart333";

#define EspSerial Serial1
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);


BlynkTimer timer;

void myTimerEvent()
{
  Blynk.virtualWrite(V5, millis() / 1000);
}


void setup()
{
  Serial.begin(115200);
  delay(10);
  
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);

}

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

Try reducing this to 9600 and changing your IDE serial monitor to the same.

What version of the Blynk library are you using? This prints in the serial monitor below the large Blynk logo.

Reconnect routines are much harder to implement when using an ESP-01 as s Wi-Fi modem, as you don’t have access to the native Wi-Fi library. Another reason to choose better hardware.
Try searching the forum for reconnect routines for Arduino and ESP-01.

Pete

i tried 9600 but also the same happens
you can find the version of Blynk shown below

i will give this a search on google on the reconnect routines, anyway i went today to the market and i bought ESP32 & ESP8266 (nodemcu)
i need to finalize the mega issue first to keep it at current home for the moment for test, then i will start to check the new pieces.

[610] Connecting to Ayman33
[3658] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK

That’s not the Blynk version, it’s the firmware version for the ESP-01.

The Blynk version is show at the bottom of the logo like this:

    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ vx.x.x on [Board Type]

Pete.

ah sorry for that
here you are V0.6.1

Blynk version

1 Like

thank you PeteKnight for your help above, i just want to know how i can control RGB led with the zeRGBa button in Blynk app as i find only virtual pins when i choose ESP32 device in the app (not the same like arduino mega where i was able to choose directly the GPIO number or digital I/O), so i think i need to add it in the sketch but i have no idea how to do it, can u help me with a sketch suggestion for such issue.

Yes, when the value of a virtual pin changes it triggers the BLYNK_WRITE(vPin) function.
You then use the param.asInt() or param.asFloat() function to extract the value or array of values from the widget.
You can then write these values directly or transform them as you wish, to GPIOs using digital.Write or analog.Write commands.
Don’t forget to include pinMode declarations for these GPIOs in your void setup.

Blynk.syncVirtual(vPin) can be used to force the server to send the latest virtual pin values, and these can be triggered each time the device connects or reconnects to the server using the BLYNK_CONNECTED() function.

This sounds complicated, but believe me, you wouldn’t get such good results using digital pin manipulation.

There are many examples of how to achieve what you’re looking for in the forum. Just take care not to exceed the rated current values of your board when driving RGB LEDs.

Pete.

Regarding the rated current, am only using 1 rgb led then after i setup everything properly i will install transistors and relays to connect external 12v strip light, so for the wiring it is ok for me as i am mainly electrical engineer, but the only problem is that am not so good in writing codes in blynk with c++
So can you help me by providing this sketch for me or tell me what exactly i should search for in the forums here to achieve that as am trying since yesterday to search for it but with no good results

I’m not going to write your code for you.
If you search for zeRGBa and RGB LEDs then you’ll find lots to be getting on with.
You are okay using a single RGB LED directly, but you should use MOSFETs to if you plan to use RGB strips.
I like the IRLB8721 as it has a suitable gate thresh voltage.

If you use code that is written for the Arduino then beware that the Arduino’s PWM output is only capable of 255 levels, whereas the ESP devices can output 1023 levels. This means that if you do an analogWrite of 255 on an ESP then you’ll only be getting 1/4 brightness so adjust the code to use 1023 as the maximum.

This is the design I was using in the past:

Although I now use these:

Pete.

First am very sorry for annoying you everytime with my noob messages,
Second very big thank you for your real support
Third i finally succeeded after some searches to make it work fine with zeRGBa
here the code worked for me
if you see something can be improved please let me know if possible
i was wondering if i can put 1 button to make the RGB totally on or off, then if it is on, so i can control the colors through zeRGBa, i will search for this i think it is possible and i will try it.

regarding the IRLB8721 if i understand correctly, i will use three MOSFETs and connect their 3 gates with three PWM GPIO of the ESP32 for the control of 12V RGB Strip light (and accordingly drains connected to the led and source connected to negative of the 12V supply), the wiring is ok like this i think

i really appreciate so much your help, do not know what i would do without your help.

#define BLYNK_PRINT Serial
//#define BLYNK_PRINT Serial // This prints to Serial Monitor

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <ESPmDNS.h>  // For OTA - ESP32
#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA

#include "esp32-hal-ledc.h" // For Servo & RGB PWM control


char auth[] = "*******";
char ssid[] = "Ayman33";
char pass[] = "braveheart333";
char server[] = "blynk-cloud.com";  // URL for Blynk Cloud Server
int port = 8080;

int rrr, ggg, bbb;  // Set RED BLUE GREEN channe

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
   //Serial.begin(115200);  // BLYNK_PRINT data

   //===== RGB LED pin setup for ESP32 =====
  ledcSetup(2, 5000, 8); // For RGB-Red - channel 2, 5000 Hz, 8-bit width
  ledcAttachPin(25, 2);   // For RGB-Red - GPIO 25 assigned to channel 2

  ledcSetup(3, 5000, 8); // For RGB-Green - channel 3, 5000 Hz, 8-bit width
  ledcAttachPin(27, 3);   // For RGB-Green - GPIO 27 assigned to channel 3

  ledcSetup(4, 5000, 8); // For RGB-Blue - channel 4, 5000 Hz, 8-bit width
  ledcAttachPin(26, 4);   // For RGB-Blue - GPIO 26 assigned to channel 4

  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);
  Blynk.connect();

  ArduinoOTA.setHostname("ESP32 Servo RGB");  // For OTA - Use your own device identifying name
  ArduinoOTA.begin();  // For OTA
}

//===== zeRGBa Widget =====
BLYNK_WRITE(V4) { // START Blynk Function
  rrr = param[0].asInt(); // get a RED channel value
  ggg = param[1].asInt(); // get a GREEN channel value
  bbb = param[2].asInt(); // get a BLUE channel value
  RGBprocess(); // Run Arduino funtion
}  // END Blynk Function

//===== Physical RGB LED Control and HEX conversion =====
void RGBprocess() {  // START Arduino funtion

  // For Common Anode+ RGB LED
  //ledcWrite(2, 256 - rrr); // Write to RED RGB pin
 // ledcWrite(3, 256 - ggg); // Write to GREEN RGB pin
  //ledcWrite(4, 256 - bbb); // Write to BLUE RGB pin

  // For Common Cathode- RGB LED
  ledcWrite(2, rrr); // Write to RED RGB pin
  ledcWrite(3, ggg); // Write to GREEN RGB pin
  ledcWrite(4, bbb); // Write to BLUE RGB pin

  // zeRGBa pin to #HEX conversion
  String strRED = String(rrr, HEX);  // Convert RED DEC to HEX
  if (rrr < 16) {
    strRED = String("0" + strRED);  // Buffer with 0 if required
  }  // END if
  String strGRN = String(ggg, HEX);  // Convert GREEN DEC to HEX
  if (ggg < 16)  {
    strGRN = String("0" + strGRN);  // Buffer with 0 if required
  }  // END if
  String strBLU = String(bbb, HEX);  // Convert BLUE DEC to HEX
  if (bbb < 16)  {
    strBLU = String("0" + strBLU);  // Buffer with 0 if required
  }  // END if
  String HEXstring = String("#" + strRED + strGRN + strBLU);  // Combine HEX fragments
  HEXstring.toUpperCase();  // Change HEX value to all upper case for ease of visuals.
  Blynk.setProperty(V3, "color", HEXstring);  // Change background colour of HEX Data Label
  Blynk.virtualWrite(V3, HEXstring);  // Display HEX data
}  // END Arduino Function

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

I’m not familiar with the ledcSetup or ledcAttachPin commands, so I can’t really comment on this, but if it works for you then stick with it.

Add a button widget in Switch mode and attach it to a virtual pin (lets say pin V1). This code will be triggered when the switch is operated and will either use the zeRGBa RGB values if the switch is On, or set RGB to 0 if its off…

BLYNK_WRITE(V1)
{
  int switch_value = param.asInt();

  if (switch_value)
  {
    Blynk.syncVirtual(V4); // Get the current RGB values from the zeRGBa widget
  }
  else
  {  
    rrr = 0;
    ggg = 0;
    bbb = 0;
    RGBprocess(); // process the RGB change    
  }
}

The circuit is explained in the Adafruit tutorial, which is a link from one of the topics I linked to earlier.

Pete.

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.