Use Node-Red to Allow Multiple Connections to Ethernet Gateway?
-
-
Wondering if you got anywhere with this? I was planning on moving to the MQTT Gateway and was wondering if Node-Red would provide TCP connectivity for various controllers as MQTT isn't widely supported etc.
but this sounds like it could work as well?
@Qu3Uk said:
Wondering if you got anywhere with this?
No, not yet. I need to play with it some more. If you're using an serial gateway on a Raspberry Pi it should be working using @tbowmo's setup. I still need to play with @Anticimex's setup to see if I can get Ethernet working in the method described above. I think the key is socat but I just have been working on other projects. Never enough time!
-
I'm loving nodered more and more now. It's so easy to route messages around, and transforming them to suit different things.
I'm still using domoticz as controller, but with nodered I have fixed a "bug" where domoticz have inverted the state of V_LOCK. And I'm able to send sensor data to influxdb as well, and advanced graphs created with grafana.
I have a non mysensor arduino reporting usage from my electricity meter. Nodered is transforming the data to mysensors protocol and injects the data into the mysensors stream towards domoticz and influxdb.
I can also emulate sensors, and new types, in order to check if a given controller is capable of understanding the sensor messages (used it to test some new features in domoticz)
So nodered is a kind of Swiss army knife. It can do almost everything :)
-
So I'm pretty sure you can't do what you're trying to do with TCP as NodeRed can't listen on a port multiple times. It seems to see it as two connections as opposed to one connection and accessing that connections input/output.
I guess this might be a security thing because you could use NodeRed as a man in the middle and do all sorts.. which is what we're trying do it. Sit between the gateway and the controllers and do awesome stuff.
I'm sure "To Vera" in your code @petewill needs to listen on the same port "From Vera" is however if you do this you'll only be able to connect to one of the nodes. Once connected the other node will throw a port in use error.
Also I'm pretty sure it's using two connections to the MYS gateway which should be fine as mine seems to handle two connections but if your using nodeRed and have something else directly connected to the GW you may have problems.
I was looking to have NR pretend to be an ethernet gateway and convert MQTT messages back and forth down a TCP connection. Seems it's not the tool for the job.
-
So I'm pretty sure you can't do what you're trying to do with TCP as NodeRed can't listen on a port multiple times. It seems to see it as two connections as opposed to one connection and accessing that connections input/output.
I guess this might be a security thing because you could use NodeRed as a man in the middle and do all sorts.. which is what we're trying do it. Sit between the gateway and the controllers and do awesome stuff.
I'm sure "To Vera" in your code @petewill needs to listen on the same port "From Vera" is however if you do this you'll only be able to connect to one of the nodes. Once connected the other node will throw a port in use error.
Also I'm pretty sure it's using two connections to the MYS gateway which should be fine as mine seems to handle two connections but if your using nodeRed and have something else directly connected to the GW you may have problems.
I was looking to have NR pretend to be an ethernet gateway and convert MQTT messages back and forth down a TCP connection. Seems it's not the tool for the job.
-
@Qu3Uk Thanks for the reply. Did you try SOCAT at all? I was hoping that would help. I haven't had a chance to do anything with this recently though.
-
It should be possible to setup a socat socket converting the tcp stream into a virtual serialport, that could be used within NodeRed as a standard serial port in / out unit. I haven't tried that part yet though, as I'm not using a ethernet GW on my production system. I could set one up though, as I have a development version of the upcomming mysensors GW device (which also is ethernet enabled)
I'll see if I can get the time to look into it, the comming days..
-
It should be possible to setup a socat socket converting the tcp stream into a virtual serialport, that could be used within NodeRed as a standard serial port in / out unit. I haven't tried that part yet though, as I'm not using a ethernet GW on my production system. I could set one up though, as I have a development version of the upcomming mysensors GW device (which also is ethernet enabled)
I'll see if I can get the time to look into it, the comming days..
-
It should be possible to setup a socat socket converting the tcp stream into a virtual serialport, that could be used within NodeRed as a standard serial port in / out unit. I haven't tried that part yet though, as I'm not using a ethernet GW on my production system. I could set one up though, as I have a development version of the upcomming mysensors GW device (which also is ethernet enabled)
I'll see if I can get the time to look into it, the comming days..
-
So I had a go at using SOCAT and although it's working it doesn't seem to like multiple connections on the TCP port. Although it will accept the connection it seems to output data from Serial>Ethernet is a round robin kind of way.
Reason I had two connections to it was to ensure the pipe was always read as the other post it was mentioned if the pipe isn't cleared there would be memory problems and I noticed not all the data was getting to all the TCP connections..
Anyway here is the code if you want to check it out.
Socat
sudo socat PTY,link=/dev/ttyS81,mode=666,group=dialout,raw TCP-LISTEN:40501,fork,reuseaddr & sudo socat PTY,link=/dev/ttyS82,mode=666,group=dialout,raw TCP-LISTEN:40502,fork,reuseaddr &NodeRead
[{"id":"e9998a90.266cc8","type":"serial-port","z":"a89027d9.b1ef08","serialport":"/dev/ttyS82","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":true},{"id":"ee7d4fbe.58c5f","type":"serial-port","z":"a89027d9.b1ef08","serialport":"/dev/ttyS81","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":true},{"id":"50839f8a.fbcaa","type":"debug","z":"a89027d9.b1ef08","name":"Full-Debug","active":true,"console":"false","complete":"true","x":595,"y":575,"wires":[]},{"id":"d5b18044.18e1f","type":"tcp in","z":"a89027d9.b1ef08","name":"MYS-GW-OUT","server":"client","host":"192.168.1.150","port":"5003","datamode":"stream","datatype":"utf8","newline":"\\n","topic":"MYS-GW-Output","base64":false,"x":103,"y":963,"wires":[["db05059b.37e4e8","4f3b7e79.739e6"]]},{"id":"c462686d.bb5a78","type":"catch","z":"a89027d9.b1ef08","name":"","scope":null,"x":387,"y":574,"wires":[["50839f8a.fbcaa"]]},{"id":"9fdda3da.86eb7","type":"debug","z":"a89027d9.b1ef08","name":"PayloadDebug","active":true,"console":"false","complete":"payload","x":584,"y":666,"wires":[]},{"id":"db05059b.37e4e8","type":"serial out","z":"a89027d9.b1ef08","name":"ControllerOne-Out","serial":"ee7d4fbe.58c5f","x":619,"y":875,"wires":[]},{"id":"75f6db75.bba3c4","type":"serial in","z":"a89027d9.b1ef08","name":"ControllerOne-IN","serial":"ee7d4fbe.58c5f","x":103,"y":894,"wires":[["6bbbe087.e897"]]},{"id":"6bbbe087.e897","type":"tcp out","z":"a89027d9.b1ef08","host":"192.168.1.150","port":"5003","beserver":"client","base64":false,"end":false,"name":"MYS-GW-IN","x":605,"y":949,"wires":[]},{"id":"4f3b7e79.739e6","type":"serial out","z":"a89027d9.b1ef08","name":"ControllerTwo-Out","serial":"e9998a90.266cc8","x":625,"y":1044,"wires":[]},{"id":"73b94814.883c88","type":"serial in","z":"a89027d9.b1ef08","name":"ControllerTwo-IN","serial":"e9998a90.266cc8","x":104,"y":1045,"wires":[["6bbbe087.e897"]]},{"id":"8121ed9b.ba597","type":"tcp in","z":"a89027d9.b1ef08","name":"ControllerOne-TCP-Out","server":"client","host":"127.0.0.1","port":"40501","datamode":"stream","datatype":"utf8","newline":"\\n","topic":"","base64":false,"x":151,"y":731,"wires":[["9fdda3da.86eb7"]]}]