From 7868ca4aa2842305a103987c30ce0a5427c49af8 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 24 Jan 2024 18:03:06 -0600 Subject: [PATCH 01/12] Add telemetry --- examples/SendReceiveClient/SendReceiveClient.ino | 15 +++++++++++++++ src/Meshtastic.h | 3 +++ src/mt_protocol.cpp | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/examples/SendReceiveClient/SendReceiveClient.ino b/examples/SendReceiveClient/SendReceiveClient.ino index 3fe528a..a100240 100644 --- a/examples/SendReceiveClient/SendReceiveClient.ino +++ b/examples/SendReceiveClient/SendReceiveClient.ino @@ -47,6 +47,18 @@ 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->variant.device_metrics) { + Serial.println("Device Metrics: %fV", 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); @@ -81,6 +93,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() { diff --git a/src/Meshtastic.h b/src/Meshtastic.h index 197e16b..f194bfe 100644 --- a/src/Meshtastic.h +++ b/src/Meshtastic.h @@ -75,6 +75,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); diff --git a/src/mt_protocol.cpp b/src/mt_protocol.cpp index 51051e0..67adee1 100644 --- a/src/mt_protocol.cpp +++ b/src/mt_protocol.cpp @@ -24,6 +24,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; @@ -120,6 +121,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; @@ -191,6 +196,9 @@ 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) { + if (telemetry_callback != NULL) + telemetry_callback(meshPacket->from, ); } else { // TODO handle other portnums return false; From e8c9bafe8ea7aabb75b51ee798a11f3091ab13b6 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 24 Jan 2024 18:03:15 -0600 Subject: [PATCH 02/12] Protos --- bin/regen-protos.bat | 2 +- protobufs | 2 +- src/meshtastic/admin.pb.h | 5 +++++ src/meshtastic/apponly.pb.h | 2 +- src/meshtastic/config.pb.h | 27 ++++++++++++++++----------- src/meshtastic/deviceonly.pb.h | 4 ++-- src/meshtastic/localonly.pb.h | 2 +- src/meshtastic/mesh.pb.h | 18 ++++++++++++++---- 8 files changed, 41 insertions(+), 21 deletions(-) diff --git a/bin/regen-protos.bat b/bin/regen-protos.bat index 350c278..59b19c9 100755 --- a/bin/regen-protos.bat +++ b/bin/regen-protos.bat @@ -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 diff --git a/protobufs b/protobufs index c1e179e..44e369e 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit c1e179ecfd86c88deaf1140e7a9c6902b763cc3d +Subproject commit 44e369e1813f8ec9c7aefe1aac7d0adc75e11f8a diff --git a/src/meshtastic/admin.pb.h b/src/meshtastic/admin.pb.h index f5f3627..48df9ba 100644 --- a/src/meshtastic/admin.pb.h +++ b/src/meshtastic/admin.pb.h @@ -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). @@ -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 @@ -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) \ diff --git a/src/meshtastic/apponly.pb.h b/src/meshtastic/apponly.pb.h index b66af0e..c9c120e 100644 --- a/src/meshtastic/apponly.pb.h +++ b/src/meshtastic/apponly.pb.h @@ -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" */ diff --git a/src/meshtastic/config.pb.h b/src/meshtastic/config.pb.h index 8406dc8..25e8d47 100644 --- a/src/meshtastic/config.pb.h +++ b/src/meshtastic/config.pb.h @@ -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 @@ -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) */ @@ -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 { @@ -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 @@ -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} @@ -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) */ @@ -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 @@ -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 @@ -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 diff --git a/src/meshtastic/deviceonly.pb.h b/src/meshtastic/deviceonly.pb.h index ef5045e..6318d7d 100644 --- a/src/meshtastic/deviceonly.pb.h +++ b/src/meshtastic/deviceonly.pb.h @@ -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 diff --git a/src/meshtastic/localonly.pb.h b/src/meshtastic/localonly.pb.h index 3f87516..5077230 100644 --- a/src/meshtastic/localonly.pb.h +++ b/src/meshtastic/localonly.pb.h @@ -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 diff --git a/src/meshtastic/mesh.pb.h b/src/meshtastic/mesh.pb.h index ae80b3f..a00273e 100644 --- a/src/meshtastic/mesh.pb.h +++ b/src/meshtastic/mesh.pb.h @@ -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. ------------------------------------------------------------------------------------------------------------------------------------------ */ @@ -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: @@ -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} @@ -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} @@ -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 @@ -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 @@ -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 From 66460e9d823be24bcf5984b26e9b6ea05addd2c6 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 24 Jan 2024 18:54:49 -0600 Subject: [PATCH 03/12] Added decode --- src/meshtastic-pb.h | 26 ++++++++++++++++++++++++++ src/mt_protocol.cpp | 9 +++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/meshtastic-pb.h diff --git a/src/meshtastic-pb.h b/src/meshtastic-pb.h new file mode 100644 index 0000000..9f9c6ca --- /dev/null +++ b/src/meshtastic-pb.h @@ -0,0 +1,26 @@ +#include +#include + +/// 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 reason='%s'\n", PB_GET_ERROR(&stream)); + } 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='%s', pb_msgdesc %p\n", PB_GET_ERROR(&stream), fields); + return false; + } else { + return true; + } +} \ No newline at end of file diff --git a/src/mt_protocol.cpp b/src/mt_protocol.cpp index 67adee1..c1b09c2 100644 --- a/src/mt_protocol.cpp +++ b/src/mt_protocol.cpp @@ -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 @@ -191,14 +192,18 @@ bool handle_config_complete_id(uint32_t now, uint32_t config_complete_id) { return true; } + if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.decoded.portnum == ourPortNum) { + + bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) { if (meshPacket->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { 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) { - if (telemetry_callback != NULL) - telemetry_callback(meshPacket->from, ); + meshtastic_Telemetry *telemetry = {0}; + if (telemetry_callback != NULL && pb_decode_from_bytes(meshPacket->decoded.payload.bytes, meshPacket->decoded.payload.bytes, &meshtastic_Telemetry_msg, &telemetry)) + telemetry_callback(meshPacket->from, telemetry); } else { // TODO handle other portnums return false; From 03ca7a1a9658528bf56736d0054665a53abf7062 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 24 Jan 2024 19:33:20 -0600 Subject: [PATCH 04/12] Whoops --- examples/SendReceiveClient/SendReceiveClient.ino | 5 +++-- src/mt_protocol.cpp | 3 --- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/SendReceiveClient/SendReceiveClient.ino b/examples/SendReceiveClient/SendReceiveClient.ino index a100240..f5c4c94 100644 --- a/examples/SendReceiveClient/SendReceiveClient.ino +++ b/examples/SendReceiveClient/SendReceiveClient.ino @@ -53,8 +53,9 @@ void telemetry_callback(uint32_t from, meshtastic_Telemetry* telemetry) { Serial.print("Received telemetry from "); Serial.print(from); Serial.print(": "); - if (telemetry->variant.device_metrics) { - Serial.println("Device Metrics: %fV", telemetry->variant.device_metrics->voltage); + if (telemetry->which_variant == meshtastic_Telemetry_device_metrics_tag) { + Serial.print("Device Metrics: "); + Serial.print(telemetry->variant.device_metrics.voltage); } } diff --git a/src/mt_protocol.cpp b/src/mt_protocol.cpp index c1b09c2..2008208 100644 --- a/src/mt_protocol.cpp +++ b/src/mt_protocol.cpp @@ -192,9 +192,6 @@ bool handle_config_complete_id(uint32_t now, uint32_t config_complete_id) { return true; } - if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.decoded.portnum == ourPortNum) { - - bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) { if (meshPacket->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { if (meshPacket->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) { From 06c891038f955f371f8b101b342e27c227c87b14 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 24 Jan 2024 19:35:21 -0600 Subject: [PATCH 05/12] Size it --- src/mt_protocol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mt_protocol.cpp b/src/mt_protocol.cpp index 2008208..97c4ac8 100644 --- a/src/mt_protocol.cpp +++ b/src/mt_protocol.cpp @@ -199,7 +199,7 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) { 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.bytes, &meshtastic_Telemetry_msg, &telemetry)) + 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 From 89f14dba84346cd61c2874cdf1451849f3460a45 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 24 Jan 2024 19:37:47 -0600 Subject: [PATCH 06/12] Simple log --- src/meshtastic-pb.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/meshtastic-pb.h b/src/meshtastic-pb.h index 9f9c6ca..80cc00c 100644 --- a/src/meshtastic-pb.h +++ b/src/meshtastic-pb.h @@ -7,7 +7,7 @@ size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc { pb_ostream_t stream = pb_ostream_from_buffer(destbuf, destbufsize); if (!pb_encode(&stream, fields, src_struct)) { - Serial.println("Panic: can't encode protobuf reason='%s'\n", PB_GET_ERROR(&stream)); + Serial.println("Panic: can't encode protobuf"); } else { return stream.bytes_written; } @@ -18,7 +18,7 @@ bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msg { pb_istream_t stream = pb_istream_from_buffer(srcbuf, srcbufsize); if (!pb_decode(&stream, fields, dest_struct)) { - Serial.println("Can't decode protobuf reason='%s', pb_msgdesc %p\n", PB_GET_ERROR(&stream), fields); + Serial.println("Can't decode protobuf reason="); return false; } else { return true; From 4adc564cfe04ada64ef0a65ada724a84f9404991 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 24 Jan 2024 19:39:25 -0600 Subject: [PATCH 07/12] Zero --- src/meshtastic-pb.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/meshtastic-pb.h b/src/meshtastic-pb.h index 80cc00c..09bcbfd 100644 --- a/src/meshtastic-pb.h +++ b/src/meshtastic-pb.h @@ -8,6 +8,7 @@ size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc 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; } From feae859ae9e2ce4081ea31391e584765a9f98463 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 25 Jan 2024 09:42:32 -0600 Subject: [PATCH 08/12] Experiment --- src/mt_internals.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mt_internals.h b/src/mt_internals.h index 4289478..3fed05a 100644 --- a/src/mt_internals.h +++ b/src/mt_internals.h @@ -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" From f8e95c8a56f00255846dec8c0e02438797c6d489 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 25 Jan 2024 12:41:16 -0600 Subject: [PATCH 09/12] Temp --- src/mt_serial.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mt_serial.cpp b/src/mt_serial.cpp index bb2e5a6..e9e3052 100644 --- a/src/mt_serial.cpp +++ b/src/mt_serial.cpp @@ -1,17 +1,17 @@ #include "mt_internals.h" -#ifdef MT_SOFTWARESERIAL_SUPPORTED - #include - SoftwareSerial *serial; -#else - #define serial (&Serial1) -#endif +// #ifdef MT_SOFTWARESERIAL_SUPPORTED +// #include +// SoftwareSerial *serial; +// #else +#define serial (&Serial1) +// #endif void mt_serial_init(int8_t rx_pin, int8_t tx_pin, uint32_t baud) { -#ifndef ARDUINO_ARCH_SAMD - serial = new SoftwareSerial(rx_pin, tx_pin); - serial->begin(baud); -#endif +// #ifndef ARDUINO_ARCH_SAMD +// serial = new SoftwareSerial(rx_pin, tx_pin); +// serial->begin(baud); +// #endif mt_wifi_mode = false; mt_serial_mode = true; } From 13b1f0693a1d85816af783983cde9e59d4519b1d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 25 Jan 2024 19:40:20 -0600 Subject: [PATCH 10/12] Fix --- src/mt_protocol.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mt_protocol.cpp b/src/mt_protocol.cpp index 97c4ac8..72ecfb7 100644 --- a/src/mt_protocol.cpp +++ b/src/mt_protocol.cpp @@ -198,9 +198,10 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) { 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); + 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; From 2cca441e92f95afff5559c53aed0d69487d7b409 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 26 Jan 2024 19:36:44 -0600 Subject: [PATCH 11/12] Added environment fields --- src/Meshtastic.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Meshtastic.h b/src/Meshtastic.h index f194bfe..3046b91 100644 --- a/src/Meshtastic.h +++ b/src/Meshtastic.h @@ -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 From 5a96426c8a78c5a790dc5bb8b6f10b071b086ce7 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 27 Jan 2024 07:14:05 -0600 Subject: [PATCH 12/12] Accidentally removed this --- src/mt_serial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mt_serial.cpp b/src/mt_serial.cpp index e9e3052..a2cd73f 100644 --- a/src/mt_serial.cpp +++ b/src/mt_serial.cpp @@ -10,8 +10,8 @@ void mt_serial_init(int8_t rx_pin, int8_t tx_pin, uint32_t baud) { // #ifndef ARDUINO_ARCH_SAMD // serial = new SoftwareSerial(rx_pin, tx_pin); -// serial->begin(baud); // #endif + serial->begin(baud); mt_wifi_mode = false; mt_serial_mode = true; }