From 03ba061b9b4ca791c9e8133c537ca2cfe3ed12ff Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 28 Jan 2023 18:05:59 -0600 Subject: [PATCH] Added logic to hide AP SSID from broadcasting when WIFI_AP_STA used for SpanPoint This does NOT effect the HomeSpan Access Point from being broadcast as usual when launched. --- .../RemoteSensors/RemoteDevice/RemoteDevice.ino | 2 +- src/HomeSpan.cpp | 10 ++++++++-- src/src.ino | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/Other Examples/RemoteSensors/RemoteDevice/RemoteDevice.ino b/examples/Other Examples/RemoteSensors/RemoteDevice/RemoteDevice.ino index 04b9dca..9859362 100644 --- a/examples/Other Examples/RemoteSensors/RemoteDevice/RemoteDevice.ino +++ b/examples/Other Examples/RemoteSensors/RemoteDevice/RemoteDevice.ino @@ -61,7 +61,7 @@ void setup() { // In the line below, replace the MAC Address with that of your MAIN HOMESPAN DEVICE - mainDevice=new SpanPoint("7C:DF:A1:61:E4:A8",sizeof(float),0); // create a SpanPoint with send size=sizeof(float) and receive size=0 + mainDevice=new SpanPoint("84:CC:A8:11:B4:84",sizeof(float),0); // create a SpanPoint with send size=sizeof(float) and receive size=0 homeSpan.setLogLevel(1); } diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 3d4dbba..2b20cf5 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -1032,13 +1032,14 @@ void Span::processSerialCommand(const char *c){ uint8_t channel; wifi_second_chan_t channel2; esp_wifi_get_channel(&channel,&channel2); - Serial.printf("\nSpanPoint Channel=%d:\n\n",channel); + Serial.printf("\nFound %d SpanPoint Links:\n\n",SpanPoint::SpanPoints.size()); Serial.printf("%-17s %18s %7s %7s %7s\n","Local MAC Address","Remote MAC Address","Send","Receive","Depth"); Serial.printf("%.17s %.18s %.7s %.7s %.7s\n",d,d,d,d,d); for(auto it=SpanPoint::SpanPoints.begin();it!=SpanPoint::SpanPoints.end();it++) Serial.printf("%-18s %02X:%02X:%02X:%02X:%02X:%02X %7d %7d %7d\n",(*it)->peerInfo.ifidx==WIFI_IF_AP?WiFi.softAPmacAddress().c_str():WiFi.macAddress().c_str(), (*it)->peerInfo.peer_addr[0],(*it)->peerInfo.peer_addr[1],(*it)->peerInfo.peer_addr[2],(*it)->peerInfo.peer_addr[3],(*it)->peerInfo.peer_addr[4],(*it)->peerInfo.peer_addr[5], (*it)->sendSize,(*it)->receiveSize,uxQueueSpacesAvailable((*it)->receiveQueue)); + Serial.printf("\nSpanPoint using WiFi Channel %d%s\n",channel,WiFi.status()!=WL_CONNECTED?" (subject to change once WiFi connection established)":""); } Serial.print("\n*** End Info ***\n\n"); @@ -2221,7 +2222,7 @@ SpanPoint::SpanPoint(const char *macAddress, int sendSize, int receiveSize, int if(receiveSize>0) WiFi.mode(WIFI_AP_STA); else if(WiFi.getMode()==WIFI_OFF) - WiFi.mode(WIFI_STA); + WiFi.mode(WIFI_STA); init(); // initialize SpanPoint peerInfo.channel=0; // 0 = matches current WiFi channel @@ -2248,6 +2249,11 @@ void SpanPoint::init(const char *password){ if(WiFi.getMode()==WIFI_OFF) WiFi.mode(WIFI_STA); + wifi_config_t conf; // make sure AP is hidden (if WIFI_AP_STA is used), since it is just a "dummy" AP to keep WiFi alive for ESP-NOW + esp_wifi_get_config(WIFI_IF_AP,&conf); + conf.ap.ssid_hidden=1; + esp_wifi_set_config(WIFI_IF_AP,&conf); + uint8_t hash[32]; mbedtls_sha256_ret((const unsigned char *)password,strlen(password),hash,0); // produce 256-bit bit hash from password diff --git a/src/src.ino b/src/src.ino index b63e1df..0bf5dcd 100644 --- a/src/src.ino +++ b/src/src.ino @@ -1,6 +1,7 @@ // This is a placeholder .ino file that allows you to easily edit the contents of this library using the Arduino IDE, // as well as compile and test from this point. This file is ignored when the library is included in other sketches. + #include "HomeSpan.h" struct RemoteTempSensor : Service::TemperatureSensor { @@ -75,7 +76,7 @@ void setup() { void loop(){ homeSpan.poll(); - + } // end of loop() //////////////////////////////////////