Blynk sync node mcu

Hello !

I am running a nodemcu with 2 relay with 2 push button to turn them on and off and also via phone (Blynk app). This is works fine . And am running a local server (for ref.) . Once the nodemcu reboots due to power failure, it turns back all the relay untill the Blynk.virtual sync All gets in contact with the local server to get the previous state. Because this takes almost a min or so for the loacl sever and the wifi router to come to life. So till then all the relays will be in on condition. And later sets itself to normal state.

So my doubt is can we for example say the nodemcu to stay off until it syncs with the server and only then turn on or off the relay according to the previous state, Instead of turning all the relays and then turning back off. Because this causes unwanted appliances to turn even though it was not on before power failure.

So is there any way to get over with this ?

Your best/easiest bet is some form of battery backup on your node/router/network… otherwise, I for one do not see any easy way to NOT turn on the NodeMCU until it detects all conditions are perfect… Although, perhaps yet another MCU monitoring network conditions and activating the primary when all is good.

2 Likes

you are right, I use a 2nd nodmcu to survey the 1st.
and the first survey the 2sd :fast_forward::rewind:
:fearful:

1 Like

Put a PinMode and DigitalWrite statement for each of your relay pins at the start of your void setup.

Edited to correct a typo, I’d previously said void loop rather than void setup.

Pete.

2 Likes

Yeah ! Battery does work. But again a separate circuit for battery management system is not good. it becomes bulkier, And there is no much room to stuff all these into a tight space such as wall board.

NO much room to add in a second nodemcu. :thinking::expressionless:

This may work. But i feel this will stop the nodemcu from booting up normally. Because the pin needs to pulled up high and low for few pins. By defining pinmode and digital write it may prevent the nodemcu to boot up.

Can you please provide a link that may help me in trying this idea ?
Or a ex. line of code that i can insert in and check. Because doing wrong may not solve the problem even thought the given solution is right ! i will definitely try myself and let you know if that works.

Thank you.

Not true… because the Node MCU will have already booted before getting to these commands. Besides, you shouldn’t be using special pins anyhow, else the sensors/controllers hooked up to them could influence the boot.

Back to the pinMode() commands, these commands would run after boot, but before the network setup… so you could preset the safest defaults until such time the connection is made and the last Blynk settings synced.

Just pick up an ESP8266 (or ESP32) with built in 18650 module… it will contain all the necessary battery management in as small a package as you are likely to get.

It won’t stop your device from booting. It’s the accepted way to handle this problem, and works perfectly.

This code snippet assumes two things:

  1. you’ve defined variables called RELAY1 and RELAY2 and assigned the appropriate NodeMCU pins to these variables
  2. pulling your relays LOW will turn them off. If not, then you need to change the code to HIGH instead.
void setup()
{
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT); 

  digitalWrite(RELAY1, LOW);                // Turn Relay 1 off  
  digitalWrite(RELAY2, LOW);                // Turn Relay 2 off  

Pete.

Actually am not using any special pins as of now . I know this can prevent booting of the nodemcu.

Pinmode should now included in the void loop or before it ? Cuz once its in loop it may interfere with blynk.run !!?? Not sure just a doubt.

Each pinout needs to given a pinmode low as of now right ?

Basic Arduino Code Research 101

My mistake, I should have said to put it in the void setup, not loop. I’ve edited my post to correct this, so as not to confuse anyone else who reads this.

My code example is corrrect.

Pete.

1 Like

Ho thanks for providing me the link. Google has a grudge on me i guess. thus not providing these links… Bad joke …

Right now the pinmode is set as output and the digitalwrite is all set to low. As per your idea i need to set these High. Or another function for this ?

Video_00412

Read my post, I explained that.

Pete.

vovovov whats that ? seems like some sci-fi fiction matrix system:sunglasses::astonished::astonished:

2 nodemecu control each other
:blush:

1 Like

I just ran across this issue with a garage door opener project. The problem was that the power would fail, the relay drive pin would startup as high and the garage door would open when the power would return. This would happen prior to my notification text being sent so I could end up with an open door and not know it! That would have been bad.
The fix I discovered was that not all the pins on the nodemcu come on as high, some com on as low!
You have to test your pinouts to see which boot up hot (prior to the bootloader even getting to the code!) and which boot up low. I simply switched my output relay driver pin from D5 to D6 and the problem was solved. Not all boards are the same, so you have to test the pins at startup.
Hope this helps,
Scott

1 Like