corvy / ha-addons

Apache License 2.0
6 stars 2 forks source link

GPS updates stops after while #31

Closed henripalmroth closed 4 months ago

henripalmroth commented 4 months ago

Hi,

I'm having this usb dongle: https://www.globalsat.com.tw/en/product-199954/GPS-Receiver-ND-105C.html

This works fine for some time but then it stops. Any idea how to debug this further? I'm having HA on Raspberry PI 5 on a boat.

Log with debug setting on looks like this and then it just goes on with pings. Restart resolves the issue. On dongle the led is blinking as expected when there is fix available.

2024-07-17 10:17:07,792 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:08,020 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:08,444 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:08,826 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:09,054 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:09,478 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:09,860 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:10,089 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:10,513 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:10,895 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:11,123 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:11,548 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:11,930 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:12,158 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:12,582 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:12,582 - MQTT Publisher - DEBUG - Sending PUBLISH (d0, q0, r0, m146), 'b'gpsd2mqtt/fcbdedf5_sky/attribute'', ... (1238 bytes) 2024-07-17 10:17:12,582 - MQTT Publisher - DEBUG - Sending PUBLISH (d0, q0, r0, m147), 'b'gpsd2mqtt/fcbdedf5_sky/state'', ... (1 bytes) 2024-07-17 10:17:12,582 - MQTT Publisher - DEBUG - Published SKY: 8 to topic: gpsd2mqtt/fcbdedf5_sky/state 2024-07-17 10:17:12,583 - MQTT Publisher - DEBUG - Published SKY: {'class': 'SKY', 'device': '/dev/ttyUSB0', 'gdop': 2.49, 'hdop': 0.92, 'pdop': 1.24, 'tdop': 1.24, 'xdop': 0.71, 'ydop': 0.84, 'vdop': 0.83, 'nSat': 12, 'uSat': 8, 'satellites': [{'PRN': 27, 'gnssid': 0, 'svid': 27, 'az': 279.0, 'el': 71.0, 'ss': 18.0, 'used': True}, {'PRN': 23, 'gnssid': 0, 'svid': 23, 'az': 111.0, 'el': 56.0, 'ss': 18.0, 'used': True}, {'PRN': 16, 'gnssid': 0, 'svid': 16, 'az': 210.0, 'el': 50.0, 'ss': 21.0, 'used': True}, {'PRN': 10, 'gnssid': 0, 'svid': 10, 'az': 163.0, 'el': 40.0, 'ss': 0.0, 'used': False}, {'PRN': 8, 'gnssid': 0, 'svid': 8, 'az': 291.0, 'el': 36.0, 'ss': 22.0, 'used': True}, {'PRN': 18, 'gnssid': 0, 'svid': 18, 'az': 69.0, 'el': 35.0, 'ss': 16.0, 'used': True}, {'PRN': 26, 'gnssid': 0, 'svid': 26, 'az': 185.0, 'el': 20.0, 'ss': 21.0, 'used': True}, {'PRN': 15, 'gnssid': 0, 'svid': 15, 'az': 53.0, 'el': 18.0, 'ss': 15.0, 'used': True}, {'PRN': 7, 'gnssid': 0, 'svid': 7, 'az': 312.0, 'el': 15.0, 'ss': 18.0, 'used': True}, {'PRN': 13, 'gnssid': 0, 'svid': 13, 'az': 23.0, 'el': 11.0, 'ss': 0.0, 'used': False}, {'PRN': 30, 'gnssid': 0, 'svid': 30, 'az': 341.0, 'el': 8.0, 'ss': 0.0, 'used': False}, {'PRN': 21, 'gnssid': 0, 'svid': 21, 'az': 250.0, 'el': 3.0, 'ss': 0.0, 'used': False}]} to topic: gpsd2mqtt/fcbdedf5_sky/attribute 2024-07-17 10:17:12,733 - MQTT Publisher - DEBUG - Accuracy achieved:3D fix 2024-07-17 10:17:12,733 - MQTT Publisher - DEBUG - Sending PUBLISH (d0, q0, r0, m148), 'b'gpsd2mqtt/fcbdedf5/attribute'', ... (426 bytes) 2024-07-17 10:17:12,733 - MQTT Publisher - DEBUG - Published TPV: {'class': 'TPV', 'device': '/dev/ttyUSB0', 'mode': 3, 'time': '2024-07-17T07:16:56.000Z', 'ept': 0.005, 'altHAE': 60.6, 'altMSL': 21.1, 'epx': 10.605, 'epy': 12.582, 'epv': 19.09, 'track': 223.91, 'magtrack': 228.3113, 'magvar': 4.4, 'speed': 0.329, 'climb': 0.0, 'eps': 25.16, 'epc': 38.18, 'geoidSep': 39.5, 'eph': 17.48, 'sep': 23.56, 'accuracy': '3D fix', 'altitude': 21.1, 'longitude': 13.814786667, 'latitude': 55.42599} to topic: gpsd2mqtt/fcbdedf5/attribute (3D-fix-only) 2024-07-17 10:17:12,965 - MQTT Publisher - DEBUG - Number of satellites: 8 of required 0 2024-07-17 10:17:24,746 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:17:24,747 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:18:24,808 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:18:24,809 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:19:24,873 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:19:24,873 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:20:24,937 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:20:24,937 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:21:24,999 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:21:25,000 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:22:25,064 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:22:25,065 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:23:25,127 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:23:25,128 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:24:25,190 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:24:25,191 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:25:25,254 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:25:25,255 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:26:25,319 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:26:25,319 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:27:25,382 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:27:25,383 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:28:25,447 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:28:25,448 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:29:25,511 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:29:25,512 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:30:25,575 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:30:25,576 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:31:25,639 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:31:25,640 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:32:25,703 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:32:25,703 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:33:25,767 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:33:25,768 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:34:25,830 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:34:25,831 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:35:25,894 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:35:25,895 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:36:25,957 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:36:25,958 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:37:26,018 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:37:26,020 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:38:26,080 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:38:26,081 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:39:26,145 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:39:26,146 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:40:26,210 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:40:26,211 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:41:26,274 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:41:26,274 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:42:26,338 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:42:26,338 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:43:26,402 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:43:26,403 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:44:26,465 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:44:26,465 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:45:26,527 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:45:26,527 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:46:26,590 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:46:26,591 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:47:26,655 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:47:26,655 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:48:26,717 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:48:26,717 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:49:26,781 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:49:26,782 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:50:26,844 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:50:26,845 - MQTT Publisher - DEBUG - Received PINGRESP 2024-07-17 10:51:26,909 - MQTT Publisher - DEBUG - Sending PINGREQ 2024-07-17 10:51:26,910 - MQTT Publisher - DEBUG - Received PINGRESP

corvy commented 4 months ago

That is strange, it kindof looks like it does not get coverage but that does not make sense if it comes back with addon restart.

Could you try to connect your dongle with a USB extension cord? Just to see if it could be interference from the Pi causing the issue? Something like this:

image

If you know how, you could also connect to the container and run a dmesg after it stops updating just to see if there are any hardware failure messages in the log.

henripalmroth commented 4 months ago

Hi and thanks for a reply. I currently have 20 cm long extension cable and this gps dongle is having small led which is blinking when it is having a fix to satellites. Of course there can be some problems sometimes. Is it so that gpsd cannot recover from those?

Here is my log from dmesg. I didn't notice anything suspicious. Do you have any thoughts how could I narrow this problem down?

image

corvy commented 4 months ago

Nah this looks ok, but we are most interested in dmesg events just when it fails. Seems you reseated the USB stick at this time? Did you see anything further up in the dmesg log?

corvy commented 4 months ago

Another thing to try, when it is working, run a gpsmon from the shell, it should look something like this:

image

This image is when it is working. The NMEA logs at the bottom is the GPS NMEA data it receives from the GPS dongle. It would be interesting to see how this looks both when it works, and when it is failed.

Again this needs to be run from the addons docker containter interactively like before.

henripalmroth commented 4 months ago

Its getting warmer. Gpsmon looks fine when everything is working but after while it looks like this. I can replicate this quite quickly after I put update frequency to 1 sec.

image

corvy commented 4 months ago

Thank you. Looks like it lost the device here. I find it strange that you can provoke this error with changing the update frequency, since that only affects the rate at which the addon updates MQTT, not how often GPSD updates internally.

Have you tried to manually set the port speed? From the manual it seems to want it to be set to 4800. Could you try that if you have not?

henripalmroth commented 4 months ago

Probably that 1 sec setting was my own misinterpretation. And yes, I'm using that 4800 baud setting. Otherwise it won't work.

But since this gpsmon is connecting directly to gpsd it probably got nothing to do with your implementation. However still all help is welcome. Do you have any thoughts how I could debug more of gpsd? Dmesg didn't reveal anything suspicious.

corvy commented 4 months ago

Had to have a think about this. Dmesg does not output a HW error at any time?

Could it be the cable? Would it be possible to swap the USB cable for another one? Or just temporarily connect the dongle directly to the Pi?

Another thing to try is to try to get serial data directly from the serial device. First stop the addon. Then open a terminal and run the following commands:

 /bin/stty -F /dev/ttyUSB0 raw 4800 cs8 clocal -cstopb
 cat -v /dev/ttyUSB0

Replace device with your device if it is wrong. See if the same error occurs outside the addon. This would just type the serial NMEA sentences directly to terminal. You could also try to pipe them to a file. Though if it is a hardware error it should happen with or without the cat command, its just easier to see.

How long in general does it take before the device "stops working".

henripalmroth commented 4 months ago

Looks like in terminal it runs "forever". Strange. Not sure how to narrow down what happens inside docker container.

I try to also find out how I could use serial integration to get e.g. boat speed and track. That way I can see if it really works for longer period.

I'm starting to believe it is not hardware issue.

image

corvy commented 4 months ago

According to this article: https://www.jfcarter.net/~jimc/documents/gps-clock-1507.html it seems the device should disable the parity bit. Maybe it is a shot in the dark, but it could be something. I would need to make some changes to let you disable it though.

corvy commented 4 months ago

Could you try a new beta version I set up? You have to add a new repository with this URL: https://github.com/corvy/ha-beta-addons. Install version 2024.7.0_b4 (or newer).

The settings should look like this:

Screenshot 2024-07-23 at 11 11 28

Please output the logs from the startup just to see if it sets the correct settings. Should be something similar to this.

s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Setting up serial device with the following: /dev/ttyAMA0 4800 cs8 -cstopb -parenb clocal
Starting GPSD with device "/dev/ttyAMA0"...
/usr/sbin/gpsd: 3.25 (revision 3.25)
Starting MQTT Publisher with integrated credentials ... 
2024-07-23 11:08:42,902 - MQTT Publisher - INFO - Connecting to MQTT broker
2024-07-23 11:08:43,906 - MQTT Publisher - INFO - Verifying MQTT Connection ....
2024-07-23 11:08:44,110 - MQTT Publisher - INFO - Connected to MQTT broker
2024-07-23 11:08:44,110 - MQTT Publisher - INFO - Subscribe to MQTT topic homeassistant/status to listen for HA reboots.
2024-07-23 11:08:44,906 - MQTT Publisher - INFO - Verifying MQTT Connection ....
2024-07-23 11:08:44,908 - MQTT Publisher - INFO - Published MQTT discovery message to topic: homeassistant/device_tracker/gpsd2mqtt/a411f609/config
2024-07-23 11:08:44,908 - MQTT Publisher - INFO - Starting location detection and sending GPS updates.
2024-07-23 11:10:43,638 - MQTT Publisher - INFO - Published 11 updates to the device_tracker in last 2.0 minutes. Achieved 3D fix, position with 10 of required 0 GPS satellites.
henripalmroth commented 4 months ago

Up and running and looks good so far:

image

henripalmroth commented 4 months ago

Actually stopped again. Is there any chance of increasing the debug logging to see what happens there?

image

corvy commented 4 months ago

I have added config option to add more debugging to GPSD in version _b5.

Screenshot 2024-07-24 at 10 38 08

Add -N to get the logs (foreground) and then try -D1 -D2 or -D3 for more logging information.

henripalmroth commented 4 months ago

Does this tell anything to you? Seems that it is not providing anything to MQTT with -N switch.

image

corvy commented 4 months ago

I disabled the use of sock in the _b7 version. Could you try that?

corvy commented 4 months ago

To get it to update it might have to run as a daemon, so just remove the -N and -D3 to get it to start updating again.

henripalmroth commented 4 months ago

Sorry to say, but it didn't make any difference. I need to dig deeper to gpsd.

corvy commented 4 months ago

Can you give me more logs from the debugging? Still the same permissions error for the tty device?

henripalmroth commented 4 months ago

Yes. This is with -N and -D2 switches:

image

corvy commented 4 months ago

I am not sure what causes this. In the last version I tried to disable apparmour, just to see if that will fix the issue. Could you. test?

corvy commented 4 months ago

I have also made a newer version with a modified apparmour, please let me know when you have tested this one and then I will upload the newer version after.

henripalmroth commented 4 months ago

Still getting this with recent version (switches -N and -D2):

image

corvy commented 4 months ago

ok, so another version then 👍 try _b9

henripalmroth commented 4 months ago

A bit different outcome

image

corvy commented 4 months ago

Cool, at least something is changing. Setgroups I do not know how to change. But in _b10 at least the setgid and setuid should be fixed.

Could you test? Have you tested to run without the -D and -N settings to see if it will work?

henripalmroth commented 4 months ago

I tested now without fixes and I think we have a success. 🥳

Have been providing value every sec for five minutes now (boat is stationary). Than you very much for your efforts.

image

corvy commented 4 months ago

Cool! Is this the _b10 version?

corvy commented 4 months ago

Merged the changes into version 2024.7.0. Please see if that works for you now. If yes we will close this isse. :)

henripalmroth commented 4 months ago

I can confirm that it works.

Noticed that 0 on update rate doesn't work but it defaults to 10 seconds. However that is another story.

Thanks and greetings from Sandhamn, Sweden!

corvy commented 4 months ago

Thanks for confirming! I will for sure check the 0 setting. Happy boating!