Re connection after wifi internet loss

I have been successfully using 3 separate ESP8266’s within the same ‘device’ and template. I decided against using Edgent because OTA probably cannot be used for updating more than one ESP. I’m guessing that it will mess with at least 2 of the 3 ESP nodes and may not work at all. Each ESP node has its own virtual pins allocated to avoid conflicts on the server side. Consequently the firmware is is slightly different for each node.

My solution has been to use the same Static Authority Token’s for each ESP node. It has been working very well, no connection issues what so ever.

Incidentally I have found that this method calls the old server in settings.h so initial connection attempts fail, but its easy to change the relevant line of code.

Cheers
GD

Can you post your example?

GDay, for myself I am looking to end up with 6 or more devices running the same code in 2 remote locations so that as I refine what I want to do I can easily update all devices at once.

This does create challenges if you want something different in each device but you can work around that with either the web dashboard or the app with input widgets specific to each device.

eg. I can have different images for each device by choosing which image displays in the image widget with a slider on the web dashboard and the use of an automation.

Sorry for the late reply, I didn’t see the reply until now.

This code is for controlling of room lighting that has a momentary switch for manual on/off. I have a number of different light controls around the house using separate MCU’s, so I just assign virtual pins within the same template so that I can access them on the same ‘page’. I recall that there are 128 virtual pins available for each template, so plenty of scope to expand. I use ‘automations’ for switch timing. It all works seamlessly even after power interrupts.

FYI This code is written / compiled in PlatformIO, if your using the Arduino IDE, you don’t need the Arduino include as its a given. You may also need to move the checkPhysicalButton() function after the void loop.

Don’t forget to modify settings.h so that it uses the correct server. You will get a login failure if you dont.

I just use different virtual pins for each MCU instance. It can of course be expanded for many different uses.

Hope it helps.

#include <Arduino.h>

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID           "TMPLixxxxxxx"
#define BLYNK_DEVICE_NAME           "HouseholdControl"

// WiFi credentials, get Auth Token from the blynk.cloud device information
char ssid[] = "XXXXXXXXXX";
char pass[] = "XXXXXXXXXX";
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx";

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial

#define APP_DEBUG

BlynkTimer myTimer;

int RelayState = LOW;
const int relayPin = D1; // on board relay pin assignment
const int btnPin = D5;  // on board button pin assignment

BLYNK_CONNECTED() {
  Blynk.syncVirtual(V3);
}

BLYNK_WRITE(V3) {
  RelayState = param.asInt();
  digitalWrite(relayPin, RelayState);
  Serial.print("Relay state is: ");
  Serial.println(RelayState);
}

void checkPhysicalButton() {

if ((digitalRead(btnPin) == LOW) && (digitalRead(relayPin) == LOW)){
      RelayState = HIGH; 
      digitalWrite(relayPin, RelayState); // set LED ON 
      Blynk.virtualWrite(V3, 1);   //Turn ON Button Widget
      
      while (digitalRead(btnPin) == LOW) {} // You have to take finger off the button to continue.
      Serial.print("Relay state is: ");
      Serial.println(RelayState);
      }

    else if ((digitalRead(btnPin) == LOW) && (digitalRead(relayPin) == HIGH)) {
        RelayState = LOW;  
        digitalWrite(relayPin, RelayState); // set LED OFF
        Blynk.virtualWrite(V3, 0);   //Turn OFF Button Widget

        while (digitalRead(btnPin) == LOW) { } // You have to take finger off the button to continue.
        Serial.print("Relay state is: ");
        Serial.println(RelayState);
        }
}


void setup()
{
  Serial.begin(9600);
  delay(100);

  Blynk.begin(auth, ssid, pass);
  WiFi.setOutputPower(20.5); // Set the wifi power.  0 -> 20.5 max. 
  
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, RelayState);
  pinMode(btnPin, INPUT);

  myTimer.setInterval(200L, checkPhysicalButton);

}

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