First crack at native wifi API
This commit is contained in:
parent
837abd6da0
commit
c5b8401a15
|
@ -78,8 +78,11 @@ INC += -Iesp-idf/components/freertos/xtensa/include
|
||||||
INC += -Iesp-idf/components/esp32s2/include
|
INC += -Iesp-idf/components/esp32s2/include
|
||||||
INC += -Iesp-idf/components/xtensa/esp32s2/include
|
INC += -Iesp-idf/components/xtensa/esp32s2/include
|
||||||
INC += -Iesp-idf/components/esp_common/include
|
INC += -Iesp-idf/components/esp_common/include
|
||||||
|
INC += -Iesp-idf/components/esp_event/include
|
||||||
|
INC += -Iesp-idf/components/esp_netif/include
|
||||||
INC += -Iesp-idf/components/esp_ringbuf/include
|
INC += -Iesp-idf/components/esp_ringbuf/include
|
||||||
INC += -Iesp-idf/components/esp_rom/include
|
INC += -Iesp-idf/components/esp_rom/include
|
||||||
|
INC += -Iesp-idf/components/esp_wifi/include
|
||||||
INC += -Iesp-idf/components/xtensa/include
|
INC += -Iesp-idf/components/xtensa/include
|
||||||
INC += -Iesp-idf/components/esp_timer/include
|
INC += -Iesp-idf/components/esp_timer/include
|
||||||
INC += -Iesp-idf/components/soc/include
|
INC += -Iesp-idf/components/soc/include
|
||||||
|
@ -129,7 +132,7 @@ LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp32s2 \
|
||||||
-Tesp32s2.rom.newlib-data.ld \
|
-Tesp32s2.rom.newlib-data.ld \
|
||||||
-Tesp32s2.rom.newlib-funcs.ld \
|
-Tesp32s2.rom.newlib-funcs.ld \
|
||||||
-Tesp32s2.rom.spiflash.ld
|
-Tesp32s2.rom.spiflash.ld
|
||||||
LIBS := -lgcc -lc
|
LIBS := -lgcc -lc -lstdc++
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -238,20 +241,25 @@ $(BUILD)/esp-idf/partition_table/partition-table.bin: $(BUILD)/esp-idf/config/sd
|
||||||
|
|
||||||
# run menuconfig
|
# run menuconfig
|
||||||
menuconfig: $(BUILD)/esp-idf/config
|
menuconfig: $(BUILD)/esp-idf/config
|
||||||
ninja -C $(BUILD)/esp-idf menuconfig
|
$(Q)ninja -C $(BUILD)/esp-idf menuconfig
|
||||||
diff --old-line-format= --unchanged-line-format= sdkconfig.defaults $(BUILD)/esp-idf/sdkconfig > boards/$(BOARD)/sdkconfig || true
|
$(Q)diff --old-line-format= --unchanged-line-format= sdkconfig.defaults $(BUILD)/esp-idf/sdkconfig > boards/$(BOARD)/sdkconfig || true
|
||||||
|
|
||||||
# qstr builds include headers so we need to make sure they are up to date
|
# qstr builds include headers so we need to make sure they are up to date
|
||||||
$(HEADER_BUILD)/qstr.i.last: | $(BUILD)/esp-idf/config/sdkconfig.h
|
$(HEADER_BUILD)/qstr.i.last: | $(BUILD)/esp-idf/config/sdkconfig.h
|
||||||
|
|
||||||
# Order here matters
|
# Order here matters
|
||||||
ESP_IDF_COMPONENTS_LINK = freertos log esp_system esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf #
|
ESP_IDF_COMPONENTS_LINK = freertos log esp_system esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf esp_wifi esp_event wpa_supplicant mbedtls efuse nvs_flash
|
||||||
|
|
||||||
ESP_IDF_COMPONENTS_INCLUDE = driver freertos log soc
|
ESP_IDF_COMPONENTS_INCLUDE = driver freertos log soc
|
||||||
|
|
||||||
INC += $(foreach component, $(ESP_IDF_COMPONENTS_INCLUDE), -Iesp-idf/components/$(component)/include)
|
INC += $(foreach component, $(ESP_IDF_COMPONENTS_INCLUDE), -Iesp-idf/components/$(component)/include)
|
||||||
|
|
||||||
ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
|
ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
|
||||||
|
ESP_IDF_WIFI_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_WIFI_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
|
||||||
|
|
||||||
|
MBEDTLS_COMPONENTS_LINK = crypto tls x509
|
||||||
|
MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component).a)
|
||||||
|
|
||||||
BINARY_BLOBS = esp-idf/components/xtensa/esp32s2/libhal.a
|
BINARY_BLOBS = esp-idf/components/xtensa/esp32s2/libhal.a
|
||||||
BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a librtc.a libsmartconfig.a libphy.a
|
BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a librtc.a libsmartconfig.a libphy.a
|
||||||
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/esp32s2/, $(BINARY_WIFI_BLOBS))
|
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/esp32s2/, $(BINARY_WIFI_BLOBS))
|
||||||
|
@ -265,18 +273,23 @@ all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
|
||||||
|
|
||||||
.PHONY: esp-idf-stamp
|
.PHONY: esp-idf-stamp
|
||||||
esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h
|
esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h
|
||||||
ninja -C $(BUILD)/esp-idf \
|
$(Q)ninja -C $(BUILD)/esp-idf \
|
||||||
bootloader/bootloader.bin \
|
bootloader/bootloader.bin \
|
||||||
esp-idf/bootloader_support/libbootloader_support.a \
|
esp-idf/bootloader_support/libbootloader_support.a \
|
||||||
esp-idf/esp32s2/ld/esp32s2.project.ld \
|
esp-idf/esp32s2/ld/esp32s2.project.ld \
|
||||||
|
esp-idf/esp_event/libesp_event.a \
|
||||||
esp-idf/esp_system/libesp_system.a \
|
esp-idf/esp_system/libesp_system.a \
|
||||||
|
esp-idf/esp_wifi/libesp_wifi.a \
|
||||||
|
esp-idf/nvs_flash/libnvs_flash.a \
|
||||||
|
esp-idf/wpa_supplicant/libwpa_supplicant.a \
|
||||||
|
esp-idf/mbedtls/libmbedtls.a \
|
||||||
esp-idf/freertos/libfreertos.a \
|
esp-idf/freertos/libfreertos.a \
|
||||||
esp-idf/log/liblog.a \
|
esp-idf/log/liblog.a \
|
||||||
esp-idf/xtensa/libxtensa.a
|
esp-idf/xtensa/libxtensa.a
|
||||||
|
|
||||||
$(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp
|
$(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp
|
||||||
$(STEPECHO) "LINK $@"
|
$(STEPECHO) "LINK $@"
|
||||||
$(Q)$(CC) -o $@ $(LDFLAGS) $^ $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) build-$(BOARD)/esp-idf/esp-idf/newlib/libnewlib.a -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group
|
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) build-$(BOARD)/esp-idf/esp-idf/newlib/libnewlib.a -Wl,--end-group -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group build-$(BOARD)/esp-idf/esp-idf/pthread/libpthread.a -u __cxx_fatal_exception
|
||||||
# $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld
|
# $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld
|
||||||
|
|
||||||
$(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf
|
$(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "shared-bindings/wifi/Network.h"
|
||||||
|
|
||||||
|
mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self) {
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_NETWORK_H
|
||||||
|
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_NETWORK_H
|
||||||
|
|
||||||
|
#include "py/obj.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
mp_obj_base_t base;
|
||||||
|
// Stores no state currently.
|
||||||
|
} wifi_network_obj_t;
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_NETWORK_H
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "shared-bindings/wifi/Radio.h"
|
||||||
|
|
||||||
|
bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
|
||||||
|
void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, mp_float_t timeout) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_obj_t common_hal_wifi_radio_get_ip_address(wifi_radio_obj_t *self) {
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address) {
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H
|
||||||
|
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H
|
||||||
|
|
||||||
|
#include "py/obj.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
mp_obj_base_t base;
|
||||||
|
// Stores no state currently.
|
||||||
|
} wifi_radio_obj_t;
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "shared-bindings/wifi/Radio.h"
|
||||||
|
|
||||||
|
#include "py/runtime.h"
|
||||||
|
|
||||||
|
#include "esp-idf/components/esp_wifi/include/esp_wifi.h"
|
||||||
|
|
||||||
|
wifi_radio_obj_t common_hal_wifi_radio_obj;
|
||||||
|
|
||||||
|
void common_hal_wifi_init(void) {
|
||||||
|
common_hal_wifi_radio_obj.base.type = &wifi_radio_type;
|
||||||
|
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
|
||||||
|
esp_err_t result = esp_wifi_init(&config);
|
||||||
|
if (result == ESP_ERR_NO_MEM) {
|
||||||
|
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate Wifi memory"));
|
||||||
|
} else if (result != ESP_OK) {
|
||||||
|
// handle this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wifi_reset(void) {
|
||||||
|
esp_wifi_deinit();
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI___INIT___H
|
||||||
|
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI___INIT___H
|
||||||
|
|
||||||
|
#include "py/obj.h"
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI___INIT___H
|
|
@ -1 +1 @@
|
||||||
Subproject commit 160ba4924d8b588e718f76e3a0d0e92c11052fa3
|
Subproject commit f5aff20b378f7c4002605a4158a41630c21f343d
|
|
@ -29,4 +29,6 @@ CIRCUITPY_RANDOM = 0 # Requires OS
|
||||||
CIRCUITPY_USB_MIDI = 0 # Requires USB
|
CIRCUITPY_USB_MIDI = 0 # Requires USB
|
||||||
CIRCUITPY_ULAB = 0 # No requirements, but takes extra flash
|
CIRCUITPY_ULAB = 0 # No requirements, but takes extra flash
|
||||||
|
|
||||||
|
CIRCUITPY_WIFI = 1
|
||||||
|
|
||||||
CIRCUITPY_MODULE ?= none
|
CIRCUITPY_MODULE ?= none
|
||||||
|
|
|
@ -279,9 +279,7 @@ CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y
|
||||||
#
|
#
|
||||||
# Ethernet
|
# Ethernet
|
||||||
#
|
#
|
||||||
CONFIG_ETH_ENABLED=y
|
# CONFIG_ETH_USE_SPI_ETHERNET is not set
|
||||||
CONFIG_ETH_USE_SPI_ETHERNET=y
|
|
||||||
# CONFIG_ETH_SPI_ETHERNET_DM9051 is not set
|
|
||||||
# CONFIG_ETH_USE_OPENETH is not set
|
# CONFIG_ETH_USE_OPENETH is not set
|
||||||
# end of Ethernet
|
# end of Ethernet
|
||||||
|
|
||||||
|
@ -299,7 +297,7 @@ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y
|
||||||
CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120
|
CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120
|
||||||
CONFIG_ESP_NETIF_TCPIP_LWIP=y
|
CONFIG_ESP_NETIF_TCPIP_LWIP=y
|
||||||
# CONFIG_ESP_NETIF_LOOPBACK is not set
|
# CONFIG_ESP_NETIF_LOOPBACK is not set
|
||||||
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=y
|
# CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER is not set
|
||||||
# end of ESP NETIF Adapter
|
# end of ESP NETIF Adapter
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -261,6 +261,9 @@ endif
|
||||||
ifeq ($(CIRCUITPY_WATCHDOG),1)
|
ifeq ($(CIRCUITPY_WATCHDOG),1)
|
||||||
SRC_PATTERNS += watchdog/%
|
SRC_PATTERNS += watchdog/%
|
||||||
endif
|
endif
|
||||||
|
ifeq ($(CIRCUITPY_WIFI),1)
|
||||||
|
SRC_PATTERNS += wifi/%
|
||||||
|
endif
|
||||||
ifeq ($(CIRCUITPY_PEW),1)
|
ifeq ($(CIRCUITPY_PEW),1)
|
||||||
SRC_PATTERNS += _pew/%
|
SRC_PATTERNS += _pew/%
|
||||||
endif
|
endif
|
||||||
|
@ -333,6 +336,9 @@ SRC_COMMON_HAL_ALL = \
|
||||||
watchdog/WatchDogMode.c \
|
watchdog/WatchDogMode.c \
|
||||||
watchdog/WatchDogTimer.c \
|
watchdog/WatchDogTimer.c \
|
||||||
watchdog/__init__.c \
|
watchdog/__init__.c \
|
||||||
|
wifi/Network.c \
|
||||||
|
wifi/Radio.c \
|
||||||
|
wifi/__init__.c \
|
||||||
|
|
||||||
SRC_COMMON_HAL = $(filter $(SRC_PATTERNS), $(SRC_COMMON_HAL_ALL))
|
SRC_COMMON_HAL = $(filter $(SRC_PATTERNS), $(SRC_COMMON_HAL_ALL))
|
||||||
|
|
||||||
|
|
|
@ -683,6 +683,13 @@ extern const struct _mp_obj_module_t watchdog_module;
|
||||||
#define WATCHDOG_MODULE
|
#define WATCHDOG_MODULE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CIRCUITPY_WIFI
|
||||||
|
extern const struct _mp_obj_module_t wifi_module;
|
||||||
|
#define WIFI_MODULE { MP_ROM_QSTR(MP_QSTR_wifi), MP_ROM_PTR(&wifi_module) },
|
||||||
|
#else
|
||||||
|
#define WIFI_MODULE
|
||||||
|
#endif
|
||||||
|
|
||||||
// Define certain native modules with weak links so they can be replaced with Python
|
// Define certain native modules with weak links so they can be replaced with Python
|
||||||
// implementations. This list may grow over time.
|
// implementations. This list may grow over time.
|
||||||
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
|
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
|
||||||
|
@ -759,6 +766,7 @@ extern const struct _mp_obj_module_t watchdog_module;
|
||||||
USB_MIDI_MODULE \
|
USB_MIDI_MODULE \
|
||||||
USTACK_MODULE \
|
USTACK_MODULE \
|
||||||
WATCHDOG_MODULE \
|
WATCHDOG_MODULE \
|
||||||
|
WIFI_MODULE \
|
||||||
|
|
||||||
// If weak links are enabled, just include strong links in the main list of modules,
|
// If weak links are enabled, just include strong links in the main list of modules,
|
||||||
// and also include the underscore alternate names.
|
// and also include the underscore alternate names.
|
||||||
|
|
|
@ -254,6 +254,9 @@ CFLAGS += -DCIRCUITPY_ULAB=$(CIRCUITPY_ULAB)
|
||||||
CIRCUITPY_WATCHDOG ?= 0
|
CIRCUITPY_WATCHDOG ?= 0
|
||||||
CFLAGS += -DCIRCUITPY_WATCHDOG=$(CIRCUITPY_WATCHDOG)
|
CFLAGS += -DCIRCUITPY_WATCHDOG=$(CIRCUITPY_WATCHDOG)
|
||||||
|
|
||||||
|
CIRCUITPY_WIFI ?= 0
|
||||||
|
CFLAGS += -DCIRCUITPY_WIFI=$(CIRCUITPY_WIFI)
|
||||||
|
|
||||||
# Enabled micropython.native decorator (experimental)
|
# Enabled micropython.native decorator (experimental)
|
||||||
CIRCUITPY_ENABLE_MPY_NATIVE ?= 0
|
CIRCUITPY_ENABLE_MPY_NATIVE ?= 0
|
||||||
CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)
|
CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "py/objproperty.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
|
#include "shared-bindings/wifi/Network.h"
|
||||||
|
|
||||||
|
//| class Network:
|
||||||
|
//| """A wifi network provided by a nearby access point.
|
||||||
|
//|
|
||||||
|
//| """
|
||||||
|
//|
|
||||||
|
|
||||||
|
//| def __init__(self) -> None:
|
||||||
|
//| """You cannot create an instance of `wifi.Network`. They are returned by `wifi.Radio.start_scanning_networks`."""
|
||||||
|
//| ...
|
||||||
|
//|
|
||||||
|
|
||||||
|
//| ssid: str
|
||||||
|
//| """True when the wifi network is enabled."""
|
||||||
|
//|
|
||||||
|
STATIC mp_obj_t wifi_network_get_ssid(mp_obj_t self) {
|
||||||
|
return common_hal_wifi_network_get_ssid(self);
|
||||||
|
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_1(wifi_network_get_ssid_obj, wifi_network_get_ssid);
|
||||||
|
|
||||||
|
const mp_obj_property_t wifi_network_ssid_obj = {
|
||||||
|
.base.type = &mp_type_property,
|
||||||
|
.proxy = { (mp_obj_t)&wifi_network_get_ssid_obj,
|
||||||
|
(mp_obj_t)&mp_const_none_obj,
|
||||||
|
(mp_obj_t)&mp_const_none_obj },
|
||||||
|
};
|
||||||
|
|
||||||
|
STATIC const mp_rom_map_elem_t wifi_network_locals_dict_table[] = {
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_ssid), MP_ROM_PTR(&wifi_network_ssid_obj) },
|
||||||
|
};
|
||||||
|
|
||||||
|
STATIC MP_DEFINE_CONST_DICT(wifi_network_locals_dict, wifi_network_locals_dict_table);
|
||||||
|
|
||||||
|
const mp_obj_type_t wifi_network_type = {
|
||||||
|
.base = { &mp_type_type },
|
||||||
|
.name = MP_QSTR_Network,
|
||||||
|
.locals_dict = (mp_obj_t)&wifi_network_locals_dict,
|
||||||
|
};
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H
|
||||||
|
#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "common-hal/wifi/Network.h"
|
||||||
|
|
||||||
|
#include "py/objstr.h"
|
||||||
|
|
||||||
|
const mp_obj_type_t wifi_network_type;
|
||||||
|
|
||||||
|
extern mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self);
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_NETWORK_H
|
|
@ -0,0 +1,196 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "py/objproperty.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
|
#include "shared-bindings/wifi/__init__.h"
|
||||||
|
|
||||||
|
//| class Radio:
|
||||||
|
//| """Native wifi radio.
|
||||||
|
//|
|
||||||
|
//| This class manages the station and access point functionality of the native
|
||||||
|
//| Wifi radio.
|
||||||
|
//|
|
||||||
|
//| """
|
||||||
|
//|
|
||||||
|
|
||||||
|
//| def __init__(self) -> None:
|
||||||
|
//| """You cannot create an instance of `wifi.Radio`.
|
||||||
|
//| Use `wifi.radio` to access the sole instance available."""
|
||||||
|
//| ...
|
||||||
|
//|
|
||||||
|
|
||||||
|
//| enabled: bool
|
||||||
|
//| """True when the wifi radio is enabled."""
|
||||||
|
//|
|
||||||
|
STATIC mp_obj_t wifi_radio_get_enabled(mp_obj_t self) {
|
||||||
|
return mp_obj_new_bool(common_hal_wifi_radio_get_enabled(self));
|
||||||
|
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_enabled_obj, wifi_radio_get_enabled);
|
||||||
|
|
||||||
|
const mp_obj_property_t wifi_radio_enabled_obj = {
|
||||||
|
.base.type = &mp_type_property,
|
||||||
|
.proxy = { (mp_obj_t)&wifi_radio_get_enabled_obj,
|
||||||
|
(mp_obj_t)&mp_const_none_obj,
|
||||||
|
(mp_obj_t)&mp_const_none_obj },
|
||||||
|
};
|
||||||
|
|
||||||
|
//| mac_address: Address
|
||||||
|
//| """MAC address of the wifi radio. (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));
|
||||||
|
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_obj, wifi_radio_get_mac_address);
|
||||||
|
|
||||||
|
const mp_obj_property_t wifi_radio_mac_address_obj = {
|
||||||
|
.base.type = &mp_type_property,
|
||||||
|
.proxy = { (mp_obj_t)&wifi_radio_get_mac_address_obj,
|
||||||
|
(mp_obj_t)&mp_const_none_obj,
|
||||||
|
(mp_obj_t)&mp_const_none_obj },
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//| def start_scanning_networks(self) -> Iterable[Network]:
|
||||||
|
//| """"""
|
||||||
|
//| ...
|
||||||
|
//|
|
||||||
|
STATIC mp_obj_t wifi_radio_start_scanning_networks(mp_obj_t self_in) {
|
||||||
|
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
|
return common_hal_wifi_radio_start_scanning_networks(self);
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_scanning_networks_obj, wifi_radio_start_scanning_networks);
|
||||||
|
|
||||||
|
//| def stop_scanning_networks(self) -> None:
|
||||||
|
//| """Stop scanning for Wifi networks and free any resources used to do it."""
|
||||||
|
//| ...
|
||||||
|
//|
|
||||||
|
STATIC mp_obj_t wifi_radio_stop_scanning_networks(mp_obj_t self_in) {
|
||||||
|
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
|
common_hal_wifi_radio_stop_scanning_networks(self);
|
||||||
|
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_scanning_networks_obj, wifi_radio_stop_scanning_networks);
|
||||||
|
|
||||||
|
//| def connect(self, ssid: ReadableBuffer, password: ReadableBuffer = b"", *, timeout: Optional[float] = None) -> bool:
|
||||||
|
//| """"""
|
||||||
|
//| ...
|
||||||
|
//|
|
||||||
|
STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
|
enum { ARG_ssid, ARG_password, ARG_timeout };
|
||||||
|
static const mp_arg_t allowed_args[] = {
|
||||||
|
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||||
|
{ MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||||
|
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
mp_float_t timeout = 0;
|
||||||
|
if (args[ARG_timeout].u_obj != mp_const_none) {
|
||||||
|
timeout = mp_obj_get_float(args[ARG_timeout].u_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mp_buffer_info_t ssid;
|
||||||
|
ssid.len = 0;
|
||||||
|
if (args[ARG_ssid].u_obj != MP_OBJ_NULL) {
|
||||||
|
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) {
|
||||||
|
mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mp_obj_new_bool(common_hal_wifi_radio_connect(self, ssid.buf, ssid.len, password.buf, password.len, timeout));
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_connect_obj, 1, wifi_radio_connect);
|
||||||
|
|
||||||
|
//| ip_address: Optional[ipaddress.IPAddress]
|
||||||
|
//| """IP Address of the radio when connected to an access point. None otherwise."""
|
||||||
|
//|
|
||||||
|
STATIC mp_obj_t wifi_radio_get_ip_address(mp_obj_t self) {
|
||||||
|
return common_hal_wifi_radio_get_ip_address(self);
|
||||||
|
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ip_address_obj, wifi_radio_get_ip_address);
|
||||||
|
|
||||||
|
const mp_obj_property_t wifi_radio_ip_address_obj = {
|
||||||
|
.base.type = &mp_type_property,
|
||||||
|
.proxy = { (mp_obj_t)&wifi_radio_get_ip_address_obj,
|
||||||
|
(mp_obj_t)&mp_const_none_obj,
|
||||||
|
(mp_obj_t)&mp_const_none_obj },
|
||||||
|
};
|
||||||
|
|
||||||
|
//| def ping(self, ip) -> int:
|
||||||
|
//| """Ping an IP to test connectivity. Returns echo time in milliseconds."""
|
||||||
|
//| ...
|
||||||
|
//|
|
||||||
|
STATIC mp_obj_t wifi_radio_ping(mp_obj_t self_in, mp_obj_t ip_address) {
|
||||||
|
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
|
common_hal_wifi_radio_ping(self, ip_address);
|
||||||
|
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_ping_obj, 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_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_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_ip_address), MP_ROM_PTR(&wifi_radio_ip_address_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) },
|
||||||
|
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_ping), MP_ROM_PTR(&wifi_radio_ping_obj) },
|
||||||
|
};
|
||||||
|
|
||||||
|
STATIC MP_DEFINE_CONST_DICT(wifi_radio_locals_dict, wifi_radio_locals_dict_table);
|
||||||
|
|
||||||
|
const mp_obj_type_t wifi_radio_type = {
|
||||||
|
.base = { &mp_type_type },
|
||||||
|
.name = MP_QSTR_Radio,
|
||||||
|
.locals_dict = (mp_obj_t)&wifi_radio_locals_dict,
|
||||||
|
};
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_RADIO_H
|
||||||
|
#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_RADIO_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "common-hal/wifi/Radio.h"
|
||||||
|
|
||||||
|
#include "py/objstr.h"
|
||||||
|
|
||||||
|
const mp_obj_type_t wifi_radio_type;
|
||||||
|
|
||||||
|
extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self);
|
||||||
|
extern void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled);
|
||||||
|
|
||||||
|
extern mp_obj_t common_hal_wifi_radio_get_mac_address(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 bool common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, mp_float_t timeout);
|
||||||
|
|
||||||
|
extern mp_obj_t common_hal_wifi_radio_get_ip_address(wifi_radio_obj_t *self);
|
||||||
|
|
||||||
|
extern mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address);
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_RADIO_H
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "py/objexcept.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
|
#include "shared-bindings/wifi/__init__.h"
|
||||||
|
#include "shared-bindings/wifi/Network.h"
|
||||||
|
#include "shared-bindings/wifi/Radio.h"
|
||||||
|
|
||||||
|
//| """
|
||||||
|
//| The `wifi` module provides necessary low-level functionality for managing wifi
|
||||||
|
//| wifi connections. Use `socketpool` for communicating over the network.
|
||||||
|
//|
|
||||||
|
//| .. attribute:: radio
|
||||||
|
//|
|
||||||
|
//| Wifi radio used to manage both station and AP modes.
|
||||||
|
//| This object is the sole instance of `wifi.Radio`."""
|
||||||
|
//|
|
||||||
|
|
||||||
|
|
||||||
|
// Called when wifi is imported.
|
||||||
|
STATIC mp_obj_t wifi___init__(void) {
|
||||||
|
common_hal_wifi_init();
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
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) },
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
{ 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) },
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
STATIC MP_DEFINE_CONST_DICT(wifi_module_globals, wifi_module_globals_table);
|
||||||
|
|
||||||
|
|
||||||
|
const mp_obj_module_t wifi_module = {
|
||||||
|
.base = { &mp_type_module },
|
||||||
|
.globals = (mp_obj_dict_t*)&wifi_module_globals,
|
||||||
|
};
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI___INIT___H
|
||||||
|
#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI___INIT___H
|
||||||
|
|
||||||
|
#include "py/objlist.h"
|
||||||
|
|
||||||
|
#include "shared-bindings/wifi/Radio.h"
|
||||||
|
|
||||||
|
extern wifi_radio_obj_t common_hal_wifi_radio_obj;
|
||||||
|
|
||||||
|
void common_hal_wifi_init(void);
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI___INIT___H
|
Loading…
Reference in New Issue