mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 22:52:07 +00:00
Send environment telemetry every minute (#1808)
This commit is contained in:
parent
d8f44d7b1b
commit
fc57a9daa4
@ -15,8 +15,9 @@ int32_t DeviceTelemetryModule::runOnce()
|
|||||||
{
|
{
|
||||||
#ifndef ARCH_PORTDUINO
|
#ifndef ARCH_PORTDUINO
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if ((lastSentToMesh == 0 || (now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval))
|
if ((lastSentToMesh == 0 ||
|
||||||
&& airTime->channelUtilizationPercent() < max_channel_util_percent) {
|
(now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval)) &&
|
||||||
|
airTime->channelUtilizationPercent() < max_channel_util_percent) {
|
||||||
sendTelemetry();
|
sendTelemetry();
|
||||||
lastSentToMesh = now;
|
lastSentToMesh = now;
|
||||||
} else if (service.isToPhoneQueueEmpty()) {
|
} else if (service.isToPhoneQueueEmpty()) {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <OLEDDisplay.h>
|
#include <OLEDDisplay.h>
|
||||||
#include <OLEDDisplayUi.h>
|
#include <OLEDDisplayUi.h>
|
||||||
|
#include "MeshService.h"
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
#include "Sensor/BMP280Sensor.h"
|
#include "Sensor/BMP280Sensor.h"
|
||||||
@ -98,15 +99,20 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||||||
// if we somehow got to a second run of this module with measurement disabled, then just wait forever
|
// if we somehow got to a second run of this module with measurement disabled, then just wait forever
|
||||||
if (!moduleConfig.telemetry.environment_measurement_enabled)
|
if (!moduleConfig.telemetry.environment_measurement_enabled)
|
||||||
return result;
|
return result;
|
||||||
// this is not the first time OSThread library has called this function
|
|
||||||
// so just do what we intend to do on the interval
|
uint32_t now = millis();
|
||||||
if (!sendOurTelemetry()) {
|
if ((lastSentToMesh == 0 ||
|
||||||
// if we failed to read the sensor, then try again
|
(now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval)) &&
|
||||||
// as soon as we can according to the maximum polling frequency
|
airTime->channelUtilizationPercent() < max_channel_util_percent) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
sendTelemetry();
|
||||||
|
lastSentToMesh = now;
|
||||||
|
} else if (service.isToPhoneQueueEmpty()) {
|
||||||
|
// Just send to phone when it's not our time to send to mesh yet
|
||||||
|
// Only send while queue is empty (phone assumed connected)
|
||||||
|
sendTelemetry(NODENUM_BROADCAST, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval);
|
return sendToPhoneIntervalMs;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +198,7 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Te
|
|||||||
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 EnvironmentTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies)
|
bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
||||||
{
|
{
|
||||||
Telemetry m;
|
Telemetry m;
|
||||||
m.time = getTime();
|
m.time = getTime();
|
||||||
@ -234,10 +240,15 @@ bool EnvironmentTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies
|
|||||||
|
|
||||||
MeshPacket *p = allocDataProtobuf(m);
|
MeshPacket *p = allocDataProtobuf(m);
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->decoded.want_response = wantReplies;
|
p->decoded.want_response = false;
|
||||||
|
|
||||||
lastMeasurementPacket = packetPool.allocCopy(*p);
|
lastMeasurementPacket = packetPool.allocCopy(*p);
|
||||||
DEBUG_MSG("Sending packet to mesh");
|
if (phoneOnly) {
|
||||||
service.sendToMesh(p, RX_SRC_LOCAL, true);
|
DEBUG_MSG("Sending packet to phone\n");
|
||||||
|
service.sendToPhone(p);
|
||||||
|
} else {
|
||||||
|
DEBUG_MSG("Sending packet to mesh\n");
|
||||||
|
service.sendToMesh(p, RX_SRC_LOCAL, true);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,13 @@ class EnvironmentTelemetryModule : private concurrency::OSThread, public Protobu
|
|||||||
/**
|
/**
|
||||||
* Send our Telemetry into the mesh
|
* Send our Telemetry into the mesh
|
||||||
*/
|
*/
|
||||||
bool sendOurTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float CelsiusToFahrenheit(float c);
|
float CelsiusToFahrenheit(float c);
|
||||||
bool firstTime = 1;
|
bool firstTime = 1;
|
||||||
const MeshPacket *lastMeasurementPacket;
|
const MeshPacket *lastMeasurementPacket;
|
||||||
|
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
|
||||||
|
uint32_t lastSentToMesh = 0;
|
||||||
uint32_t sensor_read_error_count = 0;
|
uint32_t sensor_read_error_count = 0;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user