Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry #14

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/regen-protos.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cd protobufs && ..\nanopb-0.4.7\generator-bin\protoc.exe --nanopb_out=-v:..\src -I=..\protobufs meshtastic\*.proto
cd protobufs && ..\nanopb-0.4.7\generator-bin\protoc.exe --nanopb_out=-v:..\src -I=..\protobufs ..\protobufs\meshtastic\*.proto
16 changes: 16 additions & 0 deletions examples/SendReceiveClient/SendReceiveClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ void text_message_callback(uint32_t from, const char* text) {
Serial.println(text);
}

// This callback function will be called whenever the radio receives a text message
void telemetry_callback(uint32_t from, meshtastic_Telemetry* telemetry) {
// Do your own thing here. This example just prints the message to the serial console.
Serial.print("Received telemetry from ");
Serial.print(from);
Serial.print(": ");
if (telemetry->which_variant == meshtastic_Telemetry_device_metrics_tag) {
Serial.print("Device Metrics: ");
Serial.print(telemetry->variant.device_metrics.voltage);
}
}


void setup() {
// Try for up to five seconds to find a serial port; if not, the show must go on
Serial.begin(9600);
Expand Down Expand Up @@ -81,6 +94,9 @@ void setup() {

// Register a callback function to be called whenever a text message is received
set_text_message_callback(text_message_callback);

// Register a callback function to be called whenever a telemetry payload is received
set_telemetry_callback(telemetry_callback);
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion protobufs
7 changes: 7 additions & 0 deletions src/Meshtastic.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ typedef struct {
float voltage;
float channel_utilization;
float air_util_tx;
float temperature;
float relative_humidity;
float barometric_pressure;
float gas_resistance;
} mt_node_t;

// Initialize, using wifi to connect to the MT radio
Expand Down Expand Up @@ -75,6 +79,9 @@ bool mt_request_node_report(void (*callback)(mt_node_t *, mt_nr_progress_t));
// Set the callback function that gets called when the node receives a text message.
void set_text_message_callback(void (*callback)(uint32_t from, const char * text));

// Set the callback function that gets called when the node receives a text message.
void set_telemetry_callback(void (*callback)(uint32_t from, meshtastic_Telemetry * telemetry));

// Send a text message with *text* as payload, to a destination node (optional), on a certain channel (optional).
bool mt_send_text(const char * text, uint32_t dest = BROADCAST_ADDR, uint8_t channel_index = 0);

Expand Down
27 changes: 27 additions & 0 deletions src/meshtastic-pb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <pb_decode.h>
#include <pb_encode.h>

/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
/// returns the encoded packet size
size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct)
{
pb_ostream_t stream = pb_ostream_from_buffer(destbuf, destbufsize);
if (!pb_encode(&stream, fields, src_struct)) {
Serial.println("Panic: can't encode protobuf");
return 0;
} else {
return stream.bytes_written;
}
}

/// helper function for decoding a record as a protobuf, we will return false if the decoding failed
bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msgdesc_t *fields, void *dest_struct)
{
pb_istream_t stream = pb_istream_from_buffer(srcbuf, srcbufsize);
if (!pb_decode(&stream, fields, dest_struct)) {
Serial.println("Can't decode protobuf reason=");
return false;
} else {
return true;
}
}
5 changes: 5 additions & 0 deletions src/meshtastic/admin.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ typedef struct _meshtastic_AdminMessage {
bool get_node_remote_hardware_pins_request;
/* Respond with the mesh's nodes with their available gpio pins for RemoteHardware module use */
meshtastic_NodeRemoteHardwarePinsResponse get_node_remote_hardware_pins_response;
/* Enter (UF2) DFU mode
Only implemented on NRF52 currently */
bool enter_dfu_mode_request;
/* Set the owner for this node */
meshtastic_User set_owner;
/* Set channels (using the new API).
Expand Down Expand Up @@ -224,6 +227,7 @@ extern "C" {
#define meshtastic_AdminMessage_set_ham_mode_tag 18
#define meshtastic_AdminMessage_get_node_remote_hardware_pins_request_tag 19
#define meshtastic_AdminMessage_get_node_remote_hardware_pins_response_tag 20
#define meshtastic_AdminMessage_enter_dfu_mode_request_tag 21
#define meshtastic_AdminMessage_set_owner_tag 32
#define meshtastic_AdminMessage_set_channel_tag 33
#define meshtastic_AdminMessage_set_config_tag 34
Expand Down Expand Up @@ -261,6 +265,7 @@ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,get_device_connection_status
X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_ham_mode,set_ham_mode), 18) \
X(a, STATIC, ONEOF, BOOL, (payload_variant,get_node_remote_hardware_pins_request,get_node_remote_hardware_pins_request), 19) \
X(a, STATIC, ONEOF, MESSAGE, (payload_variant,get_node_remote_hardware_pins_response,get_node_remote_hardware_pins_response), 20) \
X(a, STATIC, ONEOF, BOOL, (payload_variant,enter_dfu_mode_request,enter_dfu_mode_request), 21) \
X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_owner,set_owner), 32) \
X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_channel,set_channel), 33) \
X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_config,set_config), 34) \
Expand Down
2 changes: 1 addition & 1 deletion src/meshtastic/apponly.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extern const pb_msgdesc_t meshtastic_ChannelSet_msg;
#define meshtastic_ChannelSet_fields &meshtastic_ChannelSet_msg

/* Maximum encoded size of messages (where known) */
#define meshtastic_ChannelSet_size 591
#define meshtastic_ChannelSet_size 594

#ifdef __cplusplus
} /* extern "C" */
Expand Down
27 changes: 16 additions & 11 deletions src/meshtastic/config.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ typedef enum _meshtastic_Config_LoRaConfig_RegionCode {
/* Ukraine 433mhz */
meshtastic_Config_LoRaConfig_RegionCode_UA_433 = 14,
/* Ukraine 868mhz */
meshtastic_Config_LoRaConfig_RegionCode_UA_868 = 15
meshtastic_Config_LoRaConfig_RegionCode_UA_868 = 15,
/* Malaysia 433mhz */
meshtastic_Config_LoRaConfig_RegionCode_MY_433 = 16,
/* Malaysia 919mhz */
meshtastic_Config_LoRaConfig_RegionCode_MY_919 = 17
} meshtastic_Config_LoRaConfig_RegionCode;

/* Standard predefined channel settings
Expand Down Expand Up @@ -281,10 +285,7 @@ typedef struct _meshtastic_Config_PositionConfig {
or zero for the default of once every 30 seconds
or a very large value (maxint) to update only once at boot. */
uint32_t gps_update_interval;
/* How long should we try to get our position during each gps_update_interval attempt? (in seconds)
Or if zero, use the default of 30 seconds.
If we don't get a new gps fix in that time, the gps will be put into sleep until the next gps_update_rate
window. */
/* Deprecated in favor of using smart / regular broadcast intervals as implicit attempt time */
uint32_t gps_attempt_time;
/* Bit field of boolean configuration options for POSITION messages
(bitwise OR of PositionFlags) */
Expand Down Expand Up @@ -462,6 +463,8 @@ typedef struct _meshtastic_Config_LoRaConfig {
in ignore_incoming will have packets they send dropped on receive (by router.cpp) */
pb_size_t ignore_incoming_count;
uint32_t ignore_incoming[3];
/* If true, the device will not process any packets received via LoRa that passed via MQTT anywhere on the path towards it. */
bool ignore_mqtt;
} meshtastic_Config_LoRaConfig;

typedef struct _meshtastic_Config_BluetoothConfig {
Expand Down Expand Up @@ -525,8 +528,8 @@ extern "C" {
#define _meshtastic_Config_DisplayConfig_DisplayMode_ARRAYSIZE ((meshtastic_Config_DisplayConfig_DisplayMode)(meshtastic_Config_DisplayConfig_DisplayMode_COLOR+1))

#define _meshtastic_Config_LoRaConfig_RegionCode_MIN meshtastic_Config_LoRaConfig_RegionCode_UNSET
#define _meshtastic_Config_LoRaConfig_RegionCode_MAX meshtastic_Config_LoRaConfig_RegionCode_UA_868
#define _meshtastic_Config_LoRaConfig_RegionCode_ARRAYSIZE ((meshtastic_Config_LoRaConfig_RegionCode)(meshtastic_Config_LoRaConfig_RegionCode_UA_868+1))
#define _meshtastic_Config_LoRaConfig_RegionCode_MAX meshtastic_Config_LoRaConfig_RegionCode_MY_919
#define _meshtastic_Config_LoRaConfig_RegionCode_ARRAYSIZE ((meshtastic_Config_LoRaConfig_RegionCode)(meshtastic_Config_LoRaConfig_RegionCode_MY_919+1))

#define _meshtastic_Config_LoRaConfig_ModemPreset_MIN meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST
#define _meshtastic_Config_LoRaConfig_ModemPreset_MAX meshtastic_Config_LoRaConfig_ModemPreset_LONG_MODERATE
Expand Down Expand Up @@ -564,7 +567,7 @@ extern "C" {
#define meshtastic_Config_NetworkConfig_init_default {0, "", "", "", 0, _meshtastic_Config_NetworkConfig_AddressMode_MIN, false, meshtastic_Config_NetworkConfig_IpV4Config_init_default, ""}
#define meshtastic_Config_NetworkConfig_IpV4Config_init_default {0, 0, 0, 0}
#define meshtastic_Config_DisplayConfig_init_default {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0}
#define meshtastic_Config_LoRaConfig_init_default {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}}
#define meshtastic_Config_LoRaConfig_init_default {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0}
#define meshtastic_Config_BluetoothConfig_init_default {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0}
#define meshtastic_Config_init_zero {0, {meshtastic_Config_DeviceConfig_init_zero}}
#define meshtastic_Config_DeviceConfig_init_zero {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0}
Expand All @@ -573,7 +576,7 @@ extern "C" {
#define meshtastic_Config_NetworkConfig_init_zero {0, "", "", "", 0, _meshtastic_Config_NetworkConfig_AddressMode_MIN, false, meshtastic_Config_NetworkConfig_IpV4Config_init_zero, ""}
#define meshtastic_Config_NetworkConfig_IpV4Config_init_zero {0, 0, 0, 0}
#define meshtastic_Config_DisplayConfig_init_zero {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0}
#define meshtastic_Config_LoRaConfig_init_zero {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}}
#define meshtastic_Config_LoRaConfig_init_zero {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0}
#define meshtastic_Config_BluetoothConfig_init_zero {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0}

/* Field tags (for use in manual encoding/decoding) */
Expand Down Expand Up @@ -644,6 +647,7 @@ extern "C" {
#define meshtastic_Config_LoRaConfig_sx126x_rx_boosted_gain_tag 13
#define meshtastic_Config_LoRaConfig_override_frequency_tag 14
#define meshtastic_Config_LoRaConfig_ignore_incoming_tag 103
#define meshtastic_Config_LoRaConfig_ignore_mqtt_tag 104
#define meshtastic_Config_BluetoothConfig_enabled_tag 1
#define meshtastic_Config_BluetoothConfig_mode_tag 2
#define meshtastic_Config_BluetoothConfig_fixed_pin_tag 3
Expand Down Expand Up @@ -766,7 +770,8 @@ X(a, STATIC, SINGULAR, UINT32, channel_num, 11) \
X(a, STATIC, SINGULAR, BOOL, override_duty_cycle, 12) \
X(a, STATIC, SINGULAR, BOOL, sx126x_rx_boosted_gain, 13) \
X(a, STATIC, SINGULAR, FLOAT, override_frequency, 14) \
X(a, STATIC, REPEATED, UINT32, ignore_incoming, 103)
X(a, STATIC, REPEATED, UINT32, ignore_incoming, 103) \
X(a, STATIC, SINGULAR, BOOL, ignore_mqtt, 104)
#define meshtastic_Config_LoRaConfig_CALLBACK NULL
#define meshtastic_Config_LoRaConfig_DEFAULT NULL

Expand Down Expand Up @@ -802,7 +807,7 @@ extern const pb_msgdesc_t meshtastic_Config_BluetoothConfig_msg;
#define meshtastic_Config_BluetoothConfig_size 10
#define meshtastic_Config_DeviceConfig_size 32
#define meshtastic_Config_DisplayConfig_size 28
#define meshtastic_Config_LoRaConfig_size 77
#define meshtastic_Config_LoRaConfig_size 80
#define meshtastic_Config_NetworkConfig_IpV4Config_size 20
#define meshtastic_Config_NetworkConfig_size 196
#define meshtastic_Config_PositionConfig_size 60
Expand Down
4 changes: 2 additions & 2 deletions src/meshtastic/deviceonly.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg;

/* Maximum encoded size of messages (where known) */
#define meshtastic_ChannelFile_size 638
#define meshtastic_DeviceState_size 17056
#define meshtastic_DeviceState_size 17062
#define meshtastic_NodeInfoLite_size 153
#define meshtastic_NodeRemoteHardwarePin_size 29
#define meshtastic_OEMStore_size 3241
#define meshtastic_OEMStore_size 3244
#define meshtastic_PositionLite_size 28

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/meshtastic/localonly.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg;
#define meshtastic_LocalModuleConfig_fields &meshtastic_LocalModuleConfig_msg

/* Maximum encoded size of messages (where known) */
#define meshtastic_LocalConfig_size 464
#define meshtastic_LocalConfig_size 467
#define meshtastic_LocalModuleConfig_size 631

#ifdef __cplusplus
Expand Down
18 changes: 14 additions & 4 deletions src/meshtastic/mesh.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ typedef enum _meshtastic_HardwareModel {
meshtastic_HardwareModel_HELTEC_HT62 = 53,
/* EBYTE SPI LoRa module and ESP32-S3 */
meshtastic_HardwareModel_EBYTE_ESP32_S3 = 54,
/* Waveshare ESP32-S3-PICO with PICO LoRa HAT and 2.9inch e-Ink */
meshtastic_HardwareModel_ESP32_S3_PICO = 55,
/* CircuitMess Chatter 2 LLCC68 Lora Module and ESP32 Wroom
Lora module can be swapped out for a Heltec RA-62 which is "almost" pin compatible
with one cut and one jumper Meshtastic works */
meshtastic_HardwareModel_CHATTER_2 = 56,
/* ------------------------------------------------------------------------------------------------------------------------------------------
Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits.
------------------------------------------------------------------------------------------------------------------------------------------ */
Expand Down Expand Up @@ -571,6 +577,8 @@ typedef struct _meshtastic_MeshPacket {
int32_t rx_rssi;
/* Describe if this message is delayed */
meshtastic_MeshPacket_Delayed delayed;
/* Describes whether this packet passed via MQTT somewhere along the path it currently took. */
bool via_mqtt;
} meshtastic_MeshPacket;

/* The bluetooth to device link:
Expand Down Expand Up @@ -867,7 +875,7 @@ extern "C" {
#define meshtastic_Data_init_default {_meshtastic_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0}
#define meshtastic_Waypoint_init_default {0, 0, 0, 0, 0, "", "", 0}
#define meshtastic_MqttClientProxyMessage_init_default {"", 0, {{0, {0}}}, 0}
#define meshtastic_MeshPacket_init_default {0, 0, 0, 0, {meshtastic_Data_init_default}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN}
#define meshtastic_MeshPacket_init_default {0, 0, 0, 0, {meshtastic_Data_init_default}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN, 0}
#define meshtastic_NodeInfo_init_default {0, false, meshtastic_User_init_default, false, meshtastic_Position_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0}
#define meshtastic_MyNodeInfo_init_default {0, 0, 0}
#define meshtastic_LogRecord_init_default {"", 0, "", _meshtastic_LogRecord_Level_MIN}
Expand All @@ -885,7 +893,7 @@ extern "C" {
#define meshtastic_Data_init_zero {_meshtastic_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0}
#define meshtastic_Waypoint_init_zero {0, 0, 0, 0, 0, "", "", 0}
#define meshtastic_MqttClientProxyMessage_init_zero {"", 0, {{0, {0}}}, 0}
#define meshtastic_MeshPacket_init_zero {0, 0, 0, 0, {meshtastic_Data_init_zero}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN}
#define meshtastic_MeshPacket_init_zero {0, 0, 0, 0, {meshtastic_Data_init_zero}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN, 0}
#define meshtastic_NodeInfo_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_Position_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0}
#define meshtastic_MyNodeInfo_init_zero {0, 0, 0}
#define meshtastic_LogRecord_init_zero {"", 0, "", _meshtastic_LogRecord_Level_MIN}
Expand Down Expand Up @@ -964,6 +972,7 @@ extern "C" {
#define meshtastic_MeshPacket_priority_tag 11
#define meshtastic_MeshPacket_rx_rssi_tag 12
#define meshtastic_MeshPacket_delayed_tag 13
#define meshtastic_MeshPacket_via_mqtt_tag 14
#define meshtastic_NodeInfo_num_tag 1
#define meshtastic_NodeInfo_user_tag 2
#define meshtastic_NodeInfo_position_tag 3
Expand Down Expand Up @@ -1119,7 +1128,8 @@ X(a, STATIC, SINGULAR, UINT32, hop_limit, 9) \
X(a, STATIC, SINGULAR, BOOL, want_ack, 10) \
X(a, STATIC, SINGULAR, UENUM, priority, 11) \
X(a, STATIC, SINGULAR, INT32, rx_rssi, 12) \
X(a, STATIC, SINGULAR, UENUM, delayed, 13)
X(a, STATIC, SINGULAR, UENUM, delayed, 13) \
X(a, STATIC, SINGULAR, BOOL, via_mqtt, 14)
#define meshtastic_MeshPacket_CALLBACK NULL
#define meshtastic_MeshPacket_DEFAULT NULL
#define meshtastic_MeshPacket_payload_variant_decoded_MSGTYPE meshtastic_Data
Expand Down Expand Up @@ -1284,7 +1294,7 @@ extern const pb_msgdesc_t meshtastic_DeviceMetadata_msg;
#define meshtastic_DeviceMetadata_size 46
#define meshtastic_FromRadio_size 510
#define meshtastic_LogRecord_size 81
#define meshtastic_MeshPacket_size 321
#define meshtastic_MeshPacket_size 323
#define meshtastic_MqttClientProxyMessage_size 501
#define meshtastic_MyNodeInfo_size 18
#define meshtastic_NeighborInfo_size 258
Expand Down
8 changes: 4 additions & 4 deletions src/mt_internals.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef MT_INTERNALS_H
#define MT_INTERNALS_H

#ifdef ARDUINO_ARCH_SAMD
#define MT_WIFI_SUPPORTED
#else
// #ifdef ARDUINO_ARCH_SAMD
// #define MT_WIFI_SUPPORTED
// #else
#define MT_SOFTWARESERIAL_SUPPORTED
#endif
//#endif

#include "Meshtastic.h"

Expand Down
11 changes: 11 additions & 0 deletions src/mt_protocol.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "mt_internals.h"
#include "meshtastic-pb.h"

// Magic number at the start of all MT packets
#define MT_MAGIC_0 0x94
Expand All @@ -24,6 +25,7 @@ uint32_t my_node_num = 0;

bool mt_debugging = false;
void (*text_message_callback)(uint32_t from, const char* text) = NULL;
void (*telemetry_callback)(uint32_t from, meshtastic_Telemetry * telemetry) = NULL;
void (*node_report_callback)(mt_node_t *, mt_nr_progress_t) = NULL;
mt_node_t node;

Expand Down Expand Up @@ -120,6 +122,10 @@ void set_text_message_callback(void (*callback)(uint32_t from, const char* text)
text_message_callback = callback;
}

void set_telemetry_callback(void (*callback)(uint32_t from, meshtastic_Telemetry * telemetry)) {
telemetry_callback = callback;
}

bool handle_my_info(meshtastic_MyNodeInfo *myNodeInfo) {
my_node_num = myNodeInfo->my_node_num;
return true;
Expand Down Expand Up @@ -191,6 +197,11 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) {
if (meshPacket->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) {
if (text_message_callback != NULL)
text_message_callback(meshPacket->from, (const char*)meshPacket->decoded.payload.bytes);
} else if (meshPacket->decoded.portnum == meshtastic_PortNum_TELEMETRY_APP) {
meshtastic_Telemetry telemetry = {0};
if (telemetry_callback != NULL && pb_decode_from_bytes(meshPacket->decoded.payload.bytes, meshPacket->decoded.payload.size, &meshtastic_Telemetry_msg, &telemetry)) {
telemetry_callback(meshPacket->from, &telemetry);
}
} else {
// TODO handle other portnums
return false;
Expand Down
Loading
Loading