-
-
Notifications
You must be signed in to change notification settings - Fork 104
WifiS3 - Non blocking Wifi connect #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
99df703
7350bbb
a260388
2d6b21e
61b798f
b233fe0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,7 +26,7 @@ | |||||||||||||||
|
|
||||||||||||||||
| #include "arduino_secrets.h" | ||||||||||||||||
|
|
||||||||||||||||
| #define MaximumConnections 1 | ||||||||||||||||
| #define MaximumConnections 2 | ||||||||||||||||
|
|
||||||||||||||||
| ///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||||||||||||||||
| char ssid[] = SECRET_SSID; // your network SSID (name) | ||||||||||||||||
|
|
@@ -51,7 +51,7 @@ WiFiClient client; | |||||||||||||||
| void setup() { | ||||||||||||||||
| /* -------------------------------------------------------------------------- */ | ||||||||||||||||
| //Initialize serial and wait for port to open: | ||||||||||||||||
| Serial.begin(115200); | ||||||||||||||||
| Serial.begin(9600); | ||||||||||||||||
| while (!Serial) { | ||||||||||||||||
| ; // wait for serial port to connect. Needed for native USB port only | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -108,7 +108,7 @@ void loop() { | |||||||||||||||
|
|
||||||||||||||||
| // only allowed to connect n times | ||||||||||||||||
| if (connectionCount >= MaximumConnections) { | ||||||||||||||||
| delay(300); | ||||||||||||||||
| delay(2000); | ||||||||||||||||
| return; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -149,7 +149,7 @@ void loop() { | |||||||||||||||
| Serial.println(); | ||||||||||||||||
| Serial.println("disconnecting from server."); | ||||||||||||||||
| client.stop(); | ||||||||||||||||
| status = WL_CONNECTED; | ||||||||||||||||
| status = WL_IDLE_STATUS; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
||||||||||||||||
| } | |
| } | |
| } else { | |
| // Handle server connection failure | |
| Serial.println("Failed to connect to server."); | |
| status = WL_IDLE_STATUS; | |
| delay(1000); // Add a delay to avoid rapid retries |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,8 @@ | |||||||||||||||
|
|
||||||||||||||||
| #include "arduino_secrets.h" | ||||||||||||||||
|
|
||||||||||||||||
| #define MaximumConnections 1 | ||||||||||||||||
| // maximum number of times the uri will be checked | ||||||||||||||||
| #define MaximumConnections 2 | ||||||||||||||||
|
|
||||||||||||||||
| ///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||||||||||||||||
| char ssid[] = SECRET_SSID; // your network SSID (name) | ||||||||||||||||
|
|
@@ -39,7 +40,7 @@ WiFiSSLClient client; | |||||||||||||||
| void setup() { | ||||||||||||||||
| /* -------------------------------------------------------------------------- */ | ||||||||||||||||
| //Initialize serial and wait for port to open: | ||||||||||||||||
| Serial.begin(115200); | ||||||||||||||||
| Serial.begin(9600); | ||||||||||||||||
|
||||||||||||||||
| Serial.begin(9600); | |
| Serial.begin(115200); |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WL_CONNECT_FAILED state is not handled. If the WiFi connection fails (either immediately or after timeout), the code doesn't reset the status to WL_IDLE_STATUS to allow retry. Consider adding a check: if (status == WL_CONNECT_FAILED) { Serial.println("WiFi connection failed!"); status = WL_IDLE_STATUS; return; } before the WL_CONNECTED check.
| if (status == WL_CONNECT_FAILED) { | |
| Serial.println("WiFi connection failed!"); | |
| status = WL_IDLE_STATUS; | |
| return; | |
| } |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WiFiSSLClient connects to server over TLS without any server certificate validation or hostname verification. An on-path attacker (e.g., rogue AP on local network) can perform a MITM and intercept/modify traffic because the client does not verify the peer; fix by loading and enforcing a trusted CA or server certificate/fingerprint before client.connect, e.g., by calling the appropriate API to set a root CA or pinned certificate and validating the hostname.
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the server connection fails, the status is not reset to WL_IDLE_STATUS. This means the code will continuously stay in the WL_CONNECTED block and keep trying to connect to the server on every loop iteration without any delay, potentially causing rapid repeated connection attempts. Add status = WL_IDLE_STATUS; after the error message to reset the state.
| Serial.println("Connection to server failed!"); | |
| Serial.println("Connection to server failed!"); | |
| status = WL_IDLE_STATUS; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -63,7 +63,7 @@ class CWifi { | |||||
| void _config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2); | ||||||
| void _sortAPlist(uint8_t num); | ||||||
| unsigned long _timeout; | ||||||
| unsigned long _start_connection_time; | ||||||
| unsigned long _start_connection_time = millis(); | ||||||
|
||||||
| unsigned long _start_connection_time = millis(); | |
| unsigned long _start_connection_time; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line uses tabs for indentation while the rest of the file uses spaces. This creates inconsistent formatting. Please use spaces to match the surrounding code style.