From eecce34848d92d9ea0a9cd9e0bbfb1c30542a95d Mon Sep 17 00:00:00 2001 From: Gregg Date: Tue, 27 Dec 2022 09:55:30 -0600 Subject: [PATCH] Added NVS storage for last channel used in SpanPoint Applicable only for remote devices (i.e. not a Hub device). Last channel stored is used as initial channel upon reboot, provided that this channel is allowed by the channel mask (if not, the first allowed channel is selected instead). --- src/HomeSpan.cpp | 17 ++++++++++++++++- src/HomeSpan.h | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 6d8718c..300c524 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -2247,6 +2247,16 @@ void SpanPoint::init(const char *password){ statusQueue = xQueueCreate(1,sizeof(esp_now_send_status_t)); // create statusQueue even if not needed setChannelMask(channelMask); // default channel mask at start-up uses channels 1-13 + uint8_t channel; + if(!isHub){ // this is not a hub + nvs_flash_init(); // initialize NVS + nvs_open("POINT",NVS_READWRITE,&pointNVS); // open SpanPoint data namespace in NVS + if(!nvs_get_u8(pointNVS,"CHANNEL",&channel)){ // if channel found in NVS... + if(channelMask & (1< SpanPoint::SpanPoints; uint16_t SpanPoint::channelMask=0x3FFE; QueueHandle_t SpanPoint::statusQueue; +nvs_handle SpanPoint::pointNVS; + /////////////////////////////// // MISC // diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 97c6acc..bb6efb1 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -799,8 +799,9 @@ class SpanPoint { static boolean initialized; static boolean isHub; static vector SpanPoints; - static uint16_t channelMask; // channel mask + static uint16_t channelMask; // channel mask (only used for remote devices) static QueueHandle_t statusQueue; // queue for communication between SpanPoint::dataSend and SpanPoint::send + static nvs_handle pointNVS; // NVS storage for channel number (only used for remote devices) static void dataReceived(const uint8_t *mac, const uint8_t *incomingData, int len); static void init(const char *password="HomeSpan");