IR Sketch



  • Hi

    I am using the IR sketch and trying to send IR commands.

    I have the device added in jeedom, and then after capturing the IR code making it send the code.
    It seems to be sending the code, however the sensor seems to get into a loop and send the same code over and over. I suspect that it may have something to do with the if statement in the stretch. Below is the sketch and the output from the serial monitor

    // Example sketch showing how to control ir devices
    // An IR LED must be connected to Arduino PWM pin 3.
    // An optional ir receiver can be connected to PWM pin 8. 
    // All receied ir signals will be sent to gateway device stored in VAR_1.
    // When binary light on is clicked - sketch will send volume up ir command
    // When binary light off is clicked - sketch will send volume down ir command
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <IRLib.h>
    
    int RECV_PIN = 8;
    
    #define CHILD_1  3  // childId
    
    IRsend irsend;
    IRrecv irrecv(RECV_PIN);
    IRdecode decoder;
    //decode_results results;
    unsigned int Buffer[RAWBUF];
    MySensor gw;
    MyMessage msg(CHILD_1, V_VAR1);
    
    void setup()  
    {  
      irrecv.enableIRIn(); // Start the ir receiver
      decoder.UseExtnBuf(Buffer);
      gw.begin(incomingMessage);
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("IR Sensor", "1.0");
    
      // Register a sensors to gw. Use binary light for test purposes.
      gw.present(CHILD_1, S_LIGHT);
    }
    
    
    void loop() 
    {
      gw.process();
      if (irrecv.GetResults(&decoder)) {
        irrecv.resume(); 
        decoder.decode();
        decoder.DumpResults();
            
        char buffer[10];
        sprintf(buffer, "%08lx", decoder.value);
        // Send ir result to gw
        gw.send(msg.set(buffer));
      }
    }
    
    
    
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         int incomingRelayStatus = message.getInt();
         if (incomingRelayStatus == 1) {
          irsend.send(NEC, 0000000000, 32); // Vol up yamaha ysp-900
         } else {
          irsend.send(NEC, 0000000000, 32); // Vol down yamaha ysp-900
         }
         // Start receiving ir again...
        irrecv.enableIRIn(); 
      }
    }
        
    // Dumps out the decode_results structure.
    // Call this after IRrecv::decode()
    // void * to work around compiler issue
    //void dump(void *v) {
    //  decode_results *results = (decode_results *)v
    /*void dump(decode_results *results) {
      int count = results->rawlen;
      if (results->decode_type == UNKNOWN) {
        Serial.print("Unknown encoding: ");
      } 
      else if (results->decode_type == NEC) {
        Serial.print("Decoded NEC: ");
      } 
      else if (results->decode_type == SONY) {
        Serial.print("Decoded SONY: ");
      } 
      else if (results->decode_type == RC5) {
        Serial.print("Decoded RC5: ");
      } 
      else if (results->decode_type == RC6) {
        Serial.print("Decoded RC6: ");
      }
      else if (results->decode_type == PANASONIC) {	
        Serial.print("Decoded PANASONIC - Address: ");
        Serial.print(results->panasonicAddress,HEX);
        Serial.print(" Value: ");
      }
      else if (results->decode_type == JVC) {
         Serial.print("Decoded JVC: ");
      }
      Serial.print(results->value, HEX);
      Serial.print(" (");
      Serial.print(results->bits, DEC);
      Serial.println(" bits)");
      Serial.print("Raw (");
      Serial.print(count, DEC);
      Serial.print("): ");
    
      for (int i = 0; i < count; i++) {
        if ((i % 2) == 1) {
          Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
        } 
        else {
          Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
        }
        Serial.print(" ");
      }
      Serial.println("");
    }
    */
    
    end: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    send: 60-60-0-0 s=3,c=1,t=2,pt=0,l=10,st=ok:0x77e13adc
    read: 0-1-60 s=3,c=1,t=2,pt=0,l=10:0x77e13adc
    

    Can anybody shed some light



  • Hello,

    I successfully use this sketch. I use mine with a Vera though. The sketch creates a light switch, once you have captured the remote code via serial terminal or var1, you need to place that code in the mysensor code. When you have done that, turning on your light switch will send one code and turning off your light switch will send another. I have created 8 light switches and that let's me store 16 codes, just enough for a whole remote.

    I don't think there is a way yet to send remote codes the other way from the controller to the sensor. I am very new at this though and could be wrong.



  • Sending is possible from the controller, I have tested it, It is just the loop that is the problem



  • How do you send IR code to a light switch as declared in your code? I really want to do mine via the controller so I can update it without rewriting the code. Does Jeedom use a different method?


  • Admin

    @Dring-House said:

    I don't think there is a way yet to send remote codes the other way from the controller to the sensor. I am very new at this though and could be wrong.

    True, the ir-codes it too large to fit in one message (if you use pronto-codes).
    So to archive this you'd have to divide them into several messages (and perhaps store them in the eeprom).



  • @Terence-Faul : did you still get this issue ? around that time (1 month ago) there was a beta release of the plugin creating such error of loops, nothing about IR (my fault)

    @hek : IRLib decode the message, so it's not so long, around 12 characters. I use it myself, the node send to the controler any code received and you can store them. I have a scenario in Jeedom that is storing all codes receive until I erase it, like this pressing multiples button, I get all of them.
    After that, you can create a V_IR_SEND and as the input use any of the codes you have received.

    But must be working only for a protocole decoded by IRLib (at that time, I have try only my Sony remote) If not decoded, yes RAW message is too long to be used. And of course better to know what type of protocol it is so (but it's possible to send this value in another sensor for exemple)

    My bigger problem with this library, it's the hardcoded Sender in PIN 3 (I don't understand why, and make me impossible to use a motion sensor at same time)


Log in to reply
 

Suggested Topics

  • 87
  • 10
  • 7
  • 2
  • 5
  • 1

11
Online

11.4k
Users

11.1k
Topics

112.7k
Posts