Merge pull request #4650 from anecdata/ap

wifi.radio Access Point modes
This commit is contained in:
Scott Shawcroft 2021-05-05 08:47:55 -07:00 committed by GitHub
commit 30c7aa8fc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 330 additions and 25 deletions

View File

@ -441,6 +441,10 @@ msgstr ""
msgid "Attempted heap allocation when VM not running."
msgstr ""
#: shared-bindings/wifi/Radio.c
msgid "AuthMode.OPEN is not used with password"
msgstr ""
#: shared-bindings/wifi/Radio.c
msgid "Authentication failure"
msgstr ""
@ -1197,6 +1201,10 @@ msgstr ""
msgid "Invalid ADC Unit value"
msgstr ""
#: ports/esp32s2/common-hal/wifi/Radio.c
msgid "Invalid AuthMode"
msgstr ""
#: shared-module/displayio/OnDiskBitmap.c
msgid "Invalid BMP file"
msgstr ""

View File

@ -26,7 +26,6 @@
#include <string.h>
#include "py/enum.h"
#include "shared-bindings/wifi/Network.h"
#include "shared-bindings/wifi/AuthMode.h"

View File

@ -35,6 +35,7 @@
#include "py/runtime.h"
#include "shared-bindings/ipaddress/IPv4Address.h"
#include "shared-bindings/wifi/ScannedNetworks.h"
#include "shared-bindings/wifi/AuthMode.h"
#include "shared-module/ipaddress/__init__.h"
#include "components/esp_wifi/include/esp_wifi.h"
@ -42,19 +43,42 @@
#define MAC_ADDRESS_LENGTH 6
static void start_station(wifi_radio_obj_t *self) {
if (self->sta_mode) {
return;
}
static void set_mode_station(wifi_radio_obj_t *self, bool state) {
wifi_mode_t next_mode;
if (self->ap_mode) {
next_mode = WIFI_MODE_APSTA;
if (state) {
if (self->ap_mode) {
next_mode = WIFI_MODE_APSTA;
} else {
next_mode = WIFI_MODE_STA;
}
} else {
next_mode = WIFI_MODE_STA;
if (self->ap_mode) {
next_mode = WIFI_MODE_AP;
} else {
next_mode = WIFI_MODE_NULL;
}
}
esp_wifi_set_mode(next_mode);
self->sta_mode = state;
}
self->sta_mode = 1;
static void set_mode_ap(wifi_radio_obj_t *self, bool state) {
wifi_mode_t next_mode;
if (state) {
if (self->sta_mode) {
next_mode = WIFI_MODE_APSTA;
} else {
next_mode = WIFI_MODE_AP;
}
} else {
if (self->sta_mode) {
next_mode = WIFI_MODE_STA;
} else {
next_mode = WIFI_MODE_NULL;
}
}
esp_wifi_set_mode(next_mode);
self->ap_mode = state;
}
bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) {
@ -71,8 +95,6 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
return;
}
if (!self->started && enabled) {
// esp_wifi_start() would default to soft-AP, thus setting it to station
start_station(self);
ESP_ERROR_CHECK(esp_wifi_start());
self->started = true;
return;
@ -85,6 +107,12 @@ mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {
return mp_obj_new_bytes(mac, MAC_ADDRESS_LENGTH);
}
mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) {
uint8_t mac[MAC_ADDRESS_LENGTH];
esp_wifi_get_mac(ESP_IF_WIFI_AP, mac);
return mp_obj_new_bytes(mac, MAC_ADDRESS_LENGTH);
}
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
if (self->current_scan != NULL) {
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
@ -92,7 +120,7 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
if (!common_hal_wifi_radio_get_enabled(self)) {
mp_raise_RuntimeError(translate("wifi is not enabled"));
}
start_station(self);
set_mode_station(self, true);
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
scan->base.type = &wifi_scannednetworks_type;
@ -127,6 +155,50 @@ void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *host
esp_netif_set_hostname(self->netif, hostname);
}
void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) {
set_mode_station(self, true);
}
void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
set_mode_station(self, false);
}
void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode) {
set_mode_ap(self, true);
switch (authmode) {
case (1 << AUTHMODE_OPEN):
authmode = WIFI_AUTH_OPEN;
break;
case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_PSK)):
authmode = WIFI_AUTH_WPA_PSK;
break;
case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)):
authmode = WIFI_AUTH_WPA2_PSK;
break;
case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)):
authmode = WIFI_AUTH_WPA_WPA2_PSK;
break;
default:
mp_raise_ValueError(translate("Invalid AuthMode"));
break;
}
wifi_config_t *config = &self->ap_config;
memcpy(&config->ap.ssid, ssid, ssid_len);
config->ap.ssid[ssid_len] = 0;
memcpy(&config->ap.password, password, password_len);
config->ap.password[password_len] = 0;
config->ap.channel = channel;
config->ap.authmode = authmode;
config->ap.max_connection = 4; // kwarg?
esp_wifi_set_config(WIFI_IF_AP, config);
}
void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) {
set_mode_ap(self, false);
}
wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len) {
if (!common_hal_wifi_radio_get_enabled(self)) {
mp_raise_RuntimeError(translate("wifi is not enabled"));
@ -147,7 +219,7 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
// explicitly clear bits since xEventGroupWaitBits may have timed out
xEventGroupClearBits(self->event_group_handle, WIFI_CONNECTED_BIT);
xEventGroupClearBits(self->event_group_handle, WIFI_DISCONNECTED_BIT);
start_station(self);
set_mode_station(self, true);
wifi_config_t *config = &self->sta_config;
memcpy(&config->sta.ssid, ssid, ssid_len);
@ -239,6 +311,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) {
return common_hal_ipaddress_new_ipv4address(self->ip_info.gw.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->ap_netif)) {
return mp_const_none;
}
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.gw.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->netif)) {
return mp_const_none;
@ -247,6 +327,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) {
return common_hal_ipaddress_new_ipv4address(self->ip_info.netmask.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->ap_netif)) {
return mp_const_none;
}
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.netmask.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->netif)) {
return mp_const_none;
@ -255,6 +343,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) {
return common_hal_ipaddress_new_ipv4address(self->ip_info.ip.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->ap_netif)) {
return mp_const_none;
}
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.ip.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->netif)) {
return mp_const_none;

View File

@ -57,6 +57,10 @@ typedef struct {
uint8_t retries_left;
uint8_t starting_retries;
uint8_t last_disconnect_reason;
wifi_config_t ap_config;
esp_netif_ip_info_t ap_ip_info;
esp_netif_t *ap_netif;
} wifi_radio_obj_t;
extern void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self);

View File

@ -50,11 +50,21 @@ static void event_handler(void *arg, esp_event_base_t event_base,
ESP_LOGW(TAG, "scan");
xEventGroupSetBits(radio->event_group_handle, WIFI_SCAN_DONE_BIT);
break;
case WIFI_EVENT_AP_START:
ESP_LOGW(TAG, "ap start");
break;
case WIFI_EVENT_AP_STOP:
ESP_LOGW(TAG, "ap stop");
break;
case WIFI_EVENT_AP_STACONNECTED:
break;
case WIFI_EVENT_AP_STADISCONNECTED:
break;
case WIFI_EVENT_STA_START:
ESP_LOGW(TAG, "start");
ESP_LOGW(TAG, "sta start");
break;
case WIFI_EVENT_STA_STOP:
ESP_LOGW(TAG, "stop");
ESP_LOGW(TAG, "sta stop");
break;
case WIFI_EVENT_STA_CONNECTED:
ESP_LOGW(TAG, "connected");
@ -109,6 +119,7 @@ void common_hal_wifi_init(void) {
wifi_radio_obj_t *self = &common_hal_wifi_radio_obj;
self->netif = esp_netif_create_default_wifi_sta();
self->ap_netif = esp_netif_create_default_wifi_ap();
self->started = false;
// Even though we just called esp_netif_create_default_wifi_sta,
@ -137,6 +148,9 @@ void common_hal_wifi_init(void) {
} else if (result != ESP_OK) {
mp_raise_RuntimeError(translate("Failed to init wifi"));
}
// set station mode to avoid the default SoftAP
esp_wifi_set_mode(WIFI_MODE_STA);
// start wifi
common_hal_wifi_radio_set_enabled(self, true);
}
@ -155,6 +169,8 @@ void wifi_reset(void) {
ESP_ERROR_CHECK(esp_wifi_deinit());
esp_netif_destroy(radio->netif);
radio->netif = NULL;
esp_netif_destroy(radio->ap_netif);
radio->ap_netif = NULL;
}
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t *esp_ip_address) {

View File

@ -27,6 +27,8 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
#include "py/enum.h"
typedef enum {
AUTHMODE_OPEN,
AUTHMODE_WEP,
@ -38,5 +40,6 @@ typedef enum {
} wifi_authmode_t;
extern const mp_obj_type_t wifi_authmode_type;
extern const cp_enum_obj_t authmode_OPEN_obj;
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H

View File

@ -25,6 +25,7 @@
*/
#include "shared-bindings/wifi/__init__.h"
#include "shared-bindings/wifi/AuthMode.h"
#include <regex.h>
#include <string.h>
@ -74,7 +75,7 @@ const mp_obj_property_t wifi_radio_enabled_obj = {
};
//| mac_address: bytes
//| """MAC address of the wifi radio. (read-only)"""
//| """MAC address of the wifi radio station. (read-only)"""
//|
STATIC mp_obj_t wifi_radio_get_mac_address(mp_obj_t self) {
return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address(self));
@ -90,6 +91,23 @@ const mp_obj_property_t wifi_radio_mac_address_obj = {
};
//| mac_address_ap: bytes
//| """MAC address of the wifi radio access point. (read-only)"""
//|
STATIC mp_obj_t wifi_radio_get_mac_address_ap(mp_obj_t self) {
return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address_ap(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_ap_obj, wifi_radio_get_mac_address_ap);
const mp_obj_property_t wifi_radio_mac_address_ap_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&wifi_radio_get_mac_address_ap_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
//| def start_scanning_networks(self, *, start_channel: int = 1, stop_channel: int = 11) -> Iterable[Network]:
//| """Scans for available wifi networks over the given channel range. Make sure the channels are allowed in your country."""
//| ...
@ -153,6 +171,99 @@ const mp_obj_property_t wifi_radio_hostname_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| def start_station(self) -> None:
//| """Starts a Station."""
//| ...
//|
STATIC mp_obj_t wifi_radio_start_station(mp_obj_t self) {
common_hal_wifi_radio_start_station(self);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_station_obj, wifi_radio_start_station);
//| def stop_station(self) -> None:
//| """Stops the Station."""
//| ...
//|
STATIC mp_obj_t wifi_radio_stop_station(mp_obj_t self) {
common_hal_wifi_radio_stop_station(self);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
//| def start_ap(self,
//| ssid: ReadableBuffer,
//| password: ReadableBuffer = b"",
//| *,
//| channel: Optional[int] = 1,
//| authmode: Optional[AuthMode]) -> None:
//| """Starts an Access Point with the specified ssid and password.
//|
//| If ``channel`` is given, the access point will use that channel unless
//| a station is already operating on a different channel.
//|
//| If ``authmode`` is given, the access point will use that Authentication
//| mode. If a password is given, ``authmode`` must not be ``OPEN``.
//| If ``authmode`` isn't given, ``OPEN`` will be used when password isn't provided,
//| otherwise ``WPA_WPA2_PSK``."""
//| ...
//|
STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_ssid, ARG_password, ARG_channel, ARG_authmode };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
{ MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
};
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
uint8_t authmode = 0;
if (args[ARG_authmode].u_obj != MP_OBJ_NULL) {
mp_obj_iter_buf_t iter_buf;
mp_obj_t item, iterable = mp_getiter(args[ARG_authmode].u_obj, &iter_buf);
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
authmode |= (1 << (wifi_authmode_t)cp_enum_value(&wifi_authmode_type, item));
}
}
mp_buffer_info_t ssid;
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
mp_buffer_info_t password;
password.len = 0;
if (args[ARG_password].u_obj != MP_OBJ_NULL) {
if (authmode == 1) {
mp_raise_ValueError(translate("AuthMode.OPEN is not used with password"));
} else if (authmode == 0) {
authmode = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK);
}
mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ);
if (password.len > 0 && (password.len < 8 || password.len > 63)) {
mp_raise_ValueError(translate("WiFi password must be between 8 and 63 characters"));
}
} else {
authmode = 1;
}
common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmode);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap);
//| def stop_ap(self) -> None:
//| """Stops the Access Point."""
//| ...
//|
STATIC mp_obj_t wifi_radio_stop_ap(mp_obj_t self) {
common_hal_wifi_radio_stop_ap(self);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_ap_obj, wifi_radio_stop_ap);
//| def connect(self,
//| ssid: ReadableBuffer,
//| password: ReadableBuffer = b"",
@ -231,7 +342,7 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_connect_obj, 1, wifi_radio_connect);
//| ipv4_gateway: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the gateway when connected to an access point. None otherwise."""
//| """IP v4 Address of the station gateway when connected to an access point. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_gateway(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_gateway(self);
@ -246,8 +357,24 @@ const mp_obj_property_t wifi_radio_ipv4_gateway_obj = {
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_gateway_ap: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the access point gateway, when enabled. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_gateway_ap(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_gateway_ap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_gateway_ap_obj, wifi_radio_get_ipv4_gateway_ap);
const mp_obj_property_t wifi_radio_ipv4_gateway_ap_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&wifi_radio_get_ipv4_gateway_ap_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_subnet: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the subnet when connected to an access point. None otherwise."""
//| """IP v4 Address of the station subnet when connected to an access point. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_subnet(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_subnet(self);
@ -262,8 +389,24 @@ const mp_obj_property_t wifi_radio_ipv4_subnet_obj = {
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_subnet_ap: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the access point subnet, when enabled. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_subnet_ap(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_subnet_ap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4_subnet_ap);
const mp_obj_property_t wifi_radio_ipv4_subnet_ap_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&wifi_radio_get_ipv4_subnet_ap_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_address: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the radio when connected to an access point. None otherwise."""
//| """IP v4 Address of the station when connected to an access point. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_address(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_address(self);
@ -278,6 +421,22 @@ const mp_obj_property_t wifi_radio_ipv4_address_obj = {
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_address_ap: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the access point, when enabled. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_address_ap(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_address_ap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_address_ap_obj, wifi_radio_get_ipv4_address_ap);
const mp_obj_property_t wifi_radio_ipv4_address_ap_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&wifi_radio_get_ipv4_address_ap_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_dns: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the DNS server in use when connected to an access point. None otherwise."""
//|
@ -343,20 +502,29 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_ping_obj, 1, wifi_radio_ping);
STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_enabled), MP_ROM_PTR(&wifi_radio_enabled_obj) },
{ MP_ROM_QSTR(MP_QSTR_mac_address), MP_ROM_PTR(&wifi_radio_mac_address_obj) },
{ MP_ROM_QSTR(MP_QSTR_mac_address_ap), MP_ROM_PTR(&wifi_radio_mac_address_ap_obj) },
{ MP_ROM_QSTR(MP_QSTR_start_scanning_networks), MP_ROM_PTR(&wifi_radio_start_scanning_networks_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop_scanning_networks), MP_ROM_PTR(&wifi_radio_stop_scanning_networks_obj) },
{ MP_ROM_QSTR(MP_QSTR_hostname), MP_ROM_PTR(&wifi_radio_hostname_obj) },
{ MP_ROM_QSTR(MP_QSTR_start_station), MP_ROM_PTR(&wifi_radio_start_station_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop_station), MP_ROM_PTR(&wifi_radio_stop_station_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop_ap), MP_ROM_PTR(&wifi_radio_stop_ap_obj) },
{ MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) },
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) },
// { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) },
{ MP_ROM_QSTR(MP_QSTR_ap_info), MP_ROM_PTR(&wifi_radio_ap_info_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_dns), MP_ROM_PTR(&wifi_radio_ipv4_dns_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_gateway_ap), MP_ROM_PTR(&wifi_radio_ipv4_gateway_ap_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_subnet_ap), MP_ROM_PTR(&wifi_radio_ipv4_subnet_ap_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_address_ap), MP_ROM_PTR(&wifi_radio_ipv4_address_ap_obj) },
// { MP_ROM_QSTR(MP_QSTR_access_point_active), MP_ROM_PTR(&wifi_radio_access_point_active_obj) },
// { MP_ROM_QSTR(MP_QSTR_start_access_point), MP_ROM_PTR(&wifi_radio_start_access_point_obj) },

View File

@ -78,17 +78,26 @@ extern mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self);
extern void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname);
extern mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self);
extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self);
extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self);
extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self);
extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode);
extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self);
extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len);
extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self);
extern mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout);

View File

@ -27,11 +27,12 @@
#include "py/objexcept.h"
#include "py/runtime.h"
#include "shared-bindings/wifi/__init__.h"
#include "shared-bindings/wifi/AuthMode.h"
#include "shared-bindings/wifi/Network.h"
#include "shared-bindings/wifi/Radio.h"
//| """
//| The `wifi` module provides necessary low-level functionality for managing wifi
//| The `wifi` module provides necessary low-level functionality for managing
//| wifi connections. Use `socketpool` for communicating over the network."""
//|
//| radio: Radio
@ -49,15 +50,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(wifi___init___obj, wifi___init__);
STATIC const mp_rom_map_elem_t wifi_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wifi) },
{ MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) },
{ MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) },
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wifi) },
{ MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) },
{ MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) },
{ MP_ROM_QSTR(MP_QSTR_AuthMode), MP_ROM_PTR(&wifi_authmode_type) },
// Properties
{ MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) },
{ MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) },
// Initialization
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) },
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) },
};