Closed pkkrusty closed 1 year ago
Could you please compile with #define DEBUG_TASMOTA_SENSOR
and re-post the logs with the additional informations ?
Addionally you could try to restrict the NTP server to only reply with a valid GPS fix by changing line 725 to:
if(!TasmotaGlobal.global_state.network_down && UBX.mode.runningNTP && UBX.state.gpsFix > 1){
In this use case, I just need the ESP8266 to set its own time correctly, since I'm logging GPS data and need the time stamp. Not using the NTP feature. Maybe this line affects just internal usage also?
OK, more logging info:
Cold start, GPS reports time as 3236-1-12 23:59:46, then rolls over at "midnight" to 1980-01-06 00:00:00:
00:00:01.098 UBX: got 34 bytes, non-empty-loop: 1
00:00:01.399 WIF: Checking connection...
00:00:01.400 WIF: Attempting connection...
00:00:01.910 UBX: got NAV_STATUS
00:00:01.918 UBX: gpsFix: 0, valid: 0
00:00:02.004 UBX: got NAV_POSLLH
00:00:02.005 UBX: got NAV_TIME_UTC
00:00:02.005 UBX: got 95 bytes, non-empty-loop: 1
00:00:02.405 WIF: Checking connection...
00:00:02.406 WIF: Attempting connection...
00:00:02.912 UBX: got NAV_STATUS
00:00:02.921 UBX: gpsFix: 0, valid: 0
00:00:03.007 UBX: got NAV_POSLLH
00:00:03.007 UBX: iTOW: 3000
00:00:03.008 UBX: no valid position data
00:00:03.106 UBX: got NAV_TIME_UTC
00:00:03.107 UBX: UTC-Time: 3236-1-12 23:59:48
00:00:03.406 WIF: Checking connection...
00:00:03.406 WIF: Attempting connection...
00:00:03.407 WIF: Network 0, AP1, SSId Roatan, Channel 1, BSSId 28:DE:A8:AB:9D:68, RSSI -58, Encryption 1
00:00:03.412 WIF: Network 1, AP-, SSId Roatan-2, Channel 6, BSSId C0:4A:00:40:5F:E7, RSSI -69, Encryption 1
00:00:03.758 WIF: Connecting to AP1 Roatan Channel 1 BSSId 28:DE:A8:AB:9D:68 in mode 11n as gps-test...
00:00:03.936 UBX: got NAV_STATUS
00:00:03.937 UBX: gpsFix: 0, valid: 0
00:00:04.036 UBX: got NAV_TIME_UTC
00:00:04.037 UBX: UTC-Time: 3236-1-12 23:59:49
00:00:04.639 WIF: Checking connection...
00:00:04.640 WIF: Attempting connection...
00:00:05.002 UBX: got NAV_STATUS
00:00:05.003 UBX: gpsFix: 0, valid: 0
00:00:05.102 UBX: got NAV_POSLLH
00:00:05.103 UBX: iTOW: 5000
00:00:05.103 UBX: no valid position data
00:00:05.208 UBX: got NAV_TIME_UTC
00:00:05.220 UBX: UTC-Time: 3236-1-12 23:59:50
00:00:05.305 UBX: got NAV_STATUS
00:00:05.305 UBX: gpsFix: 0, valid: 0
00:00:05.404 UBX: got NAV_POSLLH
00:00:05.405 UBX: iTOW: 6000
00:00:05.406 UBX: no valid position data
00:00:05.504 UBX: got NAV_TIME_UTC
00:00:05.505 UBX: UTC-Time: 3236-1-12 23:59:51
00:00:05.756 WIF: Checking connection...
00:00:05.757 WIF: Attempting connection...
00:00:06.213 UBX: got NAV_STATUS
00:00:06.226 UBX: gpsFix: 0, valid: 0
00:00:06.299 QPC: Reset
00:00:06.308 UBX: got NAV_POSLLH
00:00:06.309 UBX: iTOW: 7000
00:00:06.310 UBX: no valid position data
00:00:06.408 UBX: got NAV_TIME_UTC
00:00:06.409 UBX: UTC-Time: 3236-1-12 23:59:52
00:00:06.759 WIF: Checking connection...
00:00:06.760 WIF: Attempting connection...
00:00:07.218 UBX: got NAV_STATUS
00:00:07.233 UBX: gpsFix: 0, valid: 0
00:00:07.313 UBX: got NAV_POSLLH
00:00:07.314 UBX: iTOW: 8000
00:00:07.314 UBX: no valid position data
00:00:07.412 UBX: got NAV_TIME_UTC
00:00:07.413 UBX: UTC-Time: 3236-1-12 23:59:53
00:00:07.764 WIF: Checking connection...
00:00:07.765 WIF: Connected
00:00:08.015 WIF: DNS resolved '192.168.1.23' (192.168.1.23) in 0 ms
00:00:08.129 HTP: Web server active on gps-test with IP address 192.168.1.55
00:00:08.237 UBX: got NAV_STATUS
00:00:08.252 UBX: gpsFix: 0, valid: 0
00:00:08.271 APP: Boot Count 45
00:00:08.299 WIF: Sending Gratuitous ARP
00:00:08.300 NTP: Sync time...
00:00:08.302 WIF: DNS resolved '192.168.1.23' (192.168.1.23) in 0 ms
00:00:09.309 NTP: No reply from 192.168.1.23
00:00:09.311 UBX: got NAV_POSLLH
00:00:09.311 UBX: iTOW: 9000
00:00:09.312 UBX: no valid position data
00:00:09.463 CFG: Saved to flash at 3FB, Count 82, Bytes 4096
00:00:09.476 NTP: Sync time...
00:00:09.477 WIF: DNS resolved '192.168.1.1' (192.168.1.1) in 0 ms
00:00:10.486 NTP: No reply from 192.168.1.1
00:00:10.488 UBX: got NAV_TIME_UTC
00:00:10.489 UBX: UTC-Time: 3236-1-12 23:59:54
00:00:10.499 NTP: Sync time...
00:00:10.822 WIF: DNS resolved '0.nl.pool.ntp.org' (83.98.201.134) in 321 ms
00:00:10.925 RTC: UTC 2023-02-08T10:34:51, DST 2023-03-26T02:00:00, STD 2023-10-29T03:00:00
10:34:51.001 RTC: Synced by NTP
10:34:51.003 UBX: got NAV_STATUS
10:34:51.004 UBX: gpsFix: 0, valid: 0
10:34:51.007 MQT: Attempting connection...
10:34:51.011 WIF: DNS resolved '192.168.1.23' (192.168.1.23) in 0 ms
10:34:51.029 MQT: Connected
10:34:51.032 MQT: gps-test/tele/LWT = Online (retained)
10:34:51.035 MQT: gps-test/cmnd/POWER =
10:34:51.037 MQT: Subscribe to gps-test/cmnd/#
10:34:51.040 MQT: Subscribe to tasmotas/cmnd/#
10:34:51.044 MQT: Subscribe to cmnd/pkkrusty_CF21B8_fb/#
10:34:51.049 MQT: gps-test/tele/INFO1 = {"Info1":{"Module":"Generic","Version":"12.3.1.5(tasmota)","FallbackTopic":"cmnd/pkkrusty_CF21B8_fb/","GroupTopic":"tasmotas/cmnd/"}}
10:34:51.063 MQT: gps-test/tele/INFO2 = {"Info2":{"WebServerMode":"Admin","Hostname":"gps-test","IPAddress":"192.168.1.55"}}
10:34:51.074 MQT: gps-test/tele/INFO3 = {"Info3":{"RestartReason":"External System","BootCount":46}}
10:34:51.082 TFS: File 'autoexec.bat' not found
10:34:51.051 UBX: got NAV_POSLLH
10:34:51.052 UBX: iTOW: 10000
10:34:51.053 UBX: no valid position data
10:34:51.150 UBX: got NAV_TIME_UTC
10:34:51.152 UBX: UTC-Time: 3236-1-12 23:59:55
10:34:51.222 UBX: got NAV_STATUS
10:34:51.236 UBX: gpsFix: 0, valid: 0
10:34:51.321 UBX: got NAV_POSLLH
10:34:51.323 UBX: iTOW: 11000
10:34:51.323 UBX: no valid position data
10:34:51.422 UBX: got NAV_TIME_UTC
10:34:51.423 UBX: UTC-Time: 3236-1-12 23:59:56
10:34:51.522 UBX: got NAV_STATUS
10:34:51.523 UBX: gpsFix: 0, valid: 0
10:34:51.622 UBX: got NAV_POSLLH
10:34:51.624 UBX: iTOW: 12000
10:34:51.624 UBX: no valid position data
10:34:51.723 UBX: got NAV_TIME_UTC
10:34:51.724 UBX: UTC-Time: 3236-1-12 23:59:57
10:34:52.245 UBX: got NAV_STATUS
10:34:52.262 UBX: gpsFix: 0, valid: 0
10:34:52.368 UBX: got NAV_POSLLH
10:34:52.370 UBX: iTOW: 13000
10:34:52.370 UBX: no valid position data
10:34:52.469 UBX: got NAV_TIME_UTC
10:34:52.471 UBX: UTC-Time: 3236-1-12 23:59:58
10:34:53.279 UBX: got NAV_STATUS
10:34:53.293 UBX: gpsFix: 0, valid: 0
10:34:53.370 UBX: got NAV_POSLLH
10:34:53.372 UBX: iTOW: 14000
10:34:53.372 UBX: no valid position data
10:34:53.472 UBX: got NAV_TIME_UTC
10:34:53.473 UBX: UTC-Time: 3236-1-12 23:59:59
10:34:54.234 UBX: got NAV_STATUS
10:34:54.253 UBX: gpsFix: 0, valid: 0
10:34:54.356 UBX: got NAV_POSLLH
10:34:54.357 UBX: iTOW: 15000
10:34:54.358 UBX: no valid position data
10:34:54.457 UBX: got NAV_TIME_UTC
10:34:54.458 UBX: UTC-Time: 1980-1-6 0:0:0
10:34:55.270 UBX: got NAV_STATUS
10:34:55.291 UBX: gpsFix: 0, valid: 0
10:34:55.311 MQT: gps-test/tele/STATE = {"Time":"2023-02-08T10:34:55","Uptime":"0T00:00:16","UptimeSec":16,"Heap":20,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":20,"MqttCount":1,}
10:34:55.336 MQT: gps-test/tele/SENSOR = {"Time":"2023-02-08T10:34:55","GPS":{"fil":0,"int":1}}
10:34:55.340 UBX: got NAV_POSLLH
10:34:55.342 UBX: iTOW: 16000
10:34:55.343 UBX: no valid position data
10:34:55.439 UBX: got NAV_TIME_UTC
10:34:55.441 UBX: UTC-Time: 1980-1-6 0:0:1
10:34:56.287 UBX: got NAV_STATUS
10:34:56.292 UBX: gpsFix: 0, valid: 0
then after a few minutes the GPS reports a correct time but still wrong date (however, date is adjusted to 2248 weeks before the actual date), but driver interprets that as correct date/time (and writes it into rtctime?)
10:38:30.417 UBX: UTC-Time: 1980-1-6 0:3:36
10:38:31.227 UBX: got NAV_STATUS
10:38:31.247 UBX: gpsFix: 0, valid: 0
10:38:31.322 UBX: got NAV_POSLLH
10:38:31.323 UBX: iTOW: 297530000
10:38:31.324 UBX: no valid position data
10:38:31.423 UBX: got NAV_TIME_UTC
10:38:31.424 UBX: UTC-Time: 1980-1-9 10:38:35
10:38:31.425 UBX: UTC-Time is valid
10:38:31.427 RTC: UTC 1980-01-09T10:38:35, DST 1980-03-30T02:00:00, STD 1980-10-26T03:00:00
10:38:35.001 RTC: Synced by UBX
10:38:36.231 UBX: got NAV_STATUS
10:38:36.251 UBX: gpsFix: 0, valid: 0
10:38:36.325 UBX: got NAV_POSLLH
10:38:36.326 UBX: iTOW: 297531000
10:38:36.327 UBX: no valid position data
10:38:36.424 UBX: got NAV_TIME_UTC
10:38:36.425 UBX: UTC-Time: 1980-1-9 10:38:36
10:38:36.426 UBX: UTC-Time is valid
10:38:37.241 UBX: got NAV_STATUS
10:38:37.260 UBX: gpsFix: 0, valid: 0
10:38:37.332 UBX: got NAV_POSLLH
Then 16 seconds later GPS reports correct date and time, but clock is already set as valid in tasmota, so I guess wouldn't get adjusted until the RTC re-sync that happens every x minutes.
10:38:47.229 UBX: got NAV_STATUS
10:38:47.248 UBX: gpsFix: 0, valid: 0
10:38:47.323 UBX: got NAV_POSLLH
10:38:47.324 UBX: iTOW: 297542000
10:38:47.325 UBX: no valid position data
10:38:47.423 UBX: got NAV_TIME_UTC
10:38:47.424 UBX: UTC-Time: 2023-2-8 10:38:47
10:38:47.425 UBX: UTC-Time is valid
10:38:48.233 UBX: got NAV_STATUS
10:38:48.252 UBX: gpsFix: 0, valid: 0
10:38:48.325 UBX: got NAV_POSLLH
10:38:48.327 UBX: iTOW: 297543000
10:38:48.328 UBX: no valid position data
10:38:48.426 UBX: got NAV_TIME_UTC
10:38:48.427 UBX: UTC-Time: 2023-2-8 10:38:48
10:38:48.428 UBX: UTC-Time is valid
10:38:49.232 UBX: got NAV_STATUS
10:38:49.251 UBX: gpsFix: 0, valid: 0
10:38:49.325 UBX: got NAV_POSLLH
10:38:49.326 UBX: iTOW: 297544000
10:38:49.327 UBX: no valid position data
10:38:49.424 UBX: got NAV_TIME_UTC
10:38:49.425 UBX: UTC-Time: 2023-2-8 10:38:49
10:38:49.426 UBX: UTC-Time is valid
10:38:50.236 UBX: got NAV_STATUS
10:38:50.254 UBX: gpsFix: 0, valid: 0
10:38:50.330 UBX: got NAV_POSLLH
10:38:50.331 UBX: iTOW: 297545000
10:38:50.332 UBX: no valid position data
10:38:50.430 UBX: got NAV_TIME_UTC
10:38:50.431 UBX: UTC-Time: 2023-2-8 10:38:50
10:38:50.432 UBX: UTC-Time is valid
10:38:51.433 UBX: got NAV_STATUS
10:38:51.434 UBX: gpsFix: 0, valid: 0
10:38:51.530 UBX: got NAV_POSLLH
10:38:51.531 UBX: iTOW: 297546000
10:38:51.532 UBX: no valid position data
10:38:51.630 UBX: got NAV_TIME_UTC
10:38:51.631 UBX: UTC-Time: 2023-2-8 10:38:51
10:38:51.632 UBX: UTC-Time is valid
10:38:52.236 UBX: got NAV_STATUS
10:38:52.254 UBX: gpsFix: 0, valid: 0
10:38:52.330 UBX: got NAV_POSLLH
10:38:52.331 UBX: iTOW: 297547000
10:38:52.332 UBX: no valid position data
10:38:52.431 UBX: got NAV_TIME_UTC
10:38:52.432 UBX: UTC-Time: 2023-2-8 10:38:52
10:38:52.433 UBX: UTC-Time is valid
10:38:53.242 UBX: got NAV_STATUS
10:38:53.261 UBX: gpsFix: 0, valid: 0
10:38:53.335 UBX: got NAV_POSLLH
10:38:53.336 UBX: iTOW: 297548000
10:38:53.337 UBX: no valid position data
10:38:53.436 UBX: got NAV_TIME_UTC
10:38:53.437 UBX: UTC-Time: 2023-2-8 10:38:53
10:38:53.438 UBX: UTC-Time is valid
10:38:54.243 UBX: got NAV_STATUS
10:38:54.262 UBX: gpsFix: 0, valid: 0
10:38:54.336 UBX: got NAV_POSLLH
10:38:54.337 UBX: iTOW: 297549000
10:38:54.338 UBX: no valid position data
10:38:54.436 UBX: got NAV_TIME_UTC
10:38:54.437 UBX: UTC-Time: 2023-2-8 10:38:54
10:38:54.438 UBX: UTC-Time is valid
10:38:55.243 UBX: got NAV_STATUS
10:38:55.262 UBX: gpsFix: 0, valid: 0
10:38:55.337 UBX: got NAV_POSLLH
10:38:55.338 UBX: iTOW: 297550000
10:38:55.339 UBX: no valid position data
10:38:55.437 UBX: got NAV_TIME_UTC
10:38:55.438 UBX: UTC-Time: 2023-2-8 10:38:55
10:38:55.440 UBX: UTC-Time is valid
10:38:56.247 UBX: got NAV_STATUS
10:38:56.266 UBX: gpsFix: 0, valid: 0
10:38:56.342 UBX: got NAV_POSLLH
10:38:56.343 UBX: iTOW: 297551000
10:38:56.344 UBX: no valid position data
10:38:56.442 UBX: got NAV_TIME_UTC
10:38:56.443 UBX: UTC-Time: 2023-2-8 10:38:56
10:38:56.444 UBX: UTC-Time is valid
10:38:57.351 UBX: got NAV_STATUS
10:38:57.364 UBX: gpsFix: 0, valid: 0
10:38:57.445 UBX: got NAV_POSLLH
10:38:57.446 UBX: iTOW: 297552001
10:38:57.447 UBX: no valid position data
10:38:57.545 UBX: got NAV_TIME_UTC
10:38:57.546 UBX: UTC-Time: 2023-2-8 10:38:57
10:38:57.547 UBX: UTC-Time is valid
10:38:58.253 UBX: got NAV_STATUS
10:38:58.268 UBX: gpsFix: 0, valid: 0
10:38:58.347 UBX: got NAV_POSLLH
10:38:58.348 UBX: iTOW: 297553000
10:38:58.349 UBX: no valid position data
10:38:58.446 UBX: got NAV_TIME_UTC
10:38:58.447 UBX: UTC-Time: 2023-2-8 10:38:58
10:38:58.448 UBX: UTC-Time is valid
10:38:59.206 UBX: got NAV_STATUS
10:38:59.225 UBX: gpsFix: 0, valid: 0
10:38:59.303 UBX: got NAV_POSLLH
10:38:59.304 UBX: iTOW: 297554000
10:38:59.305 UBX: no valid position data
10:38:59.403 UBX: got NAV_TIME_UTC
10:38:59.404 UBX: UTC-Time: 2023-2-8 10:38:59
10:38:59.406 UBX: UTC-Time is valid
10:39:00.213 UBX: got NAV_STATUS
10:39:00.232 UBX: gpsFix: 0, valid: 0
10:39:00.307 UBX: got NAV_POSLLH
10:39:00.308 UBX: iTOW: 297555000
I suppose I could enable the option to force time update on every valid time received (Sensor60 11), but seems like ideal would be to restrict valid time to >1554595182 (2019-04-06 23:59:42, the latest GPS week rollover).
Makes sense to me. Next rollover is a bit to go, I just think about to deny times, that are older than the firmware build time in general.
Do you want to submit a PR for that? I'm not sure where exactly in the code that check would go.
Separately, I noticed in your drift filter Line 632, you have a check:
if ((UBX.Message.navPosllh.lat-UBX.rec_buffer.values.lat<abs(UBX_LAT_LON_THRESHOLD))||(UBX.Message.navPosllh.lon-UBX.rec_buffer.values.lon<abs(UBX_LAT_LON_THRESHOLD))) {
but I think maybe it should be:
if ((abs(UBX.Message.navPosllh.lat-UBX.rec_buffer.values.lat)<UBX_LAT_LON_THRESHOLD)||(abs(UBX.Message.navPosllh.lon-UBX.rec_buffer.values.lon)<UBX_LAT_LON_THRESHOLD)) {
since you want to compare movement in any direction to the threshold.
deny times, that are older than the firmware build time in general.
I think making the test based on the build date is perfect but over-engineered Testing against <2023 should be fine and could updated in a few years if needed
@pkkrusty I agree, your change should be an improvement.
@barbudor I agree too, hardcoding 2023 should be perfectly fine.
Feel free to open a PR. My spare time is completely absorbed by a pretty large subproject for Tasmota at the moment, that’s why I can not really do testing in this case in the next days.
Done for both issue : https://github.com/arendst/Tasmota/pull/17932
Your review is welcome @pkkrusty and @Staars
Was also thinking about making new_position available to users (getting passed into JSON messages like lat and lon) so logic could be performed based on it (i.e. only logging if new_position is true). I adjusted the code to make new_position global in the driver, and it takes its value from the bool function UBXHandlePOSLLH()
so I would assume new_position would be either true or false (1/0), but in WebUI, it shows as 1073422080. JSON is displayed correctly as 1/0. I'll PR after yours is merged so you can take a look at it and see what I'm missing.
Also added a dynamic adjustment for UBX_LAT_LON_THRESHOLD
, since common cheap GPS boards will get down to 2m horizontal accuracy and 5 decimal digits in GPS coordinates is 1.11m, so a multiplier of 50 seems to be a good threshold. That filters any movement below (above?) 5 decimal digits, which is noise anyway. In my tests with 5m accuracy, a threshold of 100 was very stable in detecting movement correctly.
Assuming a bool is 0 or 1 is a shortcut I wouldn't take
Per C definition false is 0, true is anything non 0
Depending how you are using the return value of UBXHandlePOSLLH()
for the JSON and for the GUI, you may get different values depending how the compiler is re-casting
To be 100% sure (mybool ? 1: 0)
will give you the expected result
PROBLEM DESCRIPTION
Connected a GPS module to ESP8266. When ESP8266 is restarted and the GPS module already has a signal, the GPS will correctly set the date/time of the system on startup. However, if the ESP8266 is cold started (and thus the GPS is cold-started), the system date remains at 1-Jan-1970 (as expected) until GPS receives a good signal, then turns into 7-Jan-1980 with the correct time (issue opened on 6-Feb-2023, 2248 weeks or 1,359,590,400 seconds from the 1980 date).
REQUESTED INFORMATION
Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!
Backlog Template; Module; GPIO 255
:Status 0
:Abnormal operation
Note that this UBX sync happens before the LED on the GPS module starts blinking.
TO REPRODUCE
Steps to reproduce the behavior: Restart 1 with GPS already sending data gives normal date/time. Detaching and reattaching power results in GPS module reporting 7-Jan-1980 date with correct time, even after GPS starts sending location data. Maybe due to time sync before full fix is available? The on-board battery in the module is holding only time and not date?
EXPECTED BEHAVIOUR
A clear and concise description of what you expected to happen. UBX sync gives correct date/time whether hot start or cold start.
SCREENSHOTS
If applicable, add screenshots to help explain your problem.
ADDITIONAL CONTEXT
Add any other context about the problem here. Webserver seems to crash regularly while running the GPS driver. Host is still alive, responds to ping, logs data, but can't load any pages.
(Please, remember to close the issue when the problem has been addressed)