// 433 Mhz code /* Example for different sending methods https://github.com/sui77/rc-switch/ */ #include RCSwitch mySwitch = RCSwitch(); //end 433 Mhz code #define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include "CayenneDefines.h" #include "BlynkSimpleEsp8266.h" #include "CayenneWiFiClient.h" // Cayenne authentication token. This should be obtained from the Cayenne Dashboard. char token[] = "your cayenne token"; // Your network name and password. char ssid[] = "yournetwork ssid"; char password[] = "your wifi password"; // Variables used for the remote switches. int state; int switchstatus; void setup() { // 433 Mc Transmitter is connected to Wemos D1 Port 2 (which is D9 on the board) mySwitch.enableTransmit(2); switchstatus = 0; Serial.begin(9600); Cayenne.begin(token, ssid, password); } void loop() { Cayenne.run(); // Logging for debugging purposes Serial.print("switchstatus "); Serial.println(switchstatus); Serial.print("state "); Serial.println(state); //Determine the state of the button that controls the remotes. Defined that as port 5 in Cayenne state = digitalRead(5); //Check switch status if it is 1 and then activate the remote switch //Only one activation event will do, the switchstatus variable will take care of that. if( state == 1 and switchstatus == 0) mySwitch.send(*****, 24); // Below it sets the switchstatus to 1 the in the first cylce after the button was pressed. (will be reversed if the button is set to off) if( state == 1 and switchstatus == 0) switchstatus =1; delay (200); //Check switch status if it is 0 and de-activate the remote switch //Only one de-activation event will do, the switchstatus variable will take care of that. if( state == 0 and switchstatus == 1) mySwitch.send(*****, 24); if( state == 0 and switchstatus == 1) switchstatus =0; delay (200); }