First off this project was created using other peoples ideas, assistance and code:
What this project does is allows one to use Blynk to remote control wireless plugs & allow a single plug to turn on if off by checking to see if it’s connected to the blynk server. I am using this to reboot my router.
How to pair the plugs - get the plug light flashing ready for pairing and just toggle the button in blynk you want to assign the plug.
This is a modification of the project done by bitluni 2016 - http://youtube.com/bitlunislab
Project YouTube Video - https://www.youtube.com/watch?v=O_cgfj6SiTY
this allows 433.92MHZ RF plugs to be oporated by Blynk and ESP8266
biluni decoded the ON / OFF bytes and without his help this would not have been possible
Thank you to Costas for the Checkserver Blynk Code [SOLVED] How to run Blynk.run() only when WiFi connection is established - #4 by FebryKN
Please if you use this code and or project include the above people as mentioned without their support and knowledge this would not be possible
Materials:
Mains Plugs:
ESP8266:
RF-wireless-transmitter-module:
This is the code I used:
/*
This is a modification of the project done by bitluni 2016 - http://youtube.com/bitlunislab
Project YouTube Video - https://www.youtube.com/watch?v=O_cgfj6SiTY
this allows 433.92MHZ RF plugs to be oporated by Blynk and ESP8266
biluni decoded the ON / OFF bytes and without his help this would not have been possible
Thank you to Costas for the Checkserver Blynk Code [SOLVED] How to run Blynk.run() only when WiFi connection is established - #4 by FebryKN
Please if you use this code and or project include the above people as mentioned without their support and knowledge this would not be possible
*/
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include “ESP8266WiFi.h”
#include “BlynkSimpleEsp8266.h”
#include “RF.h”
#include “SimpleTimer.h”
SimpleTimer timer;
const int ID1 = 2800; //0…1048575 ID umber can be used
const int ID2 = 2801; //0…1048575 ID umber can be used
const int ID3 = 2802; //0…1048575 ID umber can be used
const int ID4 = 2803; //0…1048575 ID umber can be used
const int ID5 = 2804; //0…1048575 ID umber can be used
const int OFF = 0b0011; // code to turn unit on
const int ON = 0b1100; // code to turn unit off
const int CHANNEL = 0; //0…1
const int RF_OSC = 200; //rf signal cycle legth(µs). 200 works for me
const int RF_OUT = D2; //Pin out ESP8266
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth = “…”;
// Your WiFi credentials.
// Set password to “” for open networks.
char ssid = “…”;
char pass = “…”;
bool Connected2Blynk = false;
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(RF_OUT, OUTPUT);Blynk.connect(3333); // timeout set to 10 seconds and then continue without Blynk
while (Blynk.connect() == false) {
// Wait until connected
}
Serial.println(“Connected to Blynk server”);
timer.setInterval(11000L, CheckConnection); // check if still connected every 11 seconds
}
//Setup for V1 switch
BLYNK_WRITE(V1)
{
if (param.asInt() == 0)
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID1, OFF); //off (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, OFF = 0b0011 code for off)
}
else
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID1, ON); //on (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, ON = 0b1100 code for on)
}
}
//Setup for V2 switch
BLYNK_WRITE(V2)
{
if (param.asInt() == 0)
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID2, OFF); //off (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, OFF = 0b0011 code for off)
}
else
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID2, ON); //on (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, ON = 0b1100 code for on)
}
}
//Setup for V3 switch
BLYNK_WRITE(V3)
{
if (param.asInt() == 0)
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID3, OFF); //off (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, OFF = 0b0011 code for off)}
else
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID3, ON); //on (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, ON = 0b1100 code for on)
}
}
//Setup for V4 switch
BLYNK_WRITE(V4)
{
if (param.asInt() == 0)
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID4, OFF); //off (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, OFF = 0b0011 code for off)
}
else
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID4, ON); //on (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, ON = 0b1100 code for on)
}
}
//Setup for V5 switch
BLYNK_WRITE(V5)
{
if (param.asInt() == 0)
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID5, OFF); //off (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, OFF = 0b0011 code for off)
}
else
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID5, ON); //on (RF_OUT = Pin ESP8266 output to RF Sender, RF_OSC is rf signal cycle legth(µs)200 , ID1 is unit ID 0…1048575 new id for each unit, ON = 0b1100 code for on)
}
}
void CheckConnection(){
Connected2Blynk = Blynk.connected();
if(!Connected2Blynk){
Serial.println(“Not connected to Blynk server”);
{
for(int i = 0; i < 5; i++)
{
rfWriteCode(RF_OUT, RF_OSC, ID3, ON); //on (This is the command to turn the router on ID3 on)} } Blynk.connect(3333); // timeout set to 10 seconds and then continue without Blynk
}
else
{
Serial.println(“Connected to Blynk server”);
}
}
void loop()
{
Blynk.run();
timer.run();}
Create a file called RF.h
put the below code in the file and save
put the file in folder with the Sketch ino file
/*
Released under Creative Commons Attribution 4.0
by bitluni 2016
CC BY 4.0 Deed | Attribution 4.0 International | Creative Commons
Attribution means you can use it however you like as long you
mention that it’s base on my stuff.
I’ll be pleased if you’d do it by sharing http://youtube.com/bitlunislab
*/
inline void rfPreamble(int pin, int t)
{
int m = micros();
digitalWrite(pin, 1);
while(micros() - m < t);
digitalWrite(pin, 0);
while(micros() - m < t * 32);
}
inline void rfWriteBit(int pin, int t, int b)
{
int m = micros();
if(b)
{
digitalWrite(pin, 1);
while(micros() - m < t * 3);
digitalWrite(pin, 0);
while(micros() - m < t * 4);
}
else
{
digitalWrite(pin, 1);
while(micros() - m < t);
digitalWrite(pin, 0);
while(micros() - m < t * 4);
}
}
void rfWriteCode(int pin, int t, int code, int data)
{
rfPreamble(pin, t);
for(int i = 0; i < 20; i++)
{
rfWriteBit(pin, t, code & 1);
code >>= 1;
}
for(int i = 0; i < 4; i++)
{
rfWriteBit(pin, t, data & 1);
data >>= 1;
}
}
Shared Blynk Project: