IR Sender/Receiver built, now what?

Moderator: leecollings

User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: IR Sender/Receiver built, now what?

Post by remb0 »

Do you have this sketch also in a 2.0 sketch?
I tried to modify it so it worked in my 2.0 config, but got lots of compile errors :P

when compiling i got no errors or warnings. but when uploading to my uno i got:

Code: Select all

Using library MySensors at version 2.0.0 in folder: C:\Users\remco\Documents\Arduino\libraries\MySensors 
Using library SPI at version 1.0 in folder: C:\Users\remco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\libraries\SPI 
Using library IRLib-master in folder: C:\Users\remco\Documents\Arduino\libraries\IRLib-master (legacy)

Sketch uses 15,090 bytes (46%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,195 bytes (58%) of dynamic memory, leaving 853 bytes for local variables. Maximum is 2,048 bytes.
Invalid library found in C:\Users\remco\Documents\Arduino\libraries\IRSensor: C:\Users\remco\Documents\Arduino\libraries\IRSensor
Invalid library found in C:\Users\remco\Documents\Arduino\libraries\IRSensor: C:\Users\remco\Documents\Arduino\libraries\IRSensor
[\code]



[quote="gizmocuz"]some heads up:

in the latest beta i implemented the mysensors S_IR_RECEIVE and S_IR_SEND

going to make two posts

Post 1:

When playing with the IR sample, i noticed that 99% of my remote buttons where not recognized, i only received pulsed, instead of a code

So.... i look at the IR library, and it has a nice example to make a 32bit hash of the received IR pulses.
This proves to be working very good ! ;)

I made a new sketch, that is using this hash code, and send it to domoticz (S_IR_RECEIVE)
A new switch (type mdremote) is created, and you can use this for example as the activation code of a scene

Next, when setting the type of the switch to 'push on' (as it is only received) you can also push the button in domoticz, and it will send the code to the sketch (S_IR_SEND)

you can do what you want with it

The sketch is:

[code]/**
 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad <[email protected]>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 *******************************
 *
 * REVISION HISTORY
 * Version 1.0 - Henrik EKblad
 * 
 * DESCRIPTION
 * 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
 * http://www.mysensors.org/build/ir
 */

#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;
IRdecodeHash Hash_Decoder;

//As some remotes could have different hashes for the same button (when they are not good received or other reasons)
//we only let the following hashes go through

#define MYCODES_LENGTH 2
const unsigned long myHashes[MYCODES_LENGTH]={
  0x0BE3BB37, //volume up
  0xD4D9F2A7, //volume down
};

//decode_results results;
MySensor gw;
MyMessage msgir(CHILD_1, V_IR_RECEIVE);

void setup()  
{  
  irrecv.enableIRIn(); // Start the ir receiver
  gw.begin(incomingMessage,254);

  // Send the sketch version information to the gateway and Controller
  gw.sendSketchInfo("IR Sensor", "1.1");

  // Register a sensors to gw. Use binary light for test purposes.
  gw.present(CHILD_1, S_IR);

  Serial.println("Ready to receive...");
}


void loop() 
{
  gw.process();
  if (irrecv.GetResults(&decoder)) {
    Hash_Decoder.copyBuf(&decoder);//copy the results to the hash decoder
    //decoder.decode();
    //decoder.DumpResults();
    Hash_Decoder.decode();
    if (!FindHashInOurTable(Hash_Decoder.hash)) {
      Serial.print("Unknown IR hash received: ");
      Serial.println(Hash_Decoder.hash, HEX);
    }
    else
    {
      Serial.print("Known IR hash received: ");
      Serial.println(Hash_Decoder.hash, HEX);
      gw.send(msgir.set(Hash_Decoder.hash));
    }
    
    delay(1000);
    irrecv.resume(); 

/*    
    char buffer[10];
    sprintf(buffer, "%08lx", decoder.value);
    // Send ir result to gw
    Serial.println(buffer);
    //gw.send(msg.set(buffer));
*/    
  }
}

bool FindHashInOurTable(const unsigned long hash)
{
  for (int ii=0; ii<MYCODES_LENGTH; ii++)
  {
    if (myHashes[ii]==hash)
      return true;
  }
  return false;
}

void incomingMessage(const MyMessage &message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.type==V_IR_SEND) {
     unsigned long ir_code=(unsigned long)message.getLong();
     Serial.print("Gateway received code: ");
     Serial.println(ir_code, HEX);
     //irsend.send(NEC, ir_code, 32); // Vol up yamaha ysp-900
     //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("");
}
*/
But of course when your remote is recognized, you can make your own sketch, and use the S_IR_RECEIVED / S_IR_SEND types[/quote]
Justintime
Posts: 228
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: IR Sender/Receiver built, now what?

Post by Justintime »

Is your "problem" solved?? As i run an older version of mysensors. I even cant remember which version i have now and i have lost the *.ino files of the currently installed nodes.
So i have to upgrade to 2.0 on all devices. But i would like the way i it was.

remb0 wrote:Do you have this sketch also in a 2.0 sketch?
I tried to modify it so it worked in my 2.0 config, but got lots of compile errors :P

when compiling i got no errors or warnings. but when uploading to my uno i got:

Code: Select all

Using library MySensors at version 2.0.0 in folder: C:\Users\remco\Documents\Arduino\libraries\MySensors 
Using library SPI at version 1.0 in folder: C:\Users\remco\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\libraries\SPI 
Using library IRLib-master in folder: C:\Users\remco\Documents\Arduino\libraries\IRLib-master (legacy)

Sketch uses 15,090 bytes (46%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,195 bytes (58%) of dynamic memory, leaving 853 bytes for local variables. Maximum is 2,048 bytes.
Invalid library found in C:\Users\remco\Documents\Arduino\libraries\IRSensor: C:\Users\remco\Documents\Arduino\libraries\IRSensor
Invalid library found in C:\Users\remco\Documents\Arduino\libraries\IRSensor: C:\Users\remco\Documents\Arduino\libraries\IRSensor
[\code]



[quote="gizmocuz"]some heads up:

in the latest beta i implemented the mysensors S_IR_RECEIVE and S_IR_SEND

going to make two posts

Post 1:

When playing with the IR sample, i noticed that 99% of my remote buttons where not recognized, i only received pulsed, instead of a code

So.... i look at the IR library, and it has a nice example to make a 32bit hash of the received IR pulses.
This proves to be working very good ! ;)

I made a new sketch, that is using this hash code, and send it to domoticz (S_IR_RECEIVE)
A new switch (type mdremote) is created, and you can use this for example as the activation code of a scene

Next, when setting the type of the switch to 'push on' (as it is only received) you can also push the button in domoticz, and it will send the code to the sketch (S_IR_SEND)

you can do what you want with it

The sketch is:

[code]/**
 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad <[email protected]>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 *******************************
 *
 * REVISION HISTORY
 * Version 1.0 - Henrik EKblad
 * 
 * DESCRIPTION
 * 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
 * http://www.mysensors.org/build/ir
 */

#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;
IRdecodeHash Hash_Decoder;

//As some remotes could have different hashes for the same button (when they are not good received or other reasons)
//we only let the following hashes go through

#define MYCODES_LENGTH 2
const unsigned long myHashes[MYCODES_LENGTH]={
  0x0BE3BB37, //volume up
  0xD4D9F2A7, //volume down
};

//decode_results results;
MySensor gw;
MyMessage msgir(CHILD_1, V_IR_RECEIVE);

void setup()  
{  
  irrecv.enableIRIn(); // Start the ir receiver
  gw.begin(incomingMessage,254);

  // Send the sketch version information to the gateway and Controller
  gw.sendSketchInfo("IR Sensor", "1.1");

  // Register a sensors to gw. Use binary light for test purposes.
  gw.present(CHILD_1, S_IR);

  Serial.println("Ready to receive...");
}


void loop() 
{
  gw.process();
  if (irrecv.GetResults(&decoder)) {
    Hash_Decoder.copyBuf(&decoder);//copy the results to the hash decoder
    //decoder.decode();
    //decoder.DumpResults();
    Hash_Decoder.decode();
    if (!FindHashInOurTable(Hash_Decoder.hash)) {
      Serial.print("Unknown IR hash received: ");
      Serial.println(Hash_Decoder.hash, HEX);
    }
    else
    {
      Serial.print("Known IR hash received: ");
      Serial.println(Hash_Decoder.hash, HEX);
      gw.send(msgir.set(Hash_Decoder.hash));
    }
    
    delay(1000);
    irrecv.resume(); 

/*    
    char buffer[10];
    sprintf(buffer, "%08lx", decoder.value);
    // Send ir result to gw
    Serial.println(buffer);
    //gw.send(msg.set(buffer));
*/    
  }
}

bool FindHashInOurTable(const unsigned long hash)
{
  for (int ii=0; ii<MYCODES_LENGTH; ii++)
  {
    if (myHashes[ii]==hash)
      return true;
  }
  return false;
}

void incomingMessage(const MyMessage &message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.type==V_IR_SEND) {
     unsigned long ir_code=(unsigned long)message.getLong();
     Serial.print("Gateway received code: ");
     Serial.println(ir_code, HEX);
     //irsend.send(NEC, ir_code, 32); // Vol up yamaha ysp-900
     //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("");
}
*/
But of course when your remote is recognized, you can make your own sketch, and use the S_IR_RECEIVED / S_IR_SEND types
[/quote]
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: IR Sender/Receiver built, now what?

Post by remb0 »

I gave up. and uses a broadlink rm3 mini as alternative.
Justintime
Posts: 228
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: IR Sender/Receiver built, now what?

Post by Justintime »

Hey, that's a nice looking smart device. Very interesting.... saw on another thread that you will test and make a tutorial.
Where can i find this?
And does it work flawless?
remb0 wrote:I gave up. and uses a broadlink rm3 mini as alternative.
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: IR Sender/Receiver built, now what?

Post by remb0 »

true! it's a nice device but no api. somebody from openhab made a nice script and howto.
I used it and it works nice. but the way you intercept codes for using in a domoticz script is a lot of work. :P
Justintime
Posts: 228
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: RE: Re: IR Sender/Receiver built, now what?

Post by Justintime »

remb0 wrote:true! it's a nice device but no api. somebody from openhab made a nice script and howto.
I used it and it works nice. but the way you intercept codes for using in a domoticz script is a lot of work. :P
What exactly do you mean with the last part?
I just want a switch in Domoticz which I can use wit hopefully a blocky or something.

So bottom line there isn't a device (except mysensors) who can control Domoticz by IR commands.
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: IR Sender/Receiver built, now what?

Post by remb0 »

mysensors indeed or a more expensive and complex methode: http://domoticz.com/forum/viewtopic.php ... 199#p97199
Justintime
Posts: 228
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: IR Sender/Receiver built, now what?

Post by Justintime »

I am investigating if Lirc in combination with a rasp 1 can work.
Ordered a ir led and a I have a rasp 1 catching dust. So I will try that.
remb0 wrote:mysensors indeed or a more expensive and complex methode: http://domoticz.com/forum/viewtopic.php ... 199#p97199
Justintime
Posts: 228
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: IR Sender/Receiver built, now what?

Post by Justintime »

Took the courage to update to the 2.0 serial gateway and the IR sender.

But it was easier than i thought its working great....

Just read out the ir signal, put it in the sketch. In Domoticz Allow new hardware, give the IR command and there is a new switch available.
domogijs
Posts: 99
Joined: Monday 17 August 2015 23:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: RE: Re: IR Sender/Receiver built, now what?

Post by domogijs »

Justintime wrote:Took the courage to update to the 2.0 serial gateway and the IR sender.

But it was easier than i thought its working great....

Just read out the ir signal, put it in the sketch. In Domoticz Allow new hardware, give the IR command and there is a new switch available.
I don't understand which hardware do you use?
Raspberry Pi3, RFlink, PiZigate, Yeelight, klikaanklikuit, Kodi, harmony hub, Zwave, ThermoSmart, XiaomiGateway (Aqara), Google home hub, roomba,
marcelr
Posts: 42
Joined: Friday 22 May 2015 21:10
Target OS: Linux
Domoticz version: svn 2470
Location: Ehv, NL
Contact:

Re: IR Sender/Receiver built, now what?

Post by marcelr »

Maybe slightly off-topic, years ago I bought this device:

http://www.iguanaworks.net/products/usb-ir-transceiver/

(prices have gone way up since I bought it :-()
Works out of the box on any linux box (my rooted samsung TV has driven it for years) with LIRC. Easy-peasy.

best,

marcelr
Justintime
Posts: 228
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: RE: Re: RE: Re: IR Sender/Receiver built, now what?

Post by Justintime »

domogijs wrote:
Justintime wrote:Took the courage to update to the 2.0 serial gateway and the IR sender.

But it was easier than i thought its working great....

Just read out the ir signal, put it in the sketch. In Domoticz Allow new hardware, give the IR command and there is a new switch available.
I don't understand which hardware do you use?
I use a mysensors Arduino nano for the gateway and an mysensors Arduino ir receiver for receiving IR Commands.

And a watermeter.

Must say it works great never let me down.

Look at the mysensors website for more information.
Last edited by Justintime on Tuesday 06 December 2016 22:52, edited 2 times in total.
domogijs
Posts: 99
Joined: Monday 17 August 2015 23:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: RE: Re: RE: Re: RE: Re: IR Sender/Receiver built, now what?

Post by domogijs »

Justintime wrote:
domogijs wrote:
Justintime wrote:Took the courage to update to the 2.0 serial gateway and the IR sender.

But it was easier than i thought its working great....

Just read out the ir signal, put it in the sketch. In Domoticz Allow new hardware, give the IR command and there is a new switch available.
I don't understand which hardware do you use?
I use a mysensors Arduino nano for the gateway and an mysensors Arduino ir receiver for receiving IR Commands.

Look at the mysensors website for more information.

Verstuurd vanaf mijn LG-H815 met Tapatalk
thanks!
Raspberry Pi3, RFlink, PiZigate, Yeelight, klikaanklikuit, Kodi, harmony hub, Zwave, ThermoSmart, XiaomiGateway (Aqara), Google home hub, roomba,
extremeaudio
Posts: 47
Joined: Tuesday 24 November 2020 17:57
Target OS: Linux
Domoticz version:
Contact:

Re: IR Sender/Receiver built, now what?

Post by extremeaudio »

Hi guys, sorry if there is an updated solution but I cant find it. I am looking for the simplest IR receiver that I can use with domoticz so that I can use an IR remote to trigger actions in domoticz - press button on my TV remote and trigger a switch or scene in Domoticz. Something plug and play that domoticz recognizes would be great. I am not very comfortable or knowledgeable about arduino. Any help is appreciated!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest