From 8190098bb8bacce912aef9c082d7ecd0dbbe9b8c Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 21 Jun 2020 14:11:38 -0700 Subject: [PATCH] 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 aebb3d4a5..3aca04523 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 479435532..3d5670b78 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 45fb7a54f..b9fd68505 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 ecad282ab..2a2e4dd26 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 000000000..582f6eb6e --- /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 298032cec..0fb69a862 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 72cbde93f..fc79db459 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 72cbde93ffbc2ee917f9d7328558475e02a91cba +Subproject commit fc79db45944959ee3246f6f808db18e4debab72b diff --git a/src/main.cpp b/src/main.cpp index cfbd7e484..d79f28568 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 9bebda112..2a202f230 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 2651d6cb6..808ffab88 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