Help with Rfxcom & Node.js

Forum about MQTT, machine-to-machine (M2M), "Internet of Things" and Node.js

Moderators: Digit, Rene, Willem4ever, Bwired

Help with Rfxcom & Node.js

Postby bslo » Mon May 12, 2014 8:00 pm

Hi everybody,

Last week i started converting my domotica system from python to node.js. Almost all modules are now over to the new system (energy, opentherm gateway, raspberry pi gpio etc) but the last one, the rfxcom is giving me some problems. The reading of the device is no problem. I use some of the code of https://github.com/bigkevmcd/node-rfxcom. The receiver end is working: "0A,52,01,01,D9,04,00,C4,3D,00,79" and converted its: "10, 82, 1, 1, 217, 4, 0, 196, 61, 0, 121" and i can processes it. But the problem for me is sending data to the device.

I have all the on/off codes for my devices stored in a file like: BED_LIGHT_CMD_1= 0710020041020100, BED_LIGHT_CMD_0= 0710020041020000. In python I use serialport.write( cmd.decode('hex')) and signal is processed by the rfxcom and the light turn on/off. I would like to use this system also in node.js but i am unable to convert the commando correct for the rfxcom. I have tried a lot of different conversions to hex but none of them seems to be working.

Is there anybody who can point me in the right direction? :D tnx
bslo
Starting Member
Starting Member
 
Posts: 2
Joined: May 2014

Re: Help with Rfxcom & Node.js

Postby Digit » Mon May 12, 2014 9:58 pm

This is how I send data to my RFXCOM transmitter, where data can be a variable like your '0710020041020100'.
I put it in an array and fill a Buffer with it:
Code: Select all
  if(data.length %2 != 0) {
    logger.error('Invalid command length');
    return;
  }
  var txdata = [];
  while(data.length > 0) {
    b = parseInt(data.substr(0,2), 16);
    txdata.push(b);
    data = data.substring(2);
  }
  txbuff = new Buffer(txdata, 'hex'); 
  client.write(txbuff);
User avatar
Digit
Global Moderator
Global Moderator
 
Posts: 3388
Joined: March 2006
Location: Netherlands

Re: Help with Rfxcom & Node.js

Postby bslo » Tue May 13, 2014 6:05 pm

Ok i have it working now :D So the rfxcom wants the code broken up and converted to a "programmers" HEX value.

The message needs to be formatted like :cmd = [0x0B ,0x11 ,0x01 ,0xB6 ,0x01 ,0x11 ,0x0A ,0x0A ,0x04 ,0x00 ,0x0F ,0x00]. This can be send to the device directly: serialport.write(cmd).
bslo
Starting Member
Starting Member
 
Posts: 2
Joined: May 2014


Return to MQTT & Node.js

Who is online

Users browsing this forum: No registered users and 1 guest

cron