Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mDNS support (Initial proof of concept implementation provided in my fork) #16

Open
ForestJohnson opened this issue Feb 15, 2022 · 1 comment

Comments

@ForestJohnson
Copy link

ForestJohnson commented Feb 15, 2022

Hello I have forked your app to add mdns support because i needed it for my use case. This means you don't have to know the IP address of the gpsd UDP server as long as that UDP server is advertising a mDNS service discovery record with the service type _gpsd_.udp. and the service name equal to its hostname.

image

For example this is the avahi-daemon service unit XML file that I created on my server to advertise the GPSd service so the android app can discover it:

/etc/avahi/services/gpsd.service

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

<!-- See avahi.service(5) for more information about this configuration file -->

<service-group>

  <!-- its important that we only include the %h here (hostname) because 
       the android app checks for this to match the hostname -->
  <name replace-wildcards="yes">%h</name>

  <service protocol="any">
    <type>_gpsd._udp</type>
    <port>4200</port>
  </service>


</service-group>

ℹ️ INFO

I designed it like this (even tho it seemed wrong to me) because I wasn't able to figure out how to grab the machines hostname from the android NsdServiceManager. It looks like it only gives the service info, not the actual xyz.local domain names. So my hack was to make the service name equal to the domain name.

⚠️ WARNING

I encountered GPSd issues when I was testing this, the problem is when you ask GPSd to listen on udp://*:4200 it interprets that * as 0.0.0.0 not :: in other words it only listens on IPv4, however sometimes the mDNS discovery on android would return the ipv6 address and it didn't appear to work properly when I configured the avahi-daemon to only respond with ipv4.
.
My fix was to introduce a simple UDP forwarder app written in a language i know so I can control how it listens on the UDP port and get it to listen properly on both ipv4 and ipv6. So my forwarder listens on port 4200 and then forwards to 127.0.0.1:4201 which is the exact address gpsd is listening on. I wasn't able to get it to work reliably any other way 😩

If you are interested in merging this contribution let me know and I might be willing to help you clean it up. Otherwise feel free to pull from my fork:

ForestJohnson@fdc1598

add initial mdns support for _gpsd_.udp. service

@tiagoshibata
Copy link
Owner

tiagoshibata commented Feb 25, 2022

Sorry for the slow response, I've been busy and didn't check GitHub notifications.

Thanks, mDNS is a very nice to have feature. Unfortunately I don''t use it myself and wouldn't be interested in polishing up and testing the code to have it merged.

If you do clean it up and feel like it's good to be merged let me know; I'm happy to review a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants