I’d suggest you take a few steps back and get to know Arduino, Nodemcu and digital pin and relay behaviour first - then add Blynk/wifi on top of that.
Different pins have different behaviour on startup, some are pulled HIGH, some LOW, some momentary, some indeterminant etc . . . you need to research you board and see what is happening with the pins you are using in your sketch. Then you have a number of choice:
Modify your sketch to accommodate the startup state for each pin;
Select different pins that fit your need better, or
Set the state of the pins (digitalWrite) on startup - this may work but you may still see erratic behaviour temporarily during startup.
You need to understand your hardware and adjust your sketch accordingly.
Thanks Bill, but your reply adds nothing to my question.
All what I need is to make my nodemcu remember the last state of the relay after power loss and that is why we have this community to share help. Some god guys may help in here
Bill is absolutely right.
What you are trying to do has a lot of hidden problems behind it.
It would be nice if you start to throw some light on the basics.
Here we only help to identify the issue and point out what you are missing on, but we do not write the code/sketch here. We are all volunteers here, no one is paying us(just for your info). ONLY BLYNK RELATED
There are not some, there are many big brains in this community, but without you knowing the basics, its very hard for us to point you out on the right direction.
Now you post your sketch here (properly formatted with ``` triple backticks or tilde).
I will try to help you out .
But learning by yourself will help you out in a long run.
You have to memorize the state of the relays in a blynk virtual pin or store the state in the nodemcu memory.
Don’t forget that at start, relay will take the state of nodemcu pin till the code begin and restore the last value of the state.
This might help you choose better pins to use on your NodeMCU:
And reading-up about the Blynk.sync commands that were mentioned in the 2nd post will allow you to synchronize your relays with the state that is held on the server (if that’s actually what you want to do - it can be a dangerous or inappropriate choice).
A word of advice @1zaq1.
This is a community of users who willingly share their time and knowledge to help each other with (mostly) Blynk related stuff. @Bill_Donnelly is an extremely knowledgeable and well respected member of this community who has excellent coding skills and a wealth of experience of Blynk. As a result, this comment by you is totally inappropriate…
Bill’s advice to you was excellent, and I’m certain that all of the regulars who have contributed to this topic agree with him.
I’d suggest that you apologise to Bill for your comments, and learn a little humility. When you ask experts for advice and they give it freely then you’d do well to heed that advice and thank them for their time and patience rather than taking the approach that you did.
We expect forum members to behave in a friendly manner towards each other and those that don’t will have their use accounts suspended - either temporarily or permanently. Take this as your one and only reminder that inappropriate and unfriendly behaviour won’t be tolerated here.
From the above replies I got, I come to the conclusion that you may know the hardware basics, and you know how to connect hardware, but I see you find it difficult to connect to people. Relax and if you do not like to provide help, no offense please
Take it as a challenge and start learning… when i came here for the first time even i was treated the same way… i too felt too bad. But today this has made me learn hell lot of things.
If they had just gave me what i asked for, then i would have not been in a position to help you today. This is why there are so any volunteers(enhanced knowledge here) in this community able to help others.
I learnt many things from this community, now i am trying to serve a back a bit…
@Bill_Donnelly unfortunately you won’t be getting an apology from @1zaq1 for the while, as I’ve silenced him for the rest of the week due to the tone of his comments.
Maybe @1zaq1 hasn’t searched this forum for code you have posted or maybe he has a PhD in psychology and figured he could goad you into writing his code
The BLINK server may crash (very rarely, of course :)). If they lose information. During synchronization, what will come to the relay from the server is “0” or “1”.