Esempio n. 1
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;

}
Esempio n. 2
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;
}
Esempio n. 3
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 {
          // 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);
}
Esempio n. 5
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);
}
Esempio n. 6
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);


}
Esempio n. 7
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;
    char*  systemCode = 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[%s] unitCode[%i] command[%i] timer[%i] pin[%i] repeat[%i]\n", systemCode, unitCode, command, timer, pin, repeat);
	RCSwitch mySwitch = RCSwitch();
	mySwitch.enableTransmit(pin);
        mySwitch.setPulseLength(timer);
        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;
}
Esempio n. 8
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;
    char* sGroup = argv[1];
    int nDevice = atoi(argv[2]);
    int command  = atoi(argv[3]);
    
    if (wiringPiSetup () == -1) return 1;
	printf("sending sGroup[%s] nDevice[%i] command[%i]\n", sGroup, nDevice, command);
	RCSwitch mySwitch = RCSwitch();
	mySwitch.enableTransmit(PIN);
    
    switch(command) {
        case 1:
            mySwitch.switchOn(sGroup[0], nDevice);
            break;
        case 0:
            mySwitch.switchOff(sGroup[0], nDevice);
            break;
        default:
            printf("command[%i] is unsupported\n", command);
            return -1;
    }
	return 0;
}
Esempio n. 9
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;
    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.setProtocol(2);
	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;
}
Esempio n. 10
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;
}
Esempio n. 11
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);

}
Esempio n. 12
0
//public
	//constructor
	EX_RCSwitch::EX_RCSwitch(const __FlashStringHelper *name, byte transmitterPin, unsigned long onCode, unsigned int onLength, unsigned long offCode, unsigned int offLength, unsigned int pulseLength, byte protocol, byte repeatTransmits, bool startingState) :
		Executor(name),
		m_bCurrentState(startingState),
		m_myRCSwitch(RCSwitch()),
		m_onCode(onCode),
		m_onLength(onLength),
		m_offCode(offCode),
		m_offLength(offLength)
	{
		setPin(transmitterPin);
		m_myRCSwitch.setProtocol(protocol);					// set protocol (default is 1, will work for most outlets)
		m_myRCSwitch.setRepeatTransmit(repeatTransmits);	// set number of transmission repetitions.
		m_myRCSwitch.setPulseLength(pulseLength);			// Set pulse length.

	}
Esempio n. 13
0
Radio::Radio(unsigned long interval, int interruptIn, int pinOut) {
  m_interval = interval;
  // remote control - 433Mhz communication
  m_bytesToSent = E;
  m_radio = RCSwitch();
  m_radio.enableTransmit(
      pinOut);  // Transmitter is connected to Arduino Pin #10
  m_radio.enableReceive(
      interruptIn);             // Receiver on inerrupt 0 => that is pin #2
  m_radio.setPulseLength(500);  // Optional set pulse length.

  m_pressedButton = E;
  m_lastPressedKey = E;
  m_repeatDelay = 750;
  m_lastRequestedTime = 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;
    char* systemCode = argv[1];
    int unitCode = atoi(argv[2]);
    int command  = atoi(argv[3]);

     /*
     Added the possibility to send binaries, instead of switchOn/switchOff
     */
     int code = atoi(argv[1]);
     int pulse = atoi(argv[2]);
     int bit = atoi(argv[3]);

    
    if (wiringPiSetup () == -1) return 1;
	printf("sending systemCode[%s] unitCode[%i] command[%i]\n", systemCode, unitCode, command);
	RCSwitch mySwitch = RCSwitch();
	mySwitch.enableTransmit(PIN);
    
    switch(command) {
        case 1:
            mySwitch.switchOn(systemCode, unitCode);
            break;
        case 0:
            mySwitch.switchOff(systemCode, unitCode);
            break;
	case 2:
             mySwitch.setPulseLength(pulse);
             mySwitch.send(systemCode);
            break;
	default:
             mySwitch.setPulseLength(pulse);
             mySwitch.send(code, bit);
            break;

    }
	return 0;
}
Esempio n. 15
0
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;
}
Esempio n. 16
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[]) {
    
    /*
     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[]) {

    // 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;

     }
Esempio n. 19
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;
}
Esempio n. 20
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()) {
    
        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);


}
Esempio n. 21
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[]) {
  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;
}
Esempio n. 23
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;

}
Esempio n. 24
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;
  /**
   * using old numbering mode by default,
   * see RCSwitch.cpp for differences
   */
  bool binaryMode = false;
  char* systemCode;
  int unitCode;
  int command;

  if (argc < 4) {
    /**
     * no matter, which mode is used, at least 4 arguments are required:
     * 0: command name (send)
     * 1: systemCode
     * 2: unitCode
     * 3: command
     * if there are less arguments, the help should be printed
     * and the application should terminate.
     */
    printUsage();
    return 1;
  }

  /**
   * This needs to stand after the check of how many arguments are passed,
   * because if there is only 1 argument passed, argv[1] is NULL, which
   * will result in an error, because a std::string can't be constructed
   * by a NULL value. Therefore it is important to terminate the application
   * if there are less than 2 arguments (in this case: less than 4 arguments)
   * passed.
   */
  std::string firstArgument = argv[1];

  if (firstArgument == "-b" or firstArgument == "--binary") {
    if (argc < 5) {
    /**
     * in binaryMode, 5 arguments are required:
     * 0: command name ('send')
     * 1: binary operator ('-b')
     * 2: systemCode
     * 3: unitCode
     * 4: command
     * if there are less arguments, the help should be printed,
     * and the application should terminate.
     */
      printUsage();
      return 1;
    }

    printf("operating in binary mode...\n");
    binaryMode = true;
    //position of data in input is now shifted by 1 because of '-b'-flag
    systemCode = argv[2];
    unitCode = atoi(argv[3]);
    command  = atoi(argv[4]);
  } else if (firstArgument == "-h" or firstArgument == "--help" or firstArgument == "-?") {
    printUsage();
  } else {
    //no binary mode, therefore using normal mode with old numbering
    systemCode = argv[1];
    unitCode = atoi(argv[2]);
    command  = atoi(argv[3]);
  }

  if (wiringPiSetup () == -1) return 1;
  piHiPri(20);
  printf("sending systemCode[%s] unitCode[%i] command[%i]\n", systemCode, unitCode, command);
  RCSwitch mySwitch = RCSwitch();
  mySwitch.setPulseLength(300);
  mySwitch.enableTransmit(PIN);

  if (binaryMode) {
    switch (command){
      case 1:
        mySwitch.switchOnBinary(systemCode, unitCode);
        break;
      case 0:
        mySwitch.switchOffBinary(systemCode, unitCode);
        break;
      default:
        printf("command[%i] is unsupported\n", command);
        printUsage();
        return -1;
    }
    return 0;
  } else {
    switch(command) {
      case 1:
        mySwitch.switchOn(systemCode, unitCode);
        break;
      case 0:
        mySwitch.switchOff(systemCode, unitCode);
        break;
      case 2:
        // 00001 2 on binary coded
        mySwitch.send("010101010001000101010001");
        break;
      case 3:
        // 00001 2 on as TriState
        mySwitch.sendTriState("FFFF0F0FFF0F");
        break;
      default:
        printf("command[%i] is unsupported\n", command);
        printUsage();
        return -1;
    }
    return 0;
  }
}
Esempio n. 25
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);
}
}
void saltlamp_433::parse(String &ser_command, byte &ser_pin, String &ser_value)
{
	if (ser_command == F("REG_TRANSMITTER")) {

		if (!DEVS.in_use(ser_pin)) {
			DEVS.reg(ser_pin, m433);
			
			devicesT[ser_pin].radio = RCSwitch();
			devicesT[ser_pin].radio.enableTransmit(ser_pin);
			devicesT[ser_pin].radio.setProtocol(ser_value.toInt());

			response_msg = MSG_OK;
		} else {
			response_msg = MSG_PIN_IN_USE;
		}

	} else if (ser_command == F("REG_RECEIVER")) {

		if (!DEVS.in_use(ser_pin)) {
			
			if (!DEVS.is_interrupt(ser_pin)) {
				response_msg = MSG_NEED_INTERRUPT_PIN;
				return;
			} 

			DEVS.reg(ser_pin, m433);
			
			byte interrupt = DEVS.get_interrupt(ser_pin);
			
			devicesR[interrupt].radio = RCSwitch();
			devicesR[interrupt].radio.enableReceive( interrupt );
			devicesR[interrupt].registered = true;

			response_msg = MSG_OK;
		} else {
			response_msg = MSG_PIN_IN_USE;
		}
		
	} else if (ser_command == F("SEND")) {

		if (DEVS.is_device(ser_pin, m433)) {

			devicesT[ser_pin].radio.send(ser_value.toInt(), 24);
	
			response_msg = MSG_OK;
							
		} else {
			response_msg = MSG_NOT_DEVICE;
		}
			
	} else if (ser_command == F("PROTO")) {

		if (DEVS.is_device(ser_pin, m433)) {

			devicesT[ser_pin].radio.setProtocol(ser_value.toInt());
	
			response_msg = MSG_OK;
							
		} else {
			response_msg = MSG_NOT_DEVICE;
		}
			
	} else {
		response_msg = MSG_CMD_NOT_RECO;
	}

}
Esempio n. 27
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);


}
Esempio n. 29
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;
    if (wiringPiSetup () == -1) return 1;
    RCSwitch mySwitch = RCSwitch();
    mySwitch.enableTransmit(PIN);

    if(argc == 4)
    {
        char* sGroup = argv[1];
        int nSwitchNumber = atoi(argv[2]);

        int command  = atoi(argv[3]);

        if(strlen(sGroup) > 2)
        {
            //Type A: 10 pole DIP switches
            printf("sending [Type A] groupCode[%s] switchNumber[%i] command[%i]\n", sGroup, nSwitchNumber, command);

            switch(command) {
            case 1:
                mySwitch.switchOn(sGroup, nSwitchNumber);
                break;
            case 0:
                mySwitch.switchOff(sGroup, nSwitchNumber);
                break;
            default:
                printf("command[%i] is unsupported\n", command);
                printUsage();
                return -1;
            }
            return 0;
        } else {
            //Type B: Two rotary/sliding switches
            int nGroupNumber = atoi(sGroup);
            printf("sending [Type B] groupNumber[%i] switchNumber[%i] command[%i]\n", nGroupNumber, nSwitchNumber, command);
            switch(command) {
            case 1:
                mySwitch.switchOn(nGroupNumber, nSwitchNumber);
                break;
            case 0:
                mySwitch.switchOff(nGroupNumber, nSwitchNumber);
                break;
            default:
                printf("command[%i] is unsupported\n", command);
                printUsage();
                return -1;
            }
            return 0;
        }
    }
    else if(argc == 5)
    {
        //Type C: Intertechno
        char* sFamily = argv[1];
        int nGroup = atoi(argv[2]);
        int nDevice = atoi(argv[3]);

        int command = atoi(argv[4]);

        printf("sending [Type C] family[%s] groupNumber[%i] switchNumber[%i] command[%i]\n", sFamily, nGroup, nDevice, command);

        switch(command) {
        case 1:
            mySwitch.switchOn(sFamily[0], nGroup, nDevice);
            break;
        case 0:
            mySwitch.switchOff(sFamily[0], nGroup, nDevice);
            break;
        default:
            printf("command[%i] is unsupported\n", command);
            printUsage();
            return -1;
        }
        return 0;
    }
    else
    {
        printUsage();
    }
    return 1;
}
Esempio n. 30
0
#include <stdio.h>
#include <string.h>
#include <RCSwitch.h>
#include <math.h> 
#include "mbed.h"

#define MEASURE_SIZE 26

/******      I/O PINS      ********/
DigitalOut led_tx(LED1);
RCSwitch mySwitch = RCSwitch(D2, D3); //SERIAL2 TX & RX. (cuadrado y rectangular)
/****** End of I/O PINS     *******/

//Values to manage the received message and its ACK
char received[MEASURE_SIZE]; //Received chain in binary format
int received_value; //Received chain in int format
int received_length; //Length of the received message
char received_ack[6]; //Received chain of possible ack in binary format
int received_ack_int; //Received chain of possible ack in int format
//Values to decode the received message
char node_id[4];
char priority_message[4];
char sensor_id[4];
char lecture[14];
char* ack_message;
char decoded_message[150];

//------------------------------------
// UART configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------