Skip to content

Commit ceb5310

Browse files
committed
Add method to set custom hostname
1 parent 9de9678 commit ceb5310

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

locale/circuitpython.pot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-10-10 23:49-0700\n"
11+
"POT-Creation-Date: 2020-10-12 14:16+0530\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -947,6 +947,10 @@ msgstr ""
947947
msgid "Hardware in use, try alternative pins"
948948
msgstr ""
949949

950+
#: shared-bindings/wifi/Radio.c
951+
msgid "Hostname must be between 1 and 63 characters"
952+
msgstr ""
953+
950954
#: extmod/vfs_posix_file.c py/objstringio.c
951955
msgid "I/O operation on closed file"
952956
msgstr ""
@@ -1026,6 +1030,7 @@ msgstr ""
10261030
msgid "Invalid BSSID"
10271031
msgstr ""
10281032

1033+
#: ports/esp32s2/common-hal/analogio/AnalogOut.c
10291034
#: ports/stm/common-hal/analogio/AnalogOut.c
10301035
msgid "Invalid DAC pin supplied"
10311036
msgstr ""
@@ -1237,7 +1242,6 @@ msgid "No CCCD for this Characteristic"
12371242
msgstr ""
12381243

12391244
#: ports/atmel-samd/common-hal/analogio/AnalogOut.c
1240-
#: ports/esp32s2/common-hal/analogio/AnalogOut.c
12411245
#: ports/stm/common-hal/analogio/AnalogOut.c
12421246
msgid "No DAC on chip"
12431247
msgstr ""

ports/esp32s2/boards/microdev_micro_s2/sdkconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ CONFIG_SPIRAM_MEMTEST=y
3232
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
3333
# end of SPI RAM config
3434

35+
#
36+
# LWIP
37+
#
38+
CONFIG_LWIP_LOCAL_HOSTNAME="microS2"
39+
# end of LWIP

ports/esp32s2/common-hal/wifi/Radio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) {
104104
self->current_scan = NULL;
105105
}
106106

107+
void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname) {
108+
esp_netif_set_hostname(self->netif, hostname);
109+
}
110+
107111
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) {
108112
// check enabled
109113
start_station(self);

shared-bindings/wifi/Radio.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ STATIC mp_obj_t wifi_radio_stop_scanning_networks(mp_obj_t self_in) {
102102
}
103103
STATIC 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

shared-bindings/wifi/Radio.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
const mp_obj_type_t wifi_radio_type;
3737

38-
3938
typedef enum {
4039
WIFI_RADIO_ERROR_NONE,
4140
WIFI_RADIO_ERROR_UNKNOWN,
@@ -46,6 +45,8 @@ typedef enum {
4645
extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self);
4746
extern void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled);
4847

48+
extern void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname);
49+
4950
extern mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self);
5051

5152
extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self);

0 commit comments

Comments
 (0)