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/examples/SendReceiveClient/SendReceiveClient.ino b/examples/SendReceiveClient/SendReceiveClient.ino index 3fe528a..f5c4c94 100644 --- a/examples/SendReceiveClient/SendReceiveClient.ino +++ b/examples/SendReceiveClient/SendReceiveClient.ino @@ -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); @@ -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() { 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.h b/src/Meshtastic.h index 197e16b..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 @@ -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); diff --git a/src/meshtastic-pb.h b/src/meshtastic-pb.h new file mode 100644 index 0000000..09bcbfd --- /dev/null +++ b/src/meshtastic-pb.h @@ -0,0 +1,27 @@ +#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"); + 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; + } +} \ No newline at end of file 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 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" diff --git a/src/mt_protocol.cpp b/src/mt_protocol.cpp index 51051e0..72ecfb7 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 @@ -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; @@ -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; @@ -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; diff --git a/src/mt_serial.cpp b/src/mt_serial.cpp index bb2e5a6..a2cd73f 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); +// #ifndef ARDUINO_ARCH_SAMD +// serial = new SoftwareSerial(rx_pin, tx_pin); +// #endif serial->begin(baud); -#endif mt_wifi_mode = false; mt_serial_mode = true; }