mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-02 12:03:56 +00:00
Reply to Repeater in DeviceTelemetry module (#2661)
This commit is contained in:
parent
b799b7bf62
commit
9eeec6c083
@ -92,6 +92,9 @@ void setupModules()
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
adminModule = new AdminModule();
|
adminModule = new AdminModule();
|
||||||
|
#if HAS_TELEMETRY
|
||||||
|
new DeviceTelemetryModule();
|
||||||
|
#endif
|
||||||
traceRouteModule = new TraceRouteModule();
|
traceRouteModule = new TraceRouteModule();
|
||||||
}
|
}
|
||||||
// NOTE! This module must be added LAST because it likes to check for replies from other modules and avoid sending extra
|
// NOTE! This module must be added LAST because it likes to check for replies from other modules and avoid sending extra
|
||||||
|
@ -17,7 +17,8 @@ int32_t DeviceTelemetryModule::runOnce()
|
|||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if (((lastSentToMesh == 0) ||
|
if (((lastSentToMesh == 0) ||
|
||||||
((now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval))) &&
|
((now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval))) &&
|
||||||
airTime->isTxAllowedChannelUtil() && airTime->isTxAllowedAirUtil()) {
|
airTime->isTxAllowedChannelUtil() && airTime->isTxAllowedAirUtil() &&
|
||||||
|
config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER) {
|
||||||
sendTelemetry();
|
sendTelemetry();
|
||||||
lastSentToMesh = now;
|
lastSentToMesh = now;
|
||||||
} else if (service.isToPhoneQueueEmpty()) {
|
} else if (service.isToPhoneQueueEmpty()) {
|
||||||
@ -30,6 +31,10 @@ int32_t DeviceTelemetryModule::runOnce()
|
|||||||
|
|
||||||
bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)
|
bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)
|
||||||
{
|
{
|
||||||
|
// Don't worry about storing telemetry in NodeDB if we're a repeater
|
||||||
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (t->which_variant == meshtastic_Telemetry_device_metrics_tag) {
|
if (t->which_variant == meshtastic_Telemetry_device_metrics_tag) {
|
||||||
#ifdef DEBUG_PORT
|
#ifdef DEBUG_PORT
|
||||||
const char *sender = getSenderShortName(mp);
|
const char *sender = getSenderShortName(mp);
|
||||||
@ -43,7 +48,19 @@ bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &
|
|||||||
return false; // Let others look at this message also if they want
|
return false; // Let others look at this message also if they want
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
meshtastic_MeshPacket *DeviceTelemetryModule::allocReply()
|
||||||
|
{
|
||||||
|
if (ignoreRequest) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO("Device telemetry replying to request\n");
|
||||||
|
|
||||||
|
meshtastic_Telemetry telemetry = getDeviceTelemetry();
|
||||||
|
return allocDataProtobuf(telemetry);
|
||||||
|
}
|
||||||
|
|
||||||
|
meshtastic_Telemetry DeviceTelemetryModule::getDeviceTelemetry()
|
||||||
{
|
{
|
||||||
meshtastic_Telemetry t;
|
meshtastic_Telemetry t;
|
||||||
|
|
||||||
@ -60,16 +77,22 @@ bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
t.variant.device_metrics.channel_utilization = airTime->channelUtilizationPercent();
|
t.variant.device_metrics.channel_utilization = airTime->channelUtilizationPercent();
|
||||||
t.variant.device_metrics.voltage = powerStatus->getBatteryVoltageMv() / 1000.0;
|
t.variant.device_metrics.voltage = powerStatus->getBatteryVoltageMv() / 1000.0;
|
||||||
|
|
||||||
LOG_INFO("(Sending): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n",
|
return t;
|
||||||
t.variant.device_metrics.air_util_tx, t.variant.device_metrics.channel_utilization,
|
}
|
||||||
t.variant.device_metrics.battery_level, t.variant.device_metrics.voltage);
|
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(t);
|
bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
||||||
|
{
|
||||||
|
meshtastic_Telemetry telemetry = getDeviceTelemetry();
|
||||||
|
LOG_INFO("(Sending): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n",
|
||||||
|
telemetry.variant.device_metrics.air_util_tx, telemetry.variant.device_metrics.channel_utilization,
|
||||||
|
telemetry.variant.device_metrics.battery_level, telemetry.variant.device_metrics.voltage);
|
||||||
|
|
||||||
|
meshtastic_MeshPacket *p = allocDataProtobuf(telemetry);
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->decoded.want_response = false;
|
p->decoded.want_response = false;
|
||||||
p->priority = meshtastic_MeshPacket_Priority_MIN;
|
p->priority = meshtastic_MeshPacket_Priority_MIN;
|
||||||
|
|
||||||
nodeDB.updateTelemetry(nodeDB.getNodeNum(), t, RX_SRC_LOCAL);
|
nodeDB.updateTelemetry(nodeDB.getNodeNum(), telemetry, RX_SRC_LOCAL);
|
||||||
if (phoneOnly) {
|
if (phoneOnly) {
|
||||||
LOG_INFO("Sending packet to phone\n");
|
LOG_INFO("Sending packet to phone\n");
|
||||||
service.sendToPhone(p);
|
service.sendToPhone(p);
|
||||||
|
@ -21,6 +21,7 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu
|
|||||||
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
||||||
*/
|
*/
|
||||||
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override;
|
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override;
|
||||||
|
virtual meshtastic_MeshPacket *allocReply() override;
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
/**
|
/**
|
||||||
* Send our Telemetry into the mesh
|
* Send our Telemetry into the mesh
|
||||||
@ -28,6 +29,7 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu
|
|||||||
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool phoneOnly = false);
|
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool phoneOnly = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
meshtastic_Telemetry getDeviceTelemetry();
|
||||||
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
|
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
|
||||||
uint32_t lastSentToMesh = 0;
|
uint32_t lastSentToMesh = 0;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user