Control Relay with no WiFi

Hi there
I am new in the Blynk community and i am using ESP01 with relay module.
My project is to swith off the router at 02:00 and switch on at 02:30.
Switching off is easy using blynk timer, my problem is how can i switch on the relay,
since the router is off and there is internet connection.
Thank you

If your project uses Blynk.begin then swap to setting-up your WiFi connection yourself and swapping to Blynk.config and Blynk.connect.

Then, set a timeout timer that is triggered by your ‘off’ command which runs for 30 minutes and turns your relay back on again when the timer expires.

Pete.

Thank you Pete for your quick response.
As i am newbie i would like a little more explanation. Here is my code:
Edit:This is the modified code which does what i want.


//Blynk Home Automation


#define BLYNK_PRINT Serial            
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>  // For OTA with ESP8266
#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA


BlynkTimer timer;
unsigned long Timeoff = (1000*60*60*3); // ms*60=min*60=hour *3= 3 Hours


int relay1State = LOW;



#define auth "xxxxxxxxxxxxxxxxxxxx"  // You should get Auth Token in the Blynk App.  
#define ssid "xxxxxxx"                   //Enter Wifi Name
#define pass "xxxxxxxx"                   //Enter wifi Password

//Static IP address configuration
IPAddress local_IP(192, 168, 0, xxx); ///
// Set your Gateway IP address
IPAddress gateway(192, 168, 0, xxx);

IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);   //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

// #define SERVER "blynk-cloud.com "             // Comment-out if use Blynk hosted cloud service
// #define PORT 8442

#define RELAY_PIN_1      0   //gpio0



#define VPIN_BUTTON_1    V12 

#define OTA_HOSTNAME "Home_Automation"


BLYNK_CONNECTED() {

  // Request the latest state from the server

  //  Blynk.syncVirtual(VPIN_BUTTON_1);


  // Alternatively, you could override server state using:
  Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);

}

// When App button is pushed - switch the state

BLYNK_WRITE(VPIN_BUTTON_1) {
  relay1State = param.asInt();
  digitalWrite(RELAY_PIN_1, relay1State);
}

void RelayOff()
{
relay1State = LOW;
digitalWrite(RELAY_PIN_1, relay1State);
}


void setup()
{

  Serial.begin(115200);
  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
  }

  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

 Blynk.config(auth,"blynk-cloud.com", 8442);
  while (Blynk.connect(1000) == false) { 
  }  
 // Blynk.begin(auth, ssid, pass,"blynk-cloud.com", 8442);
  ArduinoOTA.setHostname(OTA_HOSTNAME);  // For OTA - Use your own device identifying name
  ArduinoOTA.begin();  // For OTA

  pinMode(RELAY_PIN_1, OUTPUT);
  digitalWrite(RELAY_PIN_1, relay1State);



  // Setup a function to be called every 100 ms

}

void loop()
{
  if (relay1State = HIGH) {
    timer.setTimeout(Timeoff, RelayOff);
  }
  Blynk.run();
  ArduinoOTA.handle();  // For OTA
  timer.run();
}

I have a simple idea i.e. use BLE or Bluetooth for this project. HTH :slight_smile: Also, If you need more help than you can simply reply to this :smiley:

Thank you for your response. It is now OK.

Welcome, if you ever need help on this, let us know :slight_smile:

Hi there
I am facing a problem with the timer.setTimeout function in my code.
The router is at NC of the relay connected.
At 02:30 every day and for 3 hours i switch off the relay and having so my router closed.
In my code i have defined “unsigned long Timeoff = (1000 * 60 * 60 * 3);” = 10.800.000 ms which is 3 hours or 180 min.
After that period the relay should switch on and the router will start again.
But i get 2 hours and 40 min and not 3 hours.
10.800.000 gives me 160 min
10.800.000L gives me 170 min.
I am confused.
Thank you