Components and supplies
1
RF Socket
1
FT323RL FTDI USB 3.3v
1
RF 433 Mhz module
1
ESP8266 ESP-01
1
Jumper wires (generic)
1
USB A to Mini-B Cable
Apps and platforms
1
Blynk
Project description
Code
Untitled file
c_cpp
1/********************************************************** 2 Download latest Blynk library here: 3 https://github.com/blynkkk/blynk-library/releases/latest 4 5 6 Created: 4th Dec 2017 by Manfredk 7 Last Modified: 12th Jan 2018 by Manfredk 8********************************************************* 9FT232RL to ESP8266: IMPORTANT: set to 3.3v!! 10DTR -> - 11RX -> TX 12TX -> RX 13Vcc -> Vcc & CH_PD & RST 14CTS -> - 15GND -> GND & GPIO0 16************************** 17 Module RF to ESP8266: 18 DATA -> GPIO2 19 Vcc -> Vcc 20 GND -> GND 21**********************************************************/ 22 23#include <RCSwitch.h> 24#include <ESP8266WiFi.h> 25#include <BlynkSimpleEsp8266.h> 26#define BLYNK_PRINT Serial 27 28char auth[] = "tokenByApp"; //token 29char ssid[] = "NameWifi"; // Wifi 30char pass[] = "Password"; 31RCSwitch mySwitch = RCSwitch(); 32WidgetTerminal terminal(V0); // Virtual Pin 0 33 34void setup() { 35 WiFi.persistent(false); // Debug console 36 //Serial.begin(9600); // Baud Rate 9600 (NL) 37 mySwitch.enableTransmit(2); //RF on GPIO2 38 Blynk.begin(auth, ssid, pass); 39 Blynk.connect(); 40 // You can also specify server: 41 //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442); 42 //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442); 43 44 terminal.flush(); 45 terminal.println(F("Blynk v" BLYNK_VERSION ": Ready!")); // Version Blynk (v0.5.0) 46 terminal.println(F("-------------")); 47 terminal.println(F("Hi")); //Say hi! 48 terminal.println(F("What shall we do today?")); 49 terminal.flush(); 50} 51 52BLYNK_WRITE(V0) { 53 if (String("Turn on A") == param.asStr()) { //A ON 54 mySwitch.setPulseLength(312); // my wavelength 55 mySwitch.send("000101000100010101010001"); // binary for my A ON socket 56 terminal.println("A is ON!"); // 57 } 58 else if (String("Turn off A") == param.asStr()) { // A OFF 59 mySwitch.setPulseLength(313); //optional 60 mySwitch.send("000101000100010101010100"); // binary for my A OFF 61 terminal.println("A is OFF!"); 62 } 63 else if (String("Turn on B") == param.asStr()) { // B ON 64 mySwitch.setPulseLength(314); //optional 65 mySwitch.send("000101000101000101010001"); //B ON 66 terminal.println("B is ON!"); 67 } 68 else if (String("Turn off B") == param.asStr()) { // B OFF 69 mySwitch.setPulseLength(313); //optional 70 mySwitch.send("000101000101000101010100"); //B OFF 71 terminal.println("B is OFF!"); 72 } 73 else if (String("All on") == param.asStr()) { // A &B ON 74 mySwitch.setPulseLength(312); //optional 75 mySwitch.send("000101000100010101010001"); // A ON 76 mySwitch.setPulseLength(314); //optional 77 mySwitch.send("000101000101000101010001"); // B ON 78 terminal.println("All is ON!"); 79 } 80 else if (String("All off") == param.asStr()) { // AB OFF 81 mySwitch.setPulseLength(313); //optional 82 mySwitch.send("000101000100010101010100"); // A OFF 83 mySwitch.send("000101000101000101010100"); // B OFF 84 terminal.println("All is turn OFF!"); 85 } 86 else if (String("Hi") == param.asStr()) { 87 terminal.println(" Hi lozzi'!"); 88 } 89 else { 90 // Risposta 91 terminal.print("You said:"); 92 terminal.write(param.getBuffer(), param.getLength()); 93 terminal.println(); 94 terminal.println("unrecognized command"); 95 } 96 terminal.flush(); //Sta senz pensiè 97} 98 99BLYNK_WRITE(1) { //Pin V1 100 if (param.asInt() == 1 ) { // Button on -> socket on 101 mySwitch.setPulseLength(312); //optional 102 mySwitch.send("000101000100010101010001"); // Binary A ON 103 // or mySwitch.sendTriState("0FF0F0FFFF0F"); 104 // or mySwitch.switchOn("10010", "10000"); 105 } 106if (param.asInt() == 0) { 107 mySwitch.setPulseLength(313); //optional 108 mySwitch.send("000101000100010101010100"); //Button off -> socket OFF (same button) 109 } 110} 111 BLYNK_WRITE(3) { 112 if (param.asInt() == 1 ) { //Pin V3 113 mySwitch.setPulseLength(314); //optional 114 mySwitch.send("000101000101000101010001"); //Binary B ON 115 } 116 if (param.asInt() == 0 ) { 117 mySwitch.setPulseLength(313); //optional 118 mySwitch.send("000101000101000101010100"); //B OFF 119 } 120} 121 122void loop() 123{ 124 Blynk.run(); 125 /* You can inject your own code or combine it with other sketches. 126 Check other examples on how to communicate with Blynk. 127 to avoid delay() function!*/ 128}
Comments
Only logged in users can leave comments