From 616290edcc1ae77254d3ef6b95fccd9bea45d051 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 21 Dec 2020 11:13:16 +0800 Subject: [PATCH 1/5] speed up build for my slow laptop --- bin/build-all.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/build-all.sh b/bin/build-all.sh index 5021680c3..c27760c42 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -14,6 +14,8 @@ BOARDS_ESP32="tlora-v2 tlora-v1 tlora-v2-1-1.6 tbeam heltec tbeam0.7" # FIXME note nrf52840dk build is for some reason only generating a BIN file but not a HEX file nrf52840dk-geeksville is fine BOARDS_NRF52="lora-relay-v1" +NUM_JOBS=2 + OUTDIR=release/latest # We keep all old builds (and their map files in the archive dir) @@ -49,7 +51,7 @@ function do_build() { basename=universal/firmware-$BOARD-$VERSION fi - pio run --jobs 4 --environment $BOARD # -v + pio run --jobs $NUM_JOBS --environment $BOARD # -v SRCELF=.pio/build/$BOARD/firmware.elf cp $SRCELF $OUTDIR/elfs/$basename.elf From 412916ba7cbe0ea8b83e339591be17e787fa180c Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 21 Dec 2020 11:13:30 +0800 Subject: [PATCH 2/5] fix printf format for 64 bits --- src/plugins/RemoteHardwarePlugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/RemoteHardwarePlugin.cpp b/src/plugins/RemoteHardwarePlugin.cpp index e9f25e51a..e63e05cff 100644 --- a/src/plugins/RemoteHardwarePlugin.cpp +++ b/src/plugins/RemoteHardwarePlugin.cpp @@ -89,7 +89,7 @@ bool RemoteHardwarePlugin::handleReceivedProtobuf(const MeshPacket &req, const H lastWatchMsec = 0; // Force a new publish soon previousWatch = ~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish) enabled = true; // Let our thread run at least once - DEBUG_MSG("Now watching GPIOs 0x%x\n", watchGpios); + DEBUG_MSG("Now watching GPIOs 0x%llx\n", watchGpios); break; } @@ -114,7 +114,7 @@ int32_t RemoteHardwarePlugin::runOnce() { if(curVal != previousWatch) { previousWatch = curVal; - DEBUG_MSG("Broadcasting GPIOS 0x%x changed!\n", curVal); + DEBUG_MSG("Broadcasting GPIOS 0x%llx changed!\n", curVal); // Something changed! Tell the world with a broadcast message HardwareMessage reply = HardwareMessage_init_default; From a8d770029518cddfb4f088ee3e2a3dac6a95fd20 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 21 Dec 2020 11:38:03 +0800 Subject: [PATCH 3/5] move more of is_router out of python and into the device code --- docs/software/TODO.md | 2 ++ proto | 2 +- src/PowerFSM.cpp | 5 +++-- src/gps/GPS.cpp | 6 +++--- src/mesh/NodeDB.h | 42 ++++++++++++++++++++++++++++++++++++------ src/mesh/mesh.pb.h | 13 +++++-------- 6 files changed, 50 insertions(+), 20 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index c08ddabe0..73df45a69 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -4,6 +4,8 @@ You probably don't care about this section - skip to the next one. For app cleanup: +* DONE writeup nice python options docs (common cases, link to protobuf docs) +* have android app link to user manual * DONE only do wantReplies once per packet type, if we change network settings force it again * update positions and nodeinfos based on packets we just merely witness on the mesh. via isPromsciousPort bool, remove sniffing * DONE make device build always have a valid version diff --git a/proto b/proto index 75078afe4..020ef9eea 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 75078afe43934f4ce15ef86ebc6950658a170145 +Subproject commit 020ef9eea8129756a0b45be5a3900b0355be4451 diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 7894361d4..a6ee29c98 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -173,9 +173,10 @@ void PowerFSM_setup() { // If we are not a router and we already have AC power go to POWER state after init, otherwise go to ON // We assume routers might be powered all the time, but from a low current (solar) source - bool isLowPower = radioConfig.preferences.is_low_power; - bool hasPower = !isLowPower && powerStatus && powerStatus->getHasUSB(); bool isRouter = radioConfig.preferences.is_router; + bool isLowPower = radioConfig.preferences.is_low_power || isRouter; + bool hasPower = !isLowPower && powerStatus && powerStatus->getHasUSB(); + DEBUG_MSG("PowerFSM init, USB power=%d\n", hasPower); powerFSM.add_timed_transition(&stateBOOT, hasPower ? &statePOWER : &stateON, 3 * 1000, NULL, "boot timeout"); diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 314b4c313..c0e336f0c 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -158,7 +158,7 @@ uint32_t GPS::getWakeTime() const return t; // already maxint if (t == 0) - t = 15 * 60; // Allow up to 5 mins for each attempt (probably will be much less if we can find sats) + t = radioConfig.preferences.is_router ? 5 * 60 : 15 * 60; // Allow up to 15 mins for each attempt (probably will be much less if we can find sats) or less if a router t *= 1000; // msecs @@ -179,8 +179,8 @@ uint32_t GPS::getSleepTime() const if (t == UINT32_MAX) return t; // already maxint - if (t == 0) - t = 2 * 60; // 2 mins + if (t == 0) // default - unset in preferences + t = radioConfig.preferences.is_router ? 24 * 60 * 60 : 2 * 60; // 2 mins or once per day for routers t *= 1000; diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index e8c230ced..5174f5642 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -147,23 +147,53 @@ their nodes */ const char *getChannelName(); +/* + If is_router is set, we use a number of different default values + + # FIXME - after tuning, move these params into the on-device defaults based on is_router and is_low_power + + # prefs.position_broadcast_secs = FIXME possibly broadcast only once an hr + prefs.wait_bluetooth_secs = 1 # Don't stay in bluetooth mode + prefs.mesh_sds_timeout_secs = never + prefs.phone_sds_timeout_sec = never + # try to stay in light sleep one full day, then briefly wake and sleep again + + prefs.ls_secs = oneday + + prefs.send_owner_interval = 2 # Send an owner packet every other network ping + prefs.position_broadcast_secs = 12 hours # send either position or owner every 12hrs + + # get a new GPS position once per day + prefs.gps_update_interval = oneday + + prefs.is_low_power = True + + # allow up to five minutes for each new GPS lock attempt + prefs.gps_attempt_time = 300 +*/ + +// Our delay functions check for this for times that should never expire +#define DELAY_FOREVER 0xffffffff + +#define IF_ROUTER(routerVal, normalVal) (radioConfig.preferences.is_router ? (routerVal) : (normalVal)) + #define PREF_GET(name, defaultVal) \ inline uint32_t getPref_##name() { return radioConfig.preferences.name ? radioConfig.preferences.name : (defaultVal); } -PREF_GET(send_owner_interval, 4) -PREF_GET(position_broadcast_secs, 15 * 60) +PREF_GET(send_owner_interval, IF_ROUTER(2, 4)) +PREF_GET(position_broadcast_secs, IF_ROUTER(12 * 60 * 60, 15 * 60)) // Each time we wake into the DARK state allow 1 minute to send and receive BLE packets to the phone -PREF_GET(wait_bluetooth_secs, 60) +PREF_GET(wait_bluetooth_secs, IF_ROUTER(1, 60)) PREF_GET(screen_on_secs, 60) -PREF_GET(mesh_sds_timeout_secs, 2 * 60 * 60) -PREF_GET(phone_sds_timeout_sec, 2 * 60 * 60) +PREF_GET(mesh_sds_timeout_secs, IF_ROUTER(DELAY_FOREVER, 2 * 60 * 60)) +PREF_GET(phone_sds_timeout_sec, IF_ROUTER(DELAY_FOREVER, 2 * 60 * 60)) PREF_GET(sds_secs, 365 * 24 * 60 * 60) // We default to sleeping (with bluetooth off for 5 minutes at a time). This seems to be a good tradeoff between // latency for the user sending messages and power savings because of not having to run (expensive) ESP32 bluetooth -PREF_GET(ls_secs, 5 * 60) +PREF_GET(ls_secs, IF_ROUTER(24 * 60 * 60, 5 * 60)) PREF_GET(phone_timeout_secs, 15 * 60) PREF_GET(min_wake_secs, 10) diff --git a/src/mesh/mesh.pb.h b/src/mesh/mesh.pb.h index bda4873b5..92bab3aeb 100644 --- a/src/mesh/mesh.pb.h +++ b/src/mesh/mesh.pb.h @@ -106,7 +106,6 @@ typedef struct _Position { typedef struct _RadioConfig_UserPreferences { uint32_t position_broadcast_secs; uint32_t send_owner_interval; - uint32_t num_missed_to_fail; uint32_t wait_bluetooth_secs; uint32_t screen_on_secs; uint32_t phone_timeout_secs; @@ -284,7 +283,7 @@ extern "C" { #define MeshPacket_init_default {0, 0, 0, {SubPacket_init_default}, 0, 0, 0, 0, 0, 0} #define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0} #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} #define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0} #define MyNodeInfo_init_default {0, 0, 0, "", "", "", 0, 0, 0, 0, 0, 0, 0, 0} #define DeviceState_init_default {false, RadioConfig_init_default, false, MyNodeInfo_init_default, false, User_init_default, 0, {NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default}, 0, {MeshPacket_init_default}, false, MeshPacket_init_default, 0, 0, 0, 0, {ChannelSettings_init_default, ChannelSettings_init_default, ChannelSettings_init_default, ChannelSettings_init_default}} @@ -299,7 +298,7 @@ extern "C" { #define MeshPacket_init_zero {0, 0, 0, {SubPacket_init_zero}, 0, 0, 0, 0, 0, 0} #define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} #define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0} #define MyNodeInfo_init_zero {0, 0, 0, "", "", "", 0, 0, 0, 0, 0, 0, 0, 0} #define DeviceState_init_zero {false, RadioConfig_init_zero, false, MyNodeInfo_init_zero, false, User_init_zero, 0, {NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero}, 0, {MeshPacket_init_zero}, false, MeshPacket_init_zero, 0, 0, 0, 0, {ChannelSettings_init_zero, ChannelSettings_init_zero, ChannelSettings_init_zero, ChannelSettings_init_zero}} @@ -340,7 +339,6 @@ extern "C" { #define Position_time_tag 9 #define RadioConfig_UserPreferences_position_broadcast_secs_tag 1 #define RadioConfig_UserPreferences_send_owner_interval_tag 2 -#define RadioConfig_UserPreferences_num_missed_to_fail_tag 3 #define RadioConfig_UserPreferences_wait_bluetooth_secs_tag 4 #define RadioConfig_UserPreferences_screen_on_secs_tag 5 #define RadioConfig_UserPreferences_phone_timeout_secs_tag 6 @@ -509,7 +507,6 @@ X(a, STATIC, OPTIONAL, MESSAGE, channel_settings, 2) #define RadioConfig_UserPreferences_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, UINT32, position_broadcast_secs, 1) \ X(a, STATIC, SINGULAR, UINT32, send_owner_interval, 2) \ -X(a, STATIC, SINGULAR, UINT32, num_missed_to_fail, 3) \ X(a, STATIC, SINGULAR, UINT32, wait_bluetooth_secs, 4) \ X(a, STATIC, SINGULAR, UINT32, screen_on_secs, 5) \ X(a, STATIC, SINGULAR, UINT32, phone_timeout_secs, 6) \ @@ -661,11 +658,11 @@ extern const pb_msgdesc_t ToRadio_msg; #define SubPacket_size 275 #define MeshPacket_size 320 #define ChannelSettings_size 84 -#define RadioConfig_size 314 -#define RadioConfig_UserPreferences_size 225 +#define RadioConfig_size 308 +#define RadioConfig_UserPreferences_size 219 #define NodeInfo_size 132 #define MyNodeInfo_size 110 -#define DeviceState_size 5824 +#define DeviceState_size 5818 #define DebugString_size 258 #define FromRadio_size 329 #define ToRadio_size 323 From 031c58e21c523538d2ce5add28162ad3dcc0802f Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 23 Dec 2020 17:12:48 +0800 Subject: [PATCH 4/5] remove logspam that was busting serial api --- docs/software/TODO.md | 1 - src/mesh/PhoneAPI.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 73df45a69..f96d2acb3 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -38,7 +38,6 @@ For app cleanup: * fix the RTC drift bug * move python ping functionality into device, reply with rxsnr info * use channels for gpio security https://github.com/meshtastic/Meshtastic-device/issues/104 -* generate autodocs * MeshPackets for sending should be reference counted so that API clients would have the option of checking sent status (would allow removing the nasty 30 sec timer in gpio watch sending) For high speed/lots of devices/short range tasks: diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index e122c45ce..754f0d380 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -100,7 +100,7 @@ void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) size_t PhoneAPI::getFromRadio(uint8_t *buf) { if (!available()) { - DEBUG_MSG("getFromRadio, !available\n"); + // DEBUG_MSG("getFromRadio, !available\n"); return 0; } @@ -226,7 +226,7 @@ bool PhoneAPI::available() if (!packetForPhone) packetForPhone = service.getForPhone(); bool hasPacket = !!packetForPhone; - DEBUG_MSG("available hasPacket=%d\n", hasPacket); + // DEBUG_MSG("available hasPacket=%d\n", hasPacket); return hasPacket; } From 901ff6bb1ea0e9415071ca3cf428ac1136d7feb5 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 25 Dec 2020 10:16:49 +0800 Subject: [PATCH 5/5] bug #587 try to work with old (2.x?) versions of python --- bin/platformio-custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index d56cc09f3..ec9dd4545 100644 --- a/bin/platformio-custom.py +++ b/bin/platformio-custom.py @@ -8,7 +8,7 @@ config.read(prefsLoc) version = dict(config.items('VERSION')) verStr = "{}.{}.{}".format(version["major"], version["minor"], version["build"]) -print(f"Using meshtastic platform-custom.py, firmare version {verStr}") +print("Using meshtastic platform-custom.py, firmare version " + verStr) # General options that are passed to the C and C++ compilers projenv.Append(CCFLAGS=[