Skip to content

Commit 7868ca4

Browse files
committed
Add telemetry
1 parent fc6d261 commit 7868ca4

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

examples/SendReceiveClient/SendReceiveClient.ino

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ void text_message_callback(uint32_t from, const char* text) {
4747
Serial.println(text);
4848
}
4949

50+
// This callback function will be called whenever the radio receives a text message
51+
void telemetry_callback(uint32_t from, meshtastic_Telemetry* telemetry) {
52+
// Do your own thing here. This example just prints the message to the serial console.
53+
Serial.print("Received telemetry from ");
54+
Serial.print(from);
55+
Serial.print(": ");
56+
if (telemetry->variant.device_metrics) {
57+
Serial.println("Device Metrics: %fV", telemetry->variant.device_metrics->voltage);
58+
}
59+
}
60+
61+
5062
void setup() {
5163
// Try for up to five seconds to find a serial port; if not, the show must go on
5264
Serial.begin(9600);
@@ -81,6 +93,9 @@ void setup() {
8193

8294
// Register a callback function to be called whenever a text message is received
8395
set_text_message_callback(text_message_callback);
96+
97+
// Register a callback function to be called whenever a telemetry payload is received
98+
set_telemetry_callback(telemetry_callback);
8499
}
85100

86101
void loop() {

src/Meshtastic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ bool mt_request_node_report(void (*callback)(mt_node_t *, mt_nr_progress_t));
7575
// Set the callback function that gets called when the node receives a text message.
7676
void set_text_message_callback(void (*callback)(uint32_t from, const char * text));
7777

78+
// Set the callback function that gets called when the node receives a text message.
79+
void set_telemetry_callback(void (*callback)(uint32_t from, meshtastic_Telemetry * telemetry));
80+
7881
// Send a text message with *text* as payload, to a destination node (optional), on a certain channel (optional).
7982
bool mt_send_text(const char * text, uint32_t dest = BROADCAST_ADDR, uint8_t channel_index = 0);
8083

src/mt_protocol.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ uint32_t my_node_num = 0;
2424

2525
bool mt_debugging = false;
2626
void (*text_message_callback)(uint32_t from, const char* text) = NULL;
27+
void (*telemetry_callback)(uint32_t from, meshtastic_Telemetry * telemetry) = NULL;
2728
void (*node_report_callback)(mt_node_t *, mt_nr_progress_t) = NULL;
2829
mt_node_t node;
2930

@@ -120,6 +121,10 @@ void set_text_message_callback(void (*callback)(uint32_t from, const char* text)
120121
text_message_callback = callback;
121122
}
122123

124+
void set_telemetry_callback(void (*callback)(uint32_t from, meshtastic_Telemetry * telemetry)) {
125+
telemetry_callback = callback;
126+
}
127+
123128
bool handle_my_info(meshtastic_MyNodeInfo *myNodeInfo) {
124129
my_node_num = myNodeInfo->my_node_num;
125130
return true;
@@ -191,6 +196,9 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) {
191196
if (meshPacket->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) {
192197
if (text_message_callback != NULL)
193198
text_message_callback(meshPacket->from, (const char*)meshPacket->decoded.payload.bytes);
199+
} else if (meshPacket->decoded.portnum == meshtastic_PortNum_TELEMETRY_APP) {
200+
if (telemetry_callback != NULL)
201+
telemetry_callback(meshPacket->from, );
194202
} else {
195203
// TODO handle other portnums
196204
return false;

0 commit comments

Comments
 (0)