Hi I am diving into the world of Mysensors and found out that they now also have a wifi gateway available. I don’t have the hardware for that gateway yet but I was wondering whether it is possible to redirect a serial port to a tcp-ip adress so we can use the mysensor plugin without the actual device attached to the usb port.
Quick check gave me the following command:
netcat ip_of_the_wifi_gateway 5003 < /dev/ttyS0
Can somebody confirm it would be that “easy”?
-
Mysensors WiFi Gateway
-
Should be possible with netcat or socat… if the tcp port of the mysensors wlan gateway also uses the “serial protocol”.
Currently i’m using the serial gateway for mysensors, not tested the wlan gateway yet… will probably try that later this year, after some other projects are finished. -
This is what is mentioned on the mysensors website:
•Any application capable of communicating with the regular MySensors Ethernet gateway should be able to communicate with the ESP Gateway
•Enjoy!
To verify things you can connect a telnet session (e.g. putty) to the IP address mentioned in the serial output, port 5003 and send some serial commands! -
Please report back if you get this running. I was trying to do it the other way around and bring my serial gw to network, with limited succes. At the end I decided to build a second gateway for OTA sketch updates with MYSController. But as stated in the MySensors forum this ESP GW would allow multiple connections.
-
Parts are just ordered, so let us hope our Chinese friends do a fast delivery.
-
Our chinese friends were fast this time. So today I have received the part and of course wired it to my laptop. And SUCCES!
I have added a script to the init.d directory containing the following line:( sudo /usr/bin/socat -d -d pty,link=/dev/ttyS0,raw,echo=0,waitslave tcp:192.168.178.56:5003 ) &
In the mysensors setup in pimatic I am now using the ttyS0 port and it works perfect.
-
Thanks a lot for the feedback @dynamite, mine are ordered, too. I am still waiting for them…
-
@Anduril I am also “investigating” the mysensor plugin. I have a remark on the github page but I am not sure that is the correct place to discuss. It is most probably not to hard to redirect the serial connection to a ip/port adress directly. This would make it more stable without the trick above.
-
@dynamite Just thinking out in the open and maybee a coffee specialist can comment me. Can’t the routine node-xbmc / src / TCPConnection.coffee by used in mysensors to make the connection to the node?
-
Best is to open a issue at https://github.com/DheerajKhajuria/pimatic-mysensors/issues. The board would need to be extended so that it can make a tcp connection instead of an serialport connection: https://github.com/DheerajKhajuria/pimatic-mysensors/blob/master/board.coffee#L80-L82
-
@sweetpi Thank for the info I have opened the issue at the site as indicated.
-
Hi @dynamite,
finally I got the time to play with the ESP and tried to use it as wifi gateway for MS. The gateway is running fine, but I have some problems connecting it to pimatic. As you wrote it works with your setup maybe you can give me a hint.
sudo /usr/bin/socat -d -d pty,link=/dev/ttyMS-Gateway,raw,echo=0,waitslave tcp:192.168.38.19:5003
gives me the tty device wich seems to work ok. When checking withsudo cat /dev/ttyMS-Gateway
I can see all messages arriving. So I think socat is working as expected.
I changed the config for mysensors plugin to the following:{ "plugin": "mysensors", "driver": "serialport", "protocols": "1.4.1", "driverOptions": { "serialDevice": "/dev/ttyMS-Gateway", "baudrate": 115200 }, "startingNodeId": 18 },
but I don’t see any data in pimatic. The mysensors devices simply don’t update. Could you please post your config of mysensors plugin?
-
OK solved the first part on my own. Problem was that after reading the socat tunnel with cat/dev/… the socat stops with
soclet 1 is at EOF, socket 2 is at EOF, exiting with status 0
, which might be as intended. After not looking at the tty-device I could connect pimatic to it and read the data of mysensors devices. But one problem still stands: when closing the connection, pimatic can not reconnect. So after updating and restarting pimatic, it will not connect to the gateway anymore. Is there a way to reopen socat directly after exiting with status 0? -
@Anduril Hi, you have experienced the same thing as I did and for now I have connected the my sensor directly to the pi via USB. I think it is better to change the plugin to make a connection and posted a request at github. I don’t think it will be that hard to do but my java / coffee knowledge is not sufficient.
-
Thats bad to hear because going back to serial gateway is no option for me. I need to have my gateway connectable y multiple clients to use MYSController for ota firmware updates. Maybe someone can tell me how to change the startup of pimatic to first initiate socat connection, wait few seconds and then start pimatic.
Otherwise I will have to wait for the update of the plugin to allow tcp connection, but I don’t think @Dheeraj is very active on this. -
is it possible to add this line for starting a socat tunnel to the pimatic file in /etc/init.d/ ? I would try, but I’m a beginner in linux and don’t want to crash my system by editing without knowledge… Is there a better way to create an autostart?
-
Hey there,
it’s me again asking for help with autostarting socat.
I talked with a friend who was using linux intensivly few years ago about the problem. He said the best thing to solve the problem in his eyes is to programm a little deamon script which checks if pimatic and socat are running and if not restart socat first and few seconds later pimatic. Sadly he is not familiar with programming a deamon any more and needs some time to read into that topic again. So I thought to ask here for help of someone who might also use the script.
To find out if pimatic is running we used the commandps -aux |grep pimatic |grep /usr/local/bin/pimatic
and this gives only one answer if it’s running and none if not.
For socat we tried to look for the serial device withls /dev/ttyMS-Gateway |grep cannot
which will give no answer if device exists and answerls: cannot access /dev/ttyMS-Gateway: No such file or directory
. if it does not exist (and socat tunnel is not running.
Now it’s time to turn this into a deamon… and where help is needed. We thought about running the test, start socat and few seconds later pimatic if needed and sleep for few minutes. -
Hello @dynamite,
I found at least a way to make it work for the reboot. The daemon would still be prefered, but my lack of knowledge prevents me from programming this. If someone wants to contribute, you are still very welcome.For now I solved it by creating a socat.sh in
/etc/init.d
#!/bin/sh ### BEGIN INIT INFO # Provides: socat # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start socat tunnel for use with MySensors gateway # Description: Open socat tunnel between /dev/ttyMS-Gateway and my # ESP8266 wifi gateway for MySensors ### END INIT INFO /usr/bin/socat -d -d pty,link=/dev/ttyMS-Gateway,raw,echo=0,waitslave tcp:192.168.38.19:5003 &>/dev/NULL
and active it with
sudo update-rc.d socat.sh defaults
.
I don’t know if thats the best way to do it, but it works
But the problem of restarting pimatic (for updates) still exists. Socat will close the tunnel when pimatic stops and no new connection will be established. But in this case I can still reboot my RPi… not the best, but a working way. -
In this case I would create a shell script issueing your pimatic “check” command and upon “true” start socat, more or less like you do now.
Then I would schedule this script in cron to run every 5 or 10 minutes or so.
to run every 5 minutes do:*/5 * * * * /home/<user>/pimatic/check_pim_socat.sh > /dev/null 2>&1
-
By the way: Why are you using
ps -aux |grep pimatic |grep /usr/local/bin/pimatic
?
This will always deliver 2 lines whereasps ax | grep -v grep | grep pimatic.js
will only deliver 1 line