Help needed using SW Maps with GNSS-RTK Flex pHAT - ZED-X20P

I see SW Maps is often cited as a way to record rover positions. I’ve been trying for a couple of days to get it working over Bluetooth so I can use my Android phone or an old Android tablet.

  • Raspberry Pi 5 – 8 GB
  • GNSS-RTK Flex pHat - ZED-X20P
  • PyGPSClient to verify NMEA
  • Bench testing with Raspberry Pi desktop

I’ve been trying suggestions from Google Gemini, but haven’t been able to connect SW Maps over Bluetooth.

Is there a good guide to help me accomplish this?

What are some alternatives to SW Maps for logging?

Thanks!

Hi Steve (@steve.talent ),

When you say “logging”, do you mean logging the NMEA messages from the GNSS? Or you you mean logging waypoints as you survey an area?

PyGPSClient can log NMEA messages for you.

If waypoint logging is what you need, then:

You need to achieve something like the following:

  • Pair your phone with the Raspberry Pi over Bluetooth
  • Forward the serial / UART NMEA messages from the GNSS to your phone over Bluetooth

If you have GNSS “Instrument Model” set to “Generic NMEA” or “u-blox” in SW Maps, then you should be off and running.

It should be possible to do both the pairing and forwarding using (e.g.) a little Python running on the Raspberry Pi. But it’s not something I personally have done before. I’d need to go searching for some code to try.

It’s the end of day here. If you’ve got time to poke Gemini into finding some code for you, then please do. Otherwise I will try and find you some code in the morning.

Best wishes,
Paul

Thanks, Paul,

I am making a little progress.

By “logging”, I do mean logging waypoints as a survey an area.

I have a basic Python script on the Pi that will read NMEA messages from the pHAT UART (/dev/ttyAMA0) and write them to the Pi’s Bluetooth serial port (/dev/rfcomm0).

I have tried both “u-blox” and “Generic NMEA” settings in SW Maps, but it seems the problems are on the Pi’s bluetooth configuration.

I think the following is enough to demonstrate the problem. It appears that Bluetooth service running on the PI it treating the connection as Audio device and does not recognize the correct type:

Edit /etc/systemd/system/dbus-org.bluez.service to enable SDP:

[Service]
...
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP
...
talent@rpi5-gnss-rtk-rover:~ $ sudo rfcomm bind 0 78:B6:FE:7B:E3:FA 1
talent@rpi5-gnss-rtk-rover:~ $ sudo systemctl daemon-reload
talent@rpi5-gnss-rtk-rover:~ $ sudo systemctl restart bluetooth
talent@rpi5-gnss-rtk-rover:~ $ bluetoothctl
Agent registered
[bluetoothctl]> show
Controller 88:A2:9E:28:54:84 (public)
	Manufacturer: 0x0131 (305)
	Version: 0x09 (9)
	Name: rpi5-gnss-rtk-rover
	Alias: rpi5-gnss-rtk-rover
	Class: 0x006c0000 (7077888)
	Powered: yes
	PowerState: on
	Discoverable: no
	DiscoverableTimeout: 0x000000b4 (180)
	Pairable: yes
	UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
	UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
	UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
	UUID: SIM Access                (0000112d-0000-1000-8000-00805f9b34fb)
	UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
	UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
	UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
	UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
	UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
	UUID: Vendor specific           (03b80e5a-ede8-4b33-a751-6ce34ec4c700)
	UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
	Modalias: usb:v1D6Bp0246d0552
	Discovering: no
	Roles: central
	Roles: peripheral
Advertising Features:
	ActiveInstances: 0x00 (0)
	SupportedInstances: 0x05 (5)
	SupportedIncludes: tx-power
	SupportedIncludes: appearance
	SupportedIncludes: local-name
	SupportedCapabilities.MaxAdvLen: 0x1f (31)
	SupportedCapabilities.MaxScnRspLen: 0x1f (31)
[bluetoothctl]> connect 78:B6:FE:7B:E3:FA
Attempting to connect to 78:B6:FE:7B:E3:FA
[CHG] Device 78:B6:FE:7B:E3:FA Connected: yes
[NEW] Endpoint /org/bluez/hci0/dev_78_B6_FE_7B_E3_FA/sep13 
[NEW] Endpoint /org/bluez/hci0/dev_78_B6_FE_7B_E3_FA/sep14 
[NEW] Endpoint /org/bluez/hci0/dev_78_B6_FE_7B_E3_FA/sep16 
[NEW] Endpoint /org/bluez/hci0/dev_78_B6_FE_7B_E3_FA/sep17 
Failed to connect: org.bluez.Error.Failed br-connection-unknown
[DEL] Endpoint /org/bluez/hci0/dev_78_B6_FE_7B_E3_FA/sep13 
[DEL] Endpoint /org/bluez/hci0/dev_78_B6_FE_7B_E3_FA/sep14 
[DEL] Endpoint /org/bluez/hci0/dev_78_B6_FE_7B_E3_FA/sep16 
[DEL] Endpoint /org/bluez/hci0/dev_78_B6_FE_7B_E3_FA/sep17 
[CHG] Device 78:B6:FE:7B:E3:FA Connected: no

Thanks Steve (@steve.talent ),

I’ve managed to get this to work a couple of times:

I edited /etc/systemd/system/dbus-org.bluez.service and made the same changes as you to enable SPP. I rebooted the Pi.

I made the Pi 5 discoverable and was able to pair it with my old Galaxy S7 and connect.

In a Pi terminal window, I ran /bin/stty -F /dev/ttyAMA0 38400

In another Pi terminal window, I ran sudo rfcomm watch hci0 and left it running.

I opened SW Maps on the phone, selected Bluetooth, raspberrypi and u-blox. I hit Connect and it was able to connect to the Pi.

In the first Pi terminal window, I ran sudo socat /dev/rfcomm0 /dev/ttyAMA0 and left it running. (Photo below)

SW Maps is getting data and displaying my location. (Photo below)

It’s a bit hit and miss. If I disconnect, I can’t connect again - unless I reboot the Pi… Not ideal.

So, this is the bones of a solution, but it needs a load more work…!

I hope this helps,
Paul

Hi Steve (@steve.talent ),

Hah! The following crappy Python code works surprising well!

It’s one-way. It only forwards traffic from UART to the socket.

But it seems fairly robust.

And you don’t need the sudo rfcomm watch or the sudo socat

I hope it comes in useful,
Paul

import bluetooth # sudo apt-get install python3-bluetooth
import serial
import sys

server_socket = None
client_socket = None
ser = None

print("Bluetooth to UART")

try:
    server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
    port = 1
    server_socket.bind(("",port))
    server_socket.listen(1)
    client_socket,address = server_socket.accept()
    print("Accepted connection from ",address)

    serialPort = '/dev/ttyAMA0'
    ser = serial.Serial(serialPort, 38400)
    if ser.isOpen():
        print("Serial port",serialPort,"is open")

    while True:
        uartrx = ser.read(1024)
        client_socket.send(uartrx)
except:
    if client_socket:
        client_socket.close()
    if server_socket:
        server_socket.close()
    if ser:
        ser.close()
    print("Bye!")
    sys.exit(0)
1 Like

Hi Paul (@PaulZC ),

Thanks for the sample code. It looks like a good starting point.

I believe my issue is more related to establishing the Bluetooth connection. I think it could be related to the Bluetooth configuration, and how Device and Service classes are being used when the devices are being connected. I need to study the documentation in more depth to better understand the messages I see from bluetoothctl that I posted in my previous reply. For example, sep13 refers to a Stream EndPoint (SEP), a specific D-Bus object created by the BlueZ stack to represent a media stream. In may be related to the Advanced Audio Distribution Profile (A2DP) used by audio services on the Pi.

When I look at Bluetooth connections on my Android device, it shows an icon indicating Audio/Video device.

I think there should be a different icon displayed for rpi5-gnss-rtk-rover in this image. What icon do you see when you pair the External GNSS device?

Hi Steve (@steve.talent ),

I think I’m seeing the same thing:

It doesn’t seem to matter. Serial Port Profile seems to be working fine with the sample code:

I hope this helps,
Paul

Hi Paul (@PaulZC ),

I managed to corrupt my system so I went back to the beginning with a fresh SD image. I also decided to finish the mechanical fabrication of my system for a rover pole. The head unit weighs 1.34 kg, and most of that is the batteries.

After being misdirected a few times by Google Gemini or ChatGPT, I decided I should take my time, study the docs, and document my progress from beginning steps to working system. It may be a few more days until I have something working. I want to understand what I’m doing in more depth and learn more in general about working with Bluetooth.

Steve

2 Likes

@PaulZC – Your code is working for me. Thanks!

Thanks alot @steve.talent , now you got me interested in a RTK Flex pHat - ZED-X20P :grimacing:
There goes that “free time” I had scheduled next month. LoL.

Seriously, good work Sir. :+1: