maxwellhadley / node-red-contrib-rfxcom

node-RED nodes to access an RFXtrx433 transceiver
BSD 2-Clause "Simplified" License
22 stars 13 forks source link

rfx-sensor node shows 'connecting...' but doesn't connect #114

Open mjf2708 opened 3 years ago

mjf2708 commented 3 years ago

I've got an RFXtrx433E running on RPi #1 (receiving temperature & humidity sensors, and connected to Domoticz), and I've shared the USB port with RPi #2 - which is where I run Node-RED - using ser2net and socat. I'm sure that the USB port is created on RPi #2, as tail -f /var/log/socat.log continues to show bytes transferred.

I've created a simple Node-RED flow using rfx-sensor, with the serial port as the USB port created by socat. However, the rfx-sensor node continues to show 'connecting...' and doesn't actually connect.

Any clues, please?

maxwellhadley commented 3 years ago

This sounds like the 'remoted' serial port is not being recognised by the serialport package, which is the component that handles communication with the RFX hardware. You might try searching on the serialport github page for any similar issues.

Can you please enable debug on the RFX port you are using (in Node-RED), and post the output? It should look something like this:

18 Mar 10:26:29 - [info] Starting flows
18 Mar 10:26:29 - [info] Started flows
18 Mar 10:26:29 - [info] [rfx-detector-in:c36c9483.3f59a8] connecting to /dev/tty.usbserial-A1R1A6A
2021-03-18 10:26:35.434 [rfxcom] on /dev/tty.usbserial-A1R1A6A - Sent    : 0D,00,00,00,00,00,00,00,00,00,00,00,00,00
2021-03-18 10:26:35.940 [rfxcom] on /dev/tty.usbserial-A1R1A6A - Sent    : 0D,00,00,01,02,00,00,00,00,00,00,00,00,00
2021-03-18 10:26:35.957 [rfxcom] on /dev/tty.usbserial-A1R1A6A - Received: 14,01,00,01,02,53,2B,28,00,24,00,01,03,1C,05,4C,00,00,00,00,00
2021-03-18 10:26:35.958 [rfxcom] on /dev/tty.usbserial-A1R1A6A - Sent    : 0D,00,00,02,07,00,00,00,00,00,00,00,00,00
2021-03-18 10:26:36.083 [rfxcom] on /dev/tty.usbserial-A1R1A6A - Received: 14,01,07,02,07,43,6F,70,79,72,69,67,68,74,20,52,46,58,43,4F,4D
2021-03-18 10:26:36.083 [rfxcom] on /dev/tty.usbserial-A1R1A6A - Copyright RFXCOM
2021-03-18 10:26:36.083 [rfxcom] on /dev/tty.usbserial-A1R1A6A - Started command message queue
18 Mar 10:26:36 - [info] [rfx-detector-in:c36c9483.3f59a8] connected: Serial port /dev/tty.usbserial-A1R1A6A

If not, it may give us a clue where the failure is coming from

mjf2708 commented 3 years ago

I've attached a debug node to rfx-sensor, but I'm not seeing any debug messages. If I enter 'node-red-log' in the console, I get: 18 Mar 16:34:53 - [info] Starting flows 18 Mar 16:34:53 - [info] Started flows and nothing else.

EDIT: it seems that the baud rate (115200) I was using to share the USB port was 'too fast' for the RFXCOM! I've now changed it to 38400, and the serial-in node is now displaying raw data in debug messages, whereas rfx-sensor still shows 'connecting...' EDIT(2): I'm also seeing messages in /var/log/socat.log (which appear to correspond in length to the debug messages in Node-RED.

maxwellhadley commented 3 years ago

serial-in node? Do you mean a Node-RED serial-in node? You can't have two nodes connect to the same serial port at the same time, at least not as far as I know. How are you turning the RPi 2 end of the socat link back into a (simulated) serial port?

mjf2708 commented 3 years ago

OK, look like I'm in business now. I removed the Node-RED serial-in node, and I set the baud rate for the RFXCOM on RPi #1 to 38400. I'm now seeing output similar to that in your first reply, and by adding a debug node for msg.topic I'm seeing device id's, e.g., TH1/0xBF02.

For info, I set the following parameters for socat on RPi #2 as follows: OPTIONS="pty,link=/dev/ttyUSB0,raw,user=root,group=dialout,mode=777 tcp:192.168.0.63:3333,forever,reuseaddr,keepalive"

I can now do some filtering on device id, and create my MQTT messages.

Thanks for your help.

mjf2708 commented 3 years ago

(closed in error)

maxwellhadley commented 3 years ago

OK it looks like you are getting somewhere. If you can make it work properly, it would be nice if you can document how to set up ser2net and socat so as to successfully remote an RFX over the network. I have had enquiries about this before, but I didn't know if it could be done: I could add your description to the documentation.

mjf2708 commented 3 years ago

I haven't completed my flow yet, but I've added a debug node showing msg.payload.temperature.value, and I'm getting regular temperatures displayed in the debug window, so I'm confident it's working. I got ser2net and socat working from this website: https://community.openhab.org/t/share-z-wave-dongle-over-ip-usb-over-ip-using-ser2net-socat-guide/34895 (although I don't use Zwave or OpenHAB!), but I'll happily document what I did.

EDIT: I don't have a blog, etc., so are you happy for me to do this here?

maxwellhadley commented 3 years ago

Yes sure, just post it here: I'll edit it into the README file for the node - Many thanks!

mjf2708 commented 3 years ago

Method for sharing USB port for RFXtrx433E from RPi #1 for use with Node-RED package node-red-contrib-rfxcom on RPi #2.

RPi #1

Find USB port which RFXtrx433E is connected to: lsusb e.g., /dev/ttyUSB0 Install ser2net: sudo apt-get install ser2net configure ser2net: sudo nano /etc/ser2net.conf add following line: 3333:raw:0:/dev/ttyUSB0:38400 8DATABITS NONE 1STOPBIT (haven't tried RFXtrx433 at higher baud rates) restart ser2net: sudo systemctl restart ser2net check it's sharing the device - look for line containing 3333: netstat -antp

RPi #2

install socat: sudo apt-get install socat download and install an init.d script that allows socat to run as a service and auto-start at startup: git clone https://github.com/asaif/socat-init.git and run following commands: sudo cp socat-init/socat /etc/init.d/ sudo chmod +x /etc/init.d/socat sudo update-rc.d socat defaults sudo cp socat-init/defaults/socat.conf /etc/default/ configure socat: sudo nano /etc/default/socat.conf enter the following: OPTIONS="pty,link=/dev/ttyUSB0,raw,user=root,group=dialout,mode=777 tcp:<ip_of_RPi_#1>:3333,forever,reuseaddr,keepalive" (all on one line) then restart socat: sudo systemctl restart socat check the logs to see if connection was successful: tail -f /var/log/socat.log and check /dev to see if new ttyUSB0 device is listed: ls -al /dev/ttyUSB0

Hopefully this works OK - let me know of any issues.

maxwellhadley commented 3 years ago

Thanks - I will break out a couple of Pi's and give it a go when I get a chance, though that may not be for a week or two. I'm finally getting FTTP fibre Internet installed next Friday, so I will have many other toys to play with!

I can confirm the RFX must connect at 38400 Baud

dubbfredda commented 1 year ago

Hi, I also have a problem with the RFX-sensor node. I it will not connect image And I don't know how to debug it. Could somebody help me?