With the help of gizmocuz's and blitzkneisser's sketches I was able to integrate Aldi's robot vacuum cleaner (model number KSR RVC3000) into Domoticz. This particual model has IR receiver and a remote to control it.
The challenge was the following:
1. the IR protocol is not common one, so had to use RAW values.
2. to start with the remote, you have assign the CLEAN command twice.
The basics are written in these topics:
http://domoticz.com/forum/viewtopic.php?f=42&t=7648
http://domoticz.com/forum/viewtopic.php?f=42&t=10678
Gizmocuz had the brilliant idea to assign a hash to the raw values. In theory one can use this method to control almost everything.
Below the working sketch, there's a 3 sec delay between the two CLEAN commands.
Code: Select all
#include <MySensor.h>
#include <SPI.h>
#include <IRLib.h>
#include <avr/pgmspace.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_NUM 6
#define MYCODES_LENGTH 24
const unsigned long myHashes[MYCODES_NUM] = {
0x52A3E788, // Be
};
const unsigned int myCodes[MYCODES_NUM][MYCODES_LENGTH] PROGMEM ={
4520,4332,592,484,592,1572,600,512,564,1568,596,520,556,1576,596,488,584,472,4508,4332,596,516,564,1600,568,484,592,1576,592,488,592,1568,596,476,596,480,4504,4328,596,484,596,1568,600,516,560,1568,604,480,596,1572,596,476,596,500,4484,4360,564,516,564,1572,596,476,600,1628,540,540,536,1576,588,480,600,464,4516,4328,596,484,596,1628,540,484,592,1572,596,484,596,1572,592,536,540};
int idx; // has index in table
//decode_results results;
MySensor gw;
MyMessage msgir(CHILD_1, V_IR_RECEIVE);
void setup()
{
irrecv.enableIRIn(); // Start the ir receiver
gw.begin(incomingMessage,AUTO,true);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("IR Transceiver", "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
Hash_Decoder.decode();
if (!FindHashInOurTable(Hash_Decoder.hash, &idx)) {
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();
}
}
bool FindHashInOurTable(const unsigned long hash, int * idx)
{
for (int ii=0; ii<MYCODES_NUM; ii++)
{
if (myHashes[ii]==hash)
{
* idx = ii; // store index value
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);
if (FindHashInOurTable(ir_code, &idx)) {
unsigned int tempdata[24];
Serial.print("Data to send(");
Serial.print(idx, HEX);
Serial.print("): {0x");
for (int i=0;i<24;i++)
{
tempdata[i] = pgm_read_word_near(myCodes[idx] + i);
Serial.print(tempdata[i], HEX);
if (i < 23)
Serial.print(",0x");
else
Serial.println("}");
}
for (int j=1;j<=4;j++) { //send it multiple times
irsend.IRsendRaw::send((unsigned int *)tempdata, 24, 38);
delay(15); //wait 15ms
}
delay(3000); //wait 3s
for (int j=1;j<=4;j++) { //send it multiple times
irsend.IRsendRaw::send((unsigned int *)tempdata, 24, 38);
delay(15); //wait 15ms
}
irrecv.enableIRIn();
}
}
}