-
-
Notifications
You must be signed in to change notification settings - Fork 41
WiFi: add scan() #221
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
base: main
Are you sure you want to change the base?
WiFi: add scan() #221
Conversation
1df10e1 to
390f275
Compare
ZEP-55: WiFi: try to connect using default connection parameters Device will try to connect using default connection parameters, if an SSID and a password were provided, even if the scan was unsuccessful. ZEP-55: Implemented WiFi.scan() functionality.
390f275 to
f769b0c
Compare
| WiFiClass() { | ||
| } | ||
| WiFiClass(); | ||
| ~WiFiClass(); |
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.
Since the destructor is empty we can write it in this way
| ~WiFiClass(); | |
| ~WiFiClass() = default; |
| net_mgmt(NET_REQUEST_WIFI_SCAN, wifiState.sta_iface, nullptr, 0u); | ||
|
|
||
| // Wait for the scan to finish (this is a blocking call) | ||
| while (!wifiState.scanSequenceFinished) |
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.
does it make sense to add a timeout here? if somthing strange happens underneath we may be stuck here
|
|
||
| struct wifi_connect_req_params ap_config; | ||
| struct wifi_connect_req_params sta_config; | ||
| static struct WiFiState wifiState; // Static instance to hold Wi-Fi state |
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 shouldn't be static
|
|
||
| struct wifi_iface_status sta_state = {0}; | ||
| private: | ||
| static void scanEventDispatcher(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, |
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.
we can define this function in the cpp file only
| wifiState.scanSequenceFinished = false; | ||
|
|
||
| // Trigger a new scan | ||
| net_mgmt(NET_REQUEST_WIFI_SCAN, wifiState.sta_iface, nullptr, 0u); |
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.
We can pass a pointer to this class to the handler in order to avoid having a static wifiState defined.
| net_mgmt(NET_REQUEST_WIFI_SCAN, wifiState.sta_iface, nullptr, 0u); | |
| net_mgmt(NET_REQUEST_WIFI_SCAN, wifiState.sta_iface, this, 0u); |
| // Register the Wi-Fi event callback | ||
| net_mgmt_init_event_callback(&wifiState.wifiCb, scanEventDispatcher, | ||
| NET_EVENT_WIFI_SCAN_RESULT | NET_EVENT_WIFI_SCAN_DONE); | ||
| net_mgmt_add_event_callback(&wifiState.wifiCb); |
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.
Does his operation remove the NetworkInterface event callback? In that case we have to provide an api on NetworkInterface to extend the callback capabilities
| } | ||
| } | ||
|
|
||
| void WiFiClass::handleScanEvent(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, |
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.
cp->info contains the context of the callback
| struct wifi_scan_result scanResults[MAX_SCAN_RESULTS]; | ||
| uint8_t resultCount = 0; | ||
| struct net_mgmt_event_callback wifiCb; | ||
| bool soughtNetworkFound = false; |
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 seems to be a convoluted name, what do you think about networkFound?
No description provided.