int main(int argc, char *argv[]) { /* output PIN is hardcoded for testing purposes see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ for pin mapping of the raspberry pi GPIO connector */ int PIN = 0; char* systemCode = argv[1]; int unitCode = atoi(argv[2]); int command = atoi(argv[3]); if (wiringPiSetup () == -1) return 1; printf("sending systemCode[%s] unitCode[%i] command[%i]\n", systemCode, unitCode, command); RCSwitch mySwitch = RCSwitch(); if (argv[4] != NULL) mySwitch.setPulseLength(atoi(argv[4])); mySwitch.enableTransmit(PIN); switch(command) { case 1: mySwitch.switchOn(systemCode, unitCode); break; case 0: mySwitch.switchOff(systemCode, unitCode); break; default: printf("command[%i] is unsupported\n", command); return -1; } return 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); }
int main(int argc, char *argv[]) { /* output PIN is hardcoded for testing purposes see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ for pin mapping of the raspberry pi GPIO connector */ int PIN = 17; int outlet = atoi(argv[1]); int command = atoi(argv[2]); if (wiringPiSetupSys () == -1) return 1; RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); switch(command) { case 1: mySwitch.switchOn(outlet, 4); break; case 0: mySwitch.switchOff(outlet, 4); break; default: printf("command[%i] is unsupported\n", command); return -1; } return 0; }
JNIEXPORT void JNICALL Java_com_opitz_jni_NativeRCSwitchAdapter_switchOff(JNIEnv * env, jobject obj, jstring jsGroup, jstring jsChannel ){ if (wiringPiSetup () == -1) { printf("noWiringPiSetup"); } const char *csGroup = env->GetStringUTFChars(jsGroup, 0); const char *csChannel = env->GetStringUTFChars(jsChannel, 0); char sGroup[6]; char sChannel[6]; for (int i = 0; i<5; i++) { sGroup[i] = csGroup[i]; sChannel[i] = csChannel[i]; } sGroup[5] = '\0'; sChannel[5] = '\0'; cout<<"OFF with "<<sGroup<<" and "<< sChannel <<endl; piHiPri(20); //for testing purposes set to the ELRO Power Plugs mySwitch.setPulseLength(300); mySwitch.enableTransmit(0); mySwitch.setRepeatTransmit(3); mySwitch.switchOff(sGroup, sChannel); }
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[]) { // 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; // Parse the firt parameter to this command as an integer int code = atoi(argv[1]); if (wiringPiSetup () == -1) return 1; printf("sending code[%i]\n", code); RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); // Optional set pulse length. mySwitch.setPulseLength(500); // Optional set protocol (default is 1, will work for most outlets) // mySwitch.setProtocol(2); // Optional set number of transmission repetitions. // mySwitch.setRepeatTransmit(15); mySwitch.send(code, 24); 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; 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[]) { int RXPIN = 1; int TXPIN = 0; if(wiringPiSetup() == -1) return 0; RCSwitch *rc = new RCSwitch(RXPIN,TXPIN); while (1) { if (rc->OokAvailable()) { char message[100]; rc->getOokCode(message); printf("%s\n",message); Sensor *s = Sensor::getRightSensor(message); if (s!= NULL) { printf("Temp : %f\n",s->getTemperature()); printf("Humidity : %f\n",s->getHumidity()); printf("Channel : %d\n",s->getChannel()); } delete s; } delay(1000); } }
int main(int argc, char* argv[]) { Cgicc formData; /* output rcDataPin is hardcoded for testing purposes see https://projects.drogon.net/raspberry-pi/wiringpi/rcDataPins/ for rcDataPin maprcDataPing of the raspberry pi GPIO connector */ int rcDataPin = 0; int ledPin = 1; // form_iterator fi = formData.getElement("device"); string foo = formData("cmd"); // if( !fi->isEmpty() && fi != (*formData).end()) { // cout << "selected device: " << fi->getValue() << endl; // }else{ // cout << "No text entered for first name" << endl; // } int mode = atoi(formData("cmd").c_str()); int groupId = atoi(formData("group").c_str()); int DeviceId = atoi(formData("device").c_str()); // int mode = 1; // int groupId = 1; // int DeviceId = 1; if (wiringPiSetup() == -1) return -1; RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(rcDataPin); pinMode(ledPin, OUTPUT); switch(mode) { case 1: digitalWrite(ledPin, HIGH); mySwitch.switchOn('a',groupId, DeviceId); break; case 0: digitalWrite(ledPin, LOW); mySwitch.switchOff('a',groupId, DeviceId); break; default: cout << "unsuported mode[" << mode << "]" << endl; return -1; } cout << "Location:http://raspberrypi.local/\n\n"; return 0; }
int main(int argc, char *argv[]) { /* * output PIN is hardcoded for testing purposes * see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ * for pin mapping of the raspberry pi GPIO connector */ int PIN = 0; string unitcode = argv[1]; string state = argv[2]; if (wiringPiSetup () == -1) return 1; piHiPri(20); /* printf("sending unitcode[%i] state[%i]\n", unitcode, state); */ RCSwitch mySwitch = RCSwitch(); mySwitch.setPulseLength(300); mySwitch.enableTransmit(PIN); std::cout<< "unitcode: " << unitcode << std::endl; std::cout<< "Laenge: " << unitcode.length() << std::endl; string::size_type pos = 0; while ((pos = unitcode.find("1", pos)) != string::npos) { string s2 = "x"; unitcode.replace(pos, 1, s2, 0, s2.length()); } std::cout<< "spos " << pos << std::endl; std::cout<< "find " << unitcode.find("0", pos) << std::endl; pos=0; while ((pos = unitcode.find("0", pos)) != string::npos) { string s1 = "1"; unitcode.replace(pos, 1, s1, 0, s1.length()); } pos=0; while ((pos = unitcode.find("x", pos)) != string::npos) { string s2 = "0"; unitcode.replace(pos, 1, s2, 0, s2.length()); } string execute = unitcode + state; std::cout<< "seeeeeeeeeeeeeeeeeeeeeeeeeeeeeee: " << execute << std::endl; string exe = execute; for(int i=0;i < 24;i+=2){ execute = exe.insert(i, 1, '0'); } char * buffer = new char[execute.length()]; char *kacka=strcpy(buffer,execute.c_str()); //char *array="000000000001000000000000"; mySwitch.send(kacka); std::cout<< "state: " << state << std::endl; std::cout<< "execute: " << execute << std::endl; return 0; }
int main() { int code=5,i=0; double duration,duration1,pos_arr[3][2], tmp1=0, tmp2=0, tmp3=0; struct timeval start,end,start1; RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); receiver receiver1(1),receiver2(2),receiver3(3); receiver1.init(); receiver2.init(); receiver3.init(); ofstream data; data.open ("data.txt"); printf("activating emitter\n"); mySwitch.send(code,24); // delay(3); while (true) { gettimeofday(&start1,NULL); std::thread t1(&receiver::dst,&receiver1); std::thread t2(&receiver::dst,&receiver2); std::thread t3(&receiver::dst,&receiver3); t1.join(); t2.join(); t3.join(); // std::cout<<receiver1.distance<<" "<<receiver2.distance<<" "<<receiver3.distance<<" "<<i<<std::endl; pos_arr[0][0]=tmp1; pos_arr[1][0]=tmp2; pos_arr[2][0]=tmp3; pos_arr[0][1]=receiver1.distance; pos_arr[1][1]=receiver2.distance; pos_arr[2][1]=receiver3.distance; tmp1= pos_arr[0][1]; tmp2= pos_arr[1][1]; tmp3= pos_arr[2][1]; gettimeofday(&start,NULL); kalman(pos_arr); gettimeofday(&end,NULL); duration1=(abs(end.tv_usec-start1.tv_usec)/1000.0); duration=(abs(end.tv_usec-start.tv_usec)/1000.0); //std::cout<<"receiver1"<<receiver1.distance <<"receiver2"<<receiver2.distance<< "receiver3"<<receiver3.distance << std::endl; std::cout<<"time for Kalman / calculations "<<duration<< " " << duration1<< std::endl; delay(50-duration1); // gettimeofday(&end1,NULL); // duration1=((dend1.tv_usec-start1.tv_usec)*1000+(end1.tv_sec-start1.tv_sec)/1000)+0.5; // std::cout<<"time for Kalman "<<duration<<std::endl; // delay(50-duration1/1000000); i++; } data.close(); return 0; }
/************************************************************************************** * * * Function: main() * * Executes the main program. Waits to receive a packet, and when comes, resend it * * to check if it is correct. If is, send ACK and decode the message, split it in * * node ID, priority of the message, sensor ID, and lecture * * If nothing happends, at five minutes send the information of every sensor. * * * **************************************************************************************/ int main(){ strcpy(ack_message, "101010"); //Hard code the ack string message pc.printf("Inicializacion completada. Recibiendo...\n"); while(1){ while(!mySwitch.available()){ } if(mySwitch.available()){ received_value = mySwitch.getReceivedValue(); received_length = mySwitch.getReceivedBitlength(); send_received(); mySwitch.resetAvailable(); } pc.printf("Esperando para el ACK\n"); time(&start); while(!mySwitch.available()){ time(&end); seconds_elapsed = difftime(start, end); if(seconds_elapsed >=2){ pc.printf("No se ha recibido el ACK, se considera la secuencia recibida valida y se pasa a su decodificacion\n"); break; } } if(mySwitch.available()){ received_ack_int = mySwitch.getReceivedValue(); check_received(); mySwitch.resetAvailable(); } if((received_value != 0) && (received_length >=7)){ decode_received_message(); } } }
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(); }
RCSwitch initTx(int pin, int protocol, int repetition, int delay) { pinMode(pin, OUTPUT); RCSwitch mySwitch = RCSwitch(); mySwitch.setRepeatTransmit(repetition); mySwitch.enableTransmit(pin); mySwitch.setProtocol(protocol); if (delay > 0) { mySwitch.setPulseLength(delay); } return mySwitch; }
/** * @brief arduino setup function */ void setup() { Serial.begin(9600); Display::Init(); if (RTC.get() == 0) { // following line sets the RTC to the date & time this sketch was compiled RTC.set(hhmmss()); } setSyncProvider(RTC.get); // the function to get the time from the RTC // Transmitter is connected to Arduino Pin #10 mySwitch.enableTransmit(7); dallastemp.begin(); // Inizialisieren der Dallas Temperature library dallastemp.setWaitForConversion(false); aqua.begin(); pinMode(BUTTON_PIN_1, INPUT_PULLUP); pinMode(BUTTON_PIN_2, INPUT_PULLUP); // pinMode(BUTTON_PIN_3, INPUT_PULLUP); // pinMode(BUTTON_PIN_4, INPUT_PULLUP); }
int main() { int code=5,i=0; timespec tsleep{0}; long long duration2=0,duration1=0; RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); receiver receiver1(1),receiver2(2),receiver3(3); receiver1.init(); receiver2.init(); receiver3.init(); printf("activating emitter\n"); mySwitch.send(code,24); std::ofstream data; data.open ("data.txt"); // delay(3); while (true) { auto begin = std::chrono::high_resolution_clock::now(); //////////////////////////////////////////////////////////////////////////////////// // mySwitch.send(code,24); receiver1.dst(); // receiver2.dst(); // receiver3.dst(); data<<receiver1.distance<<" "<<receiver2.distance<<" "<<receiver3.distance<<std::endl; //////////////////////////////////////////////////////////////////////////////// auto end = std::chrono::high_resolution_clock::now(); // data<<end.tv_usec<<"\n"; duration2 = std::chrono::duration_cast <std::chrono::nanoseconds>(end-begin).count(); tsleep.tv_nsec=50000000-duration2; nanosleep(&tsleep,NULL); // i++; // if (i==20) // { // mySwitch.send(code,24); // i=0; // } // auto end2 = std::chrono::high_resolution_clock::now(); // duration1 = std::chrono::duration_cast <std::chrono::nanoseconds>(end2-begin).count(); // data<<duration1<<"\n"; } 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; 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[]) { // 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 = 29; // Parse the firt parameter to this command as an integer int code = atoi(argv[1]); if (wiringPiSetup () == -1) return 1; printf("sending code[%i]\n", code); RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); mySwitch.send(code, 24); 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; 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[]) { /* output PIN is hardcoded for testing purposes see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ for pin mapping of the raspberry pi GPIO connector */ int PIN = 0; char* tristate = argv[1]; if (wiringPiSetup () == -1) return 1; printf("sending tristate[%s] \n", tristate); RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); mySwitch.setPulseLength(360); mySwitch.sendTriState(tristate); return 0; }
int main(int argc, char *argv[]) { /* output PIN is hardcoded for testing purposes see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ for pin mapping of the raspberry pi GPIO connector */ int PIN = 0; unsigned long RCcode = atol(argv[1]); unsigned int RClength = atoi(argv[2]); if (wiringPiSetup () == -1) return 1; printf("Sending RCcode[%lu] RClength[%i]\n", RCcode, RClength); RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); mySwitch.send(RCcode, RClength); 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; // Parse the firt parameter to this command as an integer int code = atoi(argv[1]); if (wiringPiSetup () == -1) return 1; printf("sending code[%i]\n", code); RCSwitch mySwitch = RCSwitch(); //Pulse length depends on the RF outlets you are using. Use RFSniffer to see what pulse length your device uses. mySwitch.setPulseLength(185); mySwitch.enableTransmit(PIN); mySwitch.send(code, 24); return 0; }
int main(int argc, char *argv[]) { /* output PIN is hardcoded for testing purposes see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ for pin mapping of the raspberry pi GPIO connector */ // int PIN = 121; int systemCode =atoi( argv[1]); int unitCode = atoi(argv[2]); int command = atoi(argv[3]); int timer = atoi(argv[4]); int pin = atoi(argv[5]); int repeat = atoi(argv[6]); // if (wiringPiSetup () == -1) return 1; printf("sending systemCode[%i] unitCode[%i] command[%i] timer[%i] pin[%i] repeat[%i]\n", systemCode, unitCode, command, timer, pin, repeat); RCSwitch mySwitch = RCSwitch(); mySwitch.setPulseLength(timer); mySwitch.enableTransmit(pin); mySwitch.setRepeatTransmit(repeat); switch(command) { case 1: mySwitch.switchOn(systemCode, unitCode); break; case 0: mySwitch.switchOff(systemCode,unitCode); break; default: printf("command[%i] is unsupported\n", command); return -1; } return 0; }
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[]) { //!!!!!!!!!!!!!!! Remove comments below for easy debugging (override command line parameters) !!!!!!!! //argv = dummy_args; //argc = sizeof(dummy_args) / sizeof(dummy_args[0]) - 1; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (wiringPiSetup() == -1) { cout << "Could not set up wiringPi\r\n" << endl; } unsigned long code = 0; uint repeats = 0; RCSwitch rc = RCSwitch(); if (argc > 1) { code = strtol(argv[1], NULL, 16); } if (argc == 3) { repeats = atoi(argv[2]); } if (argc == 3) { pinMode(RF_TX_POWER_PIN, OUTPUT); // Set the Transmitter power pin to output mode digitalWrite(RF_TX_POWER_PIN, HIGH); // Turn on power to the RF Transmitter rc.setRepeatTransmit(repeats); // Set the number of repeats rc.enableTransmit(RF_TX_DATA_PIN); // Set Transmitter to the correct IO pin rc.send(code, 24); // Send the actual code digitalWrite(RF_TX_POWER_PIN, LOW); // Turn off power to the RF Transmitter cout << "sent " << std::hex << code << endl; } else { cout << "Usage : transmit <code> <repeats>" << endl; cout << " Where is <code> is the code to send" << endl; cout << " Where is <repeats> is how many times the code is repeated" << endl; cout << "Example : transmit abcdef 10" << endl; } return 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[]) { // 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; // Parse the first tow parameters to this command as integers int count = argc - 1; int timings[count]; for(int i = 0; i < count; i++) { timings[i] = atoi(argv[i + 1]); } if (wiringPiSetup () == -1) return 1; RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); mySwitch.sendRaw(count, timings); 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 = 9; 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() ); } mySwitch.resetAvailable(); } } exit(0); }
/************************************************************************************** * * * Function: send_received() * * Prints the received binary chain and resends it. After, waits for and answer of * * the transmitter, saying if the chain was correctly received. * * * **************************************************************************************/ void send_received(){ itoa(received_value, received,2); if (received_value==0){ pc.printf("No reconocido"); } else { pc.printf("He recibido: %s de %d bits \n", received, received_length ); wait_ms(800); pc.printf("Reenviando la secuencia recibida para comprobar si es correcta\n"); led_tx = 1; mySwitch.send(received); led_tx = 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; // Parse the first parameter to this command as an integer int protocol = 0; // A value of 0 will use rc-switch's default value int pulseLength = 0; // If no command line argument is given, print the help text if (argc == 1) { printf("Usage: %s decimalcode [protocol] [pulselength]\n", argv[0]); printf("decimalcode\t- As decoded by RFSniffer\n"); printf("protocol\t- According to rc-switch definitions\n"); printf("pulselength\t- pulselength in microseconds\n"); return -1; } // Change protocol and pulse length accroding to parameters int code = atoi(argv[1]); if (argc >= 3) protocol = atoi(argv[2]); if (argc >= 4) pulseLength = atoi(argv[3]); if (wiringPiSetup () == -1) return 1; printf("sending code[%i]\n", code); RCSwitch mySwitch = RCSwitch(); if (protocol != 0) mySwitch.setProtocol(protocol); if (pulseLength != 0) mySwitch.setPulseLength(pulseLength); mySwitch.enableTransmit(PIN); mySwitch.send(code, 24); return 0; }