Relays on after reboot

Hello, I connected Blynk app on iphone to Nodemcu v0.9 on wifi to run 4 channel relay. Works fine, but when my nodemcu reboots, relay associated with Blynk buttons turn on automatically regardless of button status . It seems the board does not remember previous status of buttons. Help please.

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll(); // use this to sync all the pins [not recommended]
    Blynk.syncVirtual(V1, V2, V3, V4); // sync only the virtural pins used in you Blynk app to sync the last state stored in the Blynk server.
    isFirstConnect = false;
  }
  Serial.println("Connected");
  ReCnctCount = 0;
}

BLYNK_CONNECTED This function does what you are looking for. Please go through the docs to know more.

Thanks, but what shall I do with this, shall I creat a new sketch in Arduino IDE an dupload it, sorry Im just a biginner in this IOT.

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:

  1. Modify your sketch to accommodate the startup state for each pin;
  2. Select different pins that fit your need better, or
  3. 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.

cul
billd

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

Oā€¦Kā€¦ your comment shows that you have very, very little understanding of Arduino or the hardware . . .

It appears that you are basically asking for someone else to write a sketch for you? It wonā€™t be me.

Good luck.

billd

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.

1 Like

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.

2 Likes

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).

Pete.

2 Likes

It appears that you are basically asking for someone else to write a sketch for you? It wonā€™t be me.

I believe you canā€™t @Bill_Donnelly

Thanks @Blynk_Coeur

1 Like

This doe not really helps @PeteKnight

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.

Pete.

2 Likes

Sorry to sayā€¦ This is so RUDE.
Requesting some time helps. But being rude never helps. Everyone will step back.

I had told you to post your sketch, so that i can help you out, but you are asking for out of the box solution.

I feel no one will spoon feed you here.

1 Like

You feel it is rude to tell someone he does not know how to code, I have been told like this in the first post @Madhukesh, how it feels like

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

That user may be a beginner, doe not know how to code or whatever, you should not have used the word ā€˜rudeā€™ @Madhukesh

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ā€¦

The way you spoke you @Bill_Donnelly is totally wrongā€¦

@PeteKnight it is left to you. See how you can go through thisā€¦

1 Like

@Madhukesh you used the word ā€˜rudeā€™ for the second time. I hope other users got a better experience in this community

@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.

Pete.

4 Likes