corvy / ha-addons

Apache License 2.0
6 stars 2 forks source link

GPS cannot update location #18

Closed deanfourie1 closed 9 months ago

deanfourie1 commented 10 months ago

Hi there, Installed this addon but I still cannot get a GPS location.

I know that my GPS only operates at a BAUD of 4800,

Upon booting my PI, I run

cat /dev/ttyUSB0

And I get no output. Then if I run,

stty -F /dev/ttyUSB0 4800 followed by cat /dev/ttyUSB0

I instantly get the NMEA data.

I have set a BAUD of 4800 in your addon settings, however I am afraid it might not actually be setting the port for a BAUD of 4800.

Do you have any ideas for this?

Thanks

corvy commented 10 months ago

Thanks for reporting this. Let me look into it quickly. :)

deanfourie1 commented 10 months ago

Thanks,

Also, using Raspberry PI 4, and using the onboard UART for GPS, I am getting the following.

s6-rc: info: service s6rc-oneshot-runner: starting s6-rc: info: service s6rc-oneshot-runner successfully started 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 setserial: can't set serial info: Operation not permitted s6-rc: info: service legacy-services: stopping s6-rc: info: service legacy-services successfully stopped s6-rc: info: service legacy-cont-init: stopping s6-rc: info: service legacy-cont-init successfully stopped s6-rc: info: service fix-attrs: stopping s6-rc: info: service fix-attrs successfully stopped s6-rc: info: service s6rc-oneshot-runner: stopping s6-rc: info: service s6rc-oneshot-runner successfully stopped , Thanjs

corvy commented 10 months ago

Could you turn on debugging and try again? See if we get more information.

corvy commented 9 months ago

Hello again @deanfourie1, did you ever get the time to enable debugging?

deanfourie1 commented 9 months ago

Hi there,

I've had another look at this and now something strange is hapenning. My GPS used to work, I could get a stream via

cat /dev/ttyS0

However, now it is just spitting out a bunch of garbage.

Is it possible this addon has changed some settings on my GPS as there is no other logical explanation for this.

Thanks

deanfourie1 commented 9 months ago

Please see the video

https://github.com/corvy/ha-addons/assets/71812804/f3b08df3-1f53-4326-a8df-a15dd62d81a7

corvy commented 9 months ago

Seems like the serial port settings is wrong somehow.

What is the output of

stty < /dev/ttyUSB0

deanfourie1 commented 9 months ago

Output is

-bash: /dev/ttyUSB0: No such file or directory

This is now a directly connected RS232 GPS and it was working with cat /dev/ttyS0

Something strange has happened as now the output is as above, and no wiring or anything has changed?

corvy commented 9 months ago

Sorry, do the same with the right tty device :)

stty < /dev/ttyS0

You probably have to stop the addon before so the device is not busy.

After, you could try the following to see if you get proper NMEA sentences again.

stty -F /dev/ttyS0 raw 4800 cs8 clocal -cstopb

deanfourie1 commented 9 months ago

When attempting to start, I get the following.

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
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/ttyS0 9600 cs8 clocal -cstopb
setserial: can't set serial info: Operation not permitted**
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Any ideas?

corvy commented 9 months ago

Hello! This all seems a bit odd.

Are you able to get sane NMEA sentences from the serial device from the host now? When you force it to 4800 baud speed?

If you stop the addon, go to the host terminal and run the following

stty -F /dev/ttyS0 raw 4800 cs8 clocal -cstopb
cat /dev/ttyS0 

Add sudo in front if not root. Does that work?

corvy commented 9 months ago

Also made a small change to the add-on now. It seems that GPSD daemon does not use the set serial speed unless I specify it on start. Added that now, and I am able to change my speed using the options. So please try to update to 2024.2.1 and set the serial port information and speed in config and try again. 4800 should work now I hope.

Fingers crossed. :)

deanfourie1 commented 9 months ago

Since the update, it cannot connect to MQTT.

2024-02-20 14:23:35,751 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:23:35,752 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:23:57,752 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:23:57,752 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:24:14,244 - MQTT Publisher - INFO - Published 11 updates in the last 2.0 minutes
2024-02-20 14:24:19,754 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:24:19,755 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:24:41,748 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:24:41,748 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:25:01,758 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:25:01,758 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:25:23,752 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:25:23,752 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:25:44,757 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:25:44,757 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:26:06,749 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:26:06,749 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:26:14,352 - MQTT Publisher - INFO - Published 11 updates in the last 2.0 minutes
2024-02-20 14:26:28,755 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:26:28,755 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:26:49,754 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:26:49,754 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:27:11,753 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:27:11,754 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:27:33,753 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:27:33,753 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:27:54,754 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:27:54,754 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:28:14,356 - MQTT Publisher - INFO - Published 11 updates in the last 2.0 minutes
2024-02-20 14:28:16,754 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:28:16,755 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:28:38,756 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:28:38,756 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:28:59,753 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:28:59,754 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:29:20,755 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:29:20,755 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:29:42,754 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:29:42,755 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...
2024-02-20 14:30:04,754 - MQTT Publisher - WARNING - Disconnected from MQTT broker. Attempting reconnection...
2024-02-20 14:30:04,754 - MQTT Publisher - INFO - Trying to reconnect to MQTT broker (attempt 1 of 10)...

Thanks

corvy commented 9 months ago

Might be a good thing. Seems that maybe we have a working GPSD now.

Looks like the connection worked sometimes (published 11 updates). Did you get a mqtt device device_tracker.gps_location in HA?

Do you see anything in the MQTT logs? Which mqtt broker do you use? Is it local on HA?

Also try to enable debug just to see if we get more info.

deanfourie1 commented 9 months ago

Ok, sorry. I was using the wrong bloody password. I got confused as I am running 2 separate instances of HA at 2 different locations. My apologies.

All looks good now. It does look like I now have an entity with a published GPS location.

I do however have another question; how can I change the "Update Interval" of the location? Say send a GPSD update or location update to MQTT every 2 minutes for example.

Also, just a suggestion. Could you also provide additional entities for GPS speed, Long, Lat, and time etc published to MQTT so these show as separate entities?

Thanks again!

corvy commented 9 months ago

Thats very good news! :)

The addon publishes to MQTT every 10 seconds, if it has a fixed position to post. If there is no fix, no publish will happen. You can increase or decrease this if you like in the advanced settings by setting a preferred seconds amount in the addon.

image

The information you are looking for is available as attributes to the "device_tracker.gps_location". You can get these as separate entities if you do not want to use the attributes directly.

One way is to add via HACS: https://github.com/gjohansson-ST/attribute_as_sensor (not tried myself)

Or you could add it to configuration.yaml directly with the following code:

template:
  - sensor:
      - name: speed
        state: "{{ state_attr('device_tracker.gps_location', 'speed') }}"
        unit_of_measurement: "m/s"
      - name: lat
        state: "{{ state_attr('device_tracker.gps_location', 'latitude') }}"
      - name: lon
        state: "{{ state_attr('device_tracker.gps_location', 'longitude') }}"

image image

I can have a think about if it is something we could add to advanced options for a future release.

Thanks for getting back to me and hope you enjoy the addon-on for your use case.

corvy commented 9 months ago

Hello, if you are fine with it I will close this ticket now. Please take contact if you need further assistance!

Best regards Stian

deanfourie1 commented 9 months ago

Yes,

Thank you