int main(int argc, char *argv[]) { // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 2; if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 while(1) { #ifdef USE_RX_QUEUE unsigned int value = mySwitch.waitForRx(); printf("%i\n", value); fflush(stdout); #else if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { printf("Unknown encoding\n"); } else { printf("%i\n", value); } fflush(stdout); mySwitch.resetAvailable(); } #endif } exit(0); }
int main(int argc, char *argv[]){ // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 2; if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 while(1){ if(mySwitch.available()){ char buffer[200]; int value = mySwitch.getReceivedValue(); int delay = mySwitch.getReceivedDelay(); int protocol = mySwitch.getReceivedProtocol(); int bitlenght = mySwitch.getReceivedBitlength(); if(value == 0){ printf("Unknown encoding\n"); }else{ printf("Received %i\n", value ); sprintf(buffer, "/usr/bin/php /var/www/private/cron/trigger.php %i %i %i %i", value, delay, protocol, bitlenght); system(buffer); } mySwitch.resetAvailable(); } } exit(0); }
int main(int argc, char *argv[]) { int PIN = 2; if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 while(1) { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { printf("Unknown encoding"); } else { printf("Received %i\n", mySwitch.getReceivedValue() ); send_motion(value); } mySwitch.resetAvailable(); } sleep(1.5); } exit(0); }
int main(int argc, char *argv[]) { int PIN = 2; if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 while(1) { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { printf("Unknown encoding"); } else { // Set the URL. myRequest.setOpt(new curlpp::options::Url(std::string("http://127.0.0.1:8080/sarah/detecteurs?code=" + patch::to_string(value) ))); // Send request and get a result. myRequest.perform(); printf("%d\n", value); sleep(5); } mySwitch.resetAvailable(); } sleep(1); } exit(0); }
void rx(int pin) { RCSwitch mySwitch = RCSwitch(); pinMode(pin, INPUT); mySwitch.enableReceive(pin); do{ usleep(100000); // 0.1sec } while (!mySwitch.available()); int value = mySwitch.getReceivedValue(); if (value == 0) { cout << "Unknown encoding" << endl; } else { cout << "{\"code\":"; cout << mySwitch.getReceivedValue(); cout << ",\"bit\":"; cout << mySwitch.getReceivedBitlength(); cout << "\"protocol\":"; cout << mySwitch.getReceivedProtocol(); cout << "\"delay\":"; cout << mySwitch.getReceivedDelay(); cout << "}" << endl; } mySwitch.resetAvailable(); }
int main() { int PIN = 1; //BCM 18, GPIO1 if (wiringPiSetup () == -1) return 1; //Keine Ahnung was das soll auch nicht in den Bibliotheken gefunden //************************************************** ************************************************** ********************************************* //In Arduino Bibliothek gefunden. //************************************************** ************************************************** ********************************************* //Versuch das in CPP zu portieren RCSwitch mySwitch = RCSwitch(); // neue Instanz //Serial.begin(9600) kann IMHO weggelassen werden, weil wir keine Serielle Terminalsitzung benöen mySwitch.enableReceive(PIN); // Receiver on inerrupt PIN printf("enabled"); /*do { piLock(0); if (mySwitch.available()) { printf("available"); //output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata()); //Versuch mit printf. printf("%s",mySwitch.getReceivedValue()); printf("%i",mySwitch.getReceivedBitlength()); printf("%i",mySwitch.getReceivedDelay()); printf("%s",mySwitch.getReceivedRawdata()); mySwitch.resetAvailable(); } piUnlock(0); } while(true);*/ while(true) { if (mySwitch.available()) { printf("available\n"); printf("%lu\n",mySwitch.getReceivedValue()); printf("%s\n",mySwitch.getReceivedRawdata()); printf("%i\n",mySwitch.getReceivedDelay()); printf("%i\n",mySwitch.getReceivedBitlength()); mySwitch.resetAvailable(); } } return(0); }
int main(int argc, char *argv[]) { // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 0; if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 while(1) { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { printf("Unknown encoding"); } else { printf("Received %i\n", mySwitch.getReceivedValue() ); wiringPiSetup () ; pinMode (GREEN, OUTPUT) ; pinMode (YELLOW, OUTPUT) ; if (mySwitch.getReceivedValue() == 1001) { digitalWrite (GREEN, 1) ; // On digitalWrite (YELLOW, 0) ; // Off } if (mySwitch.getReceivedValue() == 1000) { digitalWrite (GREEN, 0) ; // Off digitalWrite (YELLOW, 1) ; // On } } mySwitch.resetAvailable(); } } exit(0); }
int main(int argc, char *argv[]) { // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 2; char command[100]; int door_value = 0;//Normally closed When it closed it reads 1 , when it is open it reads 0 if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 while(1) { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); // printf("value %d\n",value); if (value == 0) { printf("Unknown encoding\n"); } if(value == 2) { cout << "\tALERT DOOR State : [YES]\n"; cout << "\tTriggering Camera : [YES]\n"; system("raspivid --width 640 --height 480 --timeout 10000 -vf -hf --output /home/pi/video/vid.h264"); system("MP4Box -add /home/pi/video/vid.h264 /home/pi/video/vid$(date +'-%m%d%y-%H%M%S').mp4"); system("curl \-X POST \-H \"x\-pushbots\-appid\: 55d56814177959d7738b4568\" \-H \"x\-pushbots\-secret\: c35be61b3d1f9dff64c96a6e66fae97c\" \-H \"Content\-Type\: application\/json\" \-d \'\{\"platform\" \: 1 \, \"msg\" \: \"ALERT: Some One Entered ur House.\" \, \"payload\" \: \{\"article_id\"\:\"207168165150\"\}\}\' https\:\/\/api\.pushbots\.com\/push\/all"); sleep(60); } else { // cout << "Received :"<<mySwitch.getReceivedValue()<<endl; // printf("Received %s\n", mySwitch.getReceivedValue() ); // cout << "Received \n"<< bitset <32>(mySwitch.getReceivedValue()) <<endl; }
int main(int argc, char *argv[]) { // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 2; if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 while(1) { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { printf("Unknown encoding\n"); } else { printf("Received %i\n", mySwitch.getReceivedValue() ); // Shows the received code printf("Received pulse %i\n", mySwitch.getReceivedDelay() ); //Shows the pulse length } mySwitch.resetAvailable(); } } exit(0); }
int main(int argc, char *argv[]) { int max = 200; int sleep = 1000000; if(argc > 1) max = atoi(argv[1]); if(argc > 2) sleep = atoi(argv[2]); printf("max changes: %d\n\n", max); // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 2; if(wiringPiSetup() == -1) return 0; RCSwitch mySwitch = RCSwitch((unsigned int)max); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 unsigned int *timings; unsigned int last = 0; while(1) { timings = mySwitch.getReceivedRawdata(); if(timings[1] != last) { last = timings[1]; for(int i = 1; i < max; i++) printf("%i ", timings[i]); printf("\n\n"); } usleep(sleep); } return 0; }
int main(int argc, char *argv[]) { int pin; int received_code; int ok_code = 0; system("clear"); printf("RF Receiver TESTER by Sarrailh Remi\n"); printf("---------------------\n"); 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("PIN SELECTED :0\n"); pin = 0; //If no argument provided choose 0 by default } /* IS WIRING PI INSTALLED ? */ if(wiringPiSetup() == -1) //Initialize WiringPI { printf("-------------------------\n"); printf("----FATAL ERROR----------\n"); printf("wiringPi doesn't seems to work\n"); printf("Please install it before!\n"); printf("-------------------------\n"); printf("wget smarturl.it/wiringpi\n"); printf("chmod +x wiringpi\n"); printf("./wiringpi\n"); exit(1); } /* IS PIN RECEIVING RAW DATA */ printf("---------------------\n"); printf("TEST 1 - Received RAW digital\n"); printf("--------------------\n"); //We received GPIO State to see if something is happening for (int timer = 0; timer < 50; ++timer) { received_code = digitalRead(pin); if (received_code == 1) { ok_code++; } //If PIN IS HIGH add to ok_code printf("%i",digitalRead(pin)); delay(10); } printf("\n"); printf("--------------------\n"); if (ok_code == 0) //If the PIN was never on HIGH we assume there was a problem { printf("TEST 1: FAIL\n"); printf("Verify:\n"); printf("1 - That you RF Receiver is correctly powered (VCC to 5V and GROUND to GND)\n"); printf("2 - That you plugged DATA on the right pin\n"); printf("////////////////////////////////////////////////////////\n"); printf("RPI GPIO WIRING PI SCHEMATIC\n"); printf("////////////////////////////////////////////////////////\n"); printf("_____________________________________________________\n"); printf("5V 5V GND 15 16 1 GND 4 5 GND 6 10 11 \n"); printf("o o o o o o o o o o o o o \n"); printf("o o o o o o o o o o o o o \n"); printf("3V 8 9 7 GND 0 2 3 3V 12 13 14 GND \n"); printf("_____________________________________________________\n"); printf("P1\n"); printf("////////////////////////////////////////////////////////\n"); printf("DEFAULT WIRING\n"); printf("////////////////////////////////////////////////////////\n"); printf("_____________________________________________________\n"); printf("5V GND \n"); printf("+ x - x x x x x x x x x x \n"); printf("x x x x x D x x x x x x x \n"); printf(" 0 \n"); printf("_____________________________________________________\n"); printf("P1\n"); exit(1); } else //If test1 PASS { printf("TEST 1: PASS\n"); printf("\n"); printf("---------------------\n"); printf("TEST 2 - Receive Data\n"); printf("--- INSTRUCTIONS ---\n"); printf("Take a RCSwitch compatible remote\n"); printf("And press any button\n"); printf("A list of compatible devices is available here\n"); printf("https://code.google.com/p/rc-switch/wiki/List_KnownDevices\n"); printf("--------------------\n"); /* IS PIN RECEIVING RCSWITCH DATA */ mySwitch = RCSwitch(); //Settings RCSwitch mySwitch.enableReceive(pin); while(1) { //Waiting for Data if (mySwitch.available()) { //If Data is present int value = mySwitch.getReceivedValue(); //Save Data in value printf("Code Received %i\n", mySwitch.getReceivedValue() ); //Show Code in Decimal break; } } printf("--------------------\n"); printf("TEST 2: PASS\n"); printf("---------------------\n"); printf("RF RECEIVER WAS SUCCESFULLY TESTED!\n"); printf("\n"); exit(0); } }
int main(int argc, char *argv[]) { // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 2; int compteur ; if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 for (compteur=1; compteur<900; compteur++) { delay(20); if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { printf("Unknown encoding\n"); } else { printf("Type: " ); printf("\n"); printf("%i\n", mySwitch.getReceivedProtocol() ); printf("\n"); printf("Longueur: " ); printf("\n"); printf("%i\n", mySwitch.getReceivedBitlength() ); printf("\n"); printf("Protocole: " ); printf("\n"); printf("Send" ); printf("%i\n", mySwitch.getReceivedDelay() ); printf("\n"); printf("Code: " ); printf("\n"); printf("%i\n", mySwitch.getReceivedValue() ); return 0; } mySwitch.resetAvailable(); } } printf("Délai dépassé"); printf("\n"); printf("Veuillez réessayer"); return 0; }
int main(int argc, char *argv[]) { // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 2; int OPENDOOR = 3; int CLOSEDOOR = 4; time_t now1,now2; bool flag=false; if(wiringPiSetup() == -1) { printf("wiringPiSetup failed, exiting..."); return 0; } int pulseLength = 0; if (argv[1] != NULL) pulseLength = atoi(argv[1]); mySwitch = RCSwitch(); ledSwitch = RCSwitch(); closeDoorLed = RCSwitch(); if (pulseLength != 0) mySwitch.setPulseLength(pulseLength); mySwitch.enableReceive(PIN); // Receiver on interrupt 0 => that is pin #2 ledSwitch.enableTransmit(OPENDOOR); closeDoorLed.enableTransmit(CLOSEDOOR); while(1) { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { printf("Unknown encoding\n"); } else { if(value==5396){ if(!flag){ time(&now1); } flag = true; printf("Door is Open\n"); ledSwitch.send(15,24); } else { if(flag){ time(&now2); flag = false; printf("Door was open for: %.f seconds\n",difftime(now2,now1)); } printf("Door is Closed\n"); closeDoorLed.send(15,24); } } mySwitch.resetAvailable(); } } exit(0); }