diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 55b8c0b4da..841a50d658 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -114,7 +114,7 @@ NodeDB::NodeDB() uint32_t channelFileCRC = crc32Buffer(&channelFile, sizeof(channelFile)); int saveWhat = 0; - bool hasUniqueId = false; + // bool hasUniqueId = false; // Get device unique id #if defined(ARCH_ESP32) && defined(ESP_EFUSE_OPTIONAL_UNIQUE_ID) uint32_t unique_id[4]; diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index fc15aabb62..d977cfdeca 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -146,11 +146,20 @@ bool PositionModule::hasQualityTimesource() #if MESHTASTIC_EXCLUDE_GPS bool hasGpsOrRtc = (rtc_found.address != ScanI2C::ADDRESS_NONE.address); #else - bool hasGpsOrRtc = (gps && gps->isConnected()) || (rtc_found.address != ScanI2C::ADDRESS_NONE.address); + bool hasGpsOrRtc = hasGPS() || (rtc_found.address != ScanI2C::ADDRESS_NONE.address); #endif return hasGpsOrRtc || setFromPhoneOrNtpToday; } +bool PositionModule::hasGPS() +{ +#if MESHTASTIC_EXCLUDE_GPS + return false; +#else + return gps && gps->isConnected(); +#endif +} + meshtastic_MeshPacket *PositionModule::allocReply() { if (precision == 0) { @@ -194,10 +203,21 @@ meshtastic_MeshPacket *PositionModule::allocReply() p.precision_bits = precision; p.has_latitude_i = true; p.has_longitude_i = true; - p.time = getValidTime(RTCQualityNTP) > 0 ? getValidTime(RTCQualityNTP) : localPosition.time; + // Always use NTP / GPS time if available + if (getValidTime(RTCQualityNTP) > 0) { + p.time = getValidTime(RTCQualityNTP); + } else if (rtc_found.address != ScanI2C::ADDRESS_NONE.address) { + LOG_INFO("Use RTC time for position"); + p.time = getValidTime(RTCQualityDevice); + } else if (getRTCQuality() < RTCQualityNTP) { + LOG_INFO("Strip low RTCQuality (%d) time from position", getRTCQuality()); + p.time = 0; + } if (config.position.fixed_position) { p.location_source = meshtastic_Position_LocSource_LOC_MANUAL; + } else { + p.location_source = localPosition.location_source; } if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE) { @@ -242,20 +262,6 @@ meshtastic_MeshPacket *PositionModule::allocReply() p.has_ground_speed = true; } - // Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other - // nodes shouldn't trust it anyways) Note: we allow a device with a local GPS or NTP to include the time, so that devices - // without can get time. - if (getRTCQuality() < RTCQualityNTP) { - LOG_INFO("Strip time %u from position", p.time); - p.time = 0; - } else if (rtc_found.address != ScanI2C::ADDRESS_NONE.address) { - LOG_INFO("Use RTC time %u for position", p.time); - p.time = getValidTime(RTCQualityDevice); - } else { - p.time = getValidTime(RTCQualityNTP); - LOG_INFO("Provide time to mesh %u", p.time); - } - LOG_INFO("Position reply: time=%i lat=%i lon=%i", p.time, p.latitude_i, p.longitude_i); // TAK Tracker devices should send their position in a TAK packet over the ATAK port diff --git a/src/modules/PositionModule.h b/src/modules/PositionModule.h index 41b86b7951..1e4aa5d293 100644 --- a/src/modules/PositionModule.h +++ b/src/modules/PositionModule.h @@ -61,6 +61,7 @@ class PositionModule : public ProtobufModule, private concu uint32_t precision; void sendLostAndFoundText(); bool hasQualityTimesource(); + bool hasGPS(); const uint32_t minimumTimeThreshold = Default::getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30);