RFXtrx433 communicating within linux

Forum about Rfxcom home automation Domotica devices.

Moderator: b_weijenberg

Post Reply
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

RFXtrx433 communicating within linux

Post by rbmace2403 »

Hello,

Maybe somebody can help me with the RFXtrx433, I am building my own home automation software within PHP. I've built a plugin/driver for RFXtrx433 in php on Windows Webserver. This was working great, I could read everything from the USB RFX unit. But I changed to a linux server, because php is more stable on Linux. But after i made the switch to linux the driver is reporting incorrect HEX strings from the the RFXtrx433, mainly the oregon Temp sensors. It seems that not all bytes are received or some are lost in the communication from the USB. So the bytes length is 9 instead of 10. If I connect the unit to windows again with the same software version its working great, but with linux I get errors.

I am using the FTDI_sio driver for the USB connection on CENTOS. I have set the communication with the following setting:

/bin/stty -F /dev/ttyUSB0 38400 cs8

I have been trying to get this working for a few weeks now, and I honestly dont know what I am doing wrong? I hope somebody have an idea what im doing wrong :-)

Regards

Ronald
Stevexyz
Member
Member
Posts: 87
Joined: Fri Dec 14, 2007 1:45 am
Location: United Kingdom
Contact:

Re: RFXtrx433 communicating within linux

Post by Stevexyz »

Can you post the code that you are using to read from the RFXtrx433?

I have an RFXCOM receiver and I write in C but I might be able to see if there's anything wrong.

Cheers, Steve
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: RFXtrx433 communicating within linux

Post by rbmace2403 »

Hi,

The code could be better written, but main idea is to get it working. I have more code for all other sensors, but the 0A 52 (temp sensors) give the most problems.
Thanks for checking out the code!

Ronald

Code: Select all

$fp=fopen("/dev/ttyUSB0", "w+");
while (1) {
$data=fread($fp, 1);
if(!empty($data)) {
  $n=dechex(ord($data[0]));	
  $message=strtoupper(str_pad($n,2,"0",STR_PAD_LEFT));
  if ($message=="0A") {
  for ($i=0; $i<10; $i++) {
     $data2=fread($fp, 1);
     $n=dechex(ord($data2));
     $c=strtoupper(str_pad($n,2,"0",STR_PAD_LEFT));
     $message.=$c;        	
  }
  echo $message;	
}
RobertF
Starting Member
Starting Member
Posts: 7
Joined: Wed Aug 29, 2012 10:41 pm

Re: RFXtrx433 communicating within linux

Post by RobertF »

I'm currently looking to communicate with the rfxtrx433 on linux command line, out of interest Ronald, would your setup permit single bash commands to send/receive via the unit?
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: RFXtrx433 communicating within linux

Post by rbmace2403 »

Hi Robert,

Yes I can do that in the software, but how do you read constantly for incoming message through bash commands? And sending commands while receiving? I am curious how you can interact through the rfxtrx?

Ronald
RobertF
Starting Member
Starting Member
Posts: 7
Joined: Wed Aug 29, 2012 10:41 pm

Re: RFXtrx433 communicating within linux

Post by RobertF »

well I'm currently looking at fhem and xpl-perl as possible solutions to command line interaction. Fhem might be more than I need and I've yet to test xpl-perl.
Stevexyz
Member
Member
Posts: 87
Joined: Fri Dec 14, 2007 1:45 am
Location: United Kingdom
Contact:

Re: RFXtrx433 communicating within linux

Post by Stevexyz »

1. You might want to add a raw into your stty or see if php has any access to termios
2. Once you have read the number of bytes you expect, what happens if you try to read them all in one call to fread?
3. Does the RFXtrx433 have any equivalent of 32-bit or variable-length mode? Have you got the baud rate right?
4. In /sys/bus/usb-serial/devices/ttyUSB0 there's a file called latency_timer. It's how long in milliseconds the FTDI device will wait before transmitting an incomplete buffer. You may be able to write to this and vary it from 1ms to 250ms or so.

Cheers, Steve
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: RFXtrx433 communicating within linux

Post by rbmace2403 »

-1. I will try this later this evening
-2. I had this option, but because some bytes are lost I started to read 1 byte at a time
-3. The baud rate is ok according the manual, the 32bit or variable-length mode I need to check
-4. I will check this as well, didnt know this was possible :-)

Thanks for your help, and I will let you know what the results are.

Ronald
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: RFXtrx433 communicating within linux

Post by rbmace2403 »

Hi Steve,

Well i succeeded, it was the option raw within stty. Apparently without this option some bytes get lost while receiving.
The command I used for linux is : /bin/stty -F /dev/ttyUSB0 38400 cs8 raw

Thanks for pointing me to the right direction, so everything is working fine now on linux :-)

Ronald
Stevexyz
Member
Member
Posts: 87
Joined: Fri Dec 14, 2007 1:45 am
Location: United Kingdom
Contact:

Re: RFXtrx433 communicating within linux

Post by Stevexyz »

Excellent!
ssjoholm
Starting Member
Starting Member
Posts: 3
Joined: Mon Sep 17, 2012 8:23 pm

Re: RFXtrx433 communicating within linux

Post by ssjoholm »

Hi,

You can also try this python script, it is quite easy to run it from the PHP with exec()

http://code.google.com/p/rfxcmd/

The released version does not have send functionality, but I have a beta which is in testing that you can have if you send me a PM.

Regards,
Sebastian
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: RFXtrx433 communicating within linux

Post by rbmace2403 »

Hi Sebastian,

I have created my own php class for this which can do almost everything for the RFXCOM, but linux was loosing some bits on the serial port without the option raw from stty. So my code was working ok :-)

But thanks for your post!

Regards

ronald
michal001
Starting Member
Starting Member
Posts: 2
Joined: Fri Sep 28, 2012 12:58 pm

Re: RFXtrx433 communicating within linux

Post by michal001 »

Maybe somebody can help me with the RFXtrx433, I am building my own home automation software within PHP. I've built a plugin/driver for RFXtrx433 in php on Windows Webserver. This was working great, I could read everything from the USB RFX unit. But I changed to a linux server, because php is more stable on Linux. But after i made the switch to linux the driver is reporting incorrect HEX strings from the the RFXtrx433, mainly the oregon Temp sensors. It seems that not all bytes are received or some are lost in the communication from the USB. So the bytes length is 9 instead of 10. If I connect the unit to windows again with the same software version its working great, but with linux I get errors.
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: RFXtrx433 communicating within linux

Post by rbmace2403 »

Have you run this command for linux? Because this solved my problem like i mentioned in this post.

"/bin/stty -F /dev/ttyUSB0 38400 cs8 raw"
Post Reply

Return to “Rfxcom Receivers & Transmitters Forum”