From b4de495154364281bbe86ad1e607a25c9f35ed1e Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 20 Jun 2020 17:07:17 -0700 Subject: [PATCH 01/10] show app version on boot screen --- src/screen.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/screen.cpp b/src/screen.cpp index 1837ef79..b56863dc 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -52,7 +52,7 @@ namespace meshtastic // A text message frame + debug frame + all the node infos static FrameCallback normalFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES]; static uint32_t targetFramerate = IDLE_FRAMERATE; -static char btPIN[16] = "888888"; +static char btPIN[16] = "888888"; static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { @@ -64,6 +64,14 @@ static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int1 display->setFont(ArialMT_Plain_16); display->setTextAlignment(TEXT_ALIGN_CENTER); display->drawString(64 + x, SCREEN_HEIGHT - FONT_HEIGHT_16, "meshtastic.org"); + display->setFont(ArialMT_Plain_10); + const char *region = xstr(HW_VERSION); + if(*region && region[3] == '-') // Skip past 1.0- in the 1.0-EU865 string + region += 4; + char buf[16]; + snprintf(buf, sizeof(buf), "%s", xstr(APP_VERSION)); // Note: we don't bother printing region or now, it makes the string too long + display->drawString(SCREEN_WIDTH - 20, 0, buf); + } static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) From 8190098bb8bacce912aef9c082d7ecd0dbbe9b8c Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 21 Jun 2020 14:11:38 -0700 Subject: [PATCH 02/10] experiment with wifi connections for nodes --- .vscode/settings.json | 3 ++- docs/software/TODO.md | 8 ++++--- docs/software/esp32-arduino-build-notes.md | 4 ++-- docs/software/mesh-alg.md | 7 +++--- linker/esp32.extram.bss.ld | 18 +++++++++++++++ platformio.ini | 4 +++- proto | 2 +- src/main.cpp | 27 ++++++++++++++++++++++ src/mesh/NodeDB.cpp | 2 +- src/mesh/mesh.pb.h | 25 +++++++++++--------- 10 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 linker/esp32.extram.bss.ld diff --git a/.vscode/settings.json b/.vscode/settings.json index aebb3d4a..3aca0452 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -59,6 +59,7 @@ "cfsr", "descs", "ocrypto", - "protobufs" + "protobufs", + "wifi" ] } \ No newline at end of file diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 47943553..3d5670b7 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -2,9 +2,11 @@ You probably don't care about this section - skip to the next one. -- bluetooth toggle enable stress test, we are not properly restarting our connect -- make new android release -- check in our modified arduino binaries +- check in wifi code +- test BLE software update again +- iram space: https://esp32.com/viewtopic.php?t=8460 +- set https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/external-ram.html spi ram bss +- figure out if iram or bluetooth classic caused ble problems - post bug on esp32-arduino - implement first cut of router mode: preferentially handle flooding, and change sleep and GPS behaviors - let users set arbitrary params in android diff --git a/docs/software/esp32-arduino-build-notes.md b/docs/software/esp32-arduino-build-notes.md index 45fb7a54..b9fd6850 100644 --- a/docs/software/esp32-arduino-build-notes.md +++ b/docs/software/esp32-arduino-build-notes.md @@ -2,7 +2,7 @@ We build our own custom version of esp32-arduino, in order to get some fixes we've made but haven't yet been merged in master. -These are a set of currently unformatted notes on how to build and install them. Most developers should not care about this, because +These are a set of currently unformatted notes on how to build and install them. Most developers should not care about this, because you'll automatically get our fixed libraries. ``` @@ -12,5 +12,5 @@ you'll automatically get our fixed libraries. https://docs.espressif.com/projects/esp-idf/en/release-v3.3/get-started/linux-setup.html kevinh@kevin-server:~/development/meshtastic/esp32-arduino-lib-builder\$ python /home/kevinh/development/meshtastic/esp32-arduino-lib-builder/esp-idf/components/esptool*py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dout --flash_freq 40m --flash_size detect 0x1000 /home/kevinh/development/meshtastic/esp32-arduino-lib-builder/build/bootloader/bootloader.bin cp -a out/tools/sdk/* components/arduino/tools/sdk - cp -ar components/arduino/ ~/.platformio/packages/framework-arduinoespressif32@src-fba9d33740f719f712e9f8b07da6ea13/ + cp -ar components/arduino/* ~/.platformio/packages/framework-arduinoespressif32@src-fba9d33740f719f712e9f8b07da6ea13/ ``` diff --git a/docs/software/mesh-alg.md b/docs/software/mesh-alg.md index ecad282a..2a2e4dd2 100644 --- a/docs/software/mesh-alg.md +++ b/docs/software/mesh-alg.md @@ -19,17 +19,18 @@ reliable messaging tasks (stage one for DSR): - DONE once an ack comes in, remove the packet from the retry list and deliver the ack to the original sender - DONE after three retries, deliver a no-ack packet to the original sender (i.e. the phone app or mesh router service) - DONE test one hop ack/nak with the python framework -- Do stress test with acks +- DONE Do stress test with acks dsr tasks -- oops I might have broken message reception +- DONE oops I might have broken message reception - DONE Don't use broadcasts for the network pings (close open github issue) - DONE add ignoreSenders to radioconfig to allow testing different mesh topologies by refusing to see certain senders -- test multihop delivery with the python framework +- DONE test multihop delivery with the python framework optimizations / low priority: +- read this [this](http://pages.cs.wisc.edu/~suman/pubs/nadv-mobihoc05.pdf) paper and others and make our naive flood routing less naive - read @cyclomies long email with good ideas on optimizations and reply - Remove NodeNum assignment algorithm (now that we use 4 byte node nums) - make android app warn if firmware is too old or too new to talk to diff --git a/linker/esp32.extram.bss.ld b/linker/esp32.extram.bss.ld new file mode 100644 index 00000000..582f6eb6 --- /dev/null +++ b/linker/esp32.extram.bss.ld @@ -0,0 +1,18 @@ +/* This section is only included if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY + is set, to link some sections to BSS in PSRAM */ + +SECTIONS +{ + /* external memory bss, from any global variable with EXT_RAM_ATTR attribute*/ + .ext_ram.bss (NOLOAD) : + { + _ext_ram_bss_start = ABSOLUTE(.); + *(.ext_ram.bss*) + *libnet80211.a:(.dynsbss .sbss .sbss.* .gnu.linkonce.sb.* .scommon .sbss2.* .gnu.linkonce.sb2.* .dynbss .bss .bss.* .share.mem .gnu.linkonce.b.* COMMON) + *libpp.a:(.dynsbss .sbss .sbss.* .gnu.linkonce.sb.* .scommon .sbss2.* .gnu.linkonce.sb2.* .dynbss .bss .bss.* .share.mem .gnu.linkonce.b.* COMMON) + *liblwip.a:(.dynsbss .sbss .sbss.* .gnu.linkonce.sb.* .scommon .sbss2.* .gnu.linkonce.sb2.* .dynbss .bss .bss.* .share.mem .gnu.linkonce.b.* COMMON) + *libbt.a:(EXCLUDE_FILE (libbtdm_app.a) .dynsbss .sbss .sbss.* .gnu.linkonce.sb.* .scommon .sbss2.* .gnu.linkonce.sb2.* .dynbss .bss .bss.* .share.mem .gnu.linkonce.b.* COMMON) + . = ALIGN(4); + _ext_ram_bss_end = ABSOLUTE(.); + } > extern_ram_seg +} diff --git a/platformio.ini b/platformio.ini index 298032ce..0fb69a86 100644 --- a/platformio.ini +++ b/platformio.ini @@ -84,7 +84,9 @@ src_filter = upload_speed = 921600 debug_init_break = tbreak setup build_flags = - ${env.build_flags} -Wall -Wextra -Isrc/esp32 + ${env.build_flags} -Wall -Wextra -Isrc/esp32 -mfix-esp32-psram-cache-issue +# Hmm - this doesn't work yet +# board_build.ldscript = linker/esp32.extram.bss.ld lib_ignore = segger_rtt platform_packages = framework-arduinoespressif32 @ https://github.com/meshtastic/arduino-esp32.git diff --git a/proto b/proto index 72cbde93..fc79db45 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 72cbde93ffbc2ee917f9d7328558475e02a91cba +Subproject commit fc79db45944959ee3246f6f808db18e4debab72b diff --git a/src/main.cpp b/src/main.cpp index cfbd7e48..d79f2856 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ #ifndef NO_ESP32 #include "BluetoothUtil.h" +#include "WiFi.h" #endif #include "RF95Interface.h" @@ -124,7 +125,28 @@ static uint32_t ledBlinker() Periodic ledPeriodic(ledBlinker); +#ifndef NO_ESP32 +void initWifi() +{ + strcpy(radioConfig.preferences.wifi_ssid, "geeksville"); + strcpy(radioConfig.preferences.wifi_password, "xxx"); + if (radioConfig.has_preferences) { + const char *wifiName = radioConfig.preferences.wifi_ssid; + if (*wifiName) { + const char *wifiPsw = radioConfig.preferences.wifi_password; + if (radioConfig.preferences.wifi_ap_mode) { + // DEBUG_MSG("STARTING WIFI AP: ssid=%s, ok=%d\n", wifiName, WiFi.softAP(wifiName, wifiPsw)); + } else { + // WiFi.mode(WIFI_MODE_STA); + DEBUG_MSG("JOINING WIFI: ssid=%s\n", wifiName); + // WiFi.begin(wifiName, wifiPsw); + } + } + } else + DEBUG_MSG("Not using WIFI\n"); +} +#endif void setup() { @@ -213,6 +235,11 @@ void setup() service.init(); +#ifndef NO_ESP32 + // Must be after we init the service, because the wifi settings are loaded by NodeDB (oops) + initWifi(); +#endif + #ifdef SX1262_ANT_SW // make analog PA vs not PA switch on SX1262 eval board work properly pinMode(SX1262_ANT_SW, OUTPUT); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 9bebda11..2a202f23 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -19,7 +19,7 @@ NodeDB nodeDB; // we have plenty of ram so statically alloc this tempbuf (for now) -DeviceState devicestate; +EXT_RAM_ATTR DeviceState devicestate; MyNodeInfo &myNodeInfo = devicestate.my_node; RadioConfig &radioConfig = devicestate.radio; ChannelSettings &channelSettings = radioConfig.channel_settings; diff --git a/src/mesh/mesh.pb.h b/src/mesh/mesh.pb.h index 2651d6cb..808ffab8 100644 --- a/src/mesh/mesh.pb.h +++ b/src/mesh/mesh.pb.h @@ -101,8 +101,9 @@ typedef struct _RadioConfig_UserPreferences { uint32_t sds_secs; uint32_t ls_secs; uint32_t min_wake_secs; - bool keep_all_packets; - bool promiscuous_mode; + char wifi_ssid[33]; + char wifi_password[64]; + bool wifi_ap_mode; pb_size_t ignore_incoming_count; uint32_t ignore_incoming[3]; } RadioConfig_UserPreferences; @@ -241,7 +242,7 @@ typedef struct _ToRadio { #define MeshPacket_init_default {0, 0, 0, {SubPacket_init_default}, 0, 0, 0, 0, 0} #define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {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, 0, 0, {0, 0, 0}} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 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} @@ -257,7 +258,7 @@ typedef struct _ToRadio { #define MeshPacket_init_zero {0, 0, 0, {SubPacket_init_zero}, 0, 0, 0, 0, 0} #define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {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, 0, 0, {0, 0, 0}} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 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} @@ -308,8 +309,9 @@ typedef struct _ToRadio { #define RadioConfig_UserPreferences_sds_secs_tag 9 #define RadioConfig_UserPreferences_ls_secs_tag 10 #define RadioConfig_UserPreferences_min_wake_secs_tag 11 -#define RadioConfig_UserPreferences_keep_all_packets_tag 100 -#define RadioConfig_UserPreferences_promiscuous_mode_tag 101 +#define RadioConfig_UserPreferences_wifi_ssid_tag 12 +#define RadioConfig_UserPreferences_wifi_password_tag 13 +#define RadioConfig_UserPreferences_wifi_ap_mode_tag 14 #define RadioConfig_UserPreferences_ignore_incoming_tag 102 #define RouteDiscovery_route_tag 2 #define User_id_tag 1 @@ -456,8 +458,9 @@ X(a, STATIC, SINGULAR, UINT32, mesh_sds_timeout_secs, 8) \ X(a, STATIC, SINGULAR, UINT32, sds_secs, 9) \ X(a, STATIC, SINGULAR, UINT32, ls_secs, 10) \ X(a, STATIC, SINGULAR, UINT32, min_wake_secs, 11) \ -X(a, STATIC, SINGULAR, BOOL, keep_all_packets, 100) \ -X(a, STATIC, SINGULAR, BOOL, promiscuous_mode, 101) \ +X(a, STATIC, SINGULAR, STRING, wifi_ssid, 12) \ +X(a, STATIC, SINGULAR, STRING, wifi_password, 13) \ +X(a, STATIC, SINGULAR, BOOL, wifi_ap_mode, 14) \ X(a, STATIC, REPEATED, UINT32, ignore_incoming, 102) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL @@ -592,11 +595,11 @@ extern const pb_msgdesc_t ManufacturingData_msg; #define SubPacket_size 274 #define MeshPacket_size 313 #define ChannelSettings_size 60 -#define RadioConfig_size 157 -#define RadioConfig_UserPreferences_size 93 +#define RadioConfig_size 253 +#define RadioConfig_UserPreferences_size 188 #define NodeInfo_size 132 #define MyNodeInfo_size 110 -#define DeviceState_size 5305 +#define DeviceState_size 5401 #define DebugString_size 258 #define FromRadio_size 322 #define ToRadio_size 316 From 9757f9ae530acff6830c6dcd1c082d36bf2ea018 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 22 Jun 2020 09:17:04 -0700 Subject: [PATCH 03/10] geeksville personal todo list --- docs/software/TODO.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 3d5670b7..a33d090b 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -2,14 +2,14 @@ You probably don't care about this section - skip to the next one. -- check in wifi code +- @feh123 Sony Xperia Z1 C6903 running Android 5.1.1 +- don't stop advertising BLE +- first message sent is still doubled for some people +- refetch the android messages on Resume +- there is still an occasional BLE hang that happens on the android side? - test BLE software update again -- iram space: https://esp32.com/viewtopic.php?t=8460 -- set https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/external-ram.html spi ram bss -- figure out if iram or bluetooth classic caused ble problems -- post bug on esp32-arduino -- implement first cut of router mode: preferentially handle flooding, and change sleep and GPS behaviors - let users set arbitrary params in android +- implement first cut of router mode: preferentially handle flooding, and change sleep and GPS behaviors - NRF52 BLE support # Medium priority @@ -60,6 +60,13 @@ Items after the first final candidate release. - report esp32 device code bugs back to the mothership via android - change BLE bonding to something more secure. see comment by pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND) +Changes related to wifi support on ESP32: + +- iram space: https://esp32.com/viewtopic.php?t=8460 +- set https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/external-ram.html spi ram bss +- figure out if iram or bluetooth classic caused ble problems +- post bug on esp32-arduino with BLE bug findings + # Spinoff project ideas - an open source version of https://www.burnair.ch/skynet/ From 665d35196d98f59ead5f33ec7ad1e9823e577e1f Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 22 Jun 2020 09:17:15 -0700 Subject: [PATCH 04/10] never wait on GPS reads --- src/gps/UBloxGPS.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gps/UBloxGPS.cpp b/src/gps/UBloxGPS.cpp index 8427e68b..01221129 100644 --- a/src/gps/UBloxGPS.cpp +++ b/src/gps/UBloxGPS.cpp @@ -99,12 +99,12 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). */ struct tm t; - t.tm_sec = ublox.getSecond(); - t.tm_min = ublox.getMinute(); - t.tm_hour = ublox.getHour(); - t.tm_mday = ublox.getDay(); - t.tm_mon = ublox.getMonth() - 1; - t.tm_year = ublox.getYear() - 1900; + t.tm_sec = ublox.getSecond(0); + t.tm_min = ublox.getMinute(0); + t.tm_hour = ublox.getHour(0); + t.tm_mday = ublox.getDay(0); + t.tm_mon = ublox.getMonth(0) - 1; + t.tm_year = ublox.getYear(0) - 1900; t.tm_isdst = false; perhapsSetRTC(t); } @@ -112,10 +112,10 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s if ((fixtype >= 3 && fixtype <= 4) && ublox.getP(0)) // rd fixes only { // we only notify if position has changed - latitude = ublox.getLatitude(); - longitude = ublox.getLongitude(); - altitude = ublox.getAltitude() / 1000; // in mm convert to meters - dop = ublox.getPDOP(); // PDOP (an accuracy metric) is reported in 10^2 units so we have to scale down when we use it + latitude = ublox.getLatitude(0); + longitude = ublox.getLongitude(0); + altitude = ublox.getAltitude(0) / 1000; // in mm convert to meters + dop = ublox.getPDOP(0); // PDOP (an accuracy metric) is reported in 10^2 units so we have to scale down when we use it DEBUG_MSG("new gps pos lat=%f, lon=%f, alt=%d, pdop=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, dop * 1e-2); // bogus lat lon is reported as 0 or 0 (can be bogus just for one) From c5851a4a0cc99354ec56a543cd05b490c6082ba7 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 22 Jun 2020 09:36:19 -0700 Subject: [PATCH 05/10] Report battery level to other nodes in mesh (and apps). Also today I'll turn back on the the standard "has a battery" BLE device profile, so the locally connected radio should show up in the phone's bluetooth popup of battery levels (similar to how a BLE headphone battery level appears) cc @lgoix - using code from @professr ``` meshtastic --info Connected to radio... my_node_num: 2883444536 has_gps: true num_channels: 13 region: "unset" hw_model: "tbeam" firmware_version: "unset" packet_id_bits: 32 current_packet_id: 91018534 node_num_bits: 32 message_timeout_msec: 300000 min_app_version: 172 preferences { position_broadcast_secs: 900 send_owner_interval: 4 wait_bluetooth_secs: 120 screen_on_secs: 300 phone_timeout_secs: 900 phone_sds_timeout_sec: 7200 mesh_sds_timeout_secs: 7200 sds_secs: 31536000 ls_secs: 3600 } channel_settings { tx_power: 23 modem_config: Bw125Cr48Sf4096 psk: "\324\361\273: )\007Y\360\274\377\253\317Ni\277" name: "Default" } Nodes in mesh: {'num': 2883444536, 'user': {'id': '!2462abdddf38', 'longName': 'Unknown df38', 'shortName': '?38', 'macaddr': 'JGKr3d84'}, 'position': {'altitude': 96, 'batteryLevel': 100, 'latitudeI': 375210641, 'longitudeI': -1223090398, 'time': 1592843564, 'latitude': 37.5210641, 'longitude': -122.3090398}} ``` --- docs/software/TODO.md | 1 + src/mesh/MeshService.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index a33d090b..3b75aca2 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -2,6 +2,7 @@ You probably don't care about this section - skip to the next one. +- report battery level to android app - @feh123 Sony Xperia Z1 C6903 running Android 5.1.1 - don't stop advertising BLE - first message sent is still doubled for some people diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index eebfb227..59da3638 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -11,6 +11,7 @@ #include "PowerFSM.h" #include "main.h" #include "mesh-pb-constants.h" +#include "power.h" /* receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone. @@ -298,6 +299,9 @@ int MeshService::onGPSChanged(void *unused) pos.time = getValidTime(); } + // Include our current battery voltage in our position announcement + pos.battery_level = powerStatus.batteryChargePercent; + // We limit our GPS broadcasts to a max rate static uint32_t lastGpsSend; uint32_t now = millis(); From 60470211e57fba46eb8f574f32a418a7ff460a31 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 22 Jun 2020 10:04:26 -0700 Subject: [PATCH 06/10] expose battery level via the standard BLE battery service --- src/esp32/BluetoothUtil.cpp | 13 ++++++++----- src/esp32/BluetoothUtil.h | 3 +++ src/mesh/MeshService.cpp | 4 ++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/esp32/BluetoothUtil.cpp b/src/esp32/BluetoothUtil.cpp index 8d6b5d7d..2ea491fd 100644 --- a/src/esp32/BluetoothUtil.cpp +++ b/src/esp32/BluetoothUtil.cpp @@ -122,7 +122,7 @@ BLEService *createBatteryService(BLEServer *server) addWithDesc(pBattery, batteryLevelC, "Percentage 0 - 100"); batteryLevelC->addDescriptor(addBLEDescriptor(new BLE2902())); // Needed so clients can request notification - // I don't think we need to advertise this + // I don't think we need to advertise this? and some phones only see the first thing advertised anyways... // server->getAdvertising()->addServiceUUID(pBattery->getUUID()); pBattery->start(); @@ -135,8 +135,8 @@ BLEService *createBatteryService(BLEServer *server) */ void updateBatteryLevel(uint8_t level) { - // Pretend to update battery levels - fixme do elsewhere if (batteryLevelC) { + DEBUG_MSG("set BLE battery level %u\n", level); batteryLevelC->setValue(&level, 1); batteryLevelC->notify(); } @@ -215,7 +215,7 @@ class MySecurity : public BLESecurityCallbacks BLEServer *pServer; -BLEService *pDevInfo, *pUpdate; +BLEService *pDevInfo, *pUpdate, *pBattery; void deinitBLE() { @@ -230,6 +230,9 @@ void deinitBLE() pUpdate->executeDelete(); } + pBattery->stop(); + pBattery->executeDelete(); + pDevInfo->stop(); pDevInfo->executeDelete(); @@ -242,6 +245,7 @@ void deinitBLE() if (pUpdate != NULL) delete pUpdate; delete pDevInfo; + delete pBattery; delete pServer; batteryLevelC = NULL; // Don't let anyone generate bogus notifies @@ -279,8 +283,7 @@ BLEServer *initBLE(StartBluetoothPinScreenCallback startBtPinScreen, StopBluetoo pDevInfo = createDeviceInfomationService(pServer, hwVendor, swVersion, hwVersion); - // We now let users create the battery service only if they really want (not all devices have a battery) - // BLEService *pBattery = createBatteryService(pServer); + pBattery = createBatteryService(pServer); // #define BLE_SOFTWARE_UPDATE #ifdef BLE_SOFTWARE_UPDATE diff --git a/src/esp32/BluetoothUtil.h b/src/esp32/BluetoothUtil.h index b1aa77db..67797a0c 100644 --- a/src/esp32/BluetoothUtil.h +++ b/src/esp32/BluetoothUtil.h @@ -35,5 +35,8 @@ BLECharacteristic *addBLECharacteristic(BLECharacteristic *c); /// Add a characteristic that we will delete when we restart BLEDescriptor *addBLEDescriptor(BLEDescriptor *c); +/// Given a level between 0-100, update the BLE attribute +void updateBatteryLevel(uint8_t level); + /// Any bluetooth objects you allocate _must_ come from this pool if you want to be able to call deinitBLE() extern SimpleAllocator btPool; diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 59da3638..70e20f80 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -12,6 +12,7 @@ #include "main.h" #include "mesh-pb-constants.h" #include "power.h" +#include "BluetoothUtil.h" // needed for updateBatteryLevel, FIXME, eventually when we pull mesh out into a lib we shouldn't be whacking bluetooth from here /* receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone. @@ -281,6 +282,8 @@ void MeshService::sendOurPosition(NodeNum dest, bool wantReplies) sendToMesh(p); } + + int MeshService::onGPSChanged(void *unused) { // DEBUG_MSG("got gps notify\n"); @@ -301,6 +304,7 @@ int MeshService::onGPSChanged(void *unused) // Include our current battery voltage in our position announcement pos.battery_level = powerStatus.batteryChargePercent; + updateBatteryLevel(pos.battery_level); // We limit our GPS broadcasts to a max rate static uint32_t lastGpsSend; From d9e93f3944ababca3771a67eae3e432df3083e16 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 22 Jun 2020 10:06:35 -0700 Subject: [PATCH 07/10] Try turning my software update service back on... Now that I've fixed a couple of nasty esp32-arduino bugs --- docs/software/TODO.md | 3 +-- src/esp32/BluetoothUtil.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 3b75aca2..b38ab5a8 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -2,11 +2,10 @@ You probably don't care about this section - skip to the next one. -- report battery level to android app - @feh123 Sony Xperia Z1 C6903 running Android 5.1.1 - don't stop advertising BLE - first message sent is still doubled for some people -- refetch the android messages on Resume +- Android frontend should refetch the android messages from backend service on Resume - there is still an occasional BLE hang that happens on the android side? - test BLE software update again - let users set arbitrary params in android diff --git a/src/esp32/BluetoothUtil.cpp b/src/esp32/BluetoothUtil.cpp index 2ea491fd..224b8c0a 100644 --- a/src/esp32/BluetoothUtil.cpp +++ b/src/esp32/BluetoothUtil.cpp @@ -285,7 +285,7 @@ BLEServer *initBLE(StartBluetoothPinScreenCallback startBtPinScreen, StopBluetoo pBattery = createBatteryService(pServer); -// #define BLE_SOFTWARE_UPDATE +#define BLE_SOFTWARE_UPDATE #ifdef BLE_SOFTWARE_UPDATE pUpdate = createUpdateService(pServer, hwVendor, swVersion, hwVersion); // We need to advertise this so our android ble scan operation can see it From 3a69539192bf1aded8859a3dc6121320d4fb100c Mon Sep 17 00:00:00 2001 From: Marlon Spangenberg <25596663+aHVzY2g@users.noreply.github.com> Date: Mon, 22 Jun 2020 20:15:19 +0200 Subject: [PATCH 08/10] Just a link to a need little case for the TTGO LORA32 v1 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8e01ed99..273560e2 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ We currently support three models of radios. - [T-Beam V1](https://www.thingiverse.com/thing:3830711) - [TTGO LORA32](https://www.aliexpress.com/item/4000211331316.html) - No GPS + - 3D printable case + - [TTGO LORA32 v1](https://www.thingiverse.com/thing:3385109) - [Heltec LoRa 32](https://heltec.org/project/wifi-lora-32/) - No GPS - [3D Printable case](https://www.thingiverse.com/thing:3125854) From c1865f127c57476e562920668562f77cee4f3f26 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 22 Jun 2020 11:17:08 -0700 Subject: [PATCH 09/10] make sure people who are not just me, get the fixed arduino-esp32 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 0fb69a86..ab23d99d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -89,7 +89,7 @@ build_flags = # board_build.ldscript = linker/esp32.extram.bss.ld lib_ignore = segger_rtt platform_packages = - framework-arduinoespressif32 @ https://github.com/meshtastic/arduino-esp32.git + framework-arduinoespressif32 @ https://github.com/meshtastic/arduino-esp32.git#f26c4f96fefd13ed0ed042e27954f8aba6328f6b ; The 1.0 release of the TBEAM board [env:tbeam] From 2839539c6cbaf1d413206ea5d301d99f840a2351 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 22 Jun 2020 11:36:48 -0700 Subject: [PATCH 10/10] todo for my personal work queue --- docs/software/TODO.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index b38ab5a8..1e42fa30 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -2,12 +2,10 @@ You probably don't care about this section - skip to the next one. +- test BLE software update again - @feh123 Sony Xperia Z1 C6903 running Android 5.1.1 -- don't stop advertising BLE - first message sent is still doubled for some people - Android frontend should refetch the android messages from backend service on Resume -- there is still an occasional BLE hang that happens on the android side? -- test BLE software update again - let users set arbitrary params in android - implement first cut of router mode: preferentially handle flooding, and change sleep and GPS behaviors - NRF52 BLE support