Skip to content

Commit

Permalink
added the ability to connect to a hidden network
Browse files Browse the repository at this point in the history
  • Loading branch information
himikat123 committed May 25, 2024
1 parent 6925711 commit 2fbc63e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion BIM32/BIM32.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Weather Monitor BIM32 v3.6
* Weather Monitor BIM32 v3.7
* https://github.com/himikat123/Weather-monitor-BIM32
*
* © himikat123@gmail.com, Nürnberg, Deutschland, 2020-2024
Expand Down
2 changes: 1 addition & 1 deletion BIM32/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define SEPARATOR "**********************************************************************"

struct {
char fw[7] = "v3.6"; // Firmware version
char fw[7] = "v3.7"; // Firmware version
const char* remote_host = "www.google.com"; // Remote host to ping
bool clockSynchronized = false; // Is the time synchronized with the ntp server?
bool clockSynchronize = false; // Should the display RTC be updated?
Expand Down
59 changes: 34 additions & 25 deletions BIM32/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class Network {
bool isConnected(void);
void connect(void);
void runAccessPoint(void);

private:
void connecting(uint8_t num);
};

/**
Expand All @@ -26,39 +29,32 @@ void Network::connect(void) {
}
}
WiFi.mode(WIFI_STA);
WiFi.setHostname("BIM32");
bool anySSID = false;
for(unsigned int i=0; i<NETWORKS; i++) {
if(String(config.network_ssid(i)) != "") anySSID = true;
}
if(anySSID) {
if(WiFi.status() != WL_CONNECTED) {
unsigned int numberOfNetworks = WiFi.scanNetworks();
if(numberOfNetworks > 0) {
int knownNetwork = -1;
for(int i=0; i<numberOfNetworks; i++) {
for(int k=0; k<NETWORKS; k++) {
if(WiFi.SSID(i) == config.network_ssid(k)) {
knownNetwork = k;
break;
}
}
}
if(knownNetwork >= 0) {
Serial.print("Connecting to "); Serial.println(config.network_ssid(knownNetwork));
WiFi.begin(config.network_ssid(knownNetwork), config.network_pass(knownNetwork));
unsigned int attempts = 0;
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
ws2812b.connecting();
if(++attempts > 20) break;
int knownNetwork = -1;
for(int i=0; i<numberOfNetworks; i++) {
for(int k=0; k<NETWORKS; k++) {
if(WiFi.SSID(i) == config.network_ssid(k)) {
knownNetwork = k;
break;
}
if(WiFi.status() == WL_CONNECTED) Serial.println(" connected");
else Serial.println(" failed");
}
else Serial.println("No known networks found");
}
}
if(knownNetwork >= 0) {
Serial.print("Connecting to "); Serial.println(config.network_ssid(knownNetwork));
connecting(knownNetwork);
}
else {
Serial.println("No known networks found");
Serial.println("trying to connect to network 1 in case it's a hidden network");
connecting(0);
}
else Serial.println("No networks found");
}
if(WiFi.status() == WL_CONNECTED) {
WiFi.setAutoConnect(true);
Expand Down Expand Up @@ -86,6 +82,19 @@ void Network::connect(void) {
}
}

void Network::connecting(uint8_t num) {
WiFi.begin(config.network_ssid(num), config.network_pass(num));
unsigned int attempts = 0;
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
ws2812b.connecting();
if(++attempts > 20) break;
}
if(WiFi.status() == WL_CONNECTED) Serial.println(" connected");
else Serial.println(" failed");
}

/**
* Start Access point
*/
Expand All @@ -104,4 +113,4 @@ void Network::runAccessPoint(void) {
Serial.println(SEPARATOR);
Serial.println();
}
}
}
Binary file modified bin/BIM32.ino.bin
Binary file not shown.

0 comments on commit 2fbc63e

Please sign in to comment.