From a0f2d1f18add09280b0d3cd5622311c43b19a979 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 11 Feb 2020 19:06:12 -0800 Subject: [PATCH] include a human readable name for each channel --- TODO.md | 5 +++-- src/MeshRadio.cpp | 8 +++++++- src/main.ino | 2 +- src/mesh.pb.h | 15 +++++++++------ src/screen.cpp | 4 ++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 9d42be13..b7f37e88 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ # High priority -* platformio sdkconfig CONFIG_PM and turn on modem sleep mode * finish power measurements and est battery life * have node info screen show real info (including time since last contact, distance and heading) * make debug info screen show real data (including battery level & charging) @@ -27,7 +26,8 @@ # Low power consumption tasks -* keep cpu 100% in sleep (some sort - deep?) Sleep until irq from radio wakes it (make plan based on power draw spreadsheet). Then stay awake for 30 secs to attempt delivery to phone. +* platformio sdkconfig CONFIG_PM and turn on modem sleep mode +* keep cpu 100% in deepsleep until irq from radio wakes it. Then stay awake for 30 secs to attempt delivery to phone. * have radiohead ISR send messages to RX queue directly, to allow that thread to block until we have something to send * use https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/ association sleep pattern to save power - but see https://github.com/espressif/esp-idf/issues/2070 and https://esp32.com/viewtopic.php?f=13&t=12182 it seems with BLE on the 'easy' draw people are getting is 80mA * stop using loop() instead use a job queue and let cpu sleep @@ -59,6 +59,7 @@ until the phone pulls those packets. Ever so often power on bluetooth just so w # Low priority +* increase the max charging rate a bit for 18650s, currently it limits to 180mA (at 4V). Work backwards from the 500mA USB limit (at 5V) and let the AXP charge at that rate. * add receive timestamps to messages, inserted by esp32 when message is received but then shown on the phone * if radio params change fundamentally, discard the nodedb * discard very old nodedb records (> 1wk) diff --git a/src/MeshRadio.cpp b/src/MeshRadio.cpp index c4c017ff..566cee16 100644 --- a/src/MeshRadio.cpp +++ b/src/MeshRadio.cpp @@ -11,6 +11,10 @@ #define DEFAULT_CHANNEL_NUM 3 // we randomly pick one + +/// 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 @@ -35,6 +39,8 @@ MeshRadio::MeshRadio(MemoryPool &_pool, PointerQueue &_r channelSettings.tx_power = 23; channelSettings.channel_num = DEFAULT_CHANNEL_NUM; + memcpy(&channelSettings.psk, &defaultpsk, sizeof(channelSettings.psk)); + strcpy(channelSettings.name, "Default"); } bool MeshRadio::init() @@ -78,7 +84,7 @@ void MeshRadio::reloadConfig() // rf95.setPreambleLength(8); // Default is 8 assert(channelSettings.channel_num < NUM_CHANNELS); // If the phone tries to tell us to use an illegal channel then panic - + // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM float center_freq = CH0 + CH_SPACING * channelSettings.channel_num; if (!rf95.setFrequency(center_freq)) diff --git a/src/main.ino b/src/main.ino index 95bc3bfa..f49cb382 100644 --- a/src/main.ino +++ b/src/main.ino @@ -444,7 +444,7 @@ void loop() if (!wasPressed) { // just started a new press DEBUG_MSG("pressing\n"); - esp_pm_dump_locks(stdout); // FIXME, do this someplace better + // esp_pm_dump_locks(stdout); // FIXME, do this someplace better wasPressed = true; minPressMs = millis() + 3000; screen_press(); diff --git a/src/mesh.pb.h b/src/mesh.pb.h index 9ce8028a..516a78a1 100644 --- a/src/mesh.pb.h +++ b/src/mesh.pb.h @@ -39,6 +39,7 @@ typedef struct _ChannelSettings { uint32_t channel_num; ChannelSettings_ModemConfig modem_config; pb_byte_t psk[16]; + char name[12]; } ChannelSettings; typedef PB_BYTES_ARRAY_T(200) Data_payload_t; @@ -159,7 +160,7 @@ typedef struct _ToRadio { #define User_init_default {"", "", "", {0}} #define SubPacket_init_default {0, {Position_init_default}} #define MeshPacket_init_default {0, 0, false, SubPacket_init_default, 0} -#define ChannelSettings_init_default {0, 0, _ChannelSettings_ModemConfig_MIN, {0}} +#define ChannelSettings_init_default {0, 0, _ChannelSettings_ModemConfig_MIN, {0}, ""} #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default} #define RadioConfig_UserPreferences_init_default {0, 0, 0, 0} #define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0, 0} @@ -172,7 +173,7 @@ typedef struct _ToRadio { #define User_init_zero {"", "", "", {0}} #define SubPacket_init_zero {0, {Position_init_zero}} #define MeshPacket_init_zero {0, 0, false, SubPacket_init_zero, 0} -#define ChannelSettings_init_zero {0, 0, _ChannelSettings_ModemConfig_MIN, {0}} +#define ChannelSettings_init_zero {0, 0, _ChannelSettings_ModemConfig_MIN, {0}, ""} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero} #define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0} #define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0, 0} @@ -186,6 +187,7 @@ typedef struct _ToRadio { #define ChannelSettings_channel_num_tag 2 #define ChannelSettings_modem_config_tag 3 #define ChannelSettings_psk_tag 4 +#define ChannelSettings_name_tag 5 #define Data_typ_tag 1 #define Data_payload_tag 2 #define MyNodeInfo_my_node_num_tag 1 @@ -275,7 +277,8 @@ X(a, STATIC, SINGULAR, UINT64, rx_time, 4) X(a, STATIC, SINGULAR, INT32, tx_power, 1) \ X(a, STATIC, SINGULAR, UINT32, channel_num, 2) \ X(a, STATIC, SINGULAR, UENUM, modem_config, 3) \ -X(a, STATIC, SINGULAR, FIXED_LENGTH_BYTES, psk, 4) +X(a, STATIC, SINGULAR, FIXED_LENGTH_BYTES, psk, 4) \ +X(a, STATIC, SINGULAR, STRING, name, 5) #define ChannelSettings_CALLBACK NULL #define ChannelSettings_DEFAULT NULL @@ -376,12 +379,12 @@ extern const pb_msgdesc_t ToRadio_msg; #define User_size 72 #define SubPacket_size 208 #define MeshPacket_size 244 -#define ChannelSettings_size 37 -#define RadioConfig_size 59 +#define ChannelSettings_size 50 +#define RadioConfig_size 72 #define RadioConfig_UserPreferences_size 18 #define NodeInfo_size 162 #define MyNodeInfo_size 13 -#define DeviceState_size 13336 +#define DeviceState_size 13349 #define FromRadio_size 253 #define ToRadio_size 247 diff --git a/src/screen.cpp b/src/screen.cpp index fe6b8d6e..a2038359 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -304,10 +304,14 @@ void drawDebugInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, i static char usersStr[20]; snprintf(usersStr, sizeof(usersStr), "Users %d/%d", nodeDB.getNumOnlineNodes(), nodeDB.getNumNodes()); + static char channelStr[20]; + snprintf(channelStr, sizeof(channelStr), "Channel %s", channelSettings.name); + const char *fields[] = { "Batt 89%", "GPS 75%", usersStr, + channelStr, NULL}; uint32_t yo = drawRows(display, x, y, fields);