BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Nodemcu relay and blynk problem


#1

Hello… i tried to make a simple control relay, with nodemcu v3 and relay 4 channel module. first i made a button in blynk and added widget to my front screen and activate my mobile hotspot( its my device where blynk instaled too) , nodemcu with sketch “esp8266_standalone” is connected to blynk, but the problem is when i turn on relay, relay be on. but once I turn off my hotspot, after a few seconds the relay back off. why?? how i can turn relay on, until button switch again?? is my nodemcu must be always connected on hotspot?? thanks before…


#2

Because it is no longer getting the ON signal??? Hard to say without more details…

Are you using direct pin control in the App or virtual pins and code on the device… if code, can you post it here… properly formatted as required in the Welcome Topic and the instructions you deleted to post this :wink:


#3

It should stay in last condition no matter if it’s connected to wifi or not.


#4

Depends on how the device, code, power, etc. is setup… we just don’t have any hard data to work with.


#5

i use this code :

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

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

  Blynk.begin(auth, ssid, pass);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}

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

relay i used is 4 channel active high… with power 5v 2a…


#6

please whats wrong on my code?


#7

yes… i think so… its must be on last state condition… but its going off again if disconnect with hotspot… please correct my code. :thinking:


#8

Please stop with the begging for a code fix!!.. that is not what we do here. We try to assist you with learning how Blynk works.

Since you are using only the App’s direct pin control and the basic connection method Blynk.begin() (blocking if no connection), then once the device looses connection it will just stop running and that is possibly resetting the device or just the pin settings back to default? This is a guess as I never use that direct pin control method.

I recommend you try using virtual pins, Blynk.config() (non-blocking if no connection) and coding connection management that will allow your device to keep running when it looses server or internet connection. Search this forum for key words/phrases like “run device without internet”, etc.

http://docs.blynk.cc/#blynk-firmware-configuration-blynkconfig

http://docs.blynk.cc/#blynk-firmware-connection-management


#9

There’s nothing wrong with your code, because it’s not relay control related at all, it’s just a Blynk ESP standalone shell. Use virtual pins and set relay initial states and app sync in your code.

But still, relay should remain in last state condition even when disconnected from the router, no matter if direct GPIO addressing or virtual pins are used. This should be not affected by the code.


#10

@zodiac with the latest Blynk library update direct GPIO access will boot the ESP8266 to it’s default state of LOW, which can be either ON / OFF for the relay depending if it’s active HIGH / LOW.

Virtual pins should be used if a boot state of LOW is not acceptable.


#11

I forgot about library changes, sorry, I’m still using good old 0.4.10. So virtual pins are only way to go now.