IP Gateway based on ncat + socat + USB
-
I have been trying out different controllers (I use domoticz right now and have for a while). Having a TCP/IP based gateway like the ESP8266 is useful for this as you can have multiple clients connect to it, unlike a USB/Serial based one.
What I ended up doing was using ncat (nmap package) and socat in this manner to basically create a linux based version of a TCP/IP based gateway. So I can use the USB/Serial based gateways here.
So far this seems to work with mysensors and rflink very well for me (run two instances for each serial port and tcp port. I did not find much info on this when I was googling around so I thought I would share:
#!/bin/bash port=5003 serial=/dev/ttyUSB0 baudrate=b38400 ncat --listen --broker --keep-open 0.0.0.0 $port & socat $serial,$baudrate TCP:127.0.0.1:$port &
My plan is to shove this on a pi zero w on start up with my rflink and mysensors gateways attached. Then I can just tell my controller(s) to connect to my 'gateway box' over my network. I could probably put it into a docker container or systemd/init script to do things a little cleaner(&) but hey, it works.
-
What USB gateways are you using?
-
Standard USB MySensors gateway (Arduino Nano based) and an RFLink gateway(Arduino Mega based).
-
The raspberry gateway isn't supported on the Pi zero?
-
I actually didn't know that raspberry pi gateway was a thing! nice, i'll have to try that. I have been using a USB one since 1.5. I guess what i'm doing here is just more generic.
I have it running on an orange pi one right now and it's fine. I plan to move it to a r-pi zero w when I have some time. Perhaps put it all in a project box and place it strategically in the house.
To explain a little bit about what I did: A problem with socat I had was it seemed to garble the serial data between connected clients, making it useless with more than 1 client(I don't think that's a socat issue though, I think that's because more than one process is trying to access the tty device at once). Ncat fixes that by just repeating anything pushed into it to all connected clients. So it's ttyUSB0/1 <> socat <> ncat <> One of more clients.
Hopefully it's useful for people.