You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gpsd: read nSat/uSat summary fields instead of counting satellites array
The first SKY message in gpsd's output buffer can have an empty
satellites array while the position is still being acquired, even when
nSat/uSat summary fields are already populated with the correct counts.
This caused the previous len(satellites) approach to return 0 even on
receivers reporting tens of satellites in view, producing flat-0 graphs
in LibreNMS for satellites/satellites_used.
Read d["nSat"]/d["uSat"] directly (they are always present in the SKY
message once gpsd has any fix), and fall back to len(satellites)/used
count when the summary fields are missing for backward compatibility
with older gpsd builds.
Tested against gpsd 3.25 + Quectel LC29H multi-constellation GNSS HAT
(GPS+GLONASS+Galileo+BeiDou) - previously returned 0/0, now returns
correct visible/used counts.
SATSUSED=$(cat "$TMPFILE"|$BIN_GREP -m 1 "SKY"|$BIN_PYTHON -c 'import sys,json;print(len([sat for sat in json.load(sys.stdin)["satellites"] if sat["used"]]))'2> /dev/null)
# Visible: prefer len(satellites) array (full once gpsd settles), fallback to nSat summary.
45
+
SATS=$(cat "$TMPFILE"|$BIN_GREP"SKY"| tail -1 |$BIN_PYTHON -c 'import sys,json;d=json.load(sys.stdin);print(len(d.get("satellites",[])) or d.get("nSat") or 0)'2> /dev/null)
46
+
# Used: uSat summary is reliable across firmware/gpsd versions, fallback to counting flagged sats.
47
+
SATSUSED=$(cat "$TMPFILE"|$BIN_GREP"SKY"| tail -1 |$BIN_PYTHON -c 'import sys,json;d=json.load(sys.stdin);u=d.get("uSat");print(u if u is not None else len([s for s in d.get("satellites",[]) if s.get("used")]))'2> /dev/null)
0 commit comments