Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Getting Geoclue2 (and KDE/Gnome) to read data from GPSD.

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
1 post • Page 1 of 1
Author
Message
netsplit
n00b
n00b
Posts: 24
Joined: Mon Jun 10, 2024 1:53 am

Getting Geoclue2 (and KDE/Gnome) to read data from GPSD.

  • Quote

Post by netsplit » Mon Dec 15, 2025 3:55 pm

This is a script and config to create a NMEA feed for Geoclue from GPSD JSON. It works using socat and gpspipe from GPSD I'm posting it for some future person who has the same problem. So many times other people's answers have helped me here. If anyone has any suggestions to improve this please let me know. I'm at the skill level of a monkey poking a computer with a stick, so don't use this for anything important.


Scenario: Getting KDE Nightlight and other Geoclue dependent things working from GPS . It requires Geoclue which can read NMEA data. GPSD can output NMEA directly, but you have to turn off JSON data to do it. If you just want NMEA, this might something to look into. If you want both NMEA and JSON output, GPSD comes with a tool to create a NMEA feed from it's JSON so you can have both.

Method: use gpspipe which comes with GPSD to translate the JSON to NMEA, and socat to create a Unix socket to feed that data into Geoclue. Put it in a loop to hopefully make it so it recovers.

install (review GSPD use flags and configure uses if needed prior):

Code: Select all

emerge -av net-misc/socat sci-geosciences/gpsd app-misc/geoclue
Create a script to do this:
/usr/local/bin/nmeasource

Code: Select all

#!/bin/bash

while true; do
	logger -t geoclue-nmea "starting gpspipe socat listener"
	gpspipe -r | socat - UNIX-LISTEN:/run/gpsd-nmea.sock,fork,perm=666
	rm /run/gpsd-nmea.sock
	logger -t geoclue-nmea "error restarting gpspipe socat listener"
	sleep 5
done

Create an OpenRC init script to start it at boot:
/etc/init.d/nmeasource

Code: Select all

#!/sbin/openrc-run

name="$RC_SVCNAME"
description="Geoclue gpsd shim"
supervisor="supervise-daemon"
command="/usr/local/bin/nmeasource"


depend() {
    need gpsd
    after gpsd
    before geoclue
}
Set permissions and configure OpenRC to run scripts at boot:

Code: Select all

sudo chmod +x /etc/init.d/nmeasource
sudo chmod +x /usr/local/bin/nmeasource
sudo rc-update add gpsd default
sudo rc-update add nmeasource default
sudo rc-update add geoclue default

Configure Geoclue to read NMEA:
Make sure /etc/geoclue/geoclue.conf has this section:

Code: Select all

[network-nmea]
enable=true
nmea-socket=/run/gpsd-nmea.sock
Reboot! Hopefully it works now! Test it with (from a local user terminal, won't work over ssh or as root) /usr/libexec/geoclue-2.0/demos/where-am-i. If it works it'll give GPS data, If something is wrong it hang for a bit and close with no output. If this happens use this to find the problem:

From a root terminal run:

Code: Select all

killall geoclue && G_MESSAGES_DEBUG=all /usr/libexec/geoclue
Inspect for errors. If nothing obvious. Leave open the root terminal, and from a user terminal run /usr/libexec/geoclue-2.0/demos/where-am-i again. Then check the root terminal for errors.

Further semirelated. If your GPS doesn't work very well it might be in power saving mode. It goes into the reeds from that because how you fix that depends on the device. This works for my device, for example:

Code: Select all

//reset to default config
ubxtool --preset RESET
//set serial port speed
ubxtool --setspeed 9600 --file /dev/ttyAMA0
//turn of power management
ubxtool --preset CFG-PMS,0
//output twice a second 
ubxtool --preset CFG-RATE,500,1
Top
Post Reply
1 post • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic