feat(moneo): add WiFi manager with auto network selection#5
feat(moneo): add WiFi manager with auto network selection#5Ricky1207-sen wants to merge 1 commit into
Conversation
debloper
left a comment
There was a problem hiding this comment.
Most of the comments are FYI, but only a couple of them that require actual change.
Let me know if any part of the review is unclear.
| for (int i = 0; i < WIFI_NETWORK_COUNT; i++) { | ||
| for (int j = 0; j < found; j++) { | ||
| if (WiFi.SSID(j) == String(WIFI_NETWORKS[i][0])) { | ||
| DLOGF("[WiFi] Found: %s\n", WIFI_NETWORKS[i][0]); | ||
| if (_tryNetwork(WIFI_NETWORKS[i][0], WIFI_NETWORKS[i][1])) { | ||
| _saveLastNetwork(WIFI_NETWORKS[i][0], WIFI_NETWORKS[i][1]); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
From computational complexity and determinacy perspective, it makes more sense to iterate over the known networks, and check if it's available on the available networks... instead of iterating over the available networks, to match with the known networks.
For example, you have 2 networks provisioned, and there are 6 networks available when scanning... in the current approach, you iterate 6 times, in altered approach, you only iterate twice. And if the first iteration already finds the network, it's an oneshot hit. Whereas in the current approach even if the known network is in the available list, but is not the first one, it at least has to iterate as many times as the known network's order is in the scanned network list.
This doesn't break software, and is fine for a demo; but these are the things (memory and time cost, i.e. computation complexity) if you're building for scale.
| const char* WIFI_NETWORKS[WIFI_NETWORK_COUNT][2] = { | ||
| { "YOUR_WIFI_SSID", "YOUR_WIFI_PASSWORD" }, | ||
| { "SECOND_WIFI_SSID", "SECOND_WIFI_PASSWORD" }, // e.g. laptop hotspot | ||
| }; |
There was a problem hiding this comment.
The Config.h is already there, right?
Shouldn't we make use of that, or you're waiting to integrate it with the moneo.ino project file for orchestrating it?
It's fine if that's the case... this is the rudimentary part that Config.h abstracts. So it's fine for now; just confirming the reasoning.
There was a problem hiding this comment.
The final connectivity flow should be:
- Check NVS for saved networks
- If found (client mode)
- Scan the available SSIDs
- Iterate over the saved networks to find a match in the available list
- If not found (server mode)
- Start an access point for other devices to connect to
- Can be used for initial provisioning & configuration update etc.
| WiFi.localIP().toString().c_str()); | ||
| return true; | ||
| } | ||
| WiFi.disconnect(); |
| } | ||
|
|
||
| void WiFiManager::_saveLastNetwork(const char* ssid, const char* password) { | ||
| _prefs.begin("moneo_wifi", false); |
There was a problem hiding this comment.
Make this namespace moneo_runtime and store all sorts of persistent state data (last file synced etc. in future); different from the moneo_wifi which is the list of known WiFi SSIDs provisioned (saved networks).
Users/configs won't have direct access to the runtime namespace; it's just there for the firmware to work more optimally, managed by the firmware itself.
Let me know if you need more clarity on this.
There was a problem hiding this comment.
Asked the agent about this, told it to give an analogy - understood that, please check if that is what you meant.
Analogy: two drawers in a desk
Think of NVS as a desk with labeled drawers.
- Drawer moneo_wifi = "Networks I'm allowed to use" — you (the user) write these in. Like a sticky note: "Home WiFi / password123, Office WiFi / office456."
- Drawer moneo_runtime = "The device's own scratchpad" — only the firmware writes here, to remember stuff between reboots. Like the device jotting: "Last time, I connected to Home WiFi — try that first next boot."
Before, both notes were jammed in the same drawer. The maintainer wants them in separate drawers by purpose.
Concrete example
moneo_wifi (config — what the user provisioned):
ssid_0 = "HomeWiFi"
pass_0 = "password123"
ssid_1 = "OfficeWiFi"
pass_1 = "office456"
moneo_runtime (firmware's working memory):
ssid = "HomeWiFi" ← the last one that actually connected
pass = "password123"
last_sync = "2026-06-09" ← future stuff the firmware tracks
Why it helps
On next boot, the firmware opens moneo_runtime, sees "last connected = HomeWiFi", and tries that first — instant reconnect, no full scan needed. Meanwhile the user's actual network list sits untouched and safe in moneo_wifi.
Same data as before — just sorted into the right drawer so config and the device's scratchpad don't get mixed up.
There was a problem hiding this comment.
Yup... it understood perfectly.
Make sure you are both on the same page and go ahead with the implementation.
Adds
moneo/WiFiManager— handles WiFi connectivity for the Moneo firmware.Scans for known networks and auto-connects to the first available from a
configurable list, remembering the last successful network in NVS for faster
reconnects. Builds on the config added in the previous PR.
No credentials committed — network entries are placeholders only.