From 1fd92cf8ebaec9b114c7bcc593d7ece0d7a2d059 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 29 Mar 2020 12:33:14 -0700 Subject: [PATCH 1/7] fix build for Windows based on tip from @moinars --- platformio.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index d66f86de..90e551aa 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,13 +34,15 @@ build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -Os -Wl,-Map,. ; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG +; leave this commented out to avoid breaking Windows +;upload_port = /dev/ttyUSB0 +;monitor_port = /dev/ttyUSB0 + upload_speed = 921600 -upload_port = /dev/ttyUSB0 ; the default is esptool ; upload_protocol = esp-prog -monitor_port = /dev/ttyUSB0 monitor_speed = 115200 # debug_tool = esp-prog From a73f46647302b79ff0aac780da202bed408102d5 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 30 Mar 2020 13:46:46 -0700 Subject: [PATCH 2/7] Add GPL statement --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2a5e075b..b480f5ad 100644 --- a/README.md +++ b/README.md @@ -155,3 +155,5 @@ This project is run by volunteers. Past contributors include: # IMPORTANT DISCLAIMERS AND FAQ For a listing of currently missing features and a FAQ click [here](docs/faq.md). + +Copyright 2019 Geeksville Industries, LLC. GPL V3 Licensed. From 7dabad1b70556de1d59a7332d83acbc7d645bf60 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 30 Mar 2020 16:05:28 -0700 Subject: [PATCH 3/7] don't let phones send down fatally invalid RadioConfig records and if a phone did in the past, fixup the garbage we saved in flash --- src/MeshRadio.cpp | 14 +------------- src/MeshService.cpp | 1 + src/NodeDB.cpp | 41 +++++++++++++++++++++++++++++++---------- src/NodeDB.h | 3 +++ 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/MeshRadio.cpp b/src/MeshRadio.cpp index 31f229ab..c7cdcb42 100644 --- a/src/MeshRadio.cpp +++ b/src/MeshRadio.cpp @@ -10,10 +10,6 @@ #include #include -/// 16 bytes of random PSK for our _public_ default channel that all devices power up on -static const uint8_t defaultpsk[] = {0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59, - 0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0xbf}; - /** * ## LoRaWAN for North America @@ -32,14 +28,6 @@ MeshRadio::MeshRadio(MemoryPool &_pool, PointerQueue &_r { myNodeInfo.num_channels = NUM_CHANNELS; - // radioConfig.modem_config = RadioConfig_ModemConfig_Bw125Cr45Sf128; // medium range and fast - // channelSettings.modem_config = ChannelSettings_ModemConfig_Bw500Cr45Sf128; // short range and fast, but wide bandwidth so - // incompatible radios can talk together - channelSettings.modem_config = ChannelSettings_ModemConfig_Bw125Cr48Sf4096; // slow and long range - - channelSettings.tx_power = 23; - memcpy(&channelSettings.psk, &defaultpsk, sizeof(channelSettings.psk)); - strcpy(channelSettings.name, "Default"); // Can't print strings this early - serial not setup yet // DEBUG_MSG("Set meshradio defaults name=%s\n", channelSettings.name); } @@ -122,7 +110,7 @@ void MeshRadio::reloadConfig() // FIXME - can we do this? It seems to be in the Heltec board. rf95.setTxPower(channelSettings.tx_power, false); - DEBUG_MSG("Set radio: name=%s. config=%u, ch=%d, txpower=%d\n", channelSettings.name, channelSettings.modem_config, + DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, txpower=%d\n", channelSettings.name, channelSettings.modem_config, channel_num, channelSettings.tx_power); // Done with init tell radio to start receiving diff --git a/src/MeshService.cpp b/src/MeshService.cpp index bf170238..5ded40dd 100644 --- a/src/MeshService.cpp +++ b/src/MeshService.cpp @@ -217,6 +217,7 @@ void MeshService::loop() void MeshService::reloadConfig() { // If we can successfully set this radio to these settings, save them to disk + nodeDB.resetRadioConfig(); // Don't let the phone send us fatally bad settings radio.reloadConfig(); nodeDB.saveToDisk(); } diff --git a/src/NodeDB.cpp b/src/NodeDB.cpp index 638498db..7c3b194f 100644 --- a/src/NodeDB.cpp +++ b/src/NodeDB.cpp @@ -44,9 +44,37 @@ static uint8_t ourMacAddr[6]; NodeDB::NodeDB() : nodes(devicestate.node_db), numNodes(&devicestate.node_db_count) {} +void NodeDB::resetRadioConfig() +{ + /// 16 bytes of random PSK for our _public_ default channel that all devices power up on + static const uint8_t defaultpsk[] = {0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59, + 0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0xbf}; + + if (radioConfig.preferences.sds_secs == 0) { + DEBUG_MSG("RadioConfig reset!\n"); + radioConfig.preferences.send_owner_interval = 4; // per sw-design.md + radioConfig.preferences.position_broadcast_secs = 15 * 60; + radioConfig.preferences.wait_bluetooth_secs = 120; + radioConfig.preferences.screen_on_secs = 30; + radioConfig.preferences.mesh_sds_timeout_secs = 2 * 60 * 60; + radioConfig.preferences.phone_sds_timeout_sec = 2 * 60 * 60; + radioConfig.preferences.sds_secs = 365 * 24 * 60 * 60; // one year + radioConfig.preferences.ls_secs = 60 * 60; + radioConfig.preferences.phone_timeout_secs = 15 * 60; + + // radioConfig.modem_config = RadioConfig_ModemConfig_Bw125Cr45Sf128; // medium range and fast + // channelSettings.modem_config = ChannelSettings_ModemConfig_Bw500Cr45Sf128; // short range and fast, but wide bandwidth + // so incompatible radios can talk together + channelSettings.modem_config = ChannelSettings_ModemConfig_Bw125Cr48Sf4096; // slow and long range + + channelSettings.tx_power = 23; + memcpy(&channelSettings.psk, &defaultpsk, sizeof(channelSettings.psk)); + strcpy(channelSettings.name, "Default"); + } +} + void NodeDB::init() { - // init our devicestate with valid flags so protobuf writing/reading will work devicestate.has_my_node = true; devicestate.has_radio = true; @@ -57,15 +85,7 @@ void NodeDB::init() devicestate.node_db_count = 0; devicestate.receive_queue_count = 0; - radioConfig.preferences.send_owner_interval = 4; // per sw-design.md - radioConfig.preferences.position_broadcast_secs = 15 * 60; - radioConfig.preferences.wait_bluetooth_secs = 120; - radioConfig.preferences.screen_on_secs = 30; - radioConfig.preferences.mesh_sds_timeout_secs = 2 * 60 * 60; - radioConfig.preferences.phone_sds_timeout_sec = 2 * 60 * 60; - radioConfig.preferences.sds_secs = 365 * 24 * 60 * 60; // one year - radioConfig.preferences.ls_secs = 60 * 60; - radioConfig.preferences.phone_timeout_secs = 15 * 60; + resetRadioConfig(); // default to no GPS, until one has been found by probing myNodeInfo.has_gps = false; @@ -102,6 +122,7 @@ void NodeDB::init() // saveToDisk(); loadFromDisk(); + resetRadioConfig(); // If bogus settings got saved, then fix them DEBUG_MSG("NODENUM=0x%x, dbsize=%d\n", myNodeInfo.my_node_num, *numNodes); } diff --git a/src/NodeDB.h b/src/NodeDB.h index 76b043e4..ddabeb23 100644 --- a/src/NodeDB.h +++ b/src/NodeDB.h @@ -43,6 +43,9 @@ class NodeDB /// write to flash void saveToDisk(); + // Reinit radio config if needed, because sometimes a buggy android app might send us bogus settings + void resetRadioConfig(); + /// given a subpacket sniffed from the network, update our DB state /// we updateGUI and updateGUIforNode if we think our this change is big enough for a redraw void updateFrom(const MeshPacket &p); From feb6f2e59e467174c7aaa92fea79468317e8d68e Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 30 Mar 2020 17:02:09 -0700 Subject: [PATCH 4/7] extra debug output for radio config, and bump up bax handles for BLE --- src/MeshBluetoothService.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MeshBluetoothService.cpp b/src/MeshBluetoothService.cpp index 3a059230..16af1492 100644 --- a/src/MeshBluetoothService.cpp +++ b/src/MeshBluetoothService.cpp @@ -106,12 +106,13 @@ class RadioCharacteristic : public ProtobufCharacteristic void onRead(BLECharacteristic *c) { - DEBUG_MSG("Reading radio config\n"); + DEBUG_MSG("Reading radio config, sdsecs %u\n", radioConfig.preferences.sds_secs); ProtobufCharacteristic::onRead(c); } void onWrite(BLECharacteristic *c) { + DEBUG_MSG("Writing radio config\n"); ProtobufCharacteristic::onWrite(c); service.reloadConfig(); } @@ -263,7 +264,7 @@ See bluetooth-api.md for documentation. BLEService *createMeshBluetoothService(BLEServer *server) { // Create the BLE Service, we need more than the default of 15 handles - BLEService *service = server->createService(BLEUUID("6ba1b218-15a8-461f-9fa8-5dcae273eafd"), 25, 0); + BLEService *service = server->createService(BLEUUID("6ba1b218-15a8-461f-9fa8-5dcae273eafd"), 30, 0); assert(!meshFromNumCharacteristic); meshFromNumCharacteristic = new FromNumCharacteristic; From 1da62e5ba1cf87a33f8083111eeb84c97b29a3a4 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 30 Mar 2020 17:02:41 -0700 Subject: [PATCH 5/7] oops - we were previously not marking these protobuf structs as valid --- src/NodeDB.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/NodeDB.cpp b/src/NodeDB.cpp index 7c3b194f..0bdbd146 100644 --- a/src/NodeDB.cpp +++ b/src/NodeDB.cpp @@ -61,6 +61,8 @@ void NodeDB::resetRadioConfig() radioConfig.preferences.sds_secs = 365 * 24 * 60 * 60; // one year radioConfig.preferences.ls_secs = 60 * 60; radioConfig.preferences.phone_timeout_secs = 15 * 60; + radioConfig.has_channel_settings = true; + radioConfig.has_preferences = true; // radioConfig.modem_config = RadioConfig_ModemConfig_Bw125Cr45Sf128; // medium range and fast // channelSettings.modem_config = ChannelSettings_ModemConfig_Bw500Cr45Sf128; // short range and fast, but wide bandwidth From 1b050a6c3dfca8240d505744517370e4541b9fa1 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 30 Mar 2020 18:51:15 -0700 Subject: [PATCH 6/7] stop distributing the (enormous) elf files in the zip file --- bin/build-all.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/build-all.sh b/bin/build-all.sh index 2c3f1dd9..90215931 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -14,6 +14,8 @@ ARCHIVEDIR=release/archive rm -f $OUTDIR/firmware* +mkdir -p $OUTDIR/bins $OUTDIR/elfs + # build the named environment and copy the bins to the release directory function do_build { ENV_NAME=$1 @@ -22,8 +24,8 @@ function do_build { SRCELF=.pio/build/$ENV_NAME/firmware.elf rm -f $SRCBIN pio run --environment $ENV_NAME # -v - cp $SRCBIN $OUTDIR/firmware-$ENV_NAME-$COUNTRY-$VERSION.bin - cp $SRCELF $OUTDIR/firmware-$ENV_NAME-$COUNTRY-$VERSION.elf + cp $SRCBIN $OUTDIR/bins/firmware-$ENV_NAME-$COUNTRY-$VERSION.bin + cp $SRCELF $OUTDIR/elfs/firmware-$ENV_NAME-$COUNTRY-$VERSION.elf } for COUNTRY in $COUNTRIES; do @@ -56,6 +58,6 @@ Generated by bin/buildall.sh --> XML rm -f $ARCHIVEDIR/firmware-$VERSION.zip -zip --junk-paths $ARCHIVEDIR/firmware-$VERSION.zip $OUTDIR/firmware-*-$VERSION.* images/system-info.bin bin/device-install.sh +zip --junk-paths $ARCHIVEDIR/firmware-$VERSION.zip $OUTDIR/bins/firmware-*-$VERSION.* images/system-info.bin bin/device-install.sh echo BUILT ALL \ No newline at end of file From 17de6f9532e72397503c19605cb63fea21d7c6a6 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 30 Mar 2020 19:34:25 -0700 Subject: [PATCH 7/7] fix #73: allow hw-model to be longer (16 bytes including terminator) --- proto | 2 +- src/mesh.pb.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/proto b/proto index 1b2449b5..d13d741a 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 1b2449b50d11f66d90511559e94cdf40f525fafb +Subproject commit d13d741a985f75b953a9b7f8df6c8c61fcc4730d diff --git a/src/mesh.pb.h b/src/mesh.pb.h index bed7aed2..2c524662 100644 --- a/src/mesh.pb.h +++ b/src/mesh.pb.h @@ -50,7 +50,7 @@ typedef struct _MyNodeInfo { bool has_gps; int32_t num_channels; char region[12]; - char hw_model[12]; + char hw_model[16]; char firmware_version[12]; uint32_t error_code; uint32_t error_address; @@ -431,8 +431,8 @@ extern const pb_msgdesc_t ToRadio_msg; #define RadioConfig_size 120 #define RadioConfig_UserPreferences_size 72 #define NodeInfo_size 155 -#define MyNodeInfo_size 81 -#define DeviceState_size 15076 +#define MyNodeInfo_size 85 +#define DeviceState_size 15080 #define FromRadio_size 301 #define ToRadio_size 295