@@ -146,11 +146,20 @@ bool PositionModule::hasQualityTimesource()
146146#if MESHTASTIC_EXCLUDE_GPS
147147 bool hasGpsOrRtc = (rtc_found.address != ScanI2C::ADDRESS_NONE.address );
148148#else
149- bool hasGpsOrRtc = (gps && gps-> isConnected () ) || (rtc_found.address != ScanI2C::ADDRESS_NONE.address );
149+ bool hasGpsOrRtc = hasGPS ( ) || (rtc_found.address != ScanI2C::ADDRESS_NONE.address );
150150#endif
151151 return hasGpsOrRtc || setFromPhoneOrNtpToday;
152152}
153153
154+ bool PositionModule::hasGPS ()
155+ {
156+ #if MESHTASTIC_EXCLUDE_GPS
157+ return false ;
158+ #else
159+ return gps && gps->isConnected ();
160+ #endif
161+ }
162+
154163meshtastic_MeshPacket *PositionModule::allocReply ()
155164{
156165 if (precision == 0 ) {
@@ -194,10 +203,21 @@ meshtastic_MeshPacket *PositionModule::allocReply()
194203 p.precision_bits = precision;
195204 p.has_latitude_i = true ;
196205 p.has_longitude_i = true ;
197- p.time = getValidTime (RTCQualityNTP) > 0 ? getValidTime (RTCQualityNTP) : localPosition.time ;
206+ // Always use NTP / GPS time if available
207+ if (getValidTime (RTCQualityNTP) > 0 ) {
208+ p.time = getValidTime (RTCQualityNTP);
209+ } else if (rtc_found.address != ScanI2C::ADDRESS_NONE.address ) {
210+ LOG_INFO (" Use RTC time for position" );
211+ p.time = getValidTime (RTCQualityDevice);
212+ } else if (getRTCQuality () < RTCQualityNTP) {
213+ LOG_INFO (" Strip low RTCQuality (%d) time from position" , getRTCQuality ());
214+ p.time = 0 ;
215+ }
198216
199217 if (config.position .fixed_position ) {
200218 p.location_source = meshtastic_Position_LocSource_LOC_MANUAL;
219+ } else {
220+ p.location_source = localPosition.location_source ;
201221 }
202222
203223 if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE) {
@@ -242,20 +262,6 @@ meshtastic_MeshPacket *PositionModule::allocReply()
242262 p.has_ground_speed = true ;
243263 }
244264
245- // Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other
246- // nodes shouldn't trust it anyways) Note: we allow a device with a local GPS or NTP to include the time, so that devices
247- // without can get time.
248- if (getRTCQuality () < RTCQualityNTP) {
249- LOG_INFO (" Strip time %u from position" , p.time );
250- p.time = 0 ;
251- } else if (rtc_found.address != ScanI2C::ADDRESS_NONE.address ) {
252- LOG_INFO (" Use RTC time %u for position" , p.time );
253- p.time = getValidTime (RTCQualityDevice);
254- } else {
255- p.time = getValidTime (RTCQualityNTP);
256- LOG_INFO (" Provide time to mesh %u" , p.time );
257- }
258-
259265 LOG_INFO (" Position reply: time=%i lat=%i lon=%i" , p.time , p.latitude_i , p.longitude_i );
260266
261267 // TAK Tracker devices should send their position in a TAK packet over the ATAK port
0 commit comments