Hi,
I've added this rough implementation of phy_mode() to modnetwork.c (with a view to enabling LR mode) and flashed it to a sparkfun thing, but I get ESP_ERR_INVALID_ARG. Calling phy_mode() with no args just returns the error values, (0, 12289, 12292, 258), so I can decode them.
Code: Select all
STATIC mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
mp_obj_t tuple[4] = {
mp_obj_new_int(ESP_OK),
mp_obj_new_int(ESP_ERR_WIFI_NOT_INIT),
mp_obj_new_int(ESP_ERR_WIFI_IF),
mp_obj_new_int(ESP_ERR_INVALID_ARG),
};
return mp_obj_new_tuple(4, tuple);
}
uint8_t protocol_bitmap = -1;
esp_err_t esp_err = ESP_OK;
wifi_interface_t ifx = WIFI_IF_STA;
switch(n_args)
{
case 1:
ifx = mp_obj_get_int(args[0]);
//case 0:
esp_err = esp_wifi_get_protocol(ifx, &protocol_bitmap);
if(esp_err ==ESP_OK)
{
mp_obj_t tuple[2] = {
mp_const_true,
mp_obj_new_int(protocol_bitmap),
};
return mp_obj_new_tuple(2, tuple);
}
break;
case 2:
ifx = mp_obj_get_int(args[0]);
esp_err = esp_wifi_set_protocol(ifx, mp_obj_get_int(args[1]));
break;
}
mp_obj_t tuple[2] = {
mp_obj_new_bool(esp_err ==ESP_OK),
mp_obj_new_int(esp_err),
};
return mp_obj_new_tuple(2, tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_phy_mode_obj, 0, 2, esp_phy_mode);
I also added ..
Code: Select all
STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
.
{ MP_ROM_QSTR(MP_QSTR_MODE_LR), MP_ROM_INT(WIFI_PROTOCOL_LR) },
.
I call it like this..
Code: Select all
import network as nw
wlan = nw.WLAN(nw.STA_IF)
nw.phy_mode(nw.STA_IF, nw.MODE_LR)
If I leave out
the error I get is ESP_ERR_WIFI_NOT_INIT, which suggests my call to esp_wifi_set_protocol() is executing actual code and not some stub.
Code: Select all
>>>
>>>
>>>
>>>
>>> import network as nw
>>> nw.phy_mode()
(0, 12289, 12292, 258)
>>>
>>> nw.phy_mode(nw.STA_IF, nw.MODE_LR)
(False, 12289)
>>>
>>>
>>> wlan = nw.WLAN(nw.STA_IF)
I (372060) wifi: wifi driver task: 3ffe2e9c, prio:23, stack:3584, core=0
I (386295) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (386305) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (386355) wifi: wifi firmware version: aeed694
I (386355) wifi: config NVS flash: enabled
I (386355) wifi: config nano formating: disabled
I (386355) wifi: Init dynamic tx buffer num: 32
I (386355) wifi: Init data frame dynamic rx buffer num: 32
I (386365) wifi: Init management frame dynamic rx buffer num: 32
I (386365) wifi: Init management short buffer num: 32
I (386375) wifi: Init static rx buffer size: 1600
I (386375) wifi: Init static rx buffer num: 10
I (386385) wifi: Init dynamic rx buffer num: 32
>>>
>>> nw.phy_mode(nw.STA_IF, nw.MODE_LR)
(False, 258)
>>>
>>>
>>> nw.phy_mode(nw.STA_IF)
(True, 7)
>>>
>>> nw.phy_mode(nw.STA_IF, 7)
(False, 258)
>>>
>>>
Note that phy_mode() returns the (presumably) correct mode value: 7 (ie, 11b|11g|11n == 1|2|4)
But also setting mode to this value also fails with ESP_ERR_INVALID_ARG.
This is compiled against idf v3.3
Can anyone suggest what else I need to do to set phy mode, or has anyone out there successfully used ESP32 LR mode?
I'll try using the C code from
this example, but it doesn't appear to be doing anything more than I am already...