esp32: Use extmod/modnetwork.c instead of port-specific version.
Rather than duplicating the implementation of `network`, this allows ESP32 to use the shared one in extmod. In particular this gains access to network.hostname and network.country. Set default hostnames for various ESP32 boards. Other than adding these two methods and the change to the default hostname, there is no other user-visible change. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
parent
f78464c12b
commit
eb51ca4a11
@ -1,2 +1,3 @@
|
||||
#define MICROPY_HW_BOARD_NAME "LILYGO TTGO LoRa32"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-ttgo-lora32"
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "LOLIN_C3_MINI"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-C3FH4"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-c3-mini"
|
||||
|
||||
#define MICROPY_HW_ENABLE_SDCARD (0)
|
||||
#define MICROPY_PY_MACHINE_DAC (0)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "LOLIN_S2_MINI"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-s2-mini"
|
||||
|
||||
#define MICROPY_PY_BLUETOOTH (0)
|
||||
#define MICROPY_HW_ENABLE_SDCARD (0)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "LOLIN_S2_PICO"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-s2-pico"
|
||||
|
||||
#define MICROPY_PY_BLUETOOTH (0)
|
||||
#define MICROPY_HW_ENABLE_SDCARD (0)
|
||||
|
@ -1,2 +1,3 @@
|
||||
#define MICROPY_HW_BOARD_NAME "M5Stack ATOM"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-PICO-D4"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "m5stack-atom"
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "FeatherS2"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-S2"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "FeatherS2"
|
||||
|
||||
#define MICROPY_PY_BLUETOOTH (0)
|
||||
#define MICROPY_HW_ENABLE_SDCARD (0)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "FeatherS2 Neo"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "FeatherS2-Neo"
|
||||
|
||||
#define MICROPY_PY_BLUETOOTH (0)
|
||||
#define MICROPY_HW_ENABLE_SDCARD (0)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "FeatherS3"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-S3"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "FeatherS3"
|
||||
|
||||
#define MICROPY_PY_MACHINE_DAC (0)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "ProS3"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-S3"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "ProS3"
|
||||
|
||||
#define MICROPY_PY_MACHINE_DAC (0)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "TinyPICO"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-PICO-D4"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "TinyPICO"
|
||||
|
||||
#define MICROPY_HW_I2C0_SCL (22)
|
||||
#define MICROPY_HW_I2C0_SDA (21)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "TinyS2"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "TinyS2"
|
||||
|
||||
#define MICROPY_PY_BLUETOOTH (0)
|
||||
#define MICROPY_HW_ENABLE_SDCARD (0)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define MICROPY_HW_BOARD_NAME "TinyS3"
|
||||
#define MICROPY_HW_MCU_NAME "ESP32-S3-FN8"
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "TinyS3"
|
||||
|
||||
#define MICROPY_PY_MACHINE_DAC (0)
|
||||
|
||||
|
@ -68,7 +68,7 @@ set(MICROPY_SOURCE_PORT
|
||||
${PROJECT_DIR}/machine_i2s.c
|
||||
${PROJECT_DIR}/machine_uart.c
|
||||
${PROJECT_DIR}/modmachine.c
|
||||
${PROJECT_DIR}/modnetwork.c
|
||||
${PROJECT_DIR}/network_common.c
|
||||
${PROJECT_DIR}/network_lan.c
|
||||
${PROJECT_DIR}/network_ppp.c
|
||||
${PROJECT_DIR}/network_wlan.c
|
||||
|
@ -45,11 +45,13 @@ typedef struct _wlan_if_obj_t {
|
||||
int if_id;
|
||||
} wlan_if_obj_t;
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(get_wlan_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(get_lan_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(ppp_make_new_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(esp_config_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(esp_network_initialize_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_get_wlan_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(esp_network_get_lan_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(esp_network_ppp_make_new_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_ifconfig_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(esp_network_config_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj);
|
||||
|
||||
NORETURN void esp_exceptions_helper(esp_err_t e);
|
||||
|
||||
|
77
ports/esp32/modnetwork_globals.h
Normal file
77
ports/esp32/modnetwork_globals.h
Normal file
@ -0,0 +1,77 @@
|
||||
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&esp_network_initialize_obj) },
|
||||
|
||||
#if MICROPY_PY_NETWORK_WLAN
|
||||
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&esp_network_get_wlan_obj) },
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_NETWORK_LAN
|
||||
{ MP_ROM_QSTR(MP_QSTR_LAN), MP_ROM_PTR(&esp_network_get_lan_obj) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_PPP), MP_ROM_PTR(&esp_network_ppp_make_new_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_network_phy_mode_obj) },
|
||||
|
||||
#if MICROPY_PY_NETWORK_WLAN
|
||||
{ MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(WIFI_IF_STA)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_AP_IF), MP_ROM_INT(WIFI_IF_AP)},
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_11B), MP_ROM_INT(WIFI_PROTOCOL_11B) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_11G), MP_ROM_INT(WIFI_PROTOCOL_11G) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_11N), MP_ROM_INT(WIFI_PROTOCOL_11N) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_LR), MP_ROM_INT(WIFI_PROTOCOL_LR) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_OPEN), MP_ROM_INT(WIFI_AUTH_OPEN) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WEP), MP_ROM_INT(WIFI_AUTH_WEP) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA_PSK), MP_ROM_INT(WIFI_AUTH_WPA_PSK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_PSK), MP_ROM_INT(WIFI_AUTH_WPA2_PSK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK), MP_ROM_INT(WIFI_AUTH_WPA_WPA2_PSK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_ENTERPRISE), MP_ROM_INT(WIFI_AUTH_WPA2_ENTERPRISE) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_PSK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_WPA3_PSK), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) },
|
||||
#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WAPI_PSK), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_MAX), MP_ROM_INT(WIFI_AUTH_MAX) },
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_NETWORK_LAN
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_LAN8710), MP_ROM_INT(PHY_LAN8710) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_LAN8720), MP_ROM_INT(PHY_LAN8720) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_IP101), MP_ROM_INT(PHY_IP101) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_RTL8201), MP_ROM_INT(PHY_RTL8201) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_DP83848), MP_ROM_INT(PHY_DP83848) },
|
||||
#if ESP_IDF_VERSION_MINOR >= 3
|
||||
// PHY_KSZ8041 is new in ESP-IDF v4.3
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8041), MP_ROM_INT(PHY_KSZ8041) },
|
||||
#endif
|
||||
#if ESP_IDF_VERSION_MINOR >= 4
|
||||
// PHY_KSZ8081 is new in ESP-IDF v4.4
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8081), MP_ROM_INT(PHY_KSZ8081) },
|
||||
#endif
|
||||
|
||||
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8851SNL), MP_ROM_INT(PHY_KSZ8851SNL) },
|
||||
#endif
|
||||
#if CONFIG_ETH_SPI_ETHERNET_DM9051
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_DM9051), MP_ROM_INT(PHY_DM9051) },
|
||||
#endif
|
||||
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_W5500), MP_ROM_INT(PHY_W5500) },
|
||||
#endif
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_INITIALIZED), MP_ROM_INT(ETH_INITIALIZED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_STARTED), MP_ROM_INT(ETH_STARTED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_STOPPED), MP_ROM_INT(ETH_STOPPED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_CONNECTED), MP_ROM_INT(ETH_CONNECTED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_DISCONNECTED), MP_ROM_INT(ETH_DISCONNECTED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_GOT_IP), MP_ROM_INT(ETH_GOT_IP)},
|
||||
#endif
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(STAT_IDLE)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(STAT_CONNECTING)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STAT_GOT_IP)},
|
||||
// Errors from the ESP-IDF
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(WIFI_REASON_AUTH_FAIL)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_BEACON_TIMEOUT), MP_ROM_INT(WIFI_REASON_BEACON_TIMEOUT)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_ASSOC_FAIL), MP_ROM_INT(WIFI_REASON_ASSOC_FAIL)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_HANDSHAKE_TIMEOUT), MP_ROM_INT(WIFI_REASON_HANDSHAKE_TIMEOUT)},
|
@ -110,6 +110,20 @@
|
||||
#ifndef MICROPY_PY_MACHINE_I2S
|
||||
#define MICROPY_PY_MACHINE_I2S (1)
|
||||
#endif
|
||||
#define MICROPY_PY_NETWORK (1)
|
||||
#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32s2"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32s3"
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c3"
|
||||
#endif
|
||||
#endif
|
||||
#define MICROPY_PY_NETWORK_INCLUDEFILE "ports/esp32/modnetwork.h"
|
||||
#define MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE "ports/esp32/modnetwork_globals.h"
|
||||
#ifndef MICROPY_PY_NETWORK_WLAN
|
||||
#define MICROPY_PY_NETWORK_WLAN (1)
|
||||
#endif
|
||||
|
@ -48,8 +48,6 @@
|
||||
#define DNS_MAIN ESP_NETIF_DNS_MAIN
|
||||
#endif
|
||||
|
||||
#define MODNETWORK_INCLUDE_CONSTANTS (1)
|
||||
|
||||
NORETURN void esp_exceptions_helper(esp_err_t e) {
|
||||
switch (e) {
|
||||
case ESP_ERR_WIFI_NOT_INIT:
|
||||
@ -144,7 +142,7 @@ STATIC mp_obj_t esp_initialize() {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_initialize_obj, esp_initialize);
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(esp_network_initialize_obj, esp_initialize);
|
||||
|
||||
STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
@ -207,12 +205,12 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_ifconfig_obj, 1, 2, esp_ifconfig);
|
||||
|
||||
STATIC mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_phy_mode_obj, 0, 1, esp_phy_mode);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj, 0, 1, esp_phy_mode);
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
|
||||
#define TEST_WIFI_AUTH_MAX 9
|
||||
@ -220,98 +218,3 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_phy_mode_obj, 0, 1, esp_phy_mode)
|
||||
#define TEST_WIFI_AUTH_MAX 8
|
||||
#endif
|
||||
_Static_assert(WIFI_AUTH_MAX == TEST_WIFI_AUTH_MAX, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&esp_initialize_obj) },
|
||||
|
||||
#if MICROPY_PY_NETWORK_WLAN
|
||||
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&get_wlan_obj) },
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_NETWORK_LAN
|
||||
{ MP_ROM_QSTR(MP_QSTR_LAN), MP_ROM_PTR(&get_lan_obj) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_PPP), MP_ROM_PTR(&ppp_make_new_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_phy_mode_obj) },
|
||||
|
||||
#if MODNETWORK_INCLUDE_CONSTANTS
|
||||
|
||||
#if MICROPY_PY_NETWORK_WLAN
|
||||
{ MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(WIFI_IF_STA)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_AP_IF), MP_ROM_INT(WIFI_IF_AP)},
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_11B), MP_ROM_INT(WIFI_PROTOCOL_11B) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_11G), MP_ROM_INT(WIFI_PROTOCOL_11G) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_11N), MP_ROM_INT(WIFI_PROTOCOL_11N) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_LR), MP_ROM_INT(WIFI_PROTOCOL_LR) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_OPEN), MP_ROM_INT(WIFI_AUTH_OPEN) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WEP), MP_ROM_INT(WIFI_AUTH_WEP) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA_PSK), MP_ROM_INT(WIFI_AUTH_WPA_PSK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_PSK), MP_ROM_INT(WIFI_AUTH_WPA2_PSK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK), MP_ROM_INT(WIFI_AUTH_WPA_WPA2_PSK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_ENTERPRISE), MP_ROM_INT(WIFI_AUTH_WPA2_ENTERPRISE) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_PSK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_WPA3_PSK), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) },
|
||||
#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_WAPI_PSK), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_AUTH_MAX), MP_ROM_INT(WIFI_AUTH_MAX) },
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_NETWORK_LAN
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_LAN8710), MP_ROM_INT(PHY_LAN8710) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_LAN8720), MP_ROM_INT(PHY_LAN8720) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_IP101), MP_ROM_INT(PHY_IP101) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_RTL8201), MP_ROM_INT(PHY_RTL8201) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_DP83848), MP_ROM_INT(PHY_DP83848) },
|
||||
#if ESP_IDF_VERSION_MINOR >= 3
|
||||
// PHY_KSZ8041 is new in ESP-IDF v4.3
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8041), MP_ROM_INT(PHY_KSZ8041) },
|
||||
#endif
|
||||
#if ESP_IDF_VERSION_MINOR >= 4
|
||||
// PHY_KSZ8081 is new in ESP-IDF v4.4
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8081), MP_ROM_INT(PHY_KSZ8081) },
|
||||
#endif
|
||||
|
||||
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8851SNL), MP_ROM_INT(PHY_KSZ8851SNL) },
|
||||
#endif
|
||||
#if CONFIG_ETH_SPI_ETHERNET_DM9051
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_DM9051), MP_ROM_INT(PHY_DM9051) },
|
||||
#endif
|
||||
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||
{ MP_ROM_QSTR(MP_QSTR_PHY_W5500), MP_ROM_INT(PHY_W5500) },
|
||||
#endif
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_INITIALIZED), MP_ROM_INT(ETH_INITIALIZED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_STARTED), MP_ROM_INT(ETH_STARTED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_STOPPED), MP_ROM_INT(ETH_STOPPED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_CONNECTED), MP_ROM_INT(ETH_CONNECTED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_DISCONNECTED), MP_ROM_INT(ETH_DISCONNECTED)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_ETH_GOT_IP), MP_ROM_INT(ETH_GOT_IP)},
|
||||
#endif
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(STAT_IDLE)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(STAT_CONNECTING)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STAT_GOT_IP)},
|
||||
// Errors from the ESP-IDF
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(WIFI_REASON_AUTH_FAIL)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_BEACON_TIMEOUT), MP_ROM_INT(WIFI_REASON_BEACON_TIMEOUT)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_ASSOC_FAIL), MP_ROM_INT(WIFI_REASON_ASSOC_FAIL)},
|
||||
{ MP_ROM_QSTR(MP_QSTR_STAT_HANDSHAKE_TIMEOUT), MP_ROM_INT(WIFI_REASON_HANDSHAKE_TIMEOUT)},
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_network = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&mp_module_network_globals,
|
||||
};
|
||||
|
||||
// Note: This port doesn't define MICROPY_PY_NETWORK so this will not conflict
|
||||
// with the common implementation provided by extmod/modnetwork.c.
|
||||
MP_REGISTER_MODULE(MP_QSTR_network, mp_module_network);
|
@ -331,7 +331,7 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
||||
|
||||
return MP_OBJ_FROM_PTR(&lan_obj);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(get_lan_obj, 0, get_lan);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(esp_network_get_lan_obj, 0, get_lan);
|
||||
|
||||
STATIC mp_obj_t lan_active(size_t n_args, const mp_obj_t *args) {
|
||||
lan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
@ -423,7 +423,7 @@ STATIC const mp_rom_map_elem_t lan_if_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&lan_isconnected_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lan_status_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&lan_config_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_network_ifconfig_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(lan_if_locals_dict, lan_if_locals_dict_table);
|
||||
|
@ -91,7 +91,7 @@ STATIC mp_obj_t ppp_make_new(mp_obj_t stream) {
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ppp_make_new_obj, ppp_make_new);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(esp_network_ppp_make_new_obj, ppp_make_new);
|
||||
|
||||
static u32_t ppp_output_callback(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx) {
|
||||
ppp_if_obj_t *self = ctx;
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "py/objlist.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "extmod/modnetwork.h"
|
||||
#include "modnetwork.h"
|
||||
|
||||
#include "esp_wifi.h"
|
||||
@ -91,12 +92,8 @@ void network_wlan_event_handler(system_event_t *event) {
|
||||
if (!mdns_initialised) {
|
||||
mdns_init();
|
||||
#if MICROPY_HW_ENABLE_MDNS_RESPONDER
|
||||
const char *hostname = NULL;
|
||||
if (tcpip_adapter_get_hostname(WIFI_IF_STA, &hostname) != ESP_OK || hostname == NULL) {
|
||||
hostname = "esp32";
|
||||
}
|
||||
mdns_hostname_set(hostname);
|
||||
mdns_instance_name_set(hostname);
|
||||
mdns_hostname_set(mod_network_hostname);
|
||||
mdns_instance_name_set(mod_network_hostname);
|
||||
#endif
|
||||
mdns_initialised = true;
|
||||
}
|
||||
@ -182,7 +179,7 @@ STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid WLAN interface identifier"));
|
||||
}
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(get_wlan_obj, 0, 1, get_wlan);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_get_wlan_obj, 0, 1, get_wlan);
|
||||
|
||||
STATIC mp_obj_t network_wlan_active(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
@ -260,6 +257,8 @@ STATIC mp_obj_t network_wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp
|
||||
esp_exceptions(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_sta_config));
|
||||
}
|
||||
|
||||
esp_exceptions(tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, mod_network_hostname));
|
||||
|
||||
wifi_sta_reconnects = 0;
|
||||
// connect to the WiFi AP
|
||||
MP_THREAD_GIL_EXIT();
|
||||
@ -474,8 +473,13 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
|
||||
}
|
||||
case MP_QSTR_hostname:
|
||||
case MP_QSTR_dhcp_hostname: {
|
||||
const char *s = mp_obj_str_get_str(kwargs->table[i].value);
|
||||
esp_exceptions(tcpip_adapter_set_hostname(self->if_id, s));
|
||||
// TODO: Deprecated. Use network.hostname(name) instead.
|
||||
size_t len;
|
||||
const char *str = mp_obj_str_get_data(kwargs->table[i].value, &len);
|
||||
if (len >= MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) {
|
||||
mp_raise_ValueError(NULL);
|
||||
}
|
||||
strcpy(mod_network_hostname, str);
|
||||
break;
|
||||
}
|
||||
case MP_QSTR_max_clients: {
|
||||
@ -568,9 +572,9 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
|
||||
}
|
||||
case MP_QSTR_hostname:
|
||||
case MP_QSTR_dhcp_hostname: {
|
||||
const char *s;
|
||||
esp_exceptions(tcpip_adapter_get_hostname(self->if_id, &s));
|
||||
val = mp_obj_new_str(s, strlen(s));
|
||||
// TODO: Deprecated. Use network.hostname() instead.
|
||||
req_if = WIFI_IF_STA;
|
||||
val = mp_obj_new_str(mod_network_hostname, strlen(mod_network_hostname));
|
||||
break;
|
||||
}
|
||||
case MP_QSTR_max_clients: {
|
||||
@ -618,7 +622,7 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&network_wlan_scan_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_wlan_isconnected_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_wlan_config_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_network_ifconfig_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user