Skip to content

Conversation

@pennam
Copy link

@pennam pennam commented Oct 16, 2025

No description provided.

@pennam pennam mentioned this pull request Oct 16, 2025
@pennam pennam force-pushed the wifi-scan branch 3 times, most recently from 1df10e1 to 390f275 Compare November 10, 2025 14:13
@pennam pennam marked this pull request as ready for review November 10, 2025 14:28
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.
WiFiClass() {
}
WiFiClass();
~WiFiClass();

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

Suggested change
~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)

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

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,

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);

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.

Suggested change
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);

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,

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;

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants