Not found in the documentation, maybe it's time to add it?

@vshymanskyy please advise.

It is clear that the BLYNK library is primarily designed to work with the cloud and without a connection in some cases should not do anything on the device, nevertheless, it is a very big surprise to me that all the code is blocked without wifiā€¦ for me and for many, as I have read on the forums, a very acute question. I donā€™t want to use third-party code to get around this problem

In the first project, I used the previous version of BLINK as a gateway and all other devices received commands over the wires. It was a complex, expensive and inconvenient architecture to set up. She demanded a device in each room that would send commands over the wires. In a new project, I use BLINK 2.0 and wanting to simplify the architecture, I removed the gateway and made my own WiFi module based on ESP8266 in each device. How wrong I wasā€¦

Have you tried managing your own WiFi connection then using Blynk.config and Blynk.connect rather than the blocking Blynk.begin command?

Pete.

not yet. Iā€™m not a programmer, itā€™s hard for me to understand someone elseā€™s codeā€¦ if there is a simple solution it would save me. I use BlynkEdgent

Yury

You would like to use the nodemcu offline am I right ?

What is the basic functionality of your device ? Controlling appliances, monitoring temp, erc etc !?

If yes !! Why dont you put your code inside an ISR ? This will keep running despite the wifi being connected or disconnected.

Try this.

Thatā€™s right, itā€™s a classic. If WI-Fi is available, I use the application, if not, a physical button.

I have a critical situation, so Iā€™m ready to put the code anywhere, as long as it works!!! :slight_smile:
Just show me in more detail how to do it, please

I would suggest you to post your code. So that we can have a look and see what needs to done !!

Are you suggesting I handle the buttons in the interrupt? Wonā€™t that make the BLINK code unstable?

Exactly.

Depends on how you code. But we have many examples on this forum. Search ISR switch. And you will get plenty of examples.

#define BLYNK_NO_BUILTIN   // Disable built-in analog & digital pin operations
#define BLYNK_NO_FLOAT     // Disable float operations
#define BLYNK_TEMPLATE_ID             "***"
#define BLYNK_DEVICE_NAME             "RELABOX"
#define BLYNK_FIRMWARE_VERSION        "0.1.283"
#define BLYNK_PRINT Serial
#define LED_CONN 0
#define INT_PIN 13      // microcontroller pin attached to INTA/B

#include "BlynkEdgent.h"
#include "Adafruit_MCP23017.h"
#include <Wire.h>


Adafruit_MCP23017 mcpOut;
Adafruit_MCP23017 mcpInp;

int relayPins[8][2] = {{0,1},{2,3},{4,5},{6,7},{8,9},{10,11},{12,13},{14,15}};
bool inpLastState[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
bool relayToggled[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
bool btn; 

BLYNK_CONNECTED() {
  Blynk.syncAll();
  Blynk.syncVirtual(V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13);
}

BLYNK_WRITE(V0)
{
  relayChangeState(0, (bool)param.asInt());
}

BLYNK_WRITE(V1)
{
  relayChangeState(1, (bool)param.asInt());
}

BLYNK_WRITE(V2)
{
  relayChangeState(2, (bool)param.asInt());
}

BLYNK_WRITE(V3)
{
  relayChangeState(3, (bool)param.asInt());
}

BLYNK_WRITE(V4)
{
  relayChangeState(4, (bool)param.asInt());
}

BLYNK_WRITE(V5)
{
  relayChangeState(5, (bool)param.asInt());
}

BLYNK_WRITE(V6)
{
  relayChangeState(6, (bool)param.asInt());
}

BLYNK_WRITE(V7)
{
  relayChangeState(7, (bool)param.asInt());
}



void cloudState()
{
  
  if(Blynk.connected())
    digitalWrite(LED_CONN,1);  
  else
    digitalWrite(LED_CONN,!digitalRead(LED_CONN));  

}



void setup()
{
  Serial.begin(115200);
  delay(100);
  BlynkEdgent.begin();
  Wire.begin(14, 12);
  
  mcpOut.begin();      // use default address 0
  mcpInp.begin(1);      // use default address 0
  
  for(int i =0; i <16; i++){
    mcpOut.pinMode(i, OUTPUT);
    mcpOut.digitalWrite(i,0);
    mcpInp.pinMode(i, INPUT);
    mcpInp.pullUp(i, HIGH);     // turn on a 100K pullup internally

  }
  
  pinMode(LED_CONN,OUTPUT);
  pinMode(INT_PIN,INPUT);
  
  digitalWrite(LED_CONN,0);
  timer.setInterval(300L, cloudState);


}





void relayChangeState(int i, bool _state)
{
  mcpOut.digitalWrite(relayPins[i][_state],1); 
  delay(40);
  mcpOut.digitalWrite(relayPins[i][_state],0); 

  if(_state)
    inpLastState[i] = 1;
  else
    inpLastState[i] = 0;
}



void buttonPressed(){
  for(int i = 0; i<16;i++){
    btn = !mcpInp.digitalRead(i);
    if(btn && !relayToggled[i]){
      relayToggled[i] = true;
      toggleState(i);
    }else if(!btn)
    relayToggled[i] = false;
  }
}

void toggleState(int i)
{
  
  if(inpLastState[i] == 1){
    if(Blynk.connected()){
      Blynk.virtualWrite(i, 0); 
      Blynk.syncVirtual(i);
    }else
      relayChangeState(i,0);
    inpLastState[i] = 0;
  }else
  {
    if(Blynk.connected()){
      Blynk.virtualWrite(i, 1); 
      Blynk.syncVirtual(i);
    }else
      relayChangeState(i,1);
    inpLastState[i] = 1;  
  }  
}

void loop() {
  
  BlynkEdgent.run();
  timer.run(); 
 
  buttonPressed();
    
}

Check this out :

Use this library from @khoihā€¦.

Place the code that is responsible for controlling the relay inside ISR. This should work.

Thank you, I understand the meaning, but it doesnā€™t suit me because after the Internet appears, you have to manually press reset.

1 Like

Thank you, I will try

Thatā€™s not right, it will reconnect automatically.

I added the code as a Technical Research cell on the YouTube channel, but my code does not work, there are errors - there is no such function. In general, itā€™s likeā€¦ I just wouldnā€™t want to go down this path because when you have a lot of devices, itā€™s better to go the way that the developers have provided in their code. in

In file included from C:\Users\Jury\Documents\Arduino\MySensors\ESP8266\RELABOX\Relabox\Relabox.ino:28:0:
C:\Users\Jury\Documents\Arduino\MySensors\ESP8266\RELABOX\Relabox\BlynkEdgent.h: In function 'void app_loop()':
BlynkEdgent.h:114:20: error: 'manual_control' was not declared in this scope
     manual_control();
                    ^
exit status 1
'manual_control' was not declared in this scope

Part of code


Edgent BlynkEdgent;
BlynkTimer timer;

void app_loop() {
    timer.run();
    manual_control();
}


void manual_control()
{
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));  
}