Skip to content

Commit d1282c6

Browse files
authored
Merge pull request #27 from pdxlocations/master
Add function to catch DM's to the receiver
2 parents a7a40ad + aa022a1 commit d1282c6

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

examples/SendReceiveClient/SendReceiveClient.ino

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,21 @@ void connected_callback(mt_node_t *node, mt_nr_progress_t progress) {
3939
}
4040

4141
// This callback function will be called whenever the radio receives a text message
42-
void text_message_callback(uint32_t from, const char* text) {
42+
void text_message_callback(uint32_t from, uint32_t to, const char* text) {
4343
// Do your own thing here. This example just prints the message to the serial console.
44-
Serial.print("Received a text message from ");
44+
Serial.print("Received a text message from: ");
4545
Serial.print(from);
46-
Serial.print(": ");
46+
Serial.print(" to: ");
47+
Serial.print(to);
48+
Serial.print(" message: ");
4749
Serial.println(text);
50+
if (to == 0xFFFFFFFF){
51+
Serial.println("This is a BROADCAST message.");
52+
} else if (to == my_node_num){
53+
Serial.println("This is a DM to me!");
54+
} else {
55+
Serial.println("This is a DM to someone else.");
56+
}
4857
}
4958

5059
void setup() {

src/Meshtastic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ typedef enum {
7373
bool mt_request_node_report(void (*callback)(mt_node_t *, mt_nr_progress_t));
7474

7575
// Set the callback function that gets called when the node receives a text message.
76-
void set_text_message_callback(void (*callback)(uint32_t from, const char * text));
76+
void set_text_message_callback(void (*callback)(uint32_t from, uint32_t to, const char * text));
7777

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

src/mt_protocol.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ uint32_t want_config_id = 0;
2323
uint32_t my_node_num = 0;
2424

2525
bool mt_debugging = false;
26-
void (*text_message_callback)(uint32_t from, const char* text) = NULL;
26+
void (*text_message_callback)(uint32_t from, uint32_t to, const char* text) = NULL;
2727
void (*node_report_callback)(mt_node_t *, mt_nr_progress_t) = NULL;
2828
mt_node_t node;
2929

@@ -116,7 +116,7 @@ bool mt_send_text(const char * text, uint32_t dest, uint8_t channel_index) {
116116
return _mt_send_toRadio(toRadio);
117117
}
118118

119-
void set_text_message_callback(void (*callback)(uint32_t from, const char* text)) {
119+
void set_text_message_callback(void (*callback)(uint32_t from, uint32_t to, const char* text)) {
120120
text_message_callback = callback;
121121
}
122122

@@ -190,7 +190,7 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) {
190190
if (meshPacket->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
191191
if (meshPacket->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) {
192192
if (text_message_callback != NULL)
193-
text_message_callback(meshPacket->from, (const char*)meshPacket->decoded.payload.bytes);
193+
text_message_callback(meshPacket->from, meshPacket->to, (const char*)meshPacket->decoded.payload.bytes);
194194
} else {
195195
// TODO handle other portnums
196196
return false;

0 commit comments

Comments
 (0)