How to add a serial device to use in node-red
-
is /dev/ttyUSB20 your gateway device?
What I have done, is the following:
/dev/tty<gateway> <- nodered is connected to this one directly
then I have socat create a dummy set of serial ports
/dev/ttyS81 -> /dev/ttyUSB21Nodered connects to /dev/ttyS81 and domoticz connects to /dev/ttyUSB21
Now nodered is in the middle, between the gateway and your domoticz instance. You then need to create a flow in nodered, that moves data from your gateway, to domoticz, and vice versa. Start with a simple flow, that just connects input serial node, to an output serial node, and then build up on that.
Haven't got access to my nodered installation at the moment, so can't make any screenshots..
-
I tried (/dev/ttyUSB20 being the port used and created by the MySensors Gateway):
sudo socat PTY,link=/dev/ttyUSB21,mode=666,group=dialout,raw PTY,link=/dev/ttyUSB20,mode=666,group=dialout,raw(I found that Domoticz needs the port to be ttyUSB*).
I connected Domoticz to a MySensors Gateway USB on port /dev/ttyUSB21
And Node-RED to /dev/ttyUSB20But nothing worked: Domoticz did not see new data arrive and Node-RED didnt receive anything. I tried rebooting (and redo the socat dance), nothing happened.
I suppose my non-understanding of socat is the main cause of this failure.
So, I took the plunge and moved to a MySensors MQTT gateway. I had to reflash my sensors with a fixed unit_id (not sure if it's still a requirement), and voila.
Now I can play with Node-RED and try other controllers in parallel of Domoticz.
Thanks for the help.
-
here is my solution;
add a new udev rules file for permissions:
sudoedit /etc/udev/rules.d/50-usb-permissions.rulespaste the following in our new rules file:
(it gives all permission to any USB* and ACM* devices)KERNEL=="ttyUSB[0-9]*",MODE="0666" KERNEL=="ttyACM[0-9]*",MODE="0666"that's it. this will give you all the permissions to all usb devices on every boot. also you can reload udev instead of rebooting.
udevadm control --reload-rules
*** please note that this gives permissions to all USB* and ACM* devices.
if you're concerned about security you can add the following so that only the mentioned device will be accessable:
ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY"for example, in my case (output from dmesg):
[ 2654.037338] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523 [ 2654.037344] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0 [ 2654.037347] usb 1-1: Product: USB2.0-Serial [ 2654.038531] usb 1-1: ch341-uart converter now attached to ttyUSB0so, for me it's:
ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523"