ESP8266 and Blynk connected

Hello blynkers

I have this code… and i want to close all relays when the internet is offline (with send to the server true and false) if the esp take false to close all relays… I have try to do this ( check code) with LOW and HIGH but when I close the wifi the esp do not close the relays… Do you have to suggest changes to work this project? If you want an other similar project with this commands post it :slight_smile: thanks you

/* ESP & Blynk */
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
char auth[] = "*******************";

/* WiFi credentials */
char ssid[] = "******";
char pass[] = "*****";

/* TIMER */
#include <SimpleTimer.h>
SimpleTimer timer;

/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h> 
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

//BlynkTimer timer;

float temp_0;
float temp_1;
float temp_2;
boolean connected_blynk;        //an exei epikoinonia me ton server



BLYNK_CONNECTED()  //sygxronizei to esp otan bgei apo to reuma stis leitoyrgies poy eixe stamatisi
{
 Blynk.syncAll();
}


void setup() 
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  DS18B20.begin();
  timer.setInterval(2000L,getSendData);
  timer.setInterval(10000L,check_online);
 
  Serial.println(" ");
  Serial.println("Testing Dual Sensor data");
}


void loop() 
{
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
}

/***************************************************
 * Send Sensor data to Blynk
 **************************************************/
void getSendData()
{
  DS18B20.requestTemperatures(); 
  temp_0 = DS18B20.getTempCByIndex(0); // Sensor 1 will capture Temp in Celcius
  temp_1 = DS18B20.getTempCByIndex(1); // Sensor 2 will capture Temp in Celcius
  temp_2 = DS18B20.getTempCByIndex(2); // Sensor 3 will capture Temp in Celcius
  
  Blynk.virtualWrite(1, temp_0); //virtual pin V1
  Blynk.virtualWrite(2, temp_1); //virtual pin V2
  Blynk.virtualWrite(3, temp_2); //virtual pin V3

  Serial.print("temp_0= ");
  Serial.println(temp_0);
  Serial.print("temp_1= ");
  Serial.println(temp_1);
  Serial.print("temp_2= ");
  Serial.println(temp_2);
}

void check_online()
{
  connected_blynk = Blynk.connected();
  if (connected_blynk==false)
  {
    digitalWrite(0,LOW);
    digitalWrite(1,LOW);
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
  }
}

I’d say that the first thing to do is to stop using the blocking Blynk.begin command, then move to managing your own WiFi connection (in a non-blocking way) then use Blynk.config and Blynk.connect.

Pete.

ohh sorry but i dont understood very well what changes should i make… if i don keep the

how the esp will going conect with ssid, pass and auth? … Could you please post here this change so that i add it this in my code? thanks you, i am very new in this world sorry

You manage the WiFi connection, which uses the SSID and WiFi password.
The auth token is defined in Blynk.config.

No, I’m not going to write your code for you.

Pete.

very good :slight_smile: