2024-04-29 22:10:49 +12:00
|
|
|
#include "configuration.h"
|
|
|
|
|
|
2024-04-27 18:05:39 +12:00
|
|
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
|
|
|
|
|
2021-01-17 15:59:48 -05:00
|
|
|
#pragma once
|
2025-03-21 16:12:49 +01:00
|
|
|
|
|
|
|
|
#ifndef ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE
|
|
|
|
|
#define ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-01-18 08:56:47 -06:00
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
2022-05-01 14:26:05 -05:00
|
|
|
#include "NodeDB.h"
|
2022-05-07 20:31:21 +10:00
|
|
|
#include "ProtobufModule.h"
|
2025-10-13 18:09:33 +02:00
|
|
|
#include "detect/ScanI2CConsumer.h"
|
2021-02-21 16:46:46 -05:00
|
|
|
#include <OLEDDisplay.h>
|
|
|
|
|
#include <OLEDDisplayUi.h>
|
2021-01-17 15:59:48 -05:00
|
|
|
|
2025-10-13 18:09:33 +02:00
|
|
|
class EnvironmentTelemetryModule : private concurrency::OSThread,
|
|
|
|
|
public ScanI2CConsumer,
|
|
|
|
|
public ProtobufModule<meshtastic_Telemetry>
|
2021-01-17 15:59:48 -05:00
|
|
|
{
|
2024-07-13 05:59:19 -05:00
|
|
|
CallbackObserver<EnvironmentTelemetryModule, const meshtastic::Status *> nodeStatusObserver =
|
|
|
|
|
CallbackObserver<EnvironmentTelemetryModule, const meshtastic::Status *>(this,
|
|
|
|
|
&EnvironmentTelemetryModule::handleStatusUpdate);
|
|
|
|
|
|
2021-01-17 15:59:48 -05:00
|
|
|
public:
|
2022-03-27 14:55:35 +00:00
|
|
|
EnvironmentTelemetryModule()
|
2025-10-13 18:09:33 +02:00
|
|
|
: concurrency::OSThread("EnvironmentTelemetry"), ScanI2CConsumer(),
|
2023-01-21 18:22:19 +01:00
|
|
|
ProtobufModule("EnvironmentTelemetry", meshtastic_PortNum_TELEMETRY_APP, &meshtastic_Telemetry_msg)
|
2021-10-23 21:10:25 +02:00
|
|
|
{
|
2023-01-18 14:51:48 -06:00
|
|
|
lastMeasurementPacket = nullptr;
|
2024-07-13 05:59:19 -05:00
|
|
|
nodeStatusObserver.observe(&nodeStatus->onNewStatus);
|
2023-01-18 14:51:48 -06:00
|
|
|
setIntervalFromNow(10 * 1000);
|
2021-02-22 21:00:41 -05:00
|
|
|
}
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool wantUIFrame() override;
|
2022-07-31 07:11:47 -05:00
|
|
|
#if !HAS_SCREEN
|
2022-05-06 15:41:37 +02:00
|
|
|
void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
|
|
|
|
#else
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override;
|
2022-05-06 15:41:37 +02:00
|
|
|
#endif
|
2021-01-17 15:59:48 -05:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
|
|
|
|
*/
|
2023-01-21 18:22:19 +01:00
|
|
|
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override;
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2024-06-23 14:13:59 +02:00
|
|
|
/** Called to get current Environment telemetry data
|
|
|
|
|
@return true if it contains valid data
|
|
|
|
|
*/
|
|
|
|
|
bool getEnvironmentTelemetry(meshtastic_Telemetry *m);
|
|
|
|
|
virtual meshtastic_MeshPacket *allocReply() override;
|
2021-03-02 21:12:22 -05:00
|
|
|
/**
|
2022-02-26 20:52:22 -08:00
|
|
|
* Send our Telemetry into the mesh
|
2021-03-02 21:12:22 -05:00
|
|
|
*/
|
2022-10-16 11:36:38 -05:00
|
|
|
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
2021-10-23 21:10:25 +02:00
|
|
|
|
2024-06-16 02:59:22 +02:00
|
|
|
virtual AdminMessageHandleResult handleAdminMessageForModule(const meshtastic_MeshPacket &mp,
|
|
|
|
|
meshtastic_AdminMessage *request,
|
|
|
|
|
meshtastic_AdminMessage *response) override;
|
|
|
|
|
|
2025-10-13 18:09:33 +02:00
|
|
|
void i2cScanFinished(ScanI2C *i2cScanner);
|
|
|
|
|
|
2021-02-21 16:46:46 -05:00
|
|
|
private:
|
2021-03-02 21:12:22 -05:00
|
|
|
bool firstTime = 1;
|
2023-02-02 15:26:31 +01:00
|
|
|
meshtastic_MeshPacket *lastMeasurementPacket;
|
2022-10-16 11:36:38 -05:00
|
|
|
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
|
|
|
|
|
uint32_t lastSentToMesh = 0;
|
2023-05-25 14:35:45 +02:00
|
|
|
uint32_t lastSentToPhone = 0;
|
2021-03-02 21:12:22 -05:00
|
|
|
uint32_t sensor_read_error_count = 0;
|
2022-01-24 07:00:14 +00:00
|
|
|
};
|
2024-04-27 18:05:39 +12:00
|
|
|
|
|
|
|
|
#endif
|