question

nzmikec avatar image
nzmikec asked

Mikrotik LTAP Mini GPS to Cerbo over network

Hi All,

I wanted to post this here so others can find it if they are also attempting to do the same thing. Also open to feedback if something is not best practice.

I have a caravan setup using Cerbo and wanted to track the van in VRM mostly for security. We have a Mikrotik LTAP Mini router for our internet connection with a 4g connection running all the time. I wanted to send the GPS data from the router to the Cerbo instead of running a seperate GPS receiver mostly due to the fact that the router has a GPS antenna mounted externally, and the Cerbo is down "in the bowels".

I had looked around this forum and elsewhere and did have running a script sending the GPS location to the Cerbo using MQTT and https://github.com/freakent/dbus-mqtt-devices however didn't like the complexity of this setup and wanted to do it in a cleaner way.

I found this post https://community.victronenergy.com/questions/17470/venus-gx-to-pull-gps-coordinates-from-onboard-rout.html using UDP and the SOCAT command and thought I could get something like this working with my Mikrotik.

The issue with the above example is that the "remote-access" function of the mikrotik uses TCP rather than UDP.

Ive modified the SOCAT commands from the original UDP example and now have a working solution. To get this working the below steps should be all that is required.


1. Setup the router - test and then disable the GPS functionality on the router under /system gps. Make sure you get a fix and location data in the /system gps menu then make sure to disable the service so your remote-access service can use the serial port.

2. Configure "remote-access" on the router to the serial port the GPS uses. This website is useful. https://wiki.mikrotik.com/wiki/Manual:Port If using Serial0 like my example you need to disable the system console on this port. Picture of my settings.


/system console disable 0

screen-shot-2022-08-05-at-92612-pm.png

3. Create a script to run the commands at boot time of the Cerbo. Make sure to set the TCP address correctly to your router address and the port to the one you have set in remote-access above.

nano /data/etc/gps.sh
#
# get GPS from rout
/usr/bin/socat tcp-connect:192.168.88.1:10000 pty,link=/dev/ttyTCP10000,raw,nonblock,b115200
while [ `ps|grep gps_dbus|grep -v grep|wc -l` -eq 0 ]
do
  sleep 1
  /opt/victronenergy/gps-dbus/gps_dbus -s /dev/ttyTCP10000 -b 115200 -t 0 &
done

4. Modify /data/rc.local on the Cerbo to run the above script. Below is mine. Just add the line

sh /data/etc/gps.sh

nano /data/rc.local
#!/bin/bash
sh /data/etc/dbus-serialbattery/reinstalllocal.sh
sh /data/etc/gps.s

5. Reboot. Your GPS data should now show up as per this pic.

screen-shot-2022-08-05-at-95609-pm.png



This is working well for me however please let me know if you think there are any issues with this setup. Also please comment if you find it useful!

Best regards, Mike.

cerbo gxgps
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

8 Answers
nzmikec avatar image
nzmikec answered ·

Update on this - the NMEA serial data is not being past from my router since a restart of the router. Looking into the cause of this.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Holger Watermann avatar image
Holger Watermann answered ·

Use this Script to run all in Background with restoring the Connection:

# get GPS from router
/usr/bin/socat tcp-connect:192.168.88.1:10000 pty,link=/dev/ttyTCP10000,raw,nonblock,b115200
while [ `ps|grep gps_dbus|grep -v grep|wc -l` -eq 0 ]
do
  sleep 1
  /opt/victronenergy/gps-dbus/gps_dbus -s /dev/ttyTCP10000 -b 115200 -t 0
done &


-> your "&" was on the wrong line - now it will recover.

Holger

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

nzmikec avatar image
nzmikec answered ·

Thanks Holger,

I see my error thanks. Ive changed my script however still have a problem not receiving any NMEA data on that port. Ive got a post on the mikrotik forums so hopefully will have some answers soon.

Kind regards, Mike.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Holger Watermann avatar image
Holger Watermann answered ·

Hello Miike

Here is my Script, using it for one Year to get the GPS data from another Server which sends it via UDP stream on Port 8500. I did not modify any other Script on the Venus. No Problems at all with the Victron Updates. Now at 2.90-large-beta20. Check if your Server sends the UDP Stream after rebooting.


nano /data/rcS.local

#!/bin/bash

# SetupHelper reinstall all Venus mods
nohup /data/SetupHelper/reinstallMods > /dev/null &

#
# get GPS from router
#
/usr/bin/socat UDP-RECV:8500 pty,link=/dev/ttyUDP8500,raw,nonblock,echo=0,b115200 &

while [ `ps|grep gps_dbus|grep -v grep|wc -l` -eq 0 ]
        do
sleep 1
        /opt/victronenergy/gps-dbus/gps_dbus -s /dev/ttyUDP8500 -b 115200 -t 0
done &

exit 0

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

nzmikec avatar image
nzmikec answered ·

Thanks, turns out my router (Mikrotik LTAP Mini) switches the serial0 port between a DB9 mounted externally and the GPS port and the only way to specify you want to "switch" to the internal GPS port seems to be to enable GPS on the router making the port unable to be forwarded to a port (TCP in my case). I did have it running possibly by tricking the router into switching over somehow but have not been able to replicate it.

My LTE card also has onboard GPS so im just working through forwarding this to the TCP port and getting a script working. I wish I could use UDP as I think it would be more reliable during a router reboot (I think TCP would fail in this case) however mikrotik does not seem to provide provision for this using the "remote access" tool.

Will update soon with a working solution.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Greg avatar image
Greg answered ·

I decided to do the same with the LtAP mini in my bus to feed the GPS to my house system. @nzmikec I updated the mikrotik forum with my solution to the GPS feed problem.

Mikrotik Forum: LTAP Mini serial port / GPS

As for the code running on the GX I have it split into two daemontools services, one for the virtual serial port and the other for gps_dbus. I prefer this approach as it blends well with the current services and handles the logging, restarting, etc... I also have a rc.local script that takes care of adding the services back after updates. If anybody is interested I can post the code here.

cerbogx-gps.png

cerbogx-logs.png

cerbogx-svstat.png



cerbogx-gps.png (13.2 KiB)
cerbogx-logs.png (66.4 KiB)
cerbogx-svstat.png (5.1 KiB)
1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

nebulight avatar image nebulight commented ·
Hey @Greg care to share your scripts? Also any more info you can share would be great. I've got the same LtAP mini and would love to get this working so I can have one device. Thanks!
0 Likes 0 ·
nzmikec avatar image
nzmikec answered ·

Thanks so much @Greg , would love to see your GX scripts. Mine currently won't survive a router reboot as the connection is dropped. I had been running a workaround on the latp using my LTE cards GPS.

Great work on the Mikrotik script and workaround of the serial port bug!

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

nebulight avatar image
nebulight answered ·

Hmm, I can't seem to get the remote access for the serial port working. It just says invalid when I attempt to enable it. When I run @Greg 's script it just says device is busy check \port

One thing that is different is I have the LTE version: LtAP mini LTE (R11e-LTE-US)

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Related Resources