Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- rfreceive.cpp
- by Sarrailh Remi
- Description : This code receives RF codes and trigger actions
- Modificado por Juanmol para http://rsppi.blogspot.com
- */
- #include "RCSwitch.h"
- #include <stdlib.h>
- #include <stdio.h>
- RCSwitch mySwitch;
- int pin; //Pin of the RF receiver
- int codereceived; // Code received
- char buffer[200]; // Buffer for the command
- int main(int argc, char *argv[]) {
- if(argc == 2) { //Verify if there is an argument
- pin = atoi(argv[1]); //Convert first argument to INT
- printf("PIN SELECTED :%i\n",pin);
- }
- else {
- printf("No PIN Selected\n");
- printf("Usage: rfreceive PIN\n");
- printf("Example: rfreceive 0\n");
- exit(1);
- }
- if(wiringPiSetup() == -1) { //Initialize WiringPI
- printf("Wiring PI is not installed\n"); //If WiringPI is not installed give indications
- printf("You can install it with theses command:\n");
- printf("apt-get install git-core\n");
- printf("git clone git://git.drogon.net/wiringPi\n");
- printf("cd wiringPi\n");
- printf("git pull origin\n");
- printf("./build\n");
- exit(1);
- }
- mySwitch = RCSwitch(); //Settings RCSwitch (with first argument as pin)
- mySwitch.enableReceive(pin);
- while(1) { //Infinite loop
- if (mySwitch.available()) { //If Data is detected.
- codereceived = mySwitch.getReceivedValue(); //Get data in decimal
- printf("Received %i\n", mySwitch.getReceivedValue() );
- sprintf(buffer, "sh /usr/local/bin/recibe_rf.sh %i", mySwitch.getReceivedValue());
- system(buffer);
- //Want to execute something when a code is received ?
- //When 12345 is received this will execute program_to_execute for exemple)
- /*
- if (codereceived == 12345)
- {
- system("program_to_execute");
- }
- */
- }
- mySwitch.resetAvailable();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement