From 0f2aa7660df5843a00cbc9fdffd34a28c438e1bf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Jun 2022 19:09:38 -0500 Subject: [PATCH 1/8] [create-pull-request] automated change (#1537) Co-authored-by: thebentern --- protobufs | 2 +- src/mesh/generated/mesh.pb.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 3df257bb8..c63a16c32 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 3df257bb880b0e8aff15b8022afa0848dcb85c69 +Subproject commit c63a16c32f0a7b41fc348a8f42c9c13a024d2700 diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 630c714d5..37710ebc8 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -5,6 +5,7 @@ #define PB_MESH_PB_H_INCLUDED #include #include "config.pb.h" +#include "module_config.pb.h" #include "portnums.pb.h" #include "telemetry.pb.h" @@ -652,6 +653,8 @@ typedef struct _FromRadio { Not used on all transports, currently just used for the serial console. NOTE: This ID must not change - to keep (minimal) compatibility with <1.2 version of android apps. */ bool rebooted; + /* Include module config */ + ModuleConfig moduleConfig; /* Log levels, chosen to match python logging conventions. */ MeshPacket packet; }; @@ -856,6 +859,7 @@ extern "C" { #define FromRadio_log_record_tag 7 #define FromRadio_config_complete_id_tag 8 #define FromRadio_rebooted_tag 9 +#define FromRadio_moduleConfig_tag 10 #define FromRadio_packet_tag 11 #define ToRadio_packet_tag 2 #define ToRadio_peer_info_tag 3 @@ -1006,6 +1010,7 @@ X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,config,config), 6) \ X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,log_record,log_record), 7) \ X(a, STATIC, ONEOF, UINT32, (payloadVariant,config_complete_id,config_complete_id), 8) \ X(a, STATIC, ONEOF, BOOL, (payloadVariant,rebooted,rebooted), 9) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,moduleConfig,moduleConfig), 10) \ X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,packet,packet), 11) #define FromRadio_CALLBACK NULL #define FromRadio_DEFAULT NULL @@ -1013,6 +1018,7 @@ X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,packet,packet), 11) #define FromRadio_payloadVariant_node_info_MSGTYPE NodeInfo #define FromRadio_payloadVariant_config_MSGTYPE Config #define FromRadio_payloadVariant_log_record_MSGTYPE LogRecord +#define FromRadio_payloadVariant_moduleConfig_MSGTYPE ModuleConfig #define FromRadio_payloadVariant_packet_MSGTYPE MeshPacket #define ToRadio_FIELDLIST(X, a) \ From 9c6da233b95599137d360d651f149210228d8a06 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 29 Jun 2022 19:41:43 -0500 Subject: [PATCH 2/8] Phoneapi moduleconfig (#1538) --- src/mesh/PhoneAPI.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- src/mesh/PhoneAPI.h | 1 + 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index e41e2f584..a22c4c5ac 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -183,11 +183,47 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) config_state++; // Advance when we have sent all of our config objects if (config_state > Config_lora_tag) { + state = STATE_SEND_MODULECONFIG; + config_state = ModuleConfig_mqtt_tag; + } + break; + + case STATE_SEND_MODULECONFIG: + fromRadioScratch.which_payloadVariant = FromRadio_moduleConfig_tag; + switch (config_state) { + case ModuleConfig_mqtt_tag: + fromRadioScratch.moduleConfig.which_payloadVariant = ModuleConfig_mqtt_tag; + fromRadioScratch.moduleConfig.payloadVariant.mqtt = moduleConfig.mqtt; + break; + case ModuleConfig_serial_tag: + fromRadioScratch.moduleConfig.which_payloadVariant = ModuleConfig_serial_tag; + fromRadioScratch.moduleConfig.payloadVariant.serial = moduleConfig.serial; + break; + case ModuleConfig_external_notification_tag: + fromRadioScratch.moduleConfig.which_payloadVariant = ModuleConfig_external_notification_tag; + fromRadioScratch.moduleConfig.payloadVariant.external_notification = moduleConfig.external_notification; + break; + case ModuleConfig_range_test_tag: + fromRadioScratch.moduleConfig.which_payloadVariant = ModuleConfig_range_test_tag; + fromRadioScratch.moduleConfig.payloadVariant.range_test = moduleConfig.range_test; + break; + case ModuleConfig_telemetry_tag: + fromRadioScratch.moduleConfig.which_payloadVariant = ModuleConfig_telemetry_tag; + fromRadioScratch.moduleConfig.payloadVariant.telemetry = moduleConfig.telemetry; + break; + case ModuleConfig_canned_message_tag: + fromRadioScratch.moduleConfig.which_payloadVariant = ModuleConfig_canned_message_tag; + fromRadioScratch.moduleConfig.payloadVariant.canned_message = moduleConfig.canned_message; + break; + } + + config_state++; + // Advance when we have sent all of our ModuleConfig objects + if (config_state > ModuleConfig_canned_message_tag) { state = STATE_SEND_NODEINFO; config_state = Config_device_tag; } break; - case STATE_SEND_NODEINFO: { const NodeInfo *info = nodeInfoForPhone; nodeInfoForPhone = NULL; // We just consumed a nodeinfo, will need a new one next time @@ -265,6 +301,9 @@ bool PhoneAPI::available() return true; case STATE_SEND_CONFIG: + return true; + + case STATE_SEND_MODULECONFIG: return true; case STATE_SEND_NODEINFO: diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 3109a5e89..8367b3925 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -24,6 +24,7 @@ class PhoneAPI STATE_SEND_MY_INFO, // send our my info record STATE_SEND_GROUPS, // new in 1.3? STATE_SEND_CONFIG, // Replacement for the old Radioconfig + STATE_SEND_MODULECONFIG, // Send Module specific config STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client STATE_SEND_COMPLETE_ID, STATE_SEND_PACKETS // send packets or debug strings From c725a6b65f992da48d2bad4a341cc583d1579fd9 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 29 Jun 2022 20:17:51 -0500 Subject: [PATCH 3/8] Bump for next tech preview release --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 0a3457a8a..2230135ba 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 1 minor = 3 -build = 21 +build = 22 From f26441727c85cdd58805fab43fc729cae0b6c9b2 Mon Sep 17 00:00:00 2001 From: loodydo <30909547+loodydo@users.noreply.github.com> Date: Sat, 2 Jul 2022 05:53:15 -0600 Subject: [PATCH 4/8] Update MQTT.cpp (#1534) Fix returning pointer to local variable that will become invalid when returning. Co-authored-by: Ben Meadors --- src/mqtt/MQTT.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 4c50ff741..41e45e833 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -356,8 +356,8 @@ String MQTT::downstreamPacketToJson(MeshPacket *mp) {"payload", msgPayload}}; // serialize and return it - std::string jsonStr = jsonObj.dump(); + static std::string jsonStr = jsonObj.dump(); DEBUG_MSG("serialized json message: %s\n", jsonStr.c_str()); return jsonStr.c_str(); -} \ No newline at end of file +} From f8ee1ac4f936309013a2a41a85fa227f62c5bc10 Mon Sep 17 00:00:00 2001 From: loodydo <30909547+loodydo@users.noreply.github.com> Date: Sat, 2 Jul 2022 06:05:10 -0600 Subject: [PATCH 5/8] Update GeoCoord.cpp (#1540) Adding clarification to comments on GeoCoord::bearing function. Co-authored-by: Ben Meadors --- src/gps/GeoCoord.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gps/GeoCoord.cpp b/src/gps/GeoCoord.cpp index 69c36ccb9..13c24b701 100644 --- a/src/gps/GeoCoord.cpp +++ b/src/gps/GeoCoord.cpp @@ -379,7 +379,7 @@ float GeoCoord::latLongToMeter(double lat_a, double lng_a, double lat_b, double * Latitude of the second point * @param lon2 * Longitude of the second point - * @return Bearing between the two points in radians. A value of 0 means due + * @return Bearing from point 1 to point 2 in radians. A value of 0 means due * north. */ float GeoCoord::bearing(double lat1, double lon1, double lat2, double lon2) From 3f0ff452324f9e5b94f857003c89c23ba9cc6744 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 2 Jul 2022 09:09:41 -0500 Subject: [PATCH 6/8] Node db cleanup and debug prints (#1543) * Node db cleanup and debug prints * File name cleanup --- src/mesh/NodeDB.cpp | 86 +++++++++++++++++++------------------ src/mesh/NodeDB.h | 2 + src/mesh/RadioInterface.cpp | 5 +-- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index a6e617344..f790f84b3 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -89,26 +89,7 @@ bool NodeDB::resetRadioConfig() // radioConfig.has_preferences = true; if (config.device.factory_reset) { - DEBUG_MSG("Performing factory reset!\n"); - // first, remove the "/prefs" (this removes most prefs) - rmDir("/prefs"); - // second, install default state (this will deal with the duplicate mac address issue) - installDefaultDeviceState(); - // third, write to disk - saveToDisk(); -#ifndef NO_ESP32 - // This will erase what's in NVS including ssl keys, persistant variables and ble pairing - nvs_flash_erase(); -#endif -#ifdef NRF52_SERIES - Bluefruit.begin(); - DEBUG_MSG("Clearing bluetooth bonds!\n"); - bond_print_list(BLE_GAP_ROLE_PERIPH); - bond_print_list(BLE_GAP_ROLE_CENTRAL); - Bluefruit.Periph.clearBonds(); - Bluefruit.Central.clearBonds(); -#endif - didFactoryReset = true; + didFactoryReset = factoryReset(); } if (channelFile.channels_count != MAX_NUM_CHANNELS) { @@ -142,8 +123,33 @@ bool NodeDB::resetRadioConfig() return didFactoryReset; } +bool NodeDB::factoryReset() +{ + DEBUG_MSG("Performing factory reset!\n"); + // first, remove the "/prefs" (this removes most prefs) + rmDir("/prefs"); + // second, install default state (this will deal with the duplicate mac address issue) + installDefaultDeviceState(); + // third, write to disk + saveToDisk(); +#ifndef NO_ESP32 + // This will erase what's in NVS including ssl keys, persistant variables and ble pairing + nvs_flash_erase(); +#endif +#ifdef NRF52_SERIES + Bluefruit.begin(); + DEBUG_MSG("Clearing bluetooth bonds!\n"); + bond_print_list(BLE_GAP_ROLE_PERIPH); + bond_print_list(BLE_GAP_ROLE_CENTRAL); + Bluefruit.Periph.clearBonds(); + Bluefruit.Central.clearBonds(); +#endif + return true; +} + void NodeDB::installDefaultConfig() { + DEBUG_MSG("Installing default LocalConfig\n"); memset(&config, 0, sizeof(LocalConfig)); config.version = DEVICESTATE_CUR_VER; config.has_device = true; @@ -164,25 +170,28 @@ void NodeDB::installDefaultConfig() void NodeDB::installDefaultModuleConfig() { + DEBUG_MSG("Installing default ModuleConfig\n"); memset(&moduleConfig, 0, sizeof(ModuleConfig)); moduleConfig.version = DEVICESTATE_CUR_VER; - moduleConfig.has_canned_message = true; - moduleConfig.has_external_notification = true; moduleConfig.has_mqtt = true; moduleConfig.has_range_test = true; moduleConfig.has_serial = true; moduleConfig.has_store_forward = true; moduleConfig.has_telemetry = true; + moduleConfig.has_external_notification = true; + moduleConfig.has_canned_message = true; } void NodeDB::installDefaultChannels() { + DEBUG_MSG("Installing default ChannelFile\n"); memset(&channelFile, 0, sizeof(ChannelFile)); channelFile.version = DEVICESTATE_CUR_VER; } void NodeDB::installDefaultDeviceState() { + DEBUG_MSG("Installing default DeviceState\n"); memset(&devicestate, 0, sizeof(DeviceState)); *numNodes = 0; // Forget node DB @@ -209,23 +218,18 @@ void NodeDB::installDefaultDeviceState() sprintf(owner.id, "!%08x", getNodeNum()); // Default node ID now based on nodenum memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr)); - - installDefaultChannels(); - installDefaultConfig(); } void NodeDB::init() { - installDefaultDeviceState(); - + DEBUG_MSG("Initializing NodeDB\n"); // saveToDisk(); loadFromDisk(); // saveToDisk(); myNodeInfo.max_channels = MAX_NUM_CHANNELS; // tell others the max # of channels we can understand - myNodeInfo.error_code = - CriticalErrorCode_None; // For the error code, only show values from this boot (discard value from flash) + myNodeInfo.error_code = CriticalErrorCode_None; // For the error code, only show values from this boot (discard value from flash) myNodeInfo.error_address = 0; // likewise - we always want the app requirements to come from the running appload @@ -290,10 +294,10 @@ void NodeDB::pickNewNodeNum() myNodeInfo.my_node_num = r; } -static const char *preffile = "/prefs/db.proto"; -static const char *configfile = "/prefs/config.proto"; -static const char *moduleConfigfile = "/prefs/module.proto"; -static const char *channelfile = "/prefs/channels.proto"; +static const char *prefFileName = "/prefs/db.proto"; +static const char *configFileName = "/prefs/config.proto"; +static const char *moduleConfigFileName = "/prefs/module.proto"; +static const char *channelFileName = "/prefs/channels.proto"; /** Load a protobuf from a file, return true for success */ bool loadProto(const char *filename, size_t protoSize, size_t objSize, const pb_msgdesc_t *fields, void *dest_struct) @@ -330,7 +334,7 @@ bool loadProto(const char *filename, size_t protoSize, size_t objSize, const pb_ void NodeDB::loadFromDisk() { // static DeviceState scratch; We no longer read into a tempbuf because this structure is 15KB of valuable RAM - if (!loadProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate)) { + if (!loadProto(prefFileName, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate)) { installDefaultDeviceState(); // Our in RAM copy might now be corrupt } else { if (devicestate.version < DEVICESTATE_MIN_VER) { @@ -353,7 +357,7 @@ void NodeDB::loadFromDisk() } } - if (!loadProto(configfile, LocalConfig_size, sizeof(LocalConfig), LocalConfig_fields, &config)) { + if (!loadProto(configFileName, LocalConfig_size, sizeof(LocalConfig), LocalConfig_fields, &config)) { installDefaultConfig(); // Our in RAM copy might now be corrupt } else { if (config.version < DEVICESTATE_MIN_VER) { @@ -364,7 +368,7 @@ void NodeDB::loadFromDisk() } } - if (!loadProto(moduleConfigfile, LocalModuleConfig_size, sizeof(LocalModuleConfig), LocalModuleConfig_fields, &moduleConfig)) { + if (!loadProto(moduleConfigFileName, LocalModuleConfig_size, sizeof(LocalModuleConfig), LocalModuleConfig_fields, &moduleConfig)) { installDefaultModuleConfig(); // Our in RAM copy might now be corrupt } else { if (moduleConfig.version < DEVICESTATE_MIN_VER) { @@ -375,7 +379,7 @@ void NodeDB::loadFromDisk() } } - if (!loadProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile)) { + if (!loadProto(channelFileName, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile)) { installDefaultChannels(); // Our in RAM copy might now be corrupt } else { if (channelFile.version < DEVICESTATE_MIN_VER) { @@ -428,7 +432,7 @@ void NodeDB::saveChannelsToDisk() #ifdef FSCom FSCom.mkdir("/prefs"); #endif - saveProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile); + saveProto(channelFileName, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile); } } @@ -438,7 +442,7 @@ void NodeDB::saveToDisk() #ifdef FSCom FSCom.mkdir("/prefs"); #endif - saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); + saveProto(prefFileName, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); // save all config segments config.has_device = true; @@ -447,7 +451,7 @@ void NodeDB::saveToDisk() config.has_position = true; config.has_power = true; config.has_wifi = true; - saveProto(configfile, LocalConfig_size, sizeof(LocalConfig), LocalConfig_fields, &config); + saveProto(configFileName, LocalConfig_size, sizeof(LocalConfig), LocalConfig_fields, &config); moduleConfig.has_canned_message = true; moduleConfig.has_external_notification = true; @@ -456,7 +460,7 @@ void NodeDB::saveToDisk() moduleConfig.has_serial = true; moduleConfig.has_store_forward = true; moduleConfig.has_telemetry = true; - saveProto(moduleConfigfile, LocalModuleConfig_size, sizeof(LocalModuleConfig), LocalModuleConfig_fields, &moduleConfig); + saveProto(moduleConfigFileName, LocalModuleConfig_size, sizeof(LocalModuleConfig), LocalModuleConfig_fields, &moduleConfig); saveChannelsToDisk(); diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 2cd3a8331..0a2a5bdb7 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -119,6 +119,8 @@ class NodeDB newStatus.notifyObservers(&status); } + bool factoryReset(); + /// read our db from flash void loadFromDisk(); diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 09a0e3a90..05c600357 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -419,9 +419,8 @@ void RadioInterface::applyModemConfig() saveChannelNum(channel_num); saveFreq(freq); - DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, loraConfig.modem_preset, channel_num, power); - DEBUG_MSG("Radio myRegion->freqStart / myRegion->freqEnd: %f -> %f (%f mhz)\n", myRegion->freqStart, myRegion->freqEnd, - myRegion->freqEnd - myRegion->freqStart); + DEBUG_MSG("Set radio: region=%, name=%s, config=%u, ch=%d, power=%d\n", myRegion->code, channelName, loraConfig.modem_preset, channel_num, power); + DEBUG_MSG("Radio myRegion->freqStart / myRegion->freqEnd: %f -> %f (%f mhz)\n", myRegion->freqStart, myRegion->freqEnd, myRegion->freqEnd - myRegion->freqStart); DEBUG_MSG("Radio myRegion->numChannels: %d\n", numChannels); DEBUG_MSG("Radio channel_num: %d\n", channel_num); DEBUG_MSG("Radio frequency: %f\n", getFreq()); From 4a08f86f9631d10d8830fc6e0bde5a38cb264680 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 2 Jul 2022 09:25:01 -0500 Subject: [PATCH 7/8] Oops (#1545) --- src/mesh/RadioInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 05c600357..1b8edc7e1 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -419,7 +419,7 @@ void RadioInterface::applyModemConfig() saveChannelNum(channel_num); saveFreq(freq); - DEBUG_MSG("Set radio: region=%, name=%s, config=%u, ch=%d, power=%d\n", myRegion->code, channelName, loraConfig.modem_preset, channel_num, power); + DEBUG_MSG("Set radio: region=%s, name=%s, config=%u, ch=%d, power=%d\n", myRegion->name, channelName, loraConfig.modem_preset, channel_num, power); DEBUG_MSG("Radio myRegion->freqStart / myRegion->freqEnd: %f -> %f (%f mhz)\n", myRegion->freqStart, myRegion->freqEnd, myRegion->freqEnd - myRegion->freqStart); DEBUG_MSG("Radio myRegion->numChannels: %d\n", numChannels); DEBUG_MSG("Radio channel_num: %d\n", channel_num); From 9fd7abf3d4670e9f8cfd92be2a52b8fdbf5c9b1b Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 2 Jul 2022 10:16:48 -0500 Subject: [PATCH 8/8] Actually save nodeDb after we init (#1546) --- src/mesh/NodeDB.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index f790f84b3..e1779b2f7 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -225,7 +225,6 @@ void NodeDB::init() DEBUG_MSG("Initializing NodeDB\n"); // saveToDisk(); loadFromDisk(); - // saveToDisk(); myNodeInfo.max_channels = MAX_NUM_CHANNELS; // tell others the max # of channels we can understand @@ -263,8 +262,8 @@ void NodeDB::init() #endif resetRadioConfig(); // If bogus settings got saved, then fix them - DEBUG_MSG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, *numNodes); + saveToDisk(); } // We reserve a few nodenums for future use @@ -463,7 +462,6 @@ void NodeDB::saveToDisk() saveProto(moduleConfigFileName, LocalModuleConfig_size, sizeof(LocalModuleConfig), LocalModuleConfig_fields, &moduleConfig); saveChannelsToDisk(); - } else { DEBUG_MSG("***** DEVELOPMENT MODE - DO NOT RELEASE - not saving to flash *****\n"); }