@@ -102,6 +102,26 @@ STATIC mp_obj_t wifi_radio_stop_scanning_networks(mp_obj_t self_in) {
102102}
103103STATIC MP_DEFINE_CONST_FUN_OBJ_1 (wifi_radio_stop_scanning_networks_obj , wifi_radio_stop_scanning_networks );
104104
105+ //| def set_hostname(self, hostname: ReadableBuffer) -> None:
106+ //| """Sets hostname for wifi interface. When the hostname is altered after interface started/connected
107+ //| the changes would only be reflected once the interface restarts/reconnects."""
108+ //| ...
109+ //|
110+ STATIC mp_obj_t wifi_radio_set_hostname (mp_obj_t self_in , mp_obj_t hostname_in ) {
111+ mp_buffer_info_t hostname ;
112+ mp_get_buffer_raise (hostname_in , & hostname , MP_BUFFER_READ );
113+
114+ if (hostname .len < 1 || hostname .len > 63 ) {
115+ mp_raise_ValueError (translate ("Hostname must be between 1 and 63 characters" ));
116+ }
117+
118+ wifi_radio_obj_t * self = MP_OBJ_TO_PTR (self_in );
119+ common_hal_wifi_radio_set_hostname (self , hostname .buf );
120+
121+ return mp_const_none ;
122+ }
123+ MP_DEFINE_CONST_FUN_OBJ_2 (wifi_radio_set_hostname_obj , wifi_radio_set_hostname );
124+
105125//| def connect(self, ssid: ReadableBuffer, password: ReadableBuffer = b"", *, channel: Optional[int] = 0, timeout: Optional[float] = None) -> bool:
106126//| """Connects to the given ssid and waits for an ip address. Reconnections are handled
107127//| automatically once one connection succeeds."""
@@ -216,6 +236,8 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
216236 { MP_ROM_QSTR (MP_QSTR_start_scanning_networks ), MP_ROM_PTR (& wifi_radio_start_scanning_networks_obj ) },
217237 { MP_ROM_QSTR (MP_QSTR_stop_scanning_networks ), MP_ROM_PTR (& wifi_radio_stop_scanning_networks_obj ) },
218238
239+ { MP_ROM_QSTR (MP_QSTR_set_hostname ), MP_ROM_PTR (& wifi_radio_set_hostname_obj ) },
240+
219241 { MP_ROM_QSTR (MP_QSTR_connect ), MP_ROM_PTR (& wifi_radio_connect_obj ) },
220242 // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) },
221243
0 commit comments