BIG COMMIT
This commit is contained in:
parent
dfbc2c2209
commit
629e905914
108 changed files with 14873 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
wifi_config.h
|
||||
|
||||
#### UNITY
|
||||
|
||||
/[Ll]ibrary/
|
||||
|
|
7
.vscode/arduino.json
vendored
Normal file
7
.vscode/arduino.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"configuration": "JTAGAdapter=bridge,PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=1,EventsCore=1,DebugLevel=none,EraseFlash=none",
|
||||
"board": "esp32:esp32:esp32",
|
||||
"port": "/dev/ttyUSB0",
|
||||
"programmer": "esptool",
|
||||
"sketch": "braille_xr.ino"
|
||||
}
|
584
.vscode/c_cpp_properties.json
vendored
Normal file
584
.vscode/c_cpp_properties.json
vendored
Normal file
|
@ -0,0 +1,584 @@
|
|||
{
|
||||
"version": 4,
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Arduino",
|
||||
"compilerPath": "/home/spatialfree/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-g++",
|
||||
"compilerArgs": [
|
||||
"-mlongcalls",
|
||||
"-Wno-frame-address",
|
||||
"-ffunction-sections",
|
||||
"-fdata-sections",
|
||||
"-Wno-error=unused-function",
|
||||
"-Wno-error=unused-variable",
|
||||
"-Wno-error=deprecated-declarations",
|
||||
"-Wno-unused-parameter",
|
||||
"-Wno-sign-compare",
|
||||
"-freorder-blocks",
|
||||
"-Wwrite-strings",
|
||||
"-fstack-protector",
|
||||
"-fstrict-volatile-bitfields",
|
||||
"-Wno-error=unused-but-set-variable",
|
||||
"-fno-jump-tables",
|
||||
"-fno-tree-switch-conversion",
|
||||
"-std=gnu++11",
|
||||
"-fexceptions",
|
||||
"-fno-rtti"
|
||||
],
|
||||
"intelliSenseMode": "gcc-x64",
|
||||
"includePath": [
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/newlib/platform_include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/freertos/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/freertos/include/esp_additions/freertos",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/freertos/port/xtensa/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/freertos/include/esp_additions",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_hw_support/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_hw_support/include/soc",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_hw_support/include/soc/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_hw_support/port/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_hw_support/port/esp32/private_include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/heap/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/log/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/lwip/include/apps",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/lwip/include/apps/sntp",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/lwip/lwip/src/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/lwip/port/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/lwip/port/esp32/include/arch",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/soc/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/soc/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/soc/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/hal/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/hal/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/hal/platform_port/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_rom/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_rom/include/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_rom/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_common/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_system/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_system/port/soc",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_system/port/public_compat",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/xtensa/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/xtensa/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/driver/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/driver/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_pm/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_ringbuf/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/efuse/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/efuse/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/vfs/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_wifi/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_event/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_netif/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_eth/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/tcpip_adapter/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_phy/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_phy/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_ipc/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/app_trace/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_timer/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/mbedtls/port/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/mbedtls/mbedtls/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/mbedtls/esp_crt_bundle/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/app_update/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/spi_flash/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bootloader_support/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/nvs_flash/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/pthread/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_gdbstub/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_gdbstub/xtensa",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_gdbstub/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espcoredump/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espcoredump/include/port/xtensa",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/wpa_supplicant/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/wpa_supplicant/port/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/wpa_supplicant/esp_supplicant/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/ieee802154/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/console",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/asio/asio/asio/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/asio/port/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/common/osi/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/include/esp32/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/common/api/include/api",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/common/btc/profile/esp/blufi/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/common/btc/profile/esp/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/host/bluedroid/api/include/api",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_common/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_common/tinycrypt/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/storage",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/btc/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_models/common/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_models/client/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_models/server/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/api/core/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/api/models/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/bt/esp_ble_mesh/api",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/cbor/port/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/unity/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/unity/unity/src",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/cmock/CMock/src",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/coap/port/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/coap/libcoap/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/nghttp/port/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/nghttp/nghttp2/lib/includes",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-tls",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-tls/esp-tls-crypto",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_adc_cal/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_hid/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/tcp_transport/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_http_client/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_http_server/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_https_ota/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_https_server/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_lcd/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_lcd/interface",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/protobuf-c/protobuf-c",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/protocomm/include/common",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/protocomm/include/security",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/protocomm/include/transports",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/mdns/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_local_ctrl/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/sdmmc/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_serial_slave_link/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_websocket_client/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/expat/expat/expat/lib",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/expat/port/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/wear_levelling/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/fatfs/diskio",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/fatfs/vfs",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/fatfs/src",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/freemodbus/freemodbus/common/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/idf_test/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/idf_test/include/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/jsmn/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/json/cJSON",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/libsodium/libsodium/src/libsodium/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/libsodium/port_include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/mqtt/esp-mqtt/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/openssl/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/perfmon/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/spiffs/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/ulp/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/wifi_provisioning/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/rmaker_common/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_diagnostics/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/rtc_store/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_insights/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/json_parser/upstream/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/json_parser/upstream",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/json_generator/upstream",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_schedule/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp_secure_cert_mgr/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_rainmaker/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/gpio_button/button/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/qrcode/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/ws2812_led",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp_littlefs/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include/tool",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include/typedef",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include/image",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include/math",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include/nn",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include/layer",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include/detect",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp-dl/include/model_zoo",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp32-camera/driver/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/esp32-camera/conversions/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/dotprod/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/support/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/support/mem/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/windows/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/windows/hann/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/windows/blackman/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/windows/blackman_harris/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/windows/blackman_nuttall/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/windows/nuttall/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/windows/flat_top/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/iir/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/fir/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/math/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/math/add/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/math/sub/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/math/mul/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/math/addc/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/math/mulc/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/math/sqrt/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/matrix/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/fft/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/dct/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/conv/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/common/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/kalman/ekf/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/espressif__esp-dsp/modules/kalman/ekf_imu13states/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/fb_gfx/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/qio_qspi/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/variants/esp32",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/libraries/WiFi/src",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/libraries/AsyncUDP/src",
|
||||
"/home/spatialfree/Arduino/libraries/ESP32Servo/src",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/xtensa-esp32-elf/include/c++/8.4.0",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/xtensa-esp32-elf/include/c++/8.4.0/xtensa-esp32-elf",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/xtensa-esp32-elf/include/c++/8.4.0/backward",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/lib/gcc/xtensa-esp32-elf/8.4.0/include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/lib/gcc/xtensa-esp32-elf/8.4.0/include-fixed",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/xtensa-esp32-elf/sys-include",
|
||||
"/home/spatialfree/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/xtensa-esp32-elf/include"
|
||||
],
|
||||
"forcedInclude": [
|
||||
"/home/spatialfree/.arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/Arduino.h"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++11",
|
||||
"defines": [
|
||||
"HAVE_CONFIG_H",
|
||||
"MBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\"",
|
||||
"UNITY_INCLUDE_CONFIG_H",
|
||||
"WITH_POSIX",
|
||||
"_GNU_SOURCE",
|
||||
"IDF_VER=\"v4.4.5\"",
|
||||
"ESP_PLATFORM",
|
||||
"_POSIX_READER_WRITER_LOCKS",
|
||||
"F_CPU=240000000L",
|
||||
"ARDUINO=10607",
|
||||
"ARDUINO_ESP32_DEV",
|
||||
"ARDUINO_ARCH_ESP32",
|
||||
"ARDUINO_BOARD=\"ESP32_DEV\"",
|
||||
"ARDUINO_VARIANT=\"esp32\"",
|
||||
"ARDUINO_PARTITION_default",
|
||||
"ESP32",
|
||||
"CORE_DEBUG_LEVEL=0",
|
||||
"ARDUINO_RUNNING_CORE=1",
|
||||
"ARDUINO_EVENT_RUNNING_CORE=1",
|
||||
"ARDUINO_USB_CDC_ON_BOOT=0",
|
||||
"__DBL_MIN_EXP__=(-1021)",
|
||||
"__FLT32X_MAX_EXP__=1024",
|
||||
"__cpp_attributes=200809",
|
||||
"__UINT_LEAST16_MAX__=0xffff",
|
||||
"__ATOMIC_ACQUIRE=2",
|
||||
"__FLT_MIN__=1.1754943508222875e-38F",
|
||||
"__GCC_IEC_559_COMPLEX=0",
|
||||
"__cpp_aggregate_nsdmi=201304",
|
||||
"__UINT_LEAST8_TYPE__=unsigned char",
|
||||
"__INTMAX_C(c)=c ## LL",
|
||||
"__CHAR_BIT__=8",
|
||||
"__UINT8_MAX__=0xff",
|
||||
"__WINT_MAX__=0xffffffffU",
|
||||
"__FLT32_MIN_EXP__=(-125)",
|
||||
"__cpp_static_assert=200410",
|
||||
"__ORDER_LITTLE_ENDIAN__=1234",
|
||||
"__SIZE_MAX__=0xffffffffU",
|
||||
"__WCHAR_MAX__=0xffff",
|
||||
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1=1",
|
||||
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2=1",
|
||||
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4=1",
|
||||
"__DBL_DENORM_MIN__=double(4.9406564584124654e-324L)",
|
||||
"__GCC_ATOMIC_CHAR_LOCK_FREE=2",
|
||||
"__GCC_IEC_559=0",
|
||||
"__FLT32X_DECIMAL_DIG__=17",
|
||||
"__FLT_EVAL_METHOD__=0",
|
||||
"__cpp_binary_literals=201304",
|
||||
"__FLT64_DECIMAL_DIG__=17",
|
||||
"__GCC_ATOMIC_CHAR32_T_LOCK_FREE=2",
|
||||
"__cpp_variadic_templates=200704",
|
||||
"__UINT_FAST64_MAX__=0xffffffffffffffffULL",
|
||||
"__SIG_ATOMIC_TYPE__=int",
|
||||
"__DBL_MIN_10_EXP__=(-307)",
|
||||
"__FINITE_MATH_ONLY__=0",
|
||||
"__cpp_variable_templates=201304",
|
||||
"__GNUC_PATCHLEVEL__=0",
|
||||
"__FLT32_HAS_DENORM__=1",
|
||||
"__UINT_FAST8_MAX__=0xffffffffU",
|
||||
"__has_include(STR)=__has_include__(STR)",
|
||||
"__DEC64_MAX_EXP__=385",
|
||||
"__INT8_C(c)=c",
|
||||
"__INT_LEAST8_WIDTH__=8",
|
||||
"__UINT_LEAST64_MAX__=0xffffffffffffffffULL",
|
||||
"__SHRT_MAX__=0x7fff",
|
||||
"__LDBL_MAX__=1.7976931348623157e+308L",
|
||||
"__UINT_LEAST8_MAX__=0xff",
|
||||
"__GCC_ATOMIC_BOOL_LOCK_FREE=2",
|
||||
"__UINTMAX_TYPE__=long long unsigned int",
|
||||
"__DEC32_EPSILON__=1E-6DF",
|
||||
"__FLT_EVAL_METHOD_TS_18661_3__=0",
|
||||
"__CHAR_UNSIGNED__=1",
|
||||
"__UINT32_MAX__=0xffffffffU",
|
||||
"__GXX_EXPERIMENTAL_CXX0X__=1",
|
||||
"__LDBL_MAX_EXP__=1024",
|
||||
"__WINT_MIN__=0U",
|
||||
"__INT_LEAST16_WIDTH__=16",
|
||||
"__SCHAR_MAX__=0x7f",
|
||||
"__WCHAR_MIN__=0",
|
||||
"__INT64_C(c)=c ## LL",
|
||||
"__DBL_DIG__=15",
|
||||
"__GCC_ATOMIC_POINTER_LOCK_FREE=2",
|
||||
"__SIZEOF_INT__=4",
|
||||
"__SIZEOF_POINTER__=4",
|
||||
"__GCC_ATOMIC_CHAR16_T_LOCK_FREE=2",
|
||||
"__USER_LABEL_PREFIX__",
|
||||
"__STDC_HOSTED__=1",
|
||||
"__LDBL_HAS_INFINITY__=1",
|
||||
"__XTENSA_EL__=1",
|
||||
"__FLT32_DIG__=6",
|
||||
"__FLT_EPSILON__=1.1920928955078125e-7F",
|
||||
"__GXX_WEAK__=1",
|
||||
"__SHRT_WIDTH__=16",
|
||||
"__LDBL_MIN__=2.2250738585072014e-308L",
|
||||
"__DEC32_MAX__=9.999999E96DF",
|
||||
"__cpp_threadsafe_static_init=200806",
|
||||
"__FLT32X_HAS_INFINITY__=1",
|
||||
"__INT32_MAX__=0x7fffffff",
|
||||
"__INT_WIDTH__=32",
|
||||
"__SIZEOF_LONG__=4",
|
||||
"__UINT16_C(c)=c",
|
||||
"__PTRDIFF_WIDTH__=32",
|
||||
"__DECIMAL_DIG__=17",
|
||||
"__FLT64_EPSILON__=2.2204460492503131e-16F64",
|
||||
"__INTMAX_WIDTH__=64",
|
||||
"__FLT64_MIN_EXP__=(-1021)",
|
||||
"__has_include_next(STR)=__has_include_next__(STR)",
|
||||
"__LDBL_HAS_QUIET_NAN__=1",
|
||||
"__FLT64_MANT_DIG__=53",
|
||||
"__GNUC__=8",
|
||||
"__GXX_RTTI=1",
|
||||
"__cpp_delegating_constructors=200604",
|
||||
"__FLT_HAS_DENORM__=1",
|
||||
"__SIZEOF_LONG_DOUBLE__=8",
|
||||
"__BIGGEST_ALIGNMENT__=16",
|
||||
"__STDC_UTF_16__=1",
|
||||
"__FLT64_MAX_10_EXP__=308",
|
||||
"__FLT32_HAS_INFINITY__=1",
|
||||
"__DBL_MAX__=double(1.7976931348623157e+308L)",
|
||||
"__cpp_raw_strings=200710",
|
||||
"__INT_FAST32_MAX__=0x7fffffff",
|
||||
"__DBL_HAS_INFINITY__=1",
|
||||
"__DEC32_MIN_EXP__=(-94)",
|
||||
"__INTPTR_WIDTH__=32",
|
||||
"__FLT32X_HAS_DENORM__=1",
|
||||
"__INT_FAST16_TYPE__=int",
|
||||
"__LDBL_HAS_DENORM__=1",
|
||||
"__cplusplus=201402L",
|
||||
"__cpp_ref_qualifiers=200710",
|
||||
"__DEC128_MAX__=9.999999999999999999999999999999999E6144DL",
|
||||
"__INT_LEAST32_MAX__=0x7fffffff",
|
||||
"__DEC32_MIN__=1E-95DF",
|
||||
"__DEPRECATED=1",
|
||||
"__cpp_rvalue_references=200610",
|
||||
"__DBL_MAX_EXP__=1024",
|
||||
"__WCHAR_WIDTH__=16",
|
||||
"__FLT32_MAX__=3.4028234663852886e+38F32",
|
||||
"__DEC128_EPSILON__=1E-33DL",
|
||||
"__PTRDIFF_MAX__=0x7fffffff",
|
||||
"__FLT32_HAS_QUIET_NAN__=1",
|
||||
"__GNUG__=8",
|
||||
"__LONG_LONG_MAX__=0x7fffffffffffffffLL",
|
||||
"__SIZEOF_SIZE_T__=4",
|
||||
"__cpp_rvalue_reference=200610",
|
||||
"__cpp_nsdmi=200809",
|
||||
"__SIZEOF_WINT_T__=4",
|
||||
"__LONG_LONG_WIDTH__=64",
|
||||
"__cpp_initializer_lists=200806",
|
||||
"__FLT32_MAX_EXP__=128",
|
||||
"__cpp_hex_float=201603",
|
||||
"__GXX_ABI_VERSION=1013",
|
||||
"__FLT_MIN_EXP__=(-125)",
|
||||
"__cpp_lambdas=200907",
|
||||
"__INT_FAST64_TYPE__=long long int",
|
||||
"__FP_FAST_FMAF=1",
|
||||
"__FLT64_DENORM_MIN__=4.9406564584124654e-324F64",
|
||||
"__DBL_MIN__=double(2.2250738585072014e-308L)",
|
||||
"__FLT32X_EPSILON__=2.2204460492503131e-16F32x",
|
||||
"__FLT64_MIN_10_EXP__=(-307)",
|
||||
"__DEC128_MIN__=1E-6143DL",
|
||||
"__REGISTER_PREFIX__",
|
||||
"__UINT16_MAX__=0xffff",
|
||||
"__DBL_HAS_DENORM__=1",
|
||||
"__FLT32_MIN__=1.1754943508222875e-38F32",
|
||||
"__UINT8_TYPE__=unsigned char",
|
||||
"__NO_INLINE__=1",
|
||||
"__FLT_MANT_DIG__=24",
|
||||
"__LDBL_DECIMAL_DIG__=17",
|
||||
"__VERSION__=\"8.4.0\"",
|
||||
"__UINT64_C(c)=c ## ULL",
|
||||
"__cpp_unicode_characters=200704",
|
||||
"__cpp_decltype_auto=201304",
|
||||
"__GCC_ATOMIC_INT_LOCK_FREE=2",
|
||||
"__FLT32_MANT_DIG__=24",
|
||||
"__FLOAT_WORD_ORDER__=__ORDER_LITTLE_ENDIAN__",
|
||||
"__SCHAR_WIDTH__=8",
|
||||
"__INT32_C(c)=c",
|
||||
"__DEC64_EPSILON__=1E-15DD",
|
||||
"__ORDER_PDP_ENDIAN__=3412",
|
||||
"__DEC128_MIN_EXP__=(-6142)",
|
||||
"__FLT32_MAX_10_EXP__=38",
|
||||
"__INT_FAST32_TYPE__=int",
|
||||
"__UINT_LEAST16_TYPE__=short unsigned int",
|
||||
"__INT16_MAX__=0x7fff",
|
||||
"__cpp_rtti=199711",
|
||||
"__SIZE_TYPE__=unsigned int",
|
||||
"__UINT64_MAX__=0xffffffffffffffffULL",
|
||||
"__INT8_TYPE__=signed char",
|
||||
"__cpp_digit_separators=201309",
|
||||
"__ELF__=1",
|
||||
"__xtensa__=1",
|
||||
"__FLT_RADIX__=2",
|
||||
"__INT_LEAST16_TYPE__=short int",
|
||||
"__LDBL_EPSILON__=2.2204460492503131e-16L",
|
||||
"__UINTMAX_C(c)=c ## ULL",
|
||||
"__SIG_ATOMIC_MAX__=0x7fffffff",
|
||||
"__GCC_ATOMIC_WCHAR_T_LOCK_FREE=2",
|
||||
"__SIZEOF_PTRDIFF_T__=4",
|
||||
"__FLT32X_MANT_DIG__=53",
|
||||
"__FLT32X_MIN_EXP__=(-1021)",
|
||||
"__DEC32_SUBNORMAL_MIN__=0.000001E-95DF",
|
||||
"__INT_FAST16_MAX__=0x7fffffff",
|
||||
"__FLT64_DIG__=15",
|
||||
"__UINT_FAST32_MAX__=0xffffffffU",
|
||||
"__UINT_LEAST64_TYPE__=long long unsigned int",
|
||||
"__FLT_HAS_QUIET_NAN__=1",
|
||||
"__FLT_MAX_10_EXP__=38",
|
||||
"__LONG_MAX__=0x7fffffffL",
|
||||
"__DEC128_SUBNORMAL_MIN__=0.000000000000000000000000000000001E-6143DL",
|
||||
"__FLT_HAS_INFINITY__=1",
|
||||
"__cpp_unicode_literals=200710",
|
||||
"__UINT_FAST16_TYPE__=unsigned int",
|
||||
"__DEC64_MAX__=9.999999999999999E384DD",
|
||||
"__INT_FAST32_WIDTH__=32",
|
||||
"__CHAR16_TYPE__=short unsigned int",
|
||||
"__PRAGMA_REDEFINE_EXTNAME=1",
|
||||
"__SIZE_WIDTH__=32",
|
||||
"__INT_LEAST16_MAX__=0x7fff",
|
||||
"__DEC64_MANT_DIG__=16",
|
||||
"__INT64_MAX__=0x7fffffffffffffffLL",
|
||||
"__UINT_LEAST32_MAX__=0xffffffffU",
|
||||
"__FLT32_DENORM_MIN__=1.4012984643248171e-45F32",
|
||||
"__GCC_ATOMIC_LONG_LOCK_FREE=2",
|
||||
"__SIG_ATOMIC_WIDTH__=32",
|
||||
"__INT_LEAST64_TYPE__=long long int",
|
||||
"__INT16_TYPE__=short int",
|
||||
"__INT_LEAST8_TYPE__=signed char",
|
||||
"__DEC32_MAX_EXP__=97",
|
||||
"__INT_FAST8_MAX__=0x7fffffff",
|
||||
"__INTPTR_MAX__=0x7fffffff",
|
||||
"__cpp_sized_deallocation=201309",
|
||||
"__cpp_range_based_for=200907",
|
||||
"__FLT64_HAS_QUIET_NAN__=1",
|
||||
"__FLT32_MIN_10_EXP__=(-37)",
|
||||
"__EXCEPTIONS=1",
|
||||
"__LDBL_MANT_DIG__=53",
|
||||
"__DBL_HAS_QUIET_NAN__=1",
|
||||
"__FLT64_HAS_INFINITY__=1",
|
||||
"__SIG_ATOMIC_MIN__=(-__SIG_ATOMIC_MAX__ - 1)",
|
||||
"__cpp_return_type_deduction=201304",
|
||||
"__INTPTR_TYPE__=int",
|
||||
"__UINT16_TYPE__=short unsigned int",
|
||||
"__WCHAR_TYPE__=short unsigned int",
|
||||
"__SIZEOF_FLOAT__=4",
|
||||
"__UINTPTR_MAX__=0xffffffffU",
|
||||
"__INT_FAST64_WIDTH__=64",
|
||||
"__DEC64_MIN_EXP__=(-382)",
|
||||
"__cpp_decltype=200707",
|
||||
"__FLT32_DECIMAL_DIG__=9",
|
||||
"__INT_FAST64_MAX__=0x7fffffffffffffffLL",
|
||||
"__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1",
|
||||
"__FLT_DIG__=6",
|
||||
"__UINT_FAST64_TYPE__=long long unsigned int",
|
||||
"__INT_MAX__=0x7fffffff",
|
||||
"__INT64_TYPE__=long long int",
|
||||
"__FLT_MAX_EXP__=128",
|
||||
"__DBL_MANT_DIG__=53",
|
||||
"__cpp_inheriting_constructors=201511",
|
||||
"__INT_LEAST64_MAX__=0x7fffffffffffffffLL",
|
||||
"__FP_FAST_FMAF32=1",
|
||||
"__DEC64_MIN__=1E-383DD",
|
||||
"__WINT_TYPE__=unsigned int",
|
||||
"__UINT_LEAST32_TYPE__=unsigned int",
|
||||
"__SIZEOF_SHORT__=2",
|
||||
"__LDBL_MIN_EXP__=(-1021)",
|
||||
"__FLT64_MAX__=1.7976931348623157e+308F64",
|
||||
"__WINT_WIDTH__=32",
|
||||
"__INT_LEAST8_MAX__=0x7f",
|
||||
"__FLT32X_MAX_10_EXP__=308",
|
||||
"__WCHAR_UNSIGNED__=1",
|
||||
"__LDBL_MAX_10_EXP__=308",
|
||||
"__ATOMIC_RELAXED=0",
|
||||
"__DBL_EPSILON__=double(2.2204460492503131e-16L)",
|
||||
"__XTENSA_WINDOWED_ABI__=1",
|
||||
"__UINT8_C(c)=c",
|
||||
"__FLT64_MAX_EXP__=1024",
|
||||
"__INT_LEAST32_TYPE__=int",
|
||||
"__SIZEOF_WCHAR_T__=2",
|
||||
"__INT_FAST8_TYPE__=int",
|
||||
"__GNUC_STDC_INLINE__=1",
|
||||
"__FLT64_HAS_DENORM__=1",
|
||||
"__FLT32_EPSILON__=1.1920928955078125e-7F32",
|
||||
"__DBL_DECIMAL_DIG__=17",
|
||||
"__STDC_UTF_32__=1",
|
||||
"__INT_FAST8_WIDTH__=32",
|
||||
"__DEC_EVAL_METHOD__=2",
|
||||
"__FLT32X_MAX__=1.7976931348623157e+308F32x",
|
||||
"__XTENSA__=1",
|
||||
"__ORDER_BIG_ENDIAN__=4321",
|
||||
"__cpp_runtime_arrays=198712",
|
||||
"__UINT64_TYPE__=long long unsigned int",
|
||||
"__UINT32_C(c)=c ## U",
|
||||
"__INTMAX_MAX__=0x7fffffffffffffffLL",
|
||||
"__cpp_alias_templates=200704",
|
||||
"__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__",
|
||||
"__FLT_DENORM_MIN__=1.4012984643248171e-45F",
|
||||
"__INT8_MAX__=0x7f",
|
||||
"__LONG_WIDTH__=32",
|
||||
"__UINT_FAST32_TYPE__=unsigned int",
|
||||
"__CHAR32_TYPE__=unsigned int",
|
||||
"__FLT_MAX__=3.4028234663852886e+38F",
|
||||
"__cpp_constexpr=201304",
|
||||
"__INT32_TYPE__=int",
|
||||
"__SIZEOF_DOUBLE__=8",
|
||||
"__cpp_exceptions=199711",
|
||||
"__FLT_MIN_10_EXP__=(-37)",
|
||||
"__FLT64_MIN__=2.2250738585072014e-308F64",
|
||||
"__INT_LEAST32_WIDTH__=32",
|
||||
"__INTMAX_TYPE__=long long int",
|
||||
"__DEC128_MAX_EXP__=6145",
|
||||
"__FLT32X_HAS_QUIET_NAN__=1",
|
||||
"__ATOMIC_CONSUME=1",
|
||||
"__GNUC_MINOR__=4",
|
||||
"__INT_FAST16_WIDTH__=32",
|
||||
"__UINTMAX_MAX__=0xffffffffffffffffULL",
|
||||
"__DEC32_MANT_DIG__=7",
|
||||
"__FLT32X_DENORM_MIN__=4.9406564584124654e-324F32x",
|
||||
"__DBL_MAX_10_EXP__=308",
|
||||
"__LDBL_DENORM_MIN__=4.9406564584124654e-324L",
|
||||
"__INT16_C(c)=c",
|
||||
"__cpp_generic_lambdas=201304",
|
||||
"__STDC__=1",
|
||||
"__FLT32X_DIG__=15",
|
||||
"__PTRDIFF_TYPE__=int",
|
||||
"__ATOMIC_SEQ_CST=5",
|
||||
"__UINT32_TYPE__=unsigned int",
|
||||
"__FLT32X_MIN_10_EXP__=(-307)",
|
||||
"__UINTPTR_TYPE__=unsigned int",
|
||||
"__DEC64_SUBNORMAL_MIN__=0.000000000000001E-383DD",
|
||||
"__DEC128_MANT_DIG__=34",
|
||||
"__LDBL_MIN_10_EXP__=(-307)",
|
||||
"__SIZEOF_LONG_LONG__=8",
|
||||
"__cpp_user_defined_literals=200809",
|
||||
"__GCC_ATOMIC_LLONG_LOCK_FREE=1",
|
||||
"__FLT32X_MIN__=2.2250738585072014e-308F32x",
|
||||
"__LDBL_DIG__=15",
|
||||
"__FLT_DECIMAL_DIG__=9",
|
||||
"__UINT_FAST16_MAX__=0xffffffffU",
|
||||
"__GCC_ATOMIC_SHORT_LOCK_FREE=2",
|
||||
"__INT_LEAST64_WIDTH__=64",
|
||||
"__UINT_FAST8_TYPE__=unsigned int",
|
||||
"__cpp_init_captures=201304",
|
||||
"__ATOMIC_ACQ_REL=4",
|
||||
"__ATOMIC_RELEASE=3",
|
||||
"USBCON"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -3,7 +3,11 @@ refreshable braille display for rendering and input
|
|||
|
||||
## Setup
|
||||
|
||||
Tell everyone what your project needs in order to run. This might involve many components or software. Maybe some cool libraries?
|
||||
!!! edit _wifi_config.h to setup your wifi credentials first
|
||||
```shell
|
||||
# + on linux make sure you can r/w
|
||||
sudo chmod 666 /dev/ttyUSB0
|
||||
```
|
||||
|
||||
### Hardware Required
|
||||
|
||||
|
@ -19,7 +23,7 @@ Tell everyone what your project needs in order to run. This might involve many c
|
|||
## Run
|
||||
|
||||
```shell
|
||||
run()
|
||||
# ...
|
||||
```
|
||||
|
||||
## Shout-Outs
|
||||
|
|
4
_wifi_config.h
Normal file
4
_wifi_config.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
// PLEASE RENAME THIS FILE TO wifi_config.h
|
||||
// once you've filled in your wifi credentials
|
||||
const char* ssid = "your_ssid";
|
||||
const char* pass = "your_password";
|
207
braille_xr.ino
Normal file
207
braille_xr.ino
Normal file
|
@ -0,0 +1,207 @@
|
|||
#include "WiFi.h"
|
||||
#include "AsyncUDP.h"
|
||||
#include "wifi_config.h"
|
||||
AsyncUDP udp;
|
||||
|
||||
int bindex = 0;
|
||||
|
||||
#include <ESP32Servo.h>
|
||||
struct ServoPin {
|
||||
Servo servo;
|
||||
int pin;
|
||||
};
|
||||
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33
|
||||
ServoPin servos[6] = {
|
||||
{Servo(), 4 }, {Servo(), 16},
|
||||
{Servo(), 17}, {Servo(), 5 },
|
||||
{Servo(), 18}, {Servo(), 19}
|
||||
};
|
||||
|
||||
// braille alphabet
|
||||
// example:
|
||||
// *1 = 180 degrees
|
||||
// a (0 index)
|
||||
// 10
|
||||
// 00
|
||||
// 00
|
||||
// braille alphabet array
|
||||
struct BrailleChar {
|
||||
int servoStates[6];
|
||||
};
|
||||
BrailleChar brailleAlphabet[26] = {
|
||||
{{1, 0,
|
||||
0, 0,
|
||||
0, 0
|
||||
}}, // a
|
||||
{{1, 0,
|
||||
1, 0,
|
||||
0, 0
|
||||
}}, // b
|
||||
{{1, 1,
|
||||
0, 0,
|
||||
0, 0
|
||||
}}, // c
|
||||
{{1, 1,
|
||||
0, 1,
|
||||
0, 0
|
||||
}}, // d
|
||||
{{1, 0,
|
||||
0, 1,
|
||||
0, 0
|
||||
}}, // e
|
||||
{{1, 1,
|
||||
1, 0,
|
||||
0, 0
|
||||
}}, // f
|
||||
{{1, 1,
|
||||
1, 1,
|
||||
0, 0
|
||||
}}, // g
|
||||
{{1, 0,
|
||||
1, 1,
|
||||
0, 0
|
||||
}}, // h
|
||||
{{0, 1,
|
||||
1, 0,
|
||||
0, 0
|
||||
}}, // i
|
||||
{{0, 1,
|
||||
1, 1,
|
||||
0, 0
|
||||
}}, // j
|
||||
{{1, 0,
|
||||
0, 0,
|
||||
1, 0
|
||||
}}, // k
|
||||
{{1, 0,
|
||||
1, 0,
|
||||
1, 0
|
||||
}}, // l
|
||||
{{1, 1,
|
||||
0, 0,
|
||||
1, 0
|
||||
}}, // m
|
||||
{{1, 1,
|
||||
0, 1,
|
||||
1, 0
|
||||
}}, // n
|
||||
{{1, 0,
|
||||
0, 1,
|
||||
1, 0
|
||||
}}, // o
|
||||
{{1, 1,
|
||||
1, 0,
|
||||
1, 0
|
||||
}}, // p
|
||||
{{1, 1,
|
||||
1, 1,
|
||||
1, 0
|
||||
}}, // q
|
||||
{{1, 0,
|
||||
1, 1,
|
||||
1, 0
|
||||
}}, // r
|
||||
{{0, 1,
|
||||
1, 0,
|
||||
1, 0
|
||||
}}, // s
|
||||
{{0, 1,
|
||||
1, 1,
|
||||
1, 0
|
||||
}}, // t
|
||||
{{1, 0,
|
||||
0, 0,
|
||||
1, 1
|
||||
}}, // u
|
||||
{{1, 0,
|
||||
1, 0,
|
||||
1, 1
|
||||
}}, // v
|
||||
{{0, 1,
|
||||
1, 1,
|
||||
0, 1
|
||||
}}, // w
|
||||
{{1, 1,
|
||||
0, 0,
|
||||
1, 1
|
||||
}}, // x
|
||||
{{1, 1,
|
||||
0, 1,
|
||||
1, 1
|
||||
}}, // y
|
||||
{{1, 0,
|
||||
0, 1,
|
||||
1, 1
|
||||
}} // z
|
||||
};
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, pass);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
// and print status
|
||||
Serial.println(WiFi.status());
|
||||
}
|
||||
if (udp.listen(1234)) {
|
||||
Serial.print("UDP Listening on IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
udp.onPacket([](AsyncUDPPacket packet) {
|
||||
Serial.print(", Length: ");
|
||||
Serial.print(packet.length()); //dlzka packetu
|
||||
Serial.print(", Data: ");
|
||||
// Serial.write(packet.data(), packet.length());
|
||||
// that is printing a character instead of a number
|
||||
// so do this instead
|
||||
// Serial.print(packet.data()[0]);
|
||||
// and set the bindex to that value
|
||||
bindex = packet.data()[0];
|
||||
Serial.print(bindex);
|
||||
Serial.println();
|
||||
uint32_t receivedData;
|
||||
memcpy(&receivedData, packet.data(), sizeof(receivedData));
|
||||
packet.printf("Got %u bytes of data", packet.length());
|
||||
});
|
||||
}
|
||||
|
||||
// Allow allocation of all timers
|
||||
ESP32PWM::allocateTimer(0);
|
||||
ESP32PWM::allocateTimer(1);
|
||||
ESP32PWM::allocateTimer(2);
|
||||
ESP32PWM::allocateTimer(3);
|
||||
// myservo.setPeriodHertz(50); // standard 50 hz servo
|
||||
// myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin x to the servo object
|
||||
// using default min/max of 1000us and 2000us
|
||||
// different servos may require different min/max settings
|
||||
// for an accurate 0 to 180 sweep
|
||||
for (int i = 0; i < 6; i++) {
|
||||
servos[i].servo.setPeriodHertz(50);
|
||||
servos[i].servo.attach(servos[i].pin, 1000, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// delay(1000);
|
||||
// udp.broadcast("Anyone here?");
|
||||
|
||||
// for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
|
||||
// // in steps of 1 degree
|
||||
// myservo.write(pos); // tell servo to go to position in variable 'pos'
|
||||
// delay(15); // waits 15ms for the servo to reach the position
|
||||
// }
|
||||
// for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
|
||||
// myservo.write(pos); // tell servo to go to position in variable 'pos'
|
||||
// delay(15); // waits 15ms for the servo to reach the position
|
||||
// }
|
||||
|
||||
// myservo.write(bindex);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
servos[i].servo.write(bindex);
|
||||
}
|
||||
}
|
15
debug.cfg
Normal file
15
debug.cfg
Normal file
|
@ -0,0 +1,15 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#
|
||||
# Example OpenOCD configuration file for ESP32 connected via ESP USB Bridge board
|
||||
#
|
||||
# For example, OpenOCD can be started for ESP32 debugging on
|
||||
#
|
||||
# openocd -f board/esp32-bridge.cfg
|
||||
#
|
||||
|
||||
# Source the JTAG interface configuration file
|
||||
source [find interface/esp_usb_bridge.cfg]
|
||||
# ESP32 chip id defined in the idf esp_chip_model_t
|
||||
espusbjtag chip_id 1
|
||||
# Source the ESP32 configuration file
|
||||
source [find target/esp32.cfg]
|
19
debug_custom.json
Normal file
19
debug_custom.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name":"Arduino on ESP32",
|
||||
"toolchainPrefix":"xtensa-esp32-elf",
|
||||
"svdFile":"debug.svd",
|
||||
"request":"attach",
|
||||
"postAttachCommands":[
|
||||
"set remote hardware-watchpoint-limit 2",
|
||||
"monitor reset halt",
|
||||
"monitor gdb_sync",
|
||||
"thb setup",
|
||||
"c"
|
||||
],
|
||||
"overrideRestartCommands":[
|
||||
"monitor reset halt",
|
||||
"monitor gdb_sync",
|
||||
"thb setup",
|
||||
"c"
|
||||
]
|
||||
}
|
0
libs/AsyncUDP/examples/AsyncUDPClient/.skip.esp32h2
Normal file
0
libs/AsyncUDP/examples/AsyncUDPClient/.skip.esp32h2
Normal file
51
libs/AsyncUDP/examples/AsyncUDPClient/AsyncUDPClient.ino
Normal file
51
libs/AsyncUDP/examples/AsyncUDPClient/AsyncUDPClient.ino
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "WiFi.h"
|
||||
#include "AsyncUDP.h"
|
||||
|
||||
const char * ssid = "***********";
|
||||
const char * password = "***********";
|
||||
|
||||
AsyncUDP udp;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.println("WiFi Failed");
|
||||
while(1) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
if(udp.connect(IPAddress(192,168,1,100), 1234)) {
|
||||
Serial.println("UDP connected");
|
||||
udp.onPacket([](AsyncUDPPacket packet) {
|
||||
Serial.print("UDP Packet Type: ");
|
||||
Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
|
||||
Serial.print(", From: ");
|
||||
Serial.print(packet.remoteIP());
|
||||
Serial.print(":");
|
||||
Serial.print(packet.remotePort());
|
||||
Serial.print(", To: ");
|
||||
Serial.print(packet.localIP());
|
||||
Serial.print(":");
|
||||
Serial.print(packet.localPort());
|
||||
Serial.print(", Length: ");
|
||||
Serial.print(packet.length());
|
||||
Serial.print(", Data: ");
|
||||
Serial.write(packet.data(), packet.length());
|
||||
Serial.println();
|
||||
//reply to the client
|
||||
packet.printf("Got %u bytes of data", packet.length());
|
||||
});
|
||||
//Send unicast
|
||||
udp.print("Hello Server!");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
//Send broadcast on port 1234
|
||||
udp.broadcastTo("Anyone here?", 1234);
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#include "WiFi.h"
|
||||
#include "AsyncUDP.h"
|
||||
|
||||
const char * ssid = "***********";
|
||||
const char * password = "***********";
|
||||
|
||||
AsyncUDP udp;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.println("WiFi Failed");
|
||||
while(1) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
if(udp.listenMulticast(IPAddress(239,1,2,3), 1234)) {
|
||||
Serial.print("UDP Listening on IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
udp.onPacket([](AsyncUDPPacket packet) {
|
||||
Serial.print("UDP Packet Type: ");
|
||||
Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
|
||||
Serial.print(", From: ");
|
||||
Serial.print(packet.remoteIP());
|
||||
Serial.print(":");
|
||||
Serial.print(packet.remotePort());
|
||||
Serial.print(", To: ");
|
||||
Serial.print(packet.localIP());
|
||||
Serial.print(":");
|
||||
Serial.print(packet.localPort());
|
||||
Serial.print(", Length: ");
|
||||
Serial.print(packet.length());
|
||||
Serial.print(", Data: ");
|
||||
Serial.write(packet.data(), packet.length());
|
||||
Serial.println();
|
||||
//reply to the client
|
||||
packet.printf("Got %u bytes of data", packet.length());
|
||||
});
|
||||
//Send multicast
|
||||
udp.print("Hello!");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
//Send multicast
|
||||
udp.print("Anyone here?");
|
||||
}
|
0
libs/AsyncUDP/examples/AsyncUDPServer/.skip.esp32h2
Normal file
0
libs/AsyncUDP/examples/AsyncUDPServer/.skip.esp32h2
Normal file
50
libs/AsyncUDP/examples/AsyncUDPServer/AsyncUDPServer.ino
Normal file
50
libs/AsyncUDP/examples/AsyncUDPServer/AsyncUDPServer.ino
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "WiFi.h"
|
||||
#include "AsyncUDP.h"
|
||||
|
||||
const char * ssid = "***********";
|
||||
const char * password = "***********";
|
||||
|
||||
AsyncUDP udp;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.println("WiFi Failed");
|
||||
while(1) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
if(udp.listen(1234)) {
|
||||
Serial.print("UDP Listening on IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
udp.onPacket([](AsyncUDPPacket packet) {
|
||||
Serial.print("UDP Packet Type: ");
|
||||
Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
|
||||
Serial.print(", From: ");
|
||||
Serial.print(packet.remoteIP());
|
||||
Serial.print(":");
|
||||
Serial.print(packet.remotePort());
|
||||
Serial.print(", To: ");
|
||||
Serial.print(packet.localIP());
|
||||
Serial.print(":");
|
||||
Serial.print(packet.localPort());
|
||||
Serial.print(", Length: ");
|
||||
Serial.print(packet.length());
|
||||
Serial.print(", Data: ");
|
||||
Serial.write(packet.data(), packet.length());
|
||||
Serial.println();
|
||||
//reply to the client
|
||||
packet.printf("Got %u bytes of data", packet.length());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
//Send broadcast
|
||||
udp.broadcast("Anyone here?");
|
||||
}
|
33
libs/AsyncUDP/keywords.txt
Normal file
33
libs/AsyncUDP/keywords.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For Ultrasound
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
AsyncUDP KEYWORD1
|
||||
AsyncUDPPacket KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
connect KEYWORD2
|
||||
connected KEYWORD2
|
||||
listen KEYWORD2
|
||||
listenMulticast KEYWORD2
|
||||
close KEYWORD2
|
||||
write KEYWORD2
|
||||
broadcast KEYWORD2
|
||||
onPacket KEYWORD2
|
||||
data KEYWORD2
|
||||
length KEYWORD2
|
||||
localIP KEYWORD2
|
||||
localPort KEYWORD2
|
||||
remoteIP KEYWORD2
|
||||
remotePort KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
9
libs/AsyncUDP/library.properties
Normal file
9
libs/AsyncUDP/library.properties
Normal file
|
@ -0,0 +1,9 @@
|
|||
name=ESP32 Async UDP
|
||||
version=2.0.0
|
||||
author=Me-No-Dev
|
||||
maintainer=Me-No-Dev
|
||||
sentence=Async UDP Library for ESP32
|
||||
paragraph=Async UDP Library for ESP32
|
||||
category=Other
|
||||
url=https://github.com/me-no-dev/ESPAsyncUDP
|
||||
architectures=*
|
879
libs/AsyncUDP/src/AsyncUDP.cpp
Normal file
879
libs/AsyncUDP/src/AsyncUDP.cpp
Normal file
|
@ -0,0 +1,879 @@
|
|||
#include "Arduino.h"
|
||||
#include "AsyncUDP.h"
|
||||
|
||||
extern "C" {
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/mld6.h"
|
||||
#include "lwip/prot/ethernet.h"
|
||||
#include <esp_err.h>
|
||||
#include <esp_wifi.h>
|
||||
}
|
||||
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
|
||||
static const char * netif_ifkeys[TCPIP_ADAPTER_IF_MAX] = {
|
||||
"WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF", "PPP_DEF"
|
||||
};
|
||||
|
||||
static esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void ** netif){
|
||||
*netif = NULL;
|
||||
if(tcpip_if < TCPIP_ADAPTER_IF_MAX){
|
||||
esp_netif_t *esp_netif = esp_netif_get_handle_from_ifkey(netif_ifkeys[tcpip_if]);
|
||||
if(esp_netif == NULL){
|
||||
return ESP_FAIL;
|
||||
}
|
||||
int netif_index = esp_netif_get_netif_impl_index(esp_netif);
|
||||
if(netif_index < 0){
|
||||
return ESP_FAIL;
|
||||
}
|
||||
*netif = (void*)netif_get_by_index(netif_index);
|
||||
} else {
|
||||
*netif = netif_default;
|
||||
}
|
||||
return (*netif != NULL)?ESP_OK:ESP_FAIL;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
struct tcpip_api_call_data call;
|
||||
udp_pcb * pcb;
|
||||
const ip_addr_t *addr;
|
||||
uint16_t port;
|
||||
struct pbuf *pb;
|
||||
struct netif *netif;
|
||||
err_t err;
|
||||
} udp_api_call_t;
|
||||
|
||||
static err_t _udp_connect_api(struct tcpip_api_call_data *api_call_msg){
|
||||
udp_api_call_t * msg = (udp_api_call_t *)api_call_msg;
|
||||
msg->err = udp_connect(msg->pcb, msg->addr, msg->port);
|
||||
return msg->err;
|
||||
}
|
||||
|
||||
static err_t _udp_connect(struct udp_pcb *pcb, const ip_addr_t *addr, u16_t port){
|
||||
udp_api_call_t msg;
|
||||
msg.pcb = pcb;
|
||||
msg.addr = addr;
|
||||
msg.port = port;
|
||||
tcpip_api_call(_udp_connect_api, (struct tcpip_api_call_data*)&msg);
|
||||
return msg.err;
|
||||
}
|
||||
|
||||
static err_t _udp_disconnect_api(struct tcpip_api_call_data *api_call_msg){
|
||||
udp_api_call_t * msg = (udp_api_call_t *)api_call_msg;
|
||||
msg->err = 0;
|
||||
udp_disconnect(msg->pcb);
|
||||
return msg->err;
|
||||
}
|
||||
|
||||
static void _udp_disconnect(struct udp_pcb *pcb){
|
||||
udp_api_call_t msg;
|
||||
msg.pcb = pcb;
|
||||
tcpip_api_call(_udp_disconnect_api, (struct tcpip_api_call_data*)&msg);
|
||||
}
|
||||
|
||||
static err_t _udp_remove_api(struct tcpip_api_call_data *api_call_msg){
|
||||
udp_api_call_t * msg = (udp_api_call_t *)api_call_msg;
|
||||
msg->err = 0;
|
||||
udp_remove(msg->pcb);
|
||||
return msg->err;
|
||||
}
|
||||
|
||||
static void _udp_remove(struct udp_pcb *pcb){
|
||||
udp_api_call_t msg;
|
||||
msg.pcb = pcb;
|
||||
tcpip_api_call(_udp_remove_api, (struct tcpip_api_call_data*)&msg);
|
||||
}
|
||||
|
||||
static err_t _udp_bind_api(struct tcpip_api_call_data *api_call_msg){
|
||||
udp_api_call_t * msg = (udp_api_call_t *)api_call_msg;
|
||||
msg->err = udp_bind(msg->pcb, msg->addr, msg->port);
|
||||
return msg->err;
|
||||
}
|
||||
|
||||
static err_t _udp_bind(struct udp_pcb *pcb, const ip_addr_t *addr, u16_t port){
|
||||
udp_api_call_t msg;
|
||||
msg.pcb = pcb;
|
||||
msg.addr = addr;
|
||||
msg.port = port;
|
||||
tcpip_api_call(_udp_bind_api, (struct tcpip_api_call_data*)&msg);
|
||||
return msg.err;
|
||||
}
|
||||
|
||||
static err_t _udp_sendto_api(struct tcpip_api_call_data *api_call_msg){
|
||||
udp_api_call_t * msg = (udp_api_call_t *)api_call_msg;
|
||||
msg->err = udp_sendto(msg->pcb, msg->pb, msg->addr, msg->port);
|
||||
return msg->err;
|
||||
}
|
||||
|
||||
static err_t _udp_sendto(struct udp_pcb *pcb, struct pbuf *pb, const ip_addr_t *addr, u16_t port){
|
||||
udp_api_call_t msg;
|
||||
msg.pcb = pcb;
|
||||
msg.addr = addr;
|
||||
msg.port = port;
|
||||
msg.pb = pb;
|
||||
tcpip_api_call(_udp_sendto_api, (struct tcpip_api_call_data*)&msg);
|
||||
return msg.err;
|
||||
}
|
||||
|
||||
static err_t _udp_sendto_if_api(struct tcpip_api_call_data *api_call_msg){
|
||||
udp_api_call_t * msg = (udp_api_call_t *)api_call_msg;
|
||||
msg->err = udp_sendto_if(msg->pcb, msg->pb, msg->addr, msg->port, msg->netif);
|
||||
return msg->err;
|
||||
}
|
||||
|
||||
static err_t _udp_sendto_if(struct udp_pcb *pcb, struct pbuf *pb, const ip_addr_t *addr, u16_t port, struct netif *netif){
|
||||
udp_api_call_t msg;
|
||||
msg.pcb = pcb;
|
||||
msg.addr = addr;
|
||||
msg.port = port;
|
||||
msg.pb = pb;
|
||||
msg.netif = netif;
|
||||
tcpip_api_call(_udp_sendto_if_api, (struct tcpip_api_call_data*)&msg);
|
||||
return msg.err;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
void *arg;
|
||||
udp_pcb *pcb;
|
||||
pbuf *pb;
|
||||
const ip_addr_t *addr;
|
||||
uint16_t port;
|
||||
struct netif * netif;
|
||||
} lwip_event_packet_t;
|
||||
|
||||
static QueueHandle_t _udp_queue;
|
||||
static volatile TaskHandle_t _udp_task_handle = NULL;
|
||||
|
||||
static void _udp_task(void *pvParameters){
|
||||
lwip_event_packet_t * e = NULL;
|
||||
for (;;) {
|
||||
if(xQueueReceive(_udp_queue, &e, portMAX_DELAY) == pdTRUE){
|
||||
if(!e->pb){
|
||||
free((void*)(e));
|
||||
continue;
|
||||
}
|
||||
AsyncUDP::_s_recv(e->arg, e->pcb, e->pb, e->addr, e->port, e->netif);
|
||||
free((void*)(e));
|
||||
}
|
||||
}
|
||||
_udp_task_handle = NULL;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static bool _udp_task_start(){
|
||||
if(!_udp_queue){
|
||||
_udp_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *));
|
||||
if(!_udp_queue){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!_udp_task_handle){
|
||||
xTaskCreateUniversal(_udp_task, "async_udp", 4096, NULL, CONFIG_ARDUINO_UDP_TASK_PRIORITY, (TaskHandle_t*)&_udp_task_handle, CONFIG_ARDUINO_UDP_RUNNING_CORE);
|
||||
if(!_udp_task_handle){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _udp_task_post(void *arg, udp_pcb *pcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif *netif)
|
||||
{
|
||||
if(!_udp_task_handle || !_udp_queue){
|
||||
return false;
|
||||
}
|
||||
lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t));
|
||||
if(!e){
|
||||
return false;
|
||||
}
|
||||
e->arg = arg;
|
||||
e->pcb = pcb;
|
||||
e->pb = pb;
|
||||
e->addr = addr;
|
||||
e->port = port;
|
||||
e->netif = netif;
|
||||
if (xQueueSend(_udp_queue, &e, portMAX_DELAY) != pdPASS) {
|
||||
free((void*)(e));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _udp_recv(void *arg, udp_pcb *pcb, pbuf *pb, const ip_addr_t *addr, uint16_t port)
|
||||
{
|
||||
while(pb != NULL) {
|
||||
pbuf * this_pb = pb;
|
||||
pb = pb->next;
|
||||
this_pb->next = NULL;
|
||||
if(!_udp_task_post(arg, pcb, this_pb, addr, port, ip_current_input_netif())){
|
||||
pbuf_free(this_pb);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
static bool _udp_task_stop(){
|
||||
if(!_udp_task_post(NULL, NULL, NULL, NULL, 0, NULL)){
|
||||
return false;
|
||||
}
|
||||
while(_udp_task_handle){
|
||||
vTaskDelay(10);
|
||||
}
|
||||
|
||||
lwip_event_packet_t * e;
|
||||
while (xQueueReceive(_udp_queue, &e, 0) == pdTRUE) {
|
||||
if(e->pb){
|
||||
pbuf_free(e->pb);
|
||||
}
|
||||
free((void*)(e));
|
||||
}
|
||||
vQueueDelete(_udp_queue);
|
||||
_udp_queue = NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define UDP_MUTEX_LOCK() //xSemaphoreTake(_lock, portMAX_DELAY)
|
||||
#define UDP_MUTEX_UNLOCK() //xSemaphoreGive(_lock)
|
||||
|
||||
|
||||
AsyncUDPMessage::AsyncUDPMessage(size_t size)
|
||||
{
|
||||
_index = 0;
|
||||
if(size > CONFIG_TCP_MSS) {
|
||||
size = CONFIG_TCP_MSS;
|
||||
}
|
||||
_size = size;
|
||||
_buffer = (uint8_t *)malloc(size);
|
||||
}
|
||||
|
||||
AsyncUDPMessage::~AsyncUDPMessage()
|
||||
{
|
||||
if(_buffer) {
|
||||
free(_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
size_t AsyncUDPMessage::write(const uint8_t *data, size_t len)
|
||||
{
|
||||
if(_buffer == NULL) {
|
||||
return 0;
|
||||
}
|
||||
size_t s = space();
|
||||
if(len > s) {
|
||||
len = s;
|
||||
}
|
||||
memcpy(_buffer + _index, data, len);
|
||||
_index += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t AsyncUDPMessage::write(uint8_t data)
|
||||
{
|
||||
return write(&data, 1);
|
||||
}
|
||||
|
||||
size_t AsyncUDPMessage::space()
|
||||
{
|
||||
if(_buffer == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return _size - _index;
|
||||
}
|
||||
|
||||
uint8_t * AsyncUDPMessage::data()
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
size_t AsyncUDPMessage::length()
|
||||
{
|
||||
return _index;
|
||||
}
|
||||
|
||||
void AsyncUDPMessage::flush()
|
||||
{
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet){
|
||||
_udp = packet._udp;
|
||||
_pb = packet._pb;
|
||||
_if = packet._if;
|
||||
_data = packet._data;
|
||||
_len = packet._len;
|
||||
_index = 0;
|
||||
|
||||
memcpy(&_remoteIp, &packet._remoteIp, sizeof(ip_addr_t));
|
||||
memcpy(&_localIp, &packet._localIp, sizeof(ip_addr_t));
|
||||
_localPort = packet._localPort;
|
||||
_remotePort = packet._remotePort;
|
||||
memcpy(_remoteMac, packet._remoteMac, 6);
|
||||
|
||||
pbuf_ref(_pb);
|
||||
}
|
||||
|
||||
AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, uint16_t rport, struct netif * ntif)
|
||||
{
|
||||
_udp = udp;
|
||||
_pb = pb;
|
||||
_if = TCPIP_ADAPTER_IF_MAX;
|
||||
_data = (uint8_t*)(pb->payload);
|
||||
_len = pb->len;
|
||||
_index = 0;
|
||||
|
||||
pbuf_ref(_pb);
|
||||
|
||||
//memcpy(&_remoteIp, raddr, sizeof(ip_addr_t));
|
||||
_remoteIp.type = raddr->type;
|
||||
_localIp.type = _remoteIp.type;
|
||||
|
||||
eth_hdr* eth = NULL;
|
||||
udp_hdr* udphdr = (udp_hdr *)(_data - UDP_HLEN);
|
||||
_localPort = ntohs(udphdr->dest);
|
||||
_remotePort = ntohs(udphdr->src);
|
||||
|
||||
if (_remoteIp.type == IPADDR_TYPE_V4) {
|
||||
eth = (eth_hdr *)(_data - UDP_HLEN - IP_HLEN - SIZEOF_ETH_HDR);
|
||||
struct ip_hdr * iphdr = (struct ip_hdr *)(_data - UDP_HLEN - IP_HLEN);
|
||||
_localIp.u_addr.ip4.addr = iphdr->dest.addr;
|
||||
_remoteIp.u_addr.ip4.addr = iphdr->src.addr;
|
||||
} else {
|
||||
eth = (eth_hdr *)(_data - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR);
|
||||
struct ip6_hdr * ip6hdr = (struct ip6_hdr *)(_data - UDP_HLEN - IP6_HLEN);
|
||||
memcpy(&_localIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->dest.addr, 16);
|
||||
memcpy(&_remoteIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->src.addr, 16);
|
||||
}
|
||||
memcpy(_remoteMac, eth->src.addr, 6);
|
||||
|
||||
struct netif * netif = NULL;
|
||||
void * nif = NULL;
|
||||
int i;
|
||||
for (i=0; i<TCPIP_ADAPTER_IF_MAX; i++) {
|
||||
tcpip_adapter_get_netif ((tcpip_adapter_if_t)i, &nif);
|
||||
netif = (struct netif *)nif;
|
||||
if (netif && netif == ntif) {
|
||||
_if = (tcpip_adapter_if_t)i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AsyncUDPPacket::~AsyncUDPPacket()
|
||||
{
|
||||
pbuf_free(_pb);
|
||||
}
|
||||
|
||||
uint8_t * AsyncUDPPacket::data()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
size_t AsyncUDPPacket::length()
|
||||
{
|
||||
return _len;
|
||||
}
|
||||
|
||||
int AsyncUDPPacket::available(){
|
||||
return _len - _index;
|
||||
}
|
||||
|
||||
size_t AsyncUDPPacket::read(uint8_t *data, size_t len){
|
||||
size_t i;
|
||||
size_t a = _len - _index;
|
||||
if(len > a){
|
||||
len = a;
|
||||
}
|
||||
for(i=0;i<len;i++){
|
||||
data[i] = read();
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int AsyncUDPPacket::read(){
|
||||
if(_index < _len){
|
||||
return _data[_index++];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int AsyncUDPPacket::peek(){
|
||||
if(_index < _len){
|
||||
return _data[_index];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void AsyncUDPPacket::flush(){
|
||||
_index = _len;
|
||||
}
|
||||
|
||||
tcpip_adapter_if_t AsyncUDPPacket::interface()
|
||||
{
|
||||
return _if;
|
||||
}
|
||||
|
||||
IPAddress AsyncUDPPacket::localIP()
|
||||
{
|
||||
if(_localIp.type != IPADDR_TYPE_V4){
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(_localIp.u_addr.ip4.addr);
|
||||
}
|
||||
|
||||
IPAddress AsyncUDPPacket::localIPv6()
|
||||
{
|
||||
if(_localIp.type != IPADDR_TYPE_V6){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
return IPAddress(IPv6, (const uint8_t *)_localIp.u_addr.ip6.addr, _localIp.u_addr.ip6.zone);
|
||||
}
|
||||
|
||||
uint16_t AsyncUDPPacket::localPort()
|
||||
{
|
||||
return _localPort;
|
||||
}
|
||||
|
||||
IPAddress AsyncUDPPacket::remoteIP()
|
||||
{
|
||||
if(_remoteIp.type != IPADDR_TYPE_V4){
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(_remoteIp.u_addr.ip4.addr);
|
||||
}
|
||||
|
||||
IPAddress AsyncUDPPacket::remoteIPv6()
|
||||
{
|
||||
if(_remoteIp.type != IPADDR_TYPE_V6){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
return IPAddress(IPv6, (const uint8_t *)_remoteIp.u_addr.ip6.addr, _remoteIp.u_addr.ip6.zone);
|
||||
}
|
||||
|
||||
uint16_t AsyncUDPPacket::remotePort()
|
||||
{
|
||||
return _remotePort;
|
||||
}
|
||||
|
||||
void AsyncUDPPacket::remoteMac(uint8_t * mac)
|
||||
{
|
||||
memcpy(mac, _remoteMac, 6);
|
||||
}
|
||||
|
||||
bool AsyncUDPPacket::isIPv6()
|
||||
{
|
||||
return _localIp.type == IPADDR_TYPE_V6;
|
||||
}
|
||||
|
||||
bool AsyncUDPPacket::isBroadcast()
|
||||
{
|
||||
if(_localIp.type == IPADDR_TYPE_V6){
|
||||
return false;
|
||||
}
|
||||
uint32_t ip = _localIp.u_addr.ip4.addr;
|
||||
return ip == 0xFFFFFFFF || ip == 0 || (ip & 0xFF000000) == 0xFF000000;
|
||||
}
|
||||
|
||||
bool AsyncUDPPacket::isMulticast()
|
||||
{
|
||||
return ip_addr_ismulticast(&(_localIp));
|
||||
}
|
||||
|
||||
size_t AsyncUDPPacket::write(const uint8_t *data, size_t len)
|
||||
{
|
||||
if(!data){
|
||||
return 0;
|
||||
}
|
||||
return _udp->writeTo(data, len, &_remoteIp, _remotePort, _if);
|
||||
}
|
||||
|
||||
size_t AsyncUDPPacket::write(uint8_t data)
|
||||
{
|
||||
return write(&data, 1);
|
||||
}
|
||||
|
||||
size_t AsyncUDPPacket::send(AsyncUDPMessage &message)
|
||||
{
|
||||
return write(message.data(), message.length());
|
||||
}
|
||||
|
||||
bool AsyncUDP::_init(){
|
||||
if(_pcb){
|
||||
return true;
|
||||
}
|
||||
_pcb = udp_new();
|
||||
if(!_pcb){
|
||||
return false;
|
||||
}
|
||||
//_lock = xSemaphoreCreateMutex();
|
||||
udp_recv(_pcb, &_udp_recv, (void *) this);
|
||||
return true;
|
||||
}
|
||||
|
||||
AsyncUDP::AsyncUDP()
|
||||
{
|
||||
_pcb = NULL;
|
||||
_connected = false;
|
||||
_lastErr = ERR_OK;
|
||||
_handler = NULL;
|
||||
}
|
||||
|
||||
AsyncUDP::~AsyncUDP()
|
||||
{
|
||||
close();
|
||||
UDP_MUTEX_LOCK();
|
||||
udp_recv(_pcb, NULL, NULL);
|
||||
_udp_remove(_pcb);
|
||||
_pcb = NULL;
|
||||
UDP_MUTEX_UNLOCK();
|
||||
//vSemaphoreDelete(_lock);
|
||||
}
|
||||
|
||||
void AsyncUDP::close()
|
||||
{
|
||||
UDP_MUTEX_LOCK();
|
||||
if(_pcb != NULL) {
|
||||
if(_connected) {
|
||||
_udp_disconnect(_pcb);
|
||||
}
|
||||
_connected = false;
|
||||
//todo: unjoin multicast group
|
||||
}
|
||||
UDP_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
bool AsyncUDP::connect(const ip_addr_t *addr, uint16_t port)
|
||||
{
|
||||
if(!_udp_task_start()){
|
||||
log_e("failed to start task");
|
||||
return false;
|
||||
}
|
||||
if(!_init()) {
|
||||
return false;
|
||||
}
|
||||
close();
|
||||
UDP_MUTEX_LOCK();
|
||||
_lastErr = _udp_connect(_pcb, addr, port);
|
||||
if(_lastErr != ERR_OK) {
|
||||
UDP_MUTEX_UNLOCK();
|
||||
return false;
|
||||
}
|
||||
_connected = true;
|
||||
UDP_MUTEX_UNLOCK();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AsyncUDP::listen(const ip_addr_t *addr, uint16_t port)
|
||||
{
|
||||
if(!_udp_task_start()){
|
||||
log_e("failed to start task");
|
||||
return false;
|
||||
}
|
||||
if(!_init()) {
|
||||
return false;
|
||||
}
|
||||
close();
|
||||
if(addr){
|
||||
IP_SET_TYPE_VAL(_pcb->local_ip, addr->type);
|
||||
IP_SET_TYPE_VAL(_pcb->remote_ip, addr->type);
|
||||
}
|
||||
UDP_MUTEX_LOCK();
|
||||
if(_udp_bind(_pcb, addr, port) != ERR_OK) {
|
||||
UDP_MUTEX_UNLOCK();
|
||||
return false;
|
||||
}
|
||||
_connected = true;
|
||||
UDP_MUTEX_UNLOCK();
|
||||
return true;
|
||||
}
|
||||
|
||||
static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX)
|
||||
{
|
||||
struct netif * netif = NULL;
|
||||
if(tcpip_if < TCPIP_ADAPTER_IF_MAX){
|
||||
void * nif = NULL;
|
||||
esp_err_t err = tcpip_adapter_get_netif(tcpip_if, &nif);
|
||||
if (err) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
netif = (struct netif *)nif;
|
||||
|
||||
if (addr->type == IPADDR_TYPE_V4) {
|
||||
if(join){
|
||||
if (igmp_joingroup_netif(netif, (const ip4_addr *)&(addr->u_addr.ip4))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else {
|
||||
if (igmp_leavegroup_netif(netif, (const ip4_addr *)&(addr->u_addr.ip4))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(join){
|
||||
if (mld6_joingroup_netif(netif, &(addr->u_addr.ip6))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else {
|
||||
if (mld6_leavegroup_netif(netif, &(addr->u_addr.ip6))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (addr->type == IPADDR_TYPE_V4) {
|
||||
if(join){
|
||||
if (igmp_joingroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr.ip4))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else {
|
||||
if (igmp_leavegroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr.ip4))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(join){
|
||||
if (mld6_joingroup((const ip6_addr *)IP6_ADDR_ANY, &(addr->u_addr.ip6))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else {
|
||||
if (mld6_leavegroup((const ip6_addr *)IP6_ADDR_ANY, &(addr->u_addr.ip6))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
if(!ip_addr_ismulticast(addr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (joinMulticastGroup(addr, true, tcpip_if)!= ERR_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!listen(NULL, port)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UDP_MUTEX_LOCK();
|
||||
_pcb->mcast_ttl = ttl;
|
||||
_pcb->remote_port = port;
|
||||
ip_addr_copy(_pcb->remote_ip, *addr);
|
||||
//ip_addr_copy(_pcb->remote_ip, ip_addr_any_type);
|
||||
UDP_MUTEX_UNLOCK();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t AsyncUDP::writeTo(const uint8_t * data, size_t len, const ip_addr_t * addr, uint16_t port, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
if(!_pcb) {
|
||||
UDP_MUTEX_LOCK();
|
||||
_pcb = udp_new();
|
||||
UDP_MUTEX_UNLOCK();
|
||||
if(_pcb == NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(len > CONFIG_TCP_MSS) {
|
||||
len = CONFIG_TCP_MSS;
|
||||
}
|
||||
_lastErr = ERR_OK;
|
||||
pbuf* pbt = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
||||
if(pbt != NULL) {
|
||||
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
|
||||
memcpy(dst, data, len);
|
||||
UDP_MUTEX_LOCK();
|
||||
if(tcpip_if < TCPIP_ADAPTER_IF_MAX){
|
||||
void * nif = NULL;
|
||||
tcpip_adapter_get_netif((tcpip_adapter_if_t)tcpip_if, &nif);
|
||||
if(!nif){
|
||||
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
|
||||
} else {
|
||||
_lastErr = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif);
|
||||
}
|
||||
} else {
|
||||
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
|
||||
}
|
||||
UDP_MUTEX_UNLOCK();
|
||||
pbuf_free(pbt);
|
||||
if(_lastErr < ERR_OK) {
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif)
|
||||
{
|
||||
while(pb != NULL) {
|
||||
pbuf * this_pb = pb;
|
||||
pb = pb->next;
|
||||
this_pb->next = NULL;
|
||||
if(_handler) {
|
||||
AsyncUDPPacket packet(this, this_pb, addr, port, netif);
|
||||
_handler(packet);
|
||||
}
|
||||
pbuf_free(this_pb);
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncUDP::_s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif * netif)
|
||||
{
|
||||
reinterpret_cast<AsyncUDP*>(arg)->_recv(upcb, p, addr, port, netif);
|
||||
}
|
||||
|
||||
bool AsyncUDP::listen(uint16_t port)
|
||||
{
|
||||
return listen(IP_ANY_TYPE, port);
|
||||
}
|
||||
|
||||
bool AsyncUDP::listen(const IPAddress addr, uint16_t port)
|
||||
{
|
||||
ip_addr_t laddr;
|
||||
addr.to_ip_addr_t(&laddr);
|
||||
return listen(&laddr, port);
|
||||
}
|
||||
|
||||
bool AsyncUDP::listenMulticast(const IPAddress addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
ip_addr_t laddr;
|
||||
addr.to_ip_addr_t(&laddr);
|
||||
return listenMulticast(&laddr, port, ttl, tcpip_if);
|
||||
}
|
||||
|
||||
bool AsyncUDP::connect(const IPAddress addr, uint16_t port)
|
||||
{
|
||||
ip_addr_t daddr;
|
||||
addr.to_ip_addr_t(&daddr);
|
||||
return connect(&daddr, port);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::writeTo(const uint8_t *data, size_t len, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
ip_addr_t daddr;
|
||||
addr.to_ip_addr_t(&daddr);
|
||||
return writeTo(data, len, &daddr, port, tcpip_if);
|
||||
}
|
||||
|
||||
IPAddress AsyncUDP::listenIP()
|
||||
{
|
||||
if(!_pcb || _pcb->remote_ip.type != IPADDR_TYPE_V4){
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(_pcb->remote_ip.u_addr.ip4.addr);
|
||||
}
|
||||
|
||||
IPAddress AsyncUDP::listenIPv6()
|
||||
{
|
||||
if(!_pcb || _pcb->remote_ip.type != IPADDR_TYPE_V6){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
return IPAddress(IPv6, (const uint8_t *)_pcb->remote_ip.u_addr.ip6.addr, _pcb->remote_ip.u_addr.ip6.zone);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::write(const uint8_t *data, size_t len)
|
||||
{
|
||||
return writeTo(data, len, &(_pcb->remote_ip), _pcb->remote_port);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::write(uint8_t data)
|
||||
{
|
||||
return write(&data, 1);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::broadcastTo(uint8_t *data, size_t len, uint16_t port, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
return writeTo(data, len, IP_ADDR_BROADCAST, port, tcpip_if);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::broadcastTo(const char * data, uint16_t port, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
return broadcastTo((uint8_t *)data, strlen(data), port, tcpip_if);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::broadcast(uint8_t *data, size_t len)
|
||||
{
|
||||
if(_pcb->local_port != 0) {
|
||||
return broadcastTo(data, len, _pcb->local_port);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t AsyncUDP::broadcast(const char * data)
|
||||
{
|
||||
return broadcast((uint8_t *)data, strlen(data));
|
||||
}
|
||||
|
||||
|
||||
size_t AsyncUDP::sendTo(AsyncUDPMessage &message, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
if(!message) {
|
||||
return 0;
|
||||
}
|
||||
return writeTo(message.data(), message.length(), addr, port, tcpip_if);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::sendTo(AsyncUDPMessage &message, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
if(!message) {
|
||||
return 0;
|
||||
}
|
||||
return writeTo(message.data(), message.length(), addr, port, tcpip_if);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::send(AsyncUDPMessage &message)
|
||||
{
|
||||
if(!message) {
|
||||
return 0;
|
||||
}
|
||||
return writeTo(message.data(), message.length(), &(_pcb->remote_ip), _pcb->remote_port);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::broadcastTo(AsyncUDPMessage &message, uint16_t port, tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
if(!message) {
|
||||
return 0;
|
||||
}
|
||||
return broadcastTo(message.data(), message.length(), port, tcpip_if);
|
||||
}
|
||||
|
||||
size_t AsyncUDP::broadcast(AsyncUDPMessage &message)
|
||||
{
|
||||
if(!message) {
|
||||
return 0;
|
||||
}
|
||||
return broadcast(message.data(), message.length());
|
||||
}
|
||||
|
||||
AsyncUDP::operator bool()
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
bool AsyncUDP::connected()
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
esp_err_t AsyncUDP::lastErr() {
|
||||
return _lastErr;
|
||||
}
|
||||
|
||||
void AsyncUDP::onPacket(AuPacketHandlerFunctionWithArg cb, void * arg)
|
||||
{
|
||||
onPacket(std::bind(cb, arg, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void AsyncUDP::onPacket(AuPacketHandlerFunction cb)
|
||||
{
|
||||
_handler = cb;
|
||||
}
|
159
libs/AsyncUDP/src/AsyncUDP.h
Normal file
159
libs/AsyncUDP/src/AsyncUDP.h
Normal file
|
@ -0,0 +1,159 @@
|
|||
#ifndef ESPASYNCUDP_H
|
||||
#define ESPASYNCUDP_H
|
||||
|
||||
#include "IPAddress.h"
|
||||
#include "Print.h"
|
||||
#include "Stream.h"
|
||||
#include <functional>
|
||||
extern "C" {
|
||||
#include "esp_netif.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
}
|
||||
|
||||
// This enum and it's uses are copied and adapted for compatibility from ESP-IDF 4-
|
||||
typedef enum {
|
||||
TCPIP_ADAPTER_IF_STA = 0, /**< Wi-Fi STA (station) interface */
|
||||
TCPIP_ADAPTER_IF_AP, /**< Wi-Fi soft-AP interface */
|
||||
TCPIP_ADAPTER_IF_ETH, /**< Ethernet interface */
|
||||
TCPIP_ADAPTER_IF_PPP, /**< PPP interface */
|
||||
TCPIP_ADAPTER_IF_MAX
|
||||
} tcpip_adapter_if_t;
|
||||
|
||||
class AsyncUDP;
|
||||
class AsyncUDPPacket;
|
||||
class AsyncUDPMessage;
|
||||
struct udp_pcb;
|
||||
struct pbuf;
|
||||
struct netif;
|
||||
|
||||
typedef std::function<void(AsyncUDPPacket& packet)> AuPacketHandlerFunction;
|
||||
typedef std::function<void(void * arg, AsyncUDPPacket& packet)> AuPacketHandlerFunctionWithArg;
|
||||
|
||||
class AsyncUDPMessage : public Print
|
||||
{
|
||||
protected:
|
||||
uint8_t *_buffer;
|
||||
size_t _index;
|
||||
size_t _size;
|
||||
public:
|
||||
AsyncUDPMessage(size_t size=CONFIG_TCP_MSS);
|
||||
virtual ~AsyncUDPMessage();
|
||||
size_t write(const uint8_t *data, size_t len);
|
||||
size_t write(uint8_t data);
|
||||
size_t space();
|
||||
uint8_t * data();
|
||||
size_t length();
|
||||
void flush();
|
||||
operator bool()
|
||||
{
|
||||
return _buffer != NULL;
|
||||
}
|
||||
};
|
||||
|
||||
class AsyncUDPPacket : public Stream
|
||||
{
|
||||
protected:
|
||||
AsyncUDP *_udp;
|
||||
pbuf *_pb;
|
||||
tcpip_adapter_if_t _if;
|
||||
ip_addr_t _localIp;
|
||||
uint16_t _localPort;
|
||||
ip_addr_t _remoteIp;
|
||||
uint16_t _remotePort;
|
||||
uint8_t _remoteMac[6];
|
||||
uint8_t *_data;
|
||||
size_t _len;
|
||||
size_t _index;
|
||||
public:
|
||||
AsyncUDPPacket(AsyncUDPPacket &packet);
|
||||
AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif);
|
||||
virtual ~AsyncUDPPacket();
|
||||
|
||||
uint8_t * data();
|
||||
size_t length();
|
||||
bool isBroadcast();
|
||||
bool isMulticast();
|
||||
bool isIPv6();
|
||||
|
||||
tcpip_adapter_if_t interface();
|
||||
|
||||
IPAddress localIP();
|
||||
IPAddress localIPv6();
|
||||
uint16_t localPort();
|
||||
IPAddress remoteIP();
|
||||
IPAddress remoteIPv6();
|
||||
uint16_t remotePort();
|
||||
void remoteMac(uint8_t * mac);
|
||||
|
||||
size_t send(AsyncUDPMessage &message);
|
||||
|
||||
int available();
|
||||
size_t read(uint8_t *data, size_t len);
|
||||
int read();
|
||||
int peek();
|
||||
void flush();
|
||||
|
||||
size_t write(const uint8_t *data, size_t len);
|
||||
size_t write(uint8_t data);
|
||||
};
|
||||
|
||||
class AsyncUDP : public Print
|
||||
{
|
||||
protected:
|
||||
udp_pcb *_pcb;
|
||||
//SemaphoreHandle_t _lock;
|
||||
bool _connected;
|
||||
esp_err_t _lastErr;
|
||||
AuPacketHandlerFunction _handler;
|
||||
|
||||
bool _init();
|
||||
void _recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif);
|
||||
|
||||
public:
|
||||
AsyncUDP();
|
||||
virtual ~AsyncUDP();
|
||||
|
||||
void onPacket(AuPacketHandlerFunctionWithArg cb, void * arg=NULL);
|
||||
void onPacket(AuPacketHandlerFunction cb);
|
||||
|
||||
bool listen(const ip_addr_t *addr, uint16_t port);
|
||||
bool listen(const IPAddress addr, uint16_t port);
|
||||
bool listen(uint16_t port);
|
||||
|
||||
bool listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl=1, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
bool listenMulticast(const IPAddress addr, uint16_t port, uint8_t ttl=1, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
|
||||
bool connect(const ip_addr_t *addr, uint16_t port);
|
||||
bool connect(const IPAddress addr, uint16_t port);
|
||||
|
||||
void close();
|
||||
|
||||
size_t writeTo(const uint8_t *data, size_t len, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
size_t writeTo(const uint8_t *data, size_t len, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
size_t write(const uint8_t *data, size_t len);
|
||||
size_t write(uint8_t data);
|
||||
|
||||
size_t broadcastTo(uint8_t *data, size_t len, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
size_t broadcastTo(const char * data, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
size_t broadcast(uint8_t *data, size_t len);
|
||||
size_t broadcast(const char * data);
|
||||
|
||||
size_t sendTo(AsyncUDPMessage &message, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
size_t sendTo(AsyncUDPMessage &message, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
size_t send(AsyncUDPMessage &message);
|
||||
|
||||
size_t broadcastTo(AsyncUDPMessage &message, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX);
|
||||
size_t broadcast(AsyncUDPMessage &message);
|
||||
|
||||
IPAddress listenIP();
|
||||
IPAddress listenIPv6();
|
||||
bool connected();
|
||||
esp_err_t lastErr();
|
||||
operator bool();
|
||||
|
||||
static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif * netif);
|
||||
};
|
||||
|
||||
#endif
|
32
libs/ESP32Servo/AddDoxygenToGHPages.sh
Normal file
32
libs/ESP32Servo/AddDoxygenToGHPages.sh
Normal file
|
@ -0,0 +1,32 @@
|
|||
#!/bin/bash
|
||||
|
||||
GITURL=$(git config --get remote.origin.url)
|
||||
|
||||
echo $GITURL
|
||||
|
||||
rm -rf html
|
||||
git clone $GITURL html
|
||||
cd html
|
||||
if ( git checkout origin/gh-pages -b gh-pages) then
|
||||
echo "Checked out $GITURL gh-pages"
|
||||
else
|
||||
echo "Creating out $GITURL gh-pages"
|
||||
git checkout origin/master -b gh-pages
|
||||
rm -r *
|
||||
echo "# A simple README file for the gh-pages branch" > README.md
|
||||
git add README.md
|
||||
git commit -m"Replaced gh-pages html with simple readme"
|
||||
git push -u origin gh-pages
|
||||
fi
|
||||
cd ..
|
||||
|
||||
doxygen doxy.doxyfile
|
||||
|
||||
cd html
|
||||
git add *
|
||||
git add search/*
|
||||
git commit -a -m"updating the doxygen"
|
||||
git push
|
||||
cd ..
|
||||
rm -rf html
|
||||
git checkout master
|
90
libs/ESP32Servo/README.md
Normal file
90
libs/ESP32Servo/README.md
Normal file
|
@ -0,0 +1,90 @@
|
|||
# Servo Library for ESP32
|
||||
|
||||
This library attempts to faithfully replicate the semantics of the
|
||||
Arduino Servo library (see http://www.arduino.cc/en/Reference/Servo)
|
||||
for the ESP32, with two (optional) additions. The two new functions
|
||||
expose the ability of the ESP32 PWM timers to vary timer width.
|
||||
# Documentation by Doxygen
|
||||
|
||||
[ESP32Servo Doxygen](https://madhephaestus.github.io/ESP32Servo/annotated.html)
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2017 John K. Bennett. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
## Library Description:
|
||||
```
|
||||
Servo - Class for manipulating servo motors connected to ESP32 pins.
|
||||
|
||||
int attach(pin ) - Attaches the given GPIO pin to the next free channel
|
||||
(channels that have previously been detached are used first),
|
||||
returns channel number or 0 if failure. All pin numbers are allowed,
|
||||
but only pins 2,4,12-19,21-23,25-27,32-33 are recommended.
|
||||
|
||||
int attach(pin, min, max ) - Attaches to a pin setting min and max
|
||||
values in microseconds; enforced minimum min is 500, enforced max
|
||||
is 2500. Other semantics are the same as attach().
|
||||
|
||||
void write () - Sets the servo angle in degrees; a value below 500 is
|
||||
treated as a value in degrees (0 to 180). These limit are enforced,
|
||||
i.e., values are constrained as follows:
|
||||
Value Becomes
|
||||
----- -------
|
||||
< 0 0
|
||||
0 - 180 value (treated as degrees)
|
||||
181 - 499 180
|
||||
500 - (min-1) min
|
||||
min-max (from attach or default) value (treated as microseconds)
|
||||
(max+1) - 2500 max
|
||||
|
||||
void writeMicroseconds() - Sets the servo pulse width in microseconds.
|
||||
min and max are enforced (see above).
|
||||
|
||||
int read() - Gets the last written servo pulse width as an angle between 0 and 180.
|
||||
|
||||
int readMicroseconds() - Gets the last written servo pulse width in microseconds.
|
||||
|
||||
bool attached() - Returns true if this servo instance is attached to a pin.
|
||||
|
||||
void detach() - Stops an the attached servo, frees the attached pin, and frees
|
||||
its channel for reuse.
|
||||
```
|
||||
|
||||
### **New ESP32-specific functions**
|
||||
|
||||
```
|
||||
setTimerWidth(value) - Sets the PWM timer width (must be 16-20) (ESP32 ONLY);
|
||||
as a side effect, the pulse width is recomputed.
|
||||
|
||||
int readTimerWidth() - Gets the PWM timer width (ESP32 ONLY)
|
||||
```
|
||||
|
||||
### Useful Defaults:
|
||||
|
||||
default min pulse width for attach(): 544us
|
||||
|
||||
default max pulse width for attach(): 2400us
|
||||
|
||||
default timer width 16 (if timer width is not set)
|
||||
|
||||
default pulse width 1500us (servos are initialized with this value)
|
||||
|
||||
MINIMUM pulse with: 500us
|
||||
|
||||
MAXIMUM pulse with: 2500us
|
||||
|
||||
MAXIMUM number of servos: 16 (this is the number of PWM channels in the ESP32)
|
2428
libs/ESP32Servo/doxy.doxyfile
Normal file
2428
libs/ESP32Servo/doxy.doxyfile
Normal file
File diff suppressed because it is too large
Load diff
85
libs/ESP32Servo/examples/Knob/Knob.ino
Normal file
85
libs/ESP32Servo/examples/Knob/Knob.ino
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
Controlling a servo position using a potentiometer (variable resistor)
|
||||
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
|
||||
|
||||
modified on 8 Nov 2013
|
||||
by Scott Fitzgerald
|
||||
|
||||
modified for the ESP32 on March 2017
|
||||
by John Bennett
|
||||
|
||||
see http://www.arduino.cc/en/Tutorial/Knob for a description of the original code
|
||||
|
||||
* Different servos require different pulse widths to vary servo angle, but the range is
|
||||
* an approximately 500-2500 microsecond pulse every 20ms (50Hz). In general, hobbyist servos
|
||||
* sweep 180 degrees, so the lowest number in the published range for a particular servo
|
||||
* represents an angle of 0 degrees, the middle of the range represents 90 degrees, and the top
|
||||
* of the range represents 180 degrees. So for example, if the range is 1000us to 2000us,
|
||||
* 1000us would equal an angle of 0, 1500us would equal 90 degrees, and 2000us would equal 1800
|
||||
* degrees.
|
||||
*
|
||||
* Circuit: (using an ESP32 Thing from Sparkfun)
|
||||
* Servo motors have three wires: power, ground, and signal. The power wire is typically red,
|
||||
* the ground wire is typically black or brown, and the signal wire is typically yellow,
|
||||
* orange or white. Since the ESP32 can supply limited current at only 3.3V, and servos draw
|
||||
* considerable power, we will connect servo power to the VBat pin of the ESP32 (located
|
||||
* near the USB connector). THIS IS ONLY APPROPRIATE FOR SMALL SERVOS.
|
||||
*
|
||||
* We could also connect servo power to a separate external
|
||||
* power source (as long as we connect all of the grounds (ESP32, servo, and external power).
|
||||
* In this example, we just connect ESP32 ground to servo ground. The servo signal pins
|
||||
* connect to any available GPIO pins on the ESP32 (in this example, we use pin 18.
|
||||
*
|
||||
* In this example, we assume a Tower Pro SG90 small servo connected to VBat.
|
||||
* The published min and max for this servo are 500 and 2400, respectively.
|
||||
* These values actually drive the servos a little past 0 and 180, so
|
||||
* if you are particular, adjust the min and max values to match your needs.
|
||||
*/
|
||||
|
||||
// Include the ESP32 Arduino Servo Library instead of the original Arduino Servo Library
|
||||
#include <ESP32Servo.h>
|
||||
|
||||
Servo myservo; // create servo object to control a servo
|
||||
|
||||
// Possible PWM GPIO pins on the ESP32: 0(used by on-board button),2,4,5(used by on-board LED),12-19,21-23,25-27,32-33
|
||||
// Possible PWM GPIO pins on the ESP32-S2: 0(used by on-board button),1-17,18(used by on-board LED),19-21,26,33-42
|
||||
// Possible PWM GPIO pins on the ESP32-S3: 0(used by on-board button),1-21,35-45,47,48(used by on-board LED)
|
||||
// Possible PWM GPIO pins on the ESP32-C3: 0(used by on-board button),1-7,8(used by on-board LED),9-10,18-21
|
||||
int servoPin = 18; // GPIO pin used to connect the servo control (digital out)
|
||||
// Possible ADC pins on the ESP32: 0,2,4,12-15,32-39; 34-39 are recommended for analog input
|
||||
// Possible ADC pins on the ESP32-S2: 1-20 are recommended for analog input
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
int potPin = 10; // GPIO pin used to connect the potentiometer (analog in)
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
int potPin = 4; // GPIO pin used to connect the potentiometer (analog in)
|
||||
#else
|
||||
int potPin = 34; // GPIO pin used to connect the potentiometer (analog in)
|
||||
#endif
|
||||
int ADC_Max = 4096; // This is the default ADC max value on the ESP32 (12 bit ADC width);
|
||||
// this width can be set (in low-level oode) from 9-12 bits, for a
|
||||
// a range of max values of 512-4096
|
||||
|
||||
int val; // variable to read the value from the analog pin
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Allow allocation of all timers
|
||||
ESP32PWM::allocateTimer(0);
|
||||
ESP32PWM::allocateTimer(1);
|
||||
ESP32PWM::allocateTimer(2);
|
||||
ESP32PWM::allocateTimer(3);
|
||||
myservo.setPeriodHertz(50);// Standard 50hz servo
|
||||
myservo.attach(servoPin, 500, 2400); // attaches the servo on pin 18 to the servo object
|
||||
// using SG90 servo min/max of 500us and 2400us
|
||||
// for MG995 large servo, use 1000us and 2000us,
|
||||
// which are the defaults, so this line could be
|
||||
// "myservo.attach(servoPin);"
|
||||
}
|
||||
|
||||
void loop() {
|
||||
val = analogRead(potPin); // read the value of the potentiometer (value between 0 and 1023)
|
||||
val = map(val, 0, ADC_Max, 0, 180); // scale it to use it with the servo (value between 0 and 180)
|
||||
myservo.write(val); // set the servo position according to the scaled value
|
||||
delay(200); // wait for the servo to get there
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* ESP32 Servo Example Using Arduino ESP32 Servo Library
|
||||
* John K. Bennett
|
||||
* March, 2017
|
||||
*
|
||||
* This sketch uses the Arduino ESP32 Servo Library to sweep 4 servos in sequence.
|
||||
*
|
||||
* Different servos require different pulse widths to vary servo angle, but the range is
|
||||
* an approximately 500-2500 microsecond pulse every 20ms (50Hz). In general, hobbyist servos
|
||||
* sweep 180 degrees, so the lowest number in the published range for a particular servo
|
||||
* represents an angle of 0 degrees, the middle of the range represents 90 degrees, and the top
|
||||
* of the range represents 180 degrees. So for example, if the range is 1000us to 2000us,
|
||||
* 1000us would equal an angle of 0, 1500us would equal 90 degrees, and 2000us would equal 1800
|
||||
* degrees.
|
||||
*
|
||||
* Circuit:
|
||||
* Servo motors have three wires: power, ground, and signal. The power wire is typically red,
|
||||
* the ground wire is typically black or brown, and the signal wire is typically yellow,
|
||||
* orange or white. Since the ESP32 can supply limited current at only 3.3V, and servos draw
|
||||
* considerable power, we will connect servo power to the VBat pin of the ESP32 (located
|
||||
* near the USB connector). THIS IS ONLY APPROPRIATE FOR SMALL SERVOS.
|
||||
*
|
||||
* We could also connect servo power to a separate external
|
||||
* power source (as long as we connect all of the grounds (ESP32, servo, and external power).
|
||||
* In this example, we just connect ESP32 ground to servo ground. The servo signal pins
|
||||
* connect to any available GPIO pins on the ESP32 (in this example, we use pins
|
||||
* 22, 19, 23, & 18).
|
||||
*
|
||||
* In this example, we assume four Tower Pro SG90 small servos.
|
||||
* The published min and max for this servo are 500 and 2400, respectively.
|
||||
* These values actually drive the servos a little past 0 and 180, so
|
||||
* if you are particular, adjust the min and max values to match your needs.
|
||||
* Experimentally, 550 and 2350 are pretty close to 0 and 180.
|
||||
*/
|
||||
|
||||
#include <ESP32Servo.h>
|
||||
|
||||
// create four servo objects
|
||||
Servo servo1;
|
||||
Servo servo2;
|
||||
Servo servo3;
|
||||
Servo servo4;
|
||||
Servo servo5;
|
||||
// Published values for SG90 servos; adjust if needed
|
||||
int minUs = 1000;
|
||||
int maxUs = 2000;
|
||||
|
||||
// These are all GPIO pins on the ESP32
|
||||
// Recommended pins include 2,4,12-19,21-23,25-27,32-33
|
||||
// for the ESP32-S2 the GPIO pins are 1-21,26,33-42
|
||||
// for the ESP32-S3 the GPIO pins are 1-21,35-45,47-48
|
||||
// for the ESP32-C3 the GPIO pins are 1-10,18-21
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
int servo1Pin = 7;
|
||||
int servo2Pin = 6;
|
||||
int servo3Pin = 5;
|
||||
int servo4Pin = 4;
|
||||
int servo5Pin = 3;
|
||||
#else
|
||||
int servo1Pin = 15;
|
||||
int servo2Pin = 16;
|
||||
int servo3Pin = 14;
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
int servo4Pin = 13;
|
||||
#else
|
||||
int servo4Pin = 32;
|
||||
#endif
|
||||
int servo5Pin = 4;
|
||||
#endif
|
||||
|
||||
int pos = 0; // position in degrees
|
||||
ESP32PWM pwm;
|
||||
void setup() {
|
||||
// Allow allocation of all timers
|
||||
ESP32PWM::allocateTimer(0);
|
||||
ESP32PWM::allocateTimer(1);
|
||||
ESP32PWM::allocateTimer(2);
|
||||
ESP32PWM::allocateTimer(3);
|
||||
Serial.begin(115200);
|
||||
servo1.setPeriodHertz(50); // Standard 50hz servo
|
||||
servo2.setPeriodHertz(50); // Standard 50hz servo
|
||||
servo3.setPeriodHertz(330); // Standard 50hz servo
|
||||
servo4.setPeriodHertz(200); // Standard 50hz servo
|
||||
//servo5.setPeriodHertz(50); // Standard 50hz servo
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
servo1.attach(servo1Pin, minUs, maxUs);
|
||||
servo2.attach(servo2Pin, minUs, maxUs);
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
pwm.attachPin(37, 10000);//10khz
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
pwm.attachPin(7, 10000);//10khz
|
||||
#else
|
||||
pwm.attachPin(27, 10000);//10khz
|
||||
#endif
|
||||
servo3.attach(servo3Pin, minUs, maxUs);
|
||||
servo4.attach(servo4Pin, minUs, maxUs);
|
||||
|
||||
//servo5.attach(servo5Pin, minUs, maxUs);
|
||||
|
||||
|
||||
for (pos = 0; pos <= 180; pos += 1) { // sweep from 0 degrees to 180 degrees
|
||||
// in steps of 1 degree
|
||||
servo1.write(pos);
|
||||
delay(1); // waits 20ms for the servo to reach the position
|
||||
}
|
||||
for (pos = 180; pos >= 0; pos -= 1) { // sweep from 180 degrees to 0 degrees
|
||||
servo1.write(pos);
|
||||
delay(1);
|
||||
}
|
||||
|
||||
for (pos = 0; pos <= 180; pos += 1) { // sweep from 0 degrees to 180 degrees
|
||||
// in steps of 1 degree
|
||||
servo2.write(pos);
|
||||
delay(1); // waits 20ms for the servo to reach the position
|
||||
}
|
||||
for (pos = 180; pos >= 0; pos -= 1) { // sweep from 180 degrees to 0 degrees
|
||||
servo2.write(pos);
|
||||
delay(1);
|
||||
}
|
||||
|
||||
for (pos = 0; pos <= 180; pos += 1) { // sweep from 0 degrees to 180 degrees
|
||||
// in steps of 1 degree
|
||||
servo3.write(pos);
|
||||
delay(1); // waits 20ms for the servo to reach the position
|
||||
}
|
||||
for (pos = 180; pos >= 0; pos -= 1) { // sweep from 180 degrees to 0 degrees
|
||||
servo3.write(pos);
|
||||
delay(1);
|
||||
}
|
||||
|
||||
for (pos = 0; pos <= 180; pos += 1) { // sweep from 0 degrees to 180 degrees
|
||||
// in steps of 1 degree
|
||||
servo4.write(pos);
|
||||
delay(1); // waits 20ms for the servo to reach the position
|
||||
}
|
||||
for (pos = 180; pos >= 0; pos -= 1) { // sweep from 180 degrees to 0 degrees
|
||||
servo4.write(pos);
|
||||
delay(1);
|
||||
}
|
||||
for (pos = 0; pos <= 180; pos += 1) { // sweep from 0 degrees to 180 degrees
|
||||
// in steps of 1 degree
|
||||
servo5.write(pos);
|
||||
delay(1); // waits 20ms for the servo to reach the position
|
||||
}
|
||||
for (pos = 180; pos >= 0; pos -= 1) { // sweep from 180 degrees to 0 degrees
|
||||
servo5.write(pos);
|
||||
delay(1);
|
||||
}
|
||||
servo1.detach();
|
||||
servo2.detach();;
|
||||
servo3.detach();
|
||||
servo4.detach();
|
||||
pwm.detachPin(27);
|
||||
|
||||
delay(5000);
|
||||
|
||||
}
|
||||
|
36
libs/ESP32Servo/examples/PWMExample/PWMExample.ino
Normal file
36
libs/ESP32Servo/examples/PWMExample/PWMExample.ino
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <ESP32Servo.h>
|
||||
int APin = 13;
|
||||
ESP32PWM pwm;
|
||||
int freq = 1000;
|
||||
void setup() {
|
||||
// Allow allocation of all timers
|
||||
ESP32PWM::allocateTimer(0);
|
||||
ESP32PWM::allocateTimer(1);
|
||||
ESP32PWM::allocateTimer(2);
|
||||
ESP32PWM::allocateTimer(3);
|
||||
Serial.begin(115200);
|
||||
pwm.attachPin(APin, freq, 10); // 1KHz 8 bit
|
||||
|
||||
}
|
||||
void loop() {
|
||||
|
||||
// fade the LED on thisPin from off to brightest:
|
||||
for (float brightness = 0; brightness <= 0.5; brightness += 0.001) {
|
||||
// Write a unit vector value from 0.0 to 1.0
|
||||
pwm.writeScaled(brightness);
|
||||
delay(2);
|
||||
}
|
||||
//delay(1000);
|
||||
// fade the LED on thisPin from brithstest to off:
|
||||
for (float brightness = 0.5; brightness >= 0; brightness -= 0.001) {
|
||||
freq += 10;
|
||||
// Adjust the frequency on the fly with a specific brightness
|
||||
// Frequency is in herts and duty cycle is a unit vector 0.0 to 1.0
|
||||
pwm.adjustFrequency(freq, brightness); // update the time base of the PWM
|
||||
delay(2);
|
||||
}
|
||||
// pause between LEDs:
|
||||
delay(1000);
|
||||
freq = 1000;
|
||||
pwm.adjustFrequency(freq, 0.0); // reset the time base
|
||||
}
|
82
libs/ESP32Servo/examples/Sweep/Sweep.ino
Normal file
82
libs/ESP32Servo/examples/Sweep/Sweep.ino
Normal file
|
@ -0,0 +1,82 @@
|
|||
/* Sweep
|
||||
by BARRAGAN <http://barraganstudio.com>
|
||||
This example code is in the public domain.
|
||||
|
||||
modified 8 Nov 2013
|
||||
by Scott Fitzgerald
|
||||
|
||||
modified for the ESP32 on March 2017
|
||||
by John Bennett
|
||||
|
||||
see http://www.arduino.cc/en/Tutorial/Sweep for a description of the original code
|
||||
|
||||
* Different servos require different pulse widths to vary servo angle, but the range is
|
||||
* an approximately 500-2500 microsecond pulse every 20ms (50Hz). In general, hobbyist servos
|
||||
* sweep 180 degrees, so the lowest number in the published range for a particular servo
|
||||
* represents an angle of 0 degrees, the middle of the range represents 90 degrees, and the top
|
||||
* of the range represents 180 degrees. So for example, if the range is 1000us to 2000us,
|
||||
* 1000us would equal an angle of 0, 1500us would equal 90 degrees, and 2000us would equal 1800
|
||||
* degrees.
|
||||
*
|
||||
* Circuit: (using an ESP32 Thing from Sparkfun)
|
||||
* Servo motors have three wires: power, ground, and signal. The power wire is typically red,
|
||||
* the ground wire is typically black or brown, and the signal wire is typically yellow,
|
||||
* orange or white. Since the ESP32 can supply limited current at only 3.3V, and servos draw
|
||||
* considerable power, we will connect servo power to the VBat pin of the ESP32 (located
|
||||
* near the USB connector). THIS IS ONLY APPROPRIATE FOR SMALL SERVOS.
|
||||
*
|
||||
* We could also connect servo power to a separate external
|
||||
* power source (as long as we connect all of the grounds (ESP32, servo, and external power).
|
||||
* In this example, we just connect ESP32 ground to servo ground. The servo signal pins
|
||||
* connect to any available GPIO pins on the ESP32 (in this example, we use pin 18.
|
||||
*
|
||||
* In this example, we assume a Tower Pro MG995 large servo connected to an external power source.
|
||||
* The published min and max for this servo is 1000 and 2000, respectively, so the defaults are fine.
|
||||
* These values actually drive the servos a little past 0 and 180, so
|
||||
* if you are particular, adjust the min and max values to match your needs.
|
||||
*/
|
||||
|
||||
#include <ESP32Servo.h>
|
||||
|
||||
Servo myservo; // create servo object to control a servo
|
||||
// 16 servo objects can be created on the ESP32
|
||||
|
||||
int pos = 0; // variable to store the servo position
|
||||
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33
|
||||
// Possible PWM GPIO pins on the ESP32-S2: 0(used by on-board button),1-17,18(used by on-board LED),19-21,26,33-42
|
||||
// Possible PWM GPIO pins on the ESP32-S3: 0(used by on-board button),1-21,35-45,47,48(used by on-board LED)
|
||||
// Possible PWM GPIO pins on the ESP32-C3: 0(used by on-board button),1-7,8(used by on-board LED),9-10,18-21
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
int servoPin = 17;
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
int servoPin = 7;
|
||||
#else
|
||||
int servoPin = 18;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
// Allow allocation of all timers
|
||||
ESP32PWM::allocateTimer(0);
|
||||
ESP32PWM::allocateTimer(1);
|
||||
ESP32PWM::allocateTimer(2);
|
||||
ESP32PWM::allocateTimer(3);
|
||||
myservo.setPeriodHertz(50); // standard 50 hz servo
|
||||
myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin 18 to the servo object
|
||||
// using default min/max of 1000us and 2000us
|
||||
// different servos may require different min/max settings
|
||||
// for an accurate 0 to 180 sweep
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
|
||||
// in steps of 1 degree
|
||||
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
||||
delay(15); // waits 15ms for the servo to reach the position
|
||||
}
|
||||
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
|
||||
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
||||
delay(15); // waits 15ms for the servo to reach the position
|
||||
}
|
||||
}
|
||||
|
25
libs/ESP32Servo/examples/ToneExample/ToneExample.ino
Normal file
25
libs/ESP32Servo/examples/ToneExample/ToneExample.ino
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <ESP32Servo.h>
|
||||
int pin = 2;
|
||||
void setup() {
|
||||
// Allow allocation of all timers
|
||||
ESP32PWM::allocateTimer(0);
|
||||
ESP32PWM::allocateTimer(1);
|
||||
ESP32PWM::allocateTimer(2);
|
||||
ESP32PWM::allocateTimer(3);
|
||||
Serial.begin(115200);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
tone(pin, 4186, // C
|
||||
500); // half a second
|
||||
tone(pin, 5274, // E
|
||||
500); // half a second
|
||||
delay(500);
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
Mega analogWrite() test
|
||||
|
||||
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
|
||||
This sketch was written for the Arduino Mega, and will not work on previous boards.
|
||||
|
||||
The circuit:
|
||||
* LEDs attached from pins 2 through 13 to ground. or for ESP32-S2 pins 1-17,19-21,26,33-42
|
||||
|
||||
created 8 Feb 2009
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
// These constants won't change. They're used to give names
|
||||
// to the pins used:
|
||||
#if defined(ARDUINO_ESP32S2_DEV) || defined(ARDUINO_ESP32S3_DEV)
|
||||
const int lowestPin = 1;
|
||||
const int highestPin = 42;
|
||||
#elif defined(ARDUINO_ESP32C3_DEV)
|
||||
const int lowestPin = 1;
|
||||
const int highestPin = 19;
|
||||
#else
|
||||
const int lowestPin = 2;
|
||||
const int highestPin = 33;
|
||||
#endif
|
||||
#include <ESP32Servo.h>
|
||||
Servo myservo;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// Allow allocation of all timers
|
||||
ESP32PWM::allocateTimer(0);
|
||||
ESP32PWM::allocateTimer(1);
|
||||
ESP32PWM::allocateTimer(2);
|
||||
ESP32PWM::allocateTimer(3);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!myservo.attached()) {
|
||||
myservo.setPeriodHertz(50); // standard 50 hz servo
|
||||
myservo.attach(33, 1000, 2000); // Attach the servo after it has been detatched
|
||||
}
|
||||
myservo.write(0);
|
||||
// iterate over the pins:
|
||||
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
|
||||
if (ESP32PWM::hasPwm(thisPin) && // Is it possible for this pin to PWM
|
||||
(ESP32PWM::channelsRemaining() > 0 || // New channels availible to allocate
|
||||
pwmFactory(thisPin) != NULL || // already allocated this pin in the factory
|
||||
thisPin == 25 || // one of the 2 DAC outputs, no timer needed
|
||||
thisPin == 26)) { // one of the 2 DAC outputs, no timer needed
|
||||
if (pwmFactory(thisPin) == NULL) { // check if its the first time for the pin or its a DAC
|
||||
#if defined(ARDUINO_ESP32S2_DEV)
|
||||
if (thisPin == 17 || // one of the 2 DAC outputs, no timer needed
|
||||
thisPin == 18)
|
||||
#elif defined(ARDUINO_ESP32C3_DEV) || defined(ARDUINO_ESP32S3_DEV)
|
||||
if (1 == 0) // no DAC outputs for these chips
|
||||
#else
|
||||
if (thisPin == 25 || // one of the 2 DAC outputs, no timer needed
|
||||
thisPin == 26)
|
||||
#endif
|
||||
{
|
||||
Serial.println("DAC to pin " + String(thisPin));
|
||||
} else
|
||||
Serial.println("Writing to pin " + String(thisPin));
|
||||
pinMode(thisPin, OUTPUT);
|
||||
}
|
||||
// fade the LED on thisPin from off to brightest:
|
||||
for (int brightness = 0; brightness < 255; brightness++) {
|
||||
analogWrite(thisPin, brightness);
|
||||
delay(1);
|
||||
myservo.write(brightness);
|
||||
}
|
||||
// fade the LED on thisPin from brithstest to off:
|
||||
for (int brightness = 255; brightness >= 0; brightness--) {
|
||||
analogWrite(thisPin, brightness);
|
||||
myservo.write(brightness);
|
||||
delay(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
myservo.detach(); // Turn the servo off for a while
|
||||
delay(2000);
|
||||
|
||||
}
|
26
libs/ESP32Servo/keywords.txt
Normal file
26
libs/ESP32Servo/keywords.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map ESP32_Servo
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
Servo KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
attach KEYWORD2
|
||||
detach KEYWORD2
|
||||
write KEYWORD2
|
||||
read KEYWORD2
|
||||
attached KEYWORD2
|
||||
writeMicroseconds KEYWORD2
|
||||
readMicroseconds KEYWORD2
|
||||
setTimerWidth KEYWORD2
|
||||
readTimerWidth KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
11
libs/ESP32Servo/library.properties
Normal file
11
libs/ESP32Servo/library.properties
Normal file
|
@ -0,0 +1,11 @@
|
|||
name=ESP32Servo
|
||||
version=1.1.1
|
||||
author=Kevin Harrington,John K. Bennett
|
||||
maintainer=Kevin Harrington <mad.hephaestus@gmail.com>
|
||||
sentence=Allows ESP32 boards to control servo, tone and analogWrite motors using Arduino semantics.
|
||||
paragraph=This library can control a many types of servos.<br />It makes use of the ESP32 PWM timers: the library can control up to 16 servos on individual channels<br />No attempt has been made to support multiple servos per channel.<br />
|
||||
category=Device Control
|
||||
url=https://madhephaestus.github.io/ESP32Servo/annotated.html
|
||||
architectures=esp32
|
||||
includes=ESP32Servo.h,analogWrite.h,tone.h,ESP32Tone.h,ESP32PWM.h
|
||||
|
324
libs/ESP32Servo/src/ESP32PWM.cpp
Normal file
324
libs/ESP32Servo/src/ESP32PWM.cpp
Normal file
|
@ -0,0 +1,324 @@
|
|||
/*
|
||||
* ESP32PWM.cpp
|
||||
*
|
||||
* Created on: Sep 22, 2018
|
||||
* Author: hephaestus
|
||||
*/
|
||||
|
||||
#include <ESP32PWM.h>
|
||||
#include "esp32-hal-ledc.h"
|
||||
|
||||
// initialize the class variable ServoCount
|
||||
int ESP32PWM::PWMCount = -1; // the total number of attached servos
|
||||
bool ESP32PWM::explicateAllocationMode=false;
|
||||
ESP32PWM * ESP32PWM::ChannelUsed[NUM_PWM]; // used to track whether a channel is in service
|
||||
long ESP32PWM::timerFreqSet[4] = { -1, -1, -1, -1 };
|
||||
int ESP32PWM::timerCount[4] = { 0, 0, 0, 0 };
|
||||
// The ChannelUsed array elements are 0 if never used, 1 if in use, and -1 if used and disposed
|
||||
// (i.e., available for reuse)
|
||||
/**
|
||||
* allocateTimer
|
||||
* @param a timer number 0-3 indicating which timer to allocate in this library
|
||||
* Switch to explicate allocation mode
|
||||
*
|
||||
*/
|
||||
void ESP32PWM::allocateTimer(int timerNumber){
|
||||
if(timerNumber<0 || timerNumber>3)
|
||||
return;
|
||||
if(ESP32PWM::explicateAllocationMode==false){
|
||||
ESP32PWM::explicateAllocationMode=true;
|
||||
for(int i=0;i<4;i++)
|
||||
ESP32PWM::timerCount[i]=4;// deallocate all timers to start mode
|
||||
}
|
||||
ESP32PWM::timerCount[timerNumber]=0;
|
||||
}
|
||||
|
||||
ESP32PWM::ESP32PWM() {
|
||||
resolutionBits = 8;
|
||||
pwmChannel = -1;
|
||||
pin = -1;
|
||||
myFreq = -1;
|
||||
if (PWMCount == -1) {
|
||||
for (int i = 0; i < NUM_PWM; i++)
|
||||
ChannelUsed[i] = NULL; // load invalid data into the storage array of pin mapping
|
||||
PWMCount = PWM_BASE_INDEX; // 0th channel does not work with the PWM system
|
||||
}
|
||||
}
|
||||
|
||||
ESP32PWM::~ESP32PWM() {
|
||||
if (attached()) {
|
||||
ledcDetachPin(pin);
|
||||
}
|
||||
deallocate();
|
||||
}
|
||||
|
||||
double ESP32PWM::_ledcSetupTimerFreq(uint8_t chan, double freq,
|
||||
uint8_t bit_num) {
|
||||
return ledcSetup(chan, freq, bit_num);
|
||||
|
||||
}
|
||||
|
||||
int ESP32PWM::timerAndIndexToChannel(int timerNum, int index) {
|
||||
int localIndex = 0;
|
||||
for (int j = 0; j < NUM_PWM; j++) {
|
||||
if (((j / 2) % 4) == timerNum) {
|
||||
if (localIndex == index) {
|
||||
return j;
|
||||
}
|
||||
localIndex++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int ESP32PWM::allocatenext(double freq) {
|
||||
long freqlocal = (long) freq;
|
||||
if (pwmChannel < 0) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bool freqAllocated = ((timerFreqSet[i] == freqlocal)
|
||||
|| (timerFreqSet[i] == -1));
|
||||
if (freqAllocated && timerCount[i] < 4) {
|
||||
if (timerFreqSet[i] == -1) {
|
||||
//Serial.println("Starting timer "+String(i)+" at freq "+String(freq));
|
||||
timerFreqSet[i] = freqlocal;
|
||||
}
|
||||
//Serial.println("Free channel timer "+String(i)+" at freq "+String(freq)+" remaining "+String(4-timerCount[i]));
|
||||
|
||||
timerNum = i;
|
||||
for (int index=0; index<4; ++index)
|
||||
{
|
||||
int myTimerNumber = timerAndIndexToChannel(timerNum,index);
|
||||
if ((myTimerNumber >= 0) && (!ChannelUsed[myTimerNumber]))
|
||||
{
|
||||
pwmChannel = myTimerNumber;
|
||||
// Serial.println(
|
||||
// "PWM on ledc channel #" + String(pwmChannel)
|
||||
// + " using 'timer " + String(timerNum)
|
||||
// + "' to freq " + String(freq) + "Hz");
|
||||
ChannelUsed[pwmChannel] = this;
|
||||
timerCount[timerNum]++;
|
||||
PWMCount++;
|
||||
myFreq = freq;
|
||||
return pwmChannel;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if(timerFreqSet[i]>0)
|
||||
// Serial.println("Timer freq mismatch target="+String(freq)+" on timer "+String(i)+" was "+String(timerFreqSet[i]));
|
||||
// else
|
||||
// Serial.println("Timer out of channels target="+String(freq)+" on timer "+String(i)+" was "+String(timerCount[i]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return pwmChannel;
|
||||
}
|
||||
Serial.println(
|
||||
"ERROR All PWM timers allocated! Can't accomodate " + String(freq)
|
||||
+ "Hz\r\nHalting...");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
void ESP32PWM::deallocate() {
|
||||
if (pwmChannel < 0)
|
||||
return;
|
||||
// Serial.println("PWM deallocating LEDc #" + String(pwmChannel));
|
||||
timerCount[getTimer()]--;
|
||||
if (timerCount[getTimer()] == 0) {
|
||||
timerFreqSet[getTimer()] = -1; // last pwn closed out
|
||||
}
|
||||
timerNum = -1;
|
||||
attachedState = false;
|
||||
ChannelUsed[pwmChannel] = NULL;
|
||||
pwmChannel = -1;
|
||||
PWMCount--;
|
||||
|
||||
}
|
||||
|
||||
int ESP32PWM::getChannel() {
|
||||
if (pwmChannel < 0) {
|
||||
Serial.println("FAIL! must setup() before using get channel!");
|
||||
}
|
||||
return pwmChannel;
|
||||
}
|
||||
|
||||
double ESP32PWM::setup(double freq, uint8_t resolution_bits) {
|
||||
checkFrequencyForSideEffects(freq);
|
||||
|
||||
resolutionBits = resolution_bits;
|
||||
if (attached()) {
|
||||
ledcDetachPin(pin);
|
||||
double val = ledcSetup(getChannel(), freq, resolution_bits);
|
||||
attachPin(pin);
|
||||
return val;
|
||||
}
|
||||
return ledcSetup(getChannel(), freq, resolution_bits);
|
||||
}
|
||||
double ESP32PWM::getDutyScaled() {
|
||||
return mapf((double) myDuty, 0, (double) ((1 << resolutionBits) - 1), 0.0,
|
||||
1.0);
|
||||
}
|
||||
void ESP32PWM::writeScaled(double duty) {
|
||||
write(mapf(duty, 0.0, 1.0, 0, (double) ((1 << resolutionBits) - 1)));
|
||||
}
|
||||
void ESP32PWM::write(uint32_t duty) {
|
||||
myDuty = duty;
|
||||
ledcWrite(getChannel(), duty);
|
||||
}
|
||||
void ESP32PWM::adjustFrequencyLocal(double freq, double dutyScaled) {
|
||||
timerFreqSet[getTimer()] = (long) freq;
|
||||
myFreq = freq;
|
||||
if (attached()) {
|
||||
ledcDetachPin(pin);
|
||||
// Remove the PWM during frequency adjust
|
||||
_ledcSetupTimerFreq(getChannel(), freq, resolutionBits);
|
||||
writeScaled(dutyScaled);
|
||||
ledcAttachPin(pin, getChannel()); // re-attach the pin after frequency adjust
|
||||
} else {
|
||||
_ledcSetupTimerFreq(getChannel(), freq, resolutionBits);
|
||||
writeScaled(dutyScaled);
|
||||
}
|
||||
}
|
||||
void ESP32PWM::adjustFrequency(double freq, double dutyScaled) {
|
||||
if(dutyScaled<0)
|
||||
dutyScaled=getDutyScaled();
|
||||
writeScaled(dutyScaled);
|
||||
for (int i = 0; i < timerCount[getTimer()]; i++) {
|
||||
int pwm = timerAndIndexToChannel(getTimer(), i);
|
||||
if (ChannelUsed[pwm] != NULL) {
|
||||
if (ChannelUsed[pwm]->myFreq != freq) {
|
||||
ChannelUsed[pwm]->adjustFrequencyLocal(freq,
|
||||
ChannelUsed[pwm]->getDutyScaled());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
double ESP32PWM::writeTone(double freq) {
|
||||
for (int i = 0; i < timerCount[getTimer()]; i++) {
|
||||
int pwm = timerAndIndexToChannel(getTimer(), i);
|
||||
if (ChannelUsed[pwm] != NULL) {
|
||||
if (ChannelUsed[pwm]->myFreq != freq) {
|
||||
ChannelUsed[pwm]->adjustFrequencyLocal(freq,
|
||||
ChannelUsed[pwm]->getDutyScaled());
|
||||
}
|
||||
write(1 << (resolutionBits-1)); // writeScaled(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
double ESP32PWM::writeNote(note_t note, uint8_t octave) {
|
||||
const uint16_t noteFrequencyBase[12] = {
|
||||
// C C# D Eb E F F# G G# A Bb B
|
||||
4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459,
|
||||
7902 };
|
||||
|
||||
if (octave > 8 || note >= NOTE_MAX) {
|
||||
return 0;
|
||||
}
|
||||
double noteFreq = (double) noteFrequencyBase[note]
|
||||
/ (double) (1 << (8 - octave));
|
||||
return writeTone(noteFreq);
|
||||
}
|
||||
uint32_t ESP32PWM::read() {
|
||||
return ledcRead(getChannel());
|
||||
}
|
||||
double ESP32PWM::readFreq() {
|
||||
return myFreq;
|
||||
}
|
||||
void ESP32PWM::attach(int p) {
|
||||
pin = p;
|
||||
attachedState = true;
|
||||
}
|
||||
void ESP32PWM::attachPin(uint8_t pin) {
|
||||
|
||||
if (hasPwm(pin)) {
|
||||
attach(pin);
|
||||
ledcAttachPin(pin, getChannel());
|
||||
} else {
|
||||
Serial.println(
|
||||
"ERROR PWM channel unavailable on pin requested! " + String(pin)
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
+ "\r\nPWM available on: 1-21,26,33-42"
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
+ "\r\nPWM available on: 1-21,35-45,47-48"
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
+ "\r\nPWM available on: 1-10,18-21"
|
||||
#else
|
||||
+ "\r\nPWM available on: 2,4,5,12-19,21-23,25-27,32-33"
|
||||
#endif
|
||||
|
||||
// Possible PWM GPIO pins on the ESP32-S3: 0(used by on-board button),1-21,35-45,47,48(used by on-board LED)
|
||||
// Possible PWM GPIO pins on the ESP32-C3: 0(used by on-board button),1-7,8(used by on-board LED),9-10,18-21
|
||||
);
|
||||
return;
|
||||
}
|
||||
//Serial.print(" on pin "+String(pin));
|
||||
}
|
||||
void ESP32PWM::attachPin(uint8_t pin, double freq, uint8_t resolution_bits) {
|
||||
|
||||
if (hasPwm(pin))
|
||||
setup(freq, resolution_bits);
|
||||
attachPin(pin);
|
||||
}
|
||||
void ESP32PWM::detachPin(int pin) {
|
||||
ledcDetachPin(pin);
|
||||
deallocate();
|
||||
}
|
||||
/* Side effects of frequency changes happen because of shared timers
|
||||
*
|
||||
* LEDC Chan to Group/Channel/Timer Mapping
|
||||
** ledc: 0 => Group: 0, Channel: 0, Timer: 0
|
||||
** ledc: 1 => Group: 0, Channel: 1, Timer: 0
|
||||
** ledc: 2 => Group: 0, Channel: 2, Timer: 1
|
||||
** ledc: 3 => Group: 0, Channel: 3, Timer: 1
|
||||
** ledc: 4 => Group: 0, Channel: 4, Timer: 2
|
||||
** ledc: 5 => Group: 0, Channel: 5, Timer: 2
|
||||
** ledc: 6 => Group: 0, Channel: 6, Timer: 3
|
||||
** ledc: 7 => Group: 0, Channel: 7, Timer: 3
|
||||
** ledc: 8 => Group: 1, Channel: 0, Timer: 0
|
||||
** ledc: 9 => Group: 1, Channel: 1, Timer: 0
|
||||
** ledc: 10 => Group: 1, Channel: 2, Timer: 1
|
||||
** ledc: 11 => Group: 1, Channel: 3, Timer: 1
|
||||
** ledc: 12 => Group: 1, Channel: 4, Timer: 2
|
||||
** ledc: 13 => Group: 1, Channel: 5, Timer: 2
|
||||
** ledc: 14 => Group: 1, Channel: 6, Timer: 3
|
||||
** ledc: 15 => Group: 1, Channel: 7, Timer: 3
|
||||
*/
|
||||
|
||||
bool ESP32PWM::checkFrequencyForSideEffects(double freq) {
|
||||
|
||||
allocatenext(freq);
|
||||
for (int i = 0; i < timerCount[getTimer()]; i++) {
|
||||
int pwm = timerAndIndexToChannel(getTimer(), i);
|
||||
|
||||
if (pwm == pwmChannel)
|
||||
continue;
|
||||
if (ChannelUsed[pwm] != NULL)
|
||||
if (ChannelUsed[pwm]->getTimer() == getTimer()) {
|
||||
double diff = abs(ChannelUsed[pwm]->myFreq - freq);
|
||||
if (abs(diff) > 0.1) {
|
||||
Serial.println(
|
||||
"\tWARNING PWM channel " + String(pwmChannel)
|
||||
+ " shares a timer with channel "
|
||||
+ String(pwm) + "\n"
|
||||
"\tchanging the frequency to "
|
||||
+ String(freq)
|
||||
+ " Hz will ALSO change channel "
|
||||
+ String(pwm)
|
||||
+ " \n\tfrom its previous frequency of "
|
||||
+ String(ChannelUsed[pwm]->myFreq) + " Hz\n"
|
||||
" ");
|
||||
ChannelUsed[pwm]->myFreq = freq;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ESP32PWM* pwmFactory(int pin) {
|
||||
for (int i = 0; i < NUM_PWM; i++)
|
||||
if (ESP32PWM::ChannelUsed[i] != NULL) {
|
||||
if (ESP32PWM::ChannelUsed[i]->getPin() == pin)
|
||||
return ESP32PWM::ChannelUsed[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
133
libs/ESP32Servo/src/ESP32PWM.h
Normal file
133
libs/ESP32Servo/src/ESP32PWM.h
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* ESP32PWM.h
|
||||
*
|
||||
* Created on: Sep 22, 2018
|
||||
* Author: hephaestus
|
||||
*/
|
||||
|
||||
#ifndef LIBRARIES_ESP32SERVO_SRC_ESP32PWM_H_
|
||||
#define LIBRARIES_ESP32SERVO_SRC_ESP32PWM_H_
|
||||
#include "esp32-hal-ledc.h"
|
||||
#define NUM_PWM 16
|
||||
#define PWM_BASE_INDEX 0
|
||||
#define USABLE_ESP32_PWM (NUM_PWM-PWM_BASE_INDEX)
|
||||
#include <cstdint>
|
||||
|
||||
#include "Arduino.h"
|
||||
class ESP32PWM {
|
||||
private:
|
||||
|
||||
void attach(int pin);
|
||||
int pwmChannel = 0; // channel number for this servo
|
||||
bool attachedState = false;
|
||||
int pin;
|
||||
uint8_t resolutionBits;
|
||||
double myFreq;
|
||||
int allocatenext(double freq);
|
||||
|
||||
static double _ledcSetupTimerFreq(uint8_t chan, double freq,
|
||||
uint8_t bit_num);
|
||||
|
||||
bool checkFrequencyForSideEffects(double freq);
|
||||
|
||||
void adjustFrequencyLocal(double freq, double dutyScaled);
|
||||
static double mapf(double x, double in_min, double in_max, double out_min,
|
||||
double out_max) {
|
||||
if(x>in_max)
|
||||
return out_max;
|
||||
if(x<in_min)
|
||||
return out_min;
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
double setup(double freq, uint8_t resolution_bits=10);
|
||||
//channel 0-15 resolution 1-16bits freq limits depend on resolution9
|
||||
void attachPin(uint8_t pin);
|
||||
// pin allocation
|
||||
void deallocate();
|
||||
public:
|
||||
// setup
|
||||
ESP32PWM();
|
||||
virtual ~ESP32PWM();
|
||||
|
||||
|
||||
void detachPin(int pin);
|
||||
void attachPin(uint8_t pin, double freq, uint8_t resolution_bits=10);
|
||||
bool attached() {
|
||||
return attachedState;
|
||||
}
|
||||
|
||||
// write raw duty cycle
|
||||
void write(uint32_t duty);
|
||||
// Write a duty cycle to the PWM using a unit vector from 0.0-1.0
|
||||
void writeScaled(double duty);
|
||||
//Adjust frequency
|
||||
double writeTone(double freq);
|
||||
double writeNote(note_t note, uint8_t octave);
|
||||
void adjustFrequency(double freq, double dutyScaled=-1);
|
||||
|
||||
// Read pwm data
|
||||
uint32_t read();
|
||||
double readFreq();
|
||||
double getDutyScaled();
|
||||
|
||||
//Timer data
|
||||
static int timerAndIndexToChannel(int timer, int index);
|
||||
/**
|
||||
* allocateTimer
|
||||
* @param a timer number 0-3 indicating which timer to allocate in this library
|
||||
* Switch to explicate allocation mode
|
||||
*
|
||||
*/
|
||||
static void allocateTimer(int timerNumber);
|
||||
static bool explicateAllocationMode;
|
||||
int getTimer() {
|
||||
return timerNum;
|
||||
}
|
||||
int timerNum = -1;
|
||||
uint32_t myDuty = 0;
|
||||
int getChannel();
|
||||
static int PWMCount; // the total number of attached pwm
|
||||
static int timerCount[4];
|
||||
static ESP32PWM * ChannelUsed[NUM_PWM]; // used to track whether a channel is in service
|
||||
static long timerFreqSet[4];
|
||||
|
||||
// Helper functions
|
||||
int getPin() {
|
||||
return pin;
|
||||
}
|
||||
static bool hasPwm(int pin) {
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
if ((pin >=1 && pin <= 21) || //21
|
||||
(pin == 26) || //1
|
||||
(pin >= 33 && pin <= 42)) //10
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
if ((pin >=1 && pin <= 21) || //20
|
||||
(pin >= 35 && pin <= 45) || //11
|
||||
(pin == 47) || (pin == 48)) //2
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
if ((pin >=1 && pin <= 10) || //11
|
||||
(pin >= 18 && pin <= 21)) //4
|
||||
#else
|
||||
if ((pin == 2) || //1
|
||||
(pin == 4) || //1
|
||||
(pin == 5) || //1
|
||||
((pin >= 12) && (pin <= 19)) || //8
|
||||
((pin >= 21) && (pin <= 23)) || //3
|
||||
((pin >= 25) && (pin <= 27)) || //3
|
||||
(pin == 32) || (pin == 33)) //2
|
||||
#endif
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
static int channelsRemaining() {
|
||||
return NUM_PWM - PWMCount;
|
||||
}
|
||||
static boolean DISABLE_DAC;
|
||||
|
||||
|
||||
};
|
||||
|
||||
ESP32PWM* pwmFactory(int pin);
|
||||
|
||||
#endif /* LIBRARIES_ESP32SERVO_SRC_ESP32PWM_H_ */
|
257
libs/ESP32Servo/src/ESP32Servo.cpp
Normal file
257
libs/ESP32Servo/src/ESP32Servo.cpp
Normal file
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
Copyright (c) 2017 John K. Bennett. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* Notes on the implementation:
|
||||
* The ESP32 supports 16 hardware LED PWM channels that are intended
|
||||
* to be used for LED brightness control. The low level ESP32 code
|
||||
* (esp32-hal-ledc.*) allows us to set the PWM frequency and bit-depth,
|
||||
* and then manipulate them by setting bits in the relevant control
|
||||
* registers.
|
||||
*
|
||||
* Different servos require different pulse widths to vary servo angle, but the range is
|
||||
* an approximately 500-2500 microsecond pulse every 20ms (50Hz). In general, hobbyist servos
|
||||
* sweep 180 degrees, so the lowest number in the published range for a particular servo
|
||||
* represents an angle of 0 degrees, the middle of the range represents 90 degrees, and the top
|
||||
* of the range represents 180 degrees. So for example, if the range is 1000us to 2000us,
|
||||
* 1000us would equal an angle of 0, 1500us would equal 90 degrees, and 2000us would equal 180
|
||||
* degrees. We vary pulse width (recall that the pulse period is already set to 20ms) as follows:
|
||||
*
|
||||
* The ESP32 PWM timers allow us to set the timer width (max 20 bits). Thus
|
||||
* the timer "tick" length is (pulse_period/2**timer_width), and the equation for pulse_high_width
|
||||
* (the portion of the 20ms cycle that the signal is high) becomes:
|
||||
*
|
||||
* pulse_high_width = count * tick_length
|
||||
* = count * (pulse_period/2**timer_width)
|
||||
*
|
||||
* and count = (pulse_high_width / (pulse_period/2**timer_width))
|
||||
*
|
||||
* So, for example, if I want a 1500us pulse_high_width, I set pulse_period to 20ms (20000us)
|
||||
* (this value is set in the ledcSetup call), and count (used in the ledcWrite call) to
|
||||
* 1500/(20000/65536), or 4924. This is the value we write to the timer in the ledcWrite call.
|
||||
* If we increase the timer_width, the timer_count values need to be adjusted.
|
||||
*
|
||||
* The servo signal pins connect to any available GPIO pins on the ESP32, but not all pins are
|
||||
* GPIO pins.
|
||||
*
|
||||
* The ESP32 is a 32 bit processor that includes FP support; this code reflects that fact.
|
||||
*/
|
||||
|
||||
#include <ESP32Servo.h>
|
||||
#include "Arduino.h"
|
||||
|
||||
//
|
||||
Servo::Servo()
|
||||
{ // initialize this channel with plausible values, except pin # (we set pin # when attached)
|
||||
REFRESH_CPS = 50;
|
||||
this->ticks = DEFAULT_PULSE_WIDTH_TICKS;
|
||||
this->timer_width = DEFAULT_TIMER_WIDTH;
|
||||
this->pinNumber = -1; // make it clear that we haven't attached a pin to this channel
|
||||
this->min = DEFAULT_uS_LOW;
|
||||
this->max = DEFAULT_uS_HIGH;
|
||||
this->timer_width_ticks = pow(2,this->timer_width);
|
||||
|
||||
}
|
||||
ESP32PWM * Servo::getPwm(){
|
||||
|
||||
return &pwm;
|
||||
}
|
||||
|
||||
int Servo::attach(int pin)
|
||||
{
|
||||
|
||||
return (this->attach(pin, DEFAULT_uS_LOW, DEFAULT_uS_HIGH));
|
||||
}
|
||||
|
||||
int Servo::attach(int pin, int min, int max)
|
||||
{
|
||||
|
||||
#ifdef ENFORCE_PINS
|
||||
// ESP32 Recommend only the following pins 2,4,12-19,21-23,25-27,32-33
|
||||
// ESP32-S2 only the following pins 1-21,26,33-42
|
||||
if (pwm.hasPwm(pin))
|
||||
{
|
||||
#endif
|
||||
|
||||
// OK to proceed; first check for new/reuse
|
||||
if (this->pinNumber < 0) // we are attaching to a new or previously detached pin; we need to initialize/reinitialize
|
||||
{
|
||||
this->ticks = DEFAULT_PULSE_WIDTH_TICKS;
|
||||
this->timer_width = DEFAULT_TIMER_WIDTH;
|
||||
this->timer_width_ticks = pow(2,this->timer_width);
|
||||
}
|
||||
this->pinNumber = pin;
|
||||
#ifdef ENFORCE_PINS
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef __XTENSA_esp32s3__
|
||||
if(
|
||||
#endif
|
||||
Serial.println("This pin can not be a servo: "+String(pin)+
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
"\r\nServo available on: 1-21,26,33-42"
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
"\r\nPWM available on: 1-21,35-45,47-48"
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
"\r\nPWM available on: 1-10,18-21"
|
||||
#else
|
||||
"\r\nServo available on: 2,4,5,12-19,21-23,25-27,32-33"
|
||||
#endif
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// min/max checks
|
||||
if (min < MIN_PULSE_WIDTH) // ensure pulse width is valid
|
||||
min = MIN_PULSE_WIDTH;
|
||||
if (max > MAX_PULSE_WIDTH)
|
||||
max = MAX_PULSE_WIDTH;
|
||||
this->min = min; //store this value in uS
|
||||
this->max = max; //store this value in uS
|
||||
// Set up this channel
|
||||
// if you want anything other than default timer width, you must call setTimerWidth() before attach
|
||||
pwm.attachPin(this->pinNumber,REFRESH_CPS, this->timer_width ); // GPIO pin assigned to channel
|
||||
//Serial.println("Attaching servo : "+String(pin)+" on PWM "+String(pwm.getChannel()));
|
||||
return pwm.getChannel();
|
||||
}
|
||||
|
||||
void Servo::detach()
|
||||
{
|
||||
if (this->attached())
|
||||
{
|
||||
//keep track of detached servos channels so we can reuse them if needed
|
||||
pwm.detachPin(this->pinNumber);
|
||||
|
||||
this->pinNumber = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void Servo::write(int value)
|
||||
{
|
||||
// treat values less than MIN_PULSE_WIDTH (500) as angles in degrees (valid values in microseconds are handled as microseconds)
|
||||
if (value < MIN_PULSE_WIDTH)
|
||||
{
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
else if (value > 180)
|
||||
value = 180;
|
||||
|
||||
value = map(value, 0, 180, this->min, this->max);
|
||||
}
|
||||
this->writeMicroseconds(value);
|
||||
}
|
||||
|
||||
void Servo::writeMicroseconds(int value)
|
||||
{
|
||||
// calculate and store the values for the given channel
|
||||
if (this->attached()) // ensure channel is valid
|
||||
{
|
||||
if (value < this->min) // ensure pulse width is valid
|
||||
value = this->min;
|
||||
else if (value > this->max)
|
||||
value = this->max;
|
||||
|
||||
value = usToTicks(value); // convert to ticks
|
||||
this->ticks = value;
|
||||
// do the actual write
|
||||
pwm.write( this->ticks);
|
||||
}
|
||||
}
|
||||
|
||||
void Servo::release()
|
||||
{
|
||||
if (this->attached()) // ensure channel is valid
|
||||
pwm.write(0);
|
||||
}
|
||||
|
||||
int Servo::read() // return the value as degrees
|
||||
{
|
||||
return (map(readMicroseconds()+1, this->min, this->max, 0, 180));
|
||||
}
|
||||
|
||||
int Servo::readMicroseconds()
|
||||
{
|
||||
int pulsewidthUsec;
|
||||
if (this->attached())
|
||||
{
|
||||
pulsewidthUsec = ticksToUs(this->ticks);
|
||||
}
|
||||
else
|
||||
{
|
||||
pulsewidthUsec = 0;
|
||||
}
|
||||
|
||||
return (pulsewidthUsec);
|
||||
}
|
||||
|
||||
bool Servo::attached()
|
||||
{
|
||||
return (pwm.attached());
|
||||
}
|
||||
|
||||
void Servo::setTimerWidth(int value)
|
||||
{
|
||||
// only allow values between 10 and 14 for ESP32-C3
|
||||
// only allow values between 16 and 20 for other ESP32
|
||||
if (value < MINIMUM_TIMER_WIDTH )
|
||||
value = MINIMUM_TIMER_WIDTH;
|
||||
else if (value > MAXIMUM_TIMER_WIDTH)
|
||||
value = MAXIMUM_TIMER_WIDTH;
|
||||
|
||||
// Fix the current ticks value after timer width change
|
||||
// The user can reset the tick value with a write() or writeUs()
|
||||
int widthDifference = this->timer_width - value;
|
||||
// if positive multiply by diff; if neg, divide
|
||||
if (widthDifference > 0)
|
||||
{
|
||||
this->ticks = widthDifference * this->ticks;
|
||||
}
|
||||
else if (widthDifference < 0)
|
||||
{
|
||||
this->ticks = this->ticks/-widthDifference;
|
||||
}
|
||||
|
||||
this->timer_width = value;
|
||||
this->timer_width_ticks = pow(2,this->timer_width);
|
||||
|
||||
// If this is an attached servo, clean up
|
||||
if (this->attached())
|
||||
{
|
||||
// detach, setup and attach again to reflect new timer width
|
||||
pwm.detachPin(this->pinNumber);
|
||||
pwm.attachPin(this->pinNumber, REFRESH_CPS, this->timer_width);
|
||||
}
|
||||
}
|
||||
|
||||
int Servo::readTimerWidth()
|
||||
{
|
||||
return (this->timer_width);
|
||||
}
|
||||
|
||||
int Servo::usToTicks(int usec)
|
||||
{
|
||||
return (int)((double)usec / ((double)REFRESH_USEC / (double)this->timer_width_ticks)*(((double)REFRESH_CPS)/50.0));
|
||||
}
|
||||
|
||||
int Servo::ticksToUs(int ticks)
|
||||
{
|
||||
return (int)((double)ticks * ((double)REFRESH_USEC / (double)this->timer_width_ticks)/(((double)REFRESH_CPS)/50.0));
|
||||
}
|
||||
|
||||
|
169
libs/ESP32Servo/src/ESP32Servo.h
Normal file
169
libs/ESP32Servo/src/ESP32Servo.h
Normal file
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
Copyright (c) 2017 John K. Bennett. All right reserved.
|
||||
|
||||
ESP32_Servo.h - Servo library for ESP32 - Version 1
|
||||
|
||||
Original Servo.h written by Michael Margolis in 2009
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
A servo is activated by creating an instance of the Servo class, and passing
|
||||
the desired GPIO pin to the attach() method.
|
||||
The servos are pulsed in the background using the value most recently
|
||||
written using the write() method.
|
||||
|
||||
The class methods are:
|
||||
|
||||
Servo - Class for manipulating servo motors connected to ESP32 pins.
|
||||
int attach(pin ) - Attaches the given GPIO pin to the next free channel
|
||||
(channels that have previously been detached are used first),
|
||||
returns channel number or 0 if failure. All pin numbers are allowed,
|
||||
but only pins 2,4,12-19,21-23,25-27,32-33 are recommended.
|
||||
int attach(pin, min, max ) - Attaches to a pin setting min and max
|
||||
values in microseconds; enforced minimum min is 500, enforced max
|
||||
is 2500. Other semantics same as attach().
|
||||
void write () - Sets the servo angle in degrees; a value below 500 is
|
||||
treated as a value in degrees (0 to 180). These limit are enforced,
|
||||
i.e., values are treated as follows:
|
||||
Value Becomes
|
||||
----- -------
|
||||
< 0 0
|
||||
0 - 180 value (treated as degrees)
|
||||
181 - 499 180
|
||||
500 - (min-1) min
|
||||
min-max (from attach or default) value (treated as microseconds)
|
||||
(max+1) - 2500 max
|
||||
|
||||
void writeMicroseconds() - Sets the servo pulse width in microseconds.
|
||||
min and max are enforced (see above).
|
||||
int read() - Gets the last written servo pulse width as an angle between 0 and 180.
|
||||
int readMicroseconds() - Gets the last written servo pulse width in microseconds.
|
||||
bool attached() - Returns true if this servo instance is attached.
|
||||
void detach() - Stops an the attached servo, frees its attached pin, and frees
|
||||
its channel for reuse).
|
||||
|
||||
*** ESP32-specific functions **
|
||||
setTimerWidth(value) - Sets the PWM timer width (must be 16-20) (ESP32 ONLY);
|
||||
as a side effect, the pulse width is recomputed.
|
||||
int readTimerWidth() - Gets the PWM timer width (ESP32 ONLY)
|
||||
*/
|
||||
|
||||
#ifndef ESP32_Servo_h
|
||||
#define ESP32_Servo_h
|
||||
//#include "analogWrite.h"
|
||||
#include "ESP32PWM.h"
|
||||
//#include "ESP32Tone.h"
|
||||
//Enforce only using PWM pins on the ESP32
|
||||
#define ENFORCE_PINS
|
||||
// Default Arduino Servo.h
|
||||
#define DEFAULT_uS_LOW 544
|
||||
#define DEFAULT_uS_HIGH 2400
|
||||
|
||||
// Values for TowerPro MG995 large servos (and many other hobbyist servos)
|
||||
//#define DEFAULT_uS_LOW 1000 // 1000us
|
||||
//#define DEFAULT_uS_HIGH 2000 // 2000us
|
||||
|
||||
// Values for TowerPro SG90 small servos
|
||||
//#define DEFAULT_uS_LOW 400
|
||||
//#define DEFAULT_uS_HIGH 2400
|
||||
|
||||
#ifdef ARDUINO_ESP32C3_DEV
|
||||
#define MINIMUM_TIMER_WIDTH 10
|
||||
#define MAXIMUM_TIMER_WIDTH 14
|
||||
#define DEFAULT_TIMER_WIDTH 10
|
||||
#else
|
||||
#define MINIMUM_TIMER_WIDTH 10
|
||||
#define MAXIMUM_TIMER_WIDTH 20
|
||||
#define DEFAULT_TIMER_WIDTH 10
|
||||
#endif
|
||||
#define DEFAULT_TIMER_WIDTH_TICKS 1024
|
||||
|
||||
#define ESP32_Servo_VERSION 1 // software version of this library
|
||||
|
||||
#define MIN_PULSE_WIDTH 500 // the shortest pulse sent to a servo
|
||||
#define MAX_PULSE_WIDTH 2500 // the longest pulse sent to a servo
|
||||
#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached
|
||||
#define DEFAULT_PULSE_WIDTH_TICKS 4825
|
||||
//#define REFRESH_CPS 50
|
||||
#define REFRESH_USEC 20000
|
||||
|
||||
#define MAX_SERVOS 16 // no. of PWM channels in ESP32
|
||||
|
||||
/*
|
||||
* This group/channel/timmer mapping is for information only;
|
||||
* the details are handled by lower-level code
|
||||
*
|
||||
* LEDC Chan to Group/Channel/Timer Mapping
|
||||
** ledc: 0 => Group: 0, Channel: 0, Timer: 0
|
||||
** ledc: 1 => Group: 0, Channel: 1, Timer: 0
|
||||
** ledc: 2 => Group: 0, Channel: 2, Timer: 1
|
||||
** ledc: 3 => Group: 0, Channel: 3, Timer: 1
|
||||
** ledc: 4 => Group: 0, Channel: 4, Timer: 2
|
||||
** ledc: 5 => Group: 0, Channel: 5, Timer: 2
|
||||
** ledc: 6 => Group: 0, Channel: 6, Timer: 3
|
||||
** ledc: 7 => Group: 0, Channel: 7, Timer: 3
|
||||
** ledc: 8 => Group: 1, Channel: 0, Timer: 0
|
||||
** ledc: 9 => Group: 1, Channel: 1, Timer: 0
|
||||
** ledc: 10 => Group: 1, Channel: 2, Timer: 1
|
||||
** ledc: 11 => Group: 1, Channel: 3, Timer: 1
|
||||
** ledc: 12 => Group: 1, Channel: 4, Timer: 2
|
||||
** ledc: 13 => Group: 1, Channel: 5, Timer: 2
|
||||
** ledc: 14 => Group: 1, Channel: 6, Timer: 3
|
||||
** ledc: 15 => Group: 1, Channel: 7, Timer: 3
|
||||
*/
|
||||
|
||||
class Servo {
|
||||
|
||||
public:
|
||||
Servo();
|
||||
// Arduino Servo Library calls
|
||||
int attach(int pin); // attach the given pin to the next free channel, returns channel number or 0 if failure
|
||||
int attach(int pin, int min, int max); // as above but also sets min and max values for writes.
|
||||
void detach();
|
||||
void write(int value); // if value is < MIN_PULSE_WIDTH its treated as an angle, otherwise as pulse width in microseconds
|
||||
void writeMicroseconds(int value); // Write pulse width in microseconds
|
||||
void release();
|
||||
int read(); // returns current pulse width as an angle between 0 and 180 degrees
|
||||
int readMicroseconds(); // returns current pulse width in microseconds for this servo
|
||||
bool attached(); // return true if this servo is attached, otherwise false
|
||||
|
||||
// ESP32 only functions
|
||||
void setTimerWidth(int value); // set the PWM timer width (ESP32 ONLY)
|
||||
int readTimerWidth(); // get the PWM timer width (ESP32 ONLY)
|
||||
void setPeriodHertz(int hertz){
|
||||
REFRESH_CPS=hertz;
|
||||
setTimerWidth(this->timer_width);
|
||||
}
|
||||
private:
|
||||
int usToTicks(int usec);
|
||||
int ticksToUs(int ticks);
|
||||
// static int ServoCount; // the total number of attached servos
|
||||
// static int ChannelUsed[]; // used to track whether a channel is in service
|
||||
// int servoChannel = 0; // channel number for this servo
|
||||
|
||||
int min = DEFAULT_uS_LOW; // minimum pulse width for this servo
|
||||
int max = DEFAULT_uS_HIGH; // maximum pulse width for this servo
|
||||
int pinNumber = 0; // GPIO pin assigned to this channel
|
||||
int timer_width = DEFAULT_TIMER_WIDTH; // ESP32 allows variable width PWM timers
|
||||
int ticks = DEFAULT_PULSE_WIDTH_TICKS; // current pulse width on this channel
|
||||
int timer_width_ticks = DEFAULT_TIMER_WIDTH_TICKS; // no. of ticks at rollover; varies with width
|
||||
ESP32PWM * getPwm(); // get the PWM object
|
||||
ESP32PWM pwm;
|
||||
int REFRESH_CPS = 50;
|
||||
|
||||
};
|
||||
#endif
|
0
libs/WiFi/examples/FTM/FTM_Initiator/.skip.esp32h2
Normal file
0
libs/WiFi/examples/FTM/FTM_Initiator/.skip.esp32h2
Normal file
91
libs/WiFi/examples/FTM/FTM_Initiator/FTM_Initiator.ino
Normal file
91
libs/WiFi/examples/FTM/FTM_Initiator/FTM_Initiator.ino
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* Wi-Fi FTM Initiator Arduino Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include "WiFi.h"
|
||||
|
||||
/*
|
||||
THIS FEATURE IS SUPPORTED ONLY BY ESP32-S2 AND ESP32-C3
|
||||
*/
|
||||
|
||||
// Change the SSID and PASSWORD here if needed
|
||||
const char * WIFI_FTM_SSID = "WiFi_FTM_Responder"; // SSID of AP that has FTM Enabled
|
||||
const char * WIFI_FTM_PASS = "ftm_responder"; // STA Password
|
||||
|
||||
// FTM settings
|
||||
// Number of FTM frames requested in terms of 4 or 8 bursts (allowed values - 0 (No pref), 16, 24, 32, 64)
|
||||
const uint8_t FTM_FRAME_COUNT = 16;
|
||||
// Requested time period between consecutive FTM bursts in 100’s of milliseconds (allowed values - 0 (No pref) or 2-255)
|
||||
const uint16_t FTM_BURST_PERIOD = 2;
|
||||
|
||||
// Semaphore to signal when FTM Report has been received
|
||||
SemaphoreHandle_t ftmSemaphore;
|
||||
// Status of the received FTM Report
|
||||
bool ftmSuccess = true;
|
||||
|
||||
// FTM report handler with the calculated data from the round trip
|
||||
// WARNING: This function is called from a separate FreeRTOS task (thread)!
|
||||
void onFtmReport(arduino_event_t *event) {
|
||||
const char * status_str[5] = {"SUCCESS", "UNSUPPORTED", "CONF_REJECTED", "NO_RESPONSE", "FAIL"};
|
||||
wifi_event_ftm_report_t * report = &event->event_info.wifi_ftm_report;
|
||||
// Set the global report status
|
||||
ftmSuccess = report->status == FTM_STATUS_SUCCESS;
|
||||
if (ftmSuccess) {
|
||||
// The estimated distance in meters may vary depending on some factors (see README file)
|
||||
Serial.printf("FTM Estimate: Distance: %.2f m, Return Time: %lu ns\n", (float)report->dist_est / 100.0, report->rtt_est);
|
||||
// Pointer to FTM Report with multiple entries, should be freed after use
|
||||
free(report->ftm_report_data);
|
||||
} else {
|
||||
Serial.print("FTM Error: ");
|
||||
Serial.println(status_str[report->status]);
|
||||
}
|
||||
// Signal that report is received
|
||||
xSemaphoreGive(ftmSemaphore);
|
||||
}
|
||||
|
||||
// Initiate FTM Session and wait for FTM Report
|
||||
bool getFtmReport(){
|
||||
if(!WiFi.initiateFTM(FTM_FRAME_COUNT, FTM_BURST_PERIOD)){
|
||||
Serial.println("FTM Error: Initiate Session Failed");
|
||||
return false;
|
||||
}
|
||||
// Wait for signal that report is received and return true if status was success
|
||||
return xSemaphoreTake(ftmSemaphore, portMAX_DELAY) == pdPASS && ftmSuccess;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Create binary semaphore (initialized taken and can be taken/given from any thread/ISR)
|
||||
ftmSemaphore = xSemaphoreCreateBinary();
|
||||
|
||||
// Will call onFtmReport() from another thread with FTM Report events.
|
||||
WiFi.onEvent(onFtmReport, ARDUINO_EVENT_WIFI_FTM_REPORT);
|
||||
|
||||
// Connect to AP that has FTM Enabled
|
||||
Serial.println("Connecting to FTM Responder");
|
||||
WiFi.begin(WIFI_FTM_SSID, WIFI_FTM_PASS);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("WiFi Connected");
|
||||
|
||||
Serial.print("Initiating FTM session with Frame Count ");
|
||||
Serial.print(FTM_FRAME_COUNT);
|
||||
Serial.print(" and Burst Period ");
|
||||
Serial.print(FTM_BURST_PERIOD * 100);
|
||||
Serial.println(" ms");
|
||||
|
||||
// Request FTM reports until one fails
|
||||
while(getFtmReport());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(1000);
|
||||
}
|
110
libs/WiFi/examples/FTM/FTM_Initiator/README.md
Normal file
110
libs/WiFi/examples/FTM/FTM_Initiator/README.md
Normal file
|
@ -0,0 +1,110 @@
|
|||
# Wi-Fi FTM Initiator Arduino Example
|
||||
|
||||
This example demonstrates how to use the Fine Timing Measurement (FTM) to calculate the distace from the Access Point and the device. This is calculated by the Wi-Fi Round Trip Time (Wi-Fi RTT) introduced on the [IEEE Std 802.11-2016](https://en.wikipedia.org/wiki/IEEE_802.11mc) standard.
|
||||
|
||||
This example was based on the [ESP-IDF FTM](https://github.com/espressif/esp-idf/tree/master/examples/wifi/ftm). See the README file for more details about on how to use this feature.
|
||||
|
||||
Some usages for this feature includes:
|
||||
|
||||
* Indoor positioning systems.
|
||||
* Navigation.
|
||||
* Device Location.
|
||||
* Smart Devices.
|
||||
* Alarms.
|
||||
|
||||
# Supported Targets
|
||||
|
||||
Currently, this example supports the following targets:
|
||||
|
||||
| Supported Targets | ESP32-S2 | ESP32-C3 |
|
||||
| ----------------- | -------- | -------- |
|
||||
|
||||
## How to Use Example
|
||||
|
||||
In order to use the FTM, you will need a Responder or Wi-Fi router with FTM capabilities. If you don't own one, you can use a second ESP32-S2 or ESP32-C3 to simulate one.
|
||||
See the **Responder** example to prepare the environment.
|
||||
|
||||
* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide).
|
||||
|
||||
### Configure the Project
|
||||
|
||||
To configure this project, you can change the following configuration related to FTM feature:
|
||||
|
||||
```c
|
||||
// Change the SSID and PASSWORD here if needed
|
||||
const char * WIFI_FTM_SSID = "WiFi_FTM_Responder"; // SSID of AP that has FTM Enabled
|
||||
const char * WIFI_FTM_PASS = "ftm_responder"; // STA Password
|
||||
|
||||
// FTM settings
|
||||
// Number of FTM frames requested in terms of 4 or 8 bursts (allowed values - 0 (No pref), 16, 24, 32, 64)
|
||||
const uint8_t FTM_FRAME_COUNT = 16;
|
||||
// Requested time period between consecutive FTM bursts in 100’s of milliseconds (allowed values - 0 (No pref) or 2-255)
|
||||
const uint16_t FTM_BURST_PERIOD = 2;
|
||||
```
|
||||
|
||||
* Change the Wi-Fi `SSID` and `PASSWORD` as the same as the Responder/Router.
|
||||
* Change `FTM_FRAME_COUNT` with the number of frames requested to the Responder.
|
||||
* Change `FTM_BURST_PERIOD` with the time between each FTM burst.
|
||||
|
||||
To see more details about FTM, please see the [ESP-IDF docs](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/network/esp_wifi.html).
|
||||
|
||||
#### Using Arduino IDE
|
||||
|
||||
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
|
||||
|
||||
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||
|
||||
#### Using Platform IO
|
||||
|
||||
* Select the COM port: `Devices` or setting the `upload_port` option on the `platformio.ini` file.
|
||||
|
||||
## Log Output
|
||||
|
||||
Expected log output:
|
||||
|
||||
```
|
||||
ESP-ROM:esp32s2-rc4-20191025
|
||||
Build:Oct 25 2019
|
||||
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
|
||||
SPIWP:0xee
|
||||
mode:DIO, clock div:1
|
||||
load:0x3ffe6100,len:0x4b0
|
||||
load:0x4004c000,len:0xa6c
|
||||
load:0x40050000,len:0x25c4
|
||||
entry 0x4004c198
|
||||
Connecting to FTM Responder
|
||||
.....
|
||||
WiFi Connected
|
||||
Initiating FTM session with Frame Count 16 and Burst Period 200 ms
|
||||
FTM Estimate: Distance: 0.13 m, Return Time: 0 ns
|
||||
FTM Estimate: Distance: 0.13 m, Return Time: 0 ns
|
||||
FTM Estimate: Distance: 0.13 m, Return Time: 0 ns
|
||||
FTM Estimate: Distance: 0.00 m, Return Time: 0 ns
|
||||
...
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source.***
|
||||
|
||||
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
|
||||
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
|
||||
|
||||
If the error persist, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||
|
||||
## Contribute
|
||||
|
||||
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
|
||||
|
||||
Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else.
|
||||
|
||||
## Resources
|
||||
|
||||
* Official ESP32 Forum: [Link](https://esp32.com)
|
||||
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
|
||||
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
|
||||
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
|
0
libs/WiFi/examples/FTM/FTM_Responder/.skip.esp32h2
Normal file
0
libs/WiFi/examples/FTM/FTM_Responder/.skip.esp32h2
Normal file
23
libs/WiFi/examples/FTM/FTM_Responder/FTM_Responder.ino
Normal file
23
libs/WiFi/examples/FTM/FTM_Responder/FTM_Responder.ino
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* Wi-Fi FTM Responder Arduino Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include "WiFi.h"
|
||||
// Change the SSID and PASSWORD here if needed
|
||||
const char * WIFI_FTM_SSID = "WiFi_FTM_Responder";
|
||||
const char * WIFI_FTM_PASS = "ftm_responder";
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting SoftAP with FTM Responder support");
|
||||
// Enable AP with FTM support (last argument is 'true')
|
||||
WiFi.softAP(WIFI_FTM_SSID, WIFI_FTM_PASS, 1, 0, 4, true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(1000);
|
||||
}
|
94
libs/WiFi/examples/FTM/FTM_Responder/README.md
Normal file
94
libs/WiFi/examples/FTM/FTM_Responder/README.md
Normal file
|
@ -0,0 +1,94 @@
|
|||
# Wi-Fi FTM Responder Arduino Example
|
||||
|
||||
This example demonstrates how to use the Fine Timing Measurement (FTM) to calculate the distace from the Access Point and the device. This is calculated by the Wi-Fi Round Trip Time (Wi-Fi RTT) introduced on the [IEEE Std 802.11-2016](https://en.wikipedia.org/wiki/IEEE_802.11mc) standard.
|
||||
|
||||
This example will simulate the Router with FTM capability.
|
||||
|
||||
This example was based on the [ESP-IDF FTM](https://github.com/espressif/esp-idf/tree/master/examples/wifi/ftm). See the README file for more details about on how to use this feature.
|
||||
|
||||
Some usages for this feature includes:
|
||||
|
||||
* Indoor positioning systems.
|
||||
* Navigation.
|
||||
* Device Location.
|
||||
* Smart Devices.
|
||||
* Alarms.
|
||||
|
||||
# Supported Targets
|
||||
|
||||
Currently, this example supports the following targets:
|
||||
|
||||
| Supported Targets | ESP32-S2 | ESP32-C3 |
|
||||
| ----------------- | -------- | -------- |
|
||||
|
||||
## How to Use Example
|
||||
|
||||
See the **Initiator** example to prepare the environment.
|
||||
|
||||
* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide).
|
||||
|
||||
### Configure the Project
|
||||
|
||||
To configure this project, you can change the following configuration related to STA:
|
||||
|
||||
```c
|
||||
// Change the SSID and PASSWORD here if needed
|
||||
const char * WIFI_FTM_SSID = "WiFi_FTM_Responder";
|
||||
const char * WIFI_FTM_PASS = "ftm_responder";
|
||||
```
|
||||
|
||||
* Change the Wi-Fi `SSID` and `PASSWORD` as the same as the Initiator.
|
||||
|
||||
To see more details about FTM, please see the [ESP-IDF docs](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/network/esp_wifi.html).
|
||||
|
||||
#### Using Arduino IDE
|
||||
|
||||
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
|
||||
|
||||
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||
|
||||
#### Using Platform IO
|
||||
|
||||
* Select the COM port: `Devices` or setting the `upload_port` option on the `platformio.ini` file.
|
||||
|
||||
## Log Output
|
||||
|
||||
Expected log output:
|
||||
|
||||
```
|
||||
Build:Oct 25 2019
|
||||
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
|
||||
SPIWP:0xee
|
||||
mode:DIO, clock div:1
|
||||
load:0x3ffe6100,len:0x4b0
|
||||
load:0x4004c000,len:0xa6c
|
||||
load:0x40050000,len:0x25c4
|
||||
entry 0x4004c198
|
||||
Starting SoftAP with FTM Responder support
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source.***
|
||||
|
||||
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
|
||||
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
|
||||
|
||||
If the error persist, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||
|
||||
## Contribute
|
||||
|
||||
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
|
||||
|
||||
Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else.
|
||||
|
||||
## Resources
|
||||
|
||||
* Official ESP32 Forum: [Link](https://esp32.com)
|
||||
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
|
||||
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
|
||||
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
|
0
libs/WiFi/examples/SimpleWiFiServer/.skip.esp32h2
Normal file
0
libs/WiFi/examples/SimpleWiFiServer/.skip.esp32h2
Normal file
114
libs/WiFi/examples/SimpleWiFiServer/SimpleWiFiServer.ino
Normal file
114
libs/WiFi/examples/SimpleWiFiServer/SimpleWiFiServer.ino
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
WiFi Web Server LED Blink
|
||||
|
||||
A simple web server that lets you blink an LED via the web.
|
||||
This sketch will print the IP address of your WiFi Shield (once connected)
|
||||
to the Serial monitor. From there, you can open that address in a web browser
|
||||
to turn on and off the LED on pin 5.
|
||||
|
||||
If the IP address of your shield is yourAddress:
|
||||
http://yourAddress/H turns the LED on
|
||||
http://yourAddress/L turns it off
|
||||
|
||||
This example is written for a network using WPA2 encryption. For insecure
|
||||
WEP or WPA, change the Wifi.begin() call and use Wifi.setMinSecurity() accordingly.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
* LED attached to pin 5
|
||||
|
||||
created for arduino 25 Nov 2012
|
||||
by Tom Igoe
|
||||
|
||||
ported for sparkfun esp32
|
||||
31.01.2017 by Jan Hendrik Berlin
|
||||
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
const char* ssid = "yourssid";
|
||||
const char* password = "yourpasswd";
|
||||
|
||||
WiFiServer server(80);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
pinMode(5, OUTPUT); // set the LED pin mode
|
||||
|
||||
delay(10);
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected.");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
server.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
WiFiClient client = server.accept(); // listen for incoming clients
|
||||
|
||||
if (client) { // if you get a client,
|
||||
Serial.println("New Client."); // print a message out the serial port
|
||||
String currentLine = ""; // make a String to hold incoming data from the client
|
||||
while (client.connected()) { // loop while the client's connected
|
||||
if (client.available()) { // if there's bytes to read from the client,
|
||||
char c = client.read(); // read a byte, then
|
||||
Serial.write(c); // print it out the serial monitor
|
||||
if (c == '\n') { // if the byte is a newline character
|
||||
|
||||
// if the current line is blank, you got two newline characters in a row.
|
||||
// that's the end of the client HTTP request, so send a response:
|
||||
if (currentLine.length() == 0) {
|
||||
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
|
||||
// and a content-type so the client knows what's coming, then a blank line:
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-type:text/html");
|
||||
client.println();
|
||||
|
||||
// the content of the HTTP response follows the header:
|
||||
client.print("Click <a href=\"/H\">here</a> to turn the LED on pin 5 on.<br>");
|
||||
client.print("Click <a href=\"/L\">here</a> to turn the LED on pin 5 off.<br>");
|
||||
|
||||
// The HTTP response ends with another blank line:
|
||||
client.println();
|
||||
// break out of the while loop:
|
||||
break;
|
||||
} else { // if you got a newline, then clear currentLine:
|
||||
currentLine = "";
|
||||
}
|
||||
} else if (c != '\r') { // if you got anything else but a carriage return character,
|
||||
currentLine += c; // add it to the end of the currentLine
|
||||
}
|
||||
|
||||
// Check to see if the client request was "GET /H" or "GET /L":
|
||||
if (currentLine.endsWith("GET /H")) {
|
||||
digitalWrite(5, HIGH); // GET /H turns the LED on
|
||||
}
|
||||
if (currentLine.endsWith("GET /L")) {
|
||||
digitalWrite(5, LOW); // GET /L turns the LED off
|
||||
}
|
||||
}
|
||||
}
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println("Client Disconnected.");
|
||||
}
|
||||
}
|
0
libs/WiFi/examples/WPS/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WPS/.skip.esp32h2
Normal file
104
libs/WiFi/examples/WPS/README.md
Normal file
104
libs/WiFi/examples/WPS/README.md
Normal file
|
@ -0,0 +1,104 @@
|
|||
Example Serial Logs For Various Cases
|
||||
======================================
|
||||
|
||||
For WPS Push Button method,after the ESP32 boots up and prints that WPS has started, press the button that looks something like [this](https://www.verizon.com/supportresources/images/fqgrouter-frontview-wps-button.png) on your router. In case you dont find anything similar, check your router specs if it does really support WPS Push functionality.
|
||||
|
||||
As for WPS Pin Mode, it will output a 8 digit Pin on the Serial Monitor that will change every 2 minutes if it hasn't connected. You need to log in to your router (generally reaching 192.168.0.1) and enter the pin shown in Serial Monitor in the WPS Settings of your router.
|
||||
|
||||
#### WPS Push Button Failure
|
||||
|
||||
```
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0xee
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fff0010,len:4
|
||||
load:0x3fff0014,len:732
|
||||
load:0x40078000,len:0
|
||||
load:0x40078000,len:11572
|
||||
entry 0x40078a14
|
||||
|
||||
Starting WPS
|
||||
Station Mode Started
|
||||
WPS Timedout, retrying
|
||||
WPS Timedout, retrying
|
||||
```
|
||||
|
||||
#### WPS Push Button Successfull
|
||||
|
||||
```
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0xee
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fff0010,len:4
|
||||
load:0x3fff0014,len:732
|
||||
load:0x40078000,len:0
|
||||
load:0x40078000,len:11572
|
||||
entry 0x40078a14
|
||||
|
||||
Starting WPS
|
||||
Station Mode Started
|
||||
WPS Successfull, stopping WPS and connecting to: < Your Router SSID >
|
||||
Disconnected from station, attempting reconnection
|
||||
Connected to : < Your Router SSID >
|
||||
Got IP: 192.168.1.100
|
||||
```
|
||||
|
||||
#### WPS PIN Failure
|
||||
|
||||
```
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0xee
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fff0010,len:4
|
||||
load:0x3fff0014,len:732
|
||||
load:0x40078000,len:0
|
||||
load:0x40078000,len:11572
|
||||
entry 0x40078a14
|
||||
|
||||
Starting WPS
|
||||
Station Mode Started
|
||||
WPS_PIN = 94842104
|
||||
WPS Timedout, retrying
|
||||
WPS_PIN = 55814171
|
||||
WPS Timedout, retrying
|
||||
WPS_PIN = 71321622
|
||||
```
|
||||
|
||||
#### WPS PIN Successfull
|
||||
|
||||
```
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0xee
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fff0010,len:4
|
||||
load:0x3fff0014,len:732
|
||||
load:0x40078000,len:0
|
||||
load:0x40078000,len:11572
|
||||
entry 0x40078a14
|
||||
|
||||
Starting WPS
|
||||
Station Mode Started
|
||||
WPS_PIN = 36807581
|
||||
WPS Successfull, stopping WPS and connecting to: <Your Router SSID>
|
||||
Disconnected from station, attempting reconnection
|
||||
Connected to :<Your Router SSID>
|
||||
Got IP: 192.168.1.100
|
||||
```
|
116
libs/WiFi/examples/WPS/WPS.ino
Normal file
116
libs/WiFi/examples/WPS/WPS.ino
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
Example Code To Get ESP32 To Connect To A Router Using WPS
|
||||
===========================================================
|
||||
This example code provides both Push Button method and Pin
|
||||
based WPS entry to get your ESP connected to your WiFi router.
|
||||
|
||||
Hardware Requirements
|
||||
========================
|
||||
ESP32 and a Router having WPS functionality
|
||||
|
||||
This code is under Public Domain License.
|
||||
|
||||
Author:
|
||||
Pranav Cherukupalli <cherukupallip@gmail.com>
|
||||
*/
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "esp_wps.h"
|
||||
/*
|
||||
Change the definition of the WPS mode
|
||||
from WPS_TYPE_PBC to WPS_TYPE_PIN in
|
||||
the case that you are using pin type
|
||||
WPS
|
||||
*/
|
||||
#define ESP_WPS_MODE WPS_TYPE_PBC
|
||||
#define ESP_MANUFACTURER "ESPRESSIF"
|
||||
#define ESP_MODEL_NUMBER "ESP32"
|
||||
#define ESP_MODEL_NAME "ESPRESSIF IOT"
|
||||
#define ESP_DEVICE_NAME "ESP STATION"
|
||||
|
||||
static esp_wps_config_t config;
|
||||
|
||||
void wpsInitConfig(){
|
||||
config.wps_type = ESP_WPS_MODE;
|
||||
strcpy(config.factory_info.manufacturer, ESP_MANUFACTURER);
|
||||
strcpy(config.factory_info.model_number, ESP_MODEL_NUMBER);
|
||||
strcpy(config.factory_info.model_name, ESP_MODEL_NAME);
|
||||
strcpy(config.factory_info.device_name, ESP_DEVICE_NAME);
|
||||
}
|
||||
|
||||
void wpsStart(){
|
||||
if(esp_wifi_wps_enable(&config)){
|
||||
Serial.println("WPS Enable Failed");
|
||||
} else if(esp_wifi_wps_start(0)){
|
||||
Serial.println("WPS Start Failed");
|
||||
}
|
||||
}
|
||||
|
||||
void wpsStop(){
|
||||
if(esp_wifi_wps_disable()){
|
||||
Serial.println("WPS Disable Failed");
|
||||
}
|
||||
}
|
||||
|
||||
String wpspin2string(uint8_t a[]){
|
||||
char wps_pin[9];
|
||||
for(int i=0;i<8;i++){
|
||||
wps_pin[i] = a[i];
|
||||
}
|
||||
wps_pin[8] = '\0';
|
||||
return (String)wps_pin;
|
||||
}
|
||||
|
||||
// WARNING: WiFiEvent is called from a separate FreeRTOS task (thread)!
|
||||
void WiFiEvent(WiFiEvent_t event, arduino_event_info_t info){
|
||||
switch(event){
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
Serial.println("Station Mode Started");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
Serial.println("Connected to :" + String(WiFi.SSID()));
|
||||
Serial.print("Got IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Serial.println("Disconnected from station, attempting reconnection");
|
||||
WiFi.reconnect();
|
||||
break;
|
||||
case ARDUINO_EVENT_WPS_ER_SUCCESS:
|
||||
Serial.println("WPS Successfull, stopping WPS and connecting to: " + String(WiFi.SSID()));
|
||||
wpsStop();
|
||||
delay(10);
|
||||
WiFi.begin();
|
||||
break;
|
||||
case ARDUINO_EVENT_WPS_ER_FAILED:
|
||||
Serial.println("WPS Failed, retrying");
|
||||
wpsStop();
|
||||
wpsStart();
|
||||
break;
|
||||
case ARDUINO_EVENT_WPS_ER_TIMEOUT:
|
||||
Serial.println("WPS Timedout, retrying");
|
||||
wpsStop();
|
||||
wpsStart();
|
||||
break;
|
||||
case ARDUINO_EVENT_WPS_ER_PIN:
|
||||
Serial.println("WPS_PIN = " + wpspin2string(info.wps_er_pin.pin_code));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
Serial.println();
|
||||
WiFi.onEvent(WiFiEvent); // Will call WiFiEvent() from another thread.
|
||||
WiFi.mode(WIFI_MODE_STA);
|
||||
Serial.println("Starting WPS");
|
||||
wpsInitConfig();
|
||||
wpsStart();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
//nothing to do here
|
||||
}
|
0
libs/WiFi/examples/WiFiAccessPoint/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiAccessPoint/.skip.esp32h2
Normal file
99
libs/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
Normal file
99
libs/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
WiFiAccessPoint.ino creates a WiFi access point and provides a web server on it.
|
||||
|
||||
Steps:
|
||||
1. Connect to the access point "yourAp"
|
||||
2. Point your web browser to http://192.168.4.1/H to turn the LED on or http://192.168.4.1/L to turn it off
|
||||
OR
|
||||
Run raw TCP "GET /H" and "GET /L" on PuTTY terminal with 192.168.4.1 as IP address and 80 as port
|
||||
|
||||
Created for arduino-esp32 on 04 July, 2018
|
||||
by Elochukwu Ifediora (fedy0)
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiAP.h>
|
||||
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN 2 // Set the GPIO pin where you connected your test LED or comment this line out if your dev board has a built-in LED
|
||||
#endif
|
||||
|
||||
// Set these to your desired credentials.
|
||||
const char *ssid = "yourAP";
|
||||
const char *password = "yourPassword";
|
||||
|
||||
WiFiServer server(80);
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println("Configuring access point...");
|
||||
|
||||
// You can remove the password parameter if you want the AP to be open.
|
||||
// a valid password must have more than 7 characters
|
||||
if (!WiFi.softAP(ssid, password)) {
|
||||
log_e("Soft AP creation failed.");
|
||||
while(1);
|
||||
}
|
||||
IPAddress myIP = WiFi.softAPIP();
|
||||
Serial.print("AP IP address: ");
|
||||
Serial.println(myIP);
|
||||
server.begin();
|
||||
|
||||
Serial.println("Server started");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
WiFiClient client = server.accept(); // listen for incoming clients
|
||||
|
||||
if (client) { // if you get a client,
|
||||
Serial.println("New Client."); // print a message out the serial port
|
||||
String currentLine = ""; // make a String to hold incoming data from the client
|
||||
while (client.connected()) { // loop while the client's connected
|
||||
if (client.available()) { // if there's bytes to read from the client,
|
||||
char c = client.read(); // read a byte, then
|
||||
Serial.write(c); // print it out the serial monitor
|
||||
if (c == '\n') { // if the byte is a newline character
|
||||
|
||||
// if the current line is blank, you got two newline characters in a row.
|
||||
// that's the end of the client HTTP request, so send a response:
|
||||
if (currentLine.length() == 0) {
|
||||
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
|
||||
// and a content-type so the client knows what's coming, then a blank line:
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-type:text/html");
|
||||
client.println();
|
||||
|
||||
// the content of the HTTP response follows the header:
|
||||
client.print("Click <a href=\"/H\">here</a> to turn ON the LED.<br>");
|
||||
client.print("Click <a href=\"/L\">here</a> to turn OFF the LED.<br>");
|
||||
|
||||
// The HTTP response ends with another blank line:
|
||||
client.println();
|
||||
// break out of the while loop:
|
||||
break;
|
||||
} else { // if you got a newline, then clear currentLine:
|
||||
currentLine = "";
|
||||
}
|
||||
} else if (c != '\r') { // if you got anything else but a carriage return character,
|
||||
currentLine += c; // add it to the end of the currentLine
|
||||
}
|
||||
|
||||
// Check to see if the client request was "GET /H" or "GET /L":
|
||||
if (currentLine.endsWith("GET /H")) {
|
||||
digitalWrite(LED_BUILTIN, HIGH); // GET /H turns the LED on
|
||||
}
|
||||
if (currentLine.endsWith("GET /L")) {
|
||||
digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off
|
||||
}
|
||||
}
|
||||
}
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println("Client Disconnected.");
|
||||
}
|
||||
}
|
0
libs/WiFi/examples/WiFiBlueToothSwitch/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiBlueToothSwitch/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiBlueToothSwitch/.skip.esp32s2
Normal file
0
libs/WiFi/examples/WiFiBlueToothSwitch/.skip.esp32s2
Normal file
129
libs/WiFi/examples/WiFiBlueToothSwitch/WiFiBlueToothSwitch.ino
Normal file
129
libs/WiFi/examples/WiFiBlueToothSwitch/WiFiBlueToothSwitch.ino
Normal file
|
@ -0,0 +1,129 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Sketch shows how to switch between WiFi and BlueTooth or use both
|
||||
// Button is attached between GPIO 0 and GND and modes are switched with each press
|
||||
|
||||
#include "WiFi.h"
|
||||
#define STA_SSID "your-ssid"
|
||||
#define STA_PASS "your-pass"
|
||||
#define AP_SSID "esp32"
|
||||
|
||||
enum { STEP_BTON, STEP_BTOFF, STEP_STA, STEP_AP, STEP_AP_STA, STEP_OFF, STEP_BT_STA, STEP_END };
|
||||
|
||||
void onButton(){
|
||||
static uint32_t step = STEP_BTON;
|
||||
switch(step){
|
||||
case STEP_BTON://BT Only
|
||||
Serial.println("** Starting BT");
|
||||
btStart();
|
||||
break;
|
||||
case STEP_BTOFF://All Off
|
||||
Serial.println("** Stopping BT");
|
||||
btStop();
|
||||
break;
|
||||
case STEP_STA://STA Only
|
||||
Serial.println("** Starting STA");
|
||||
WiFi.begin(STA_SSID, STA_PASS);
|
||||
break;
|
||||
case STEP_AP://AP Only
|
||||
Serial.println("** Stopping STA");
|
||||
WiFi.mode(WIFI_AP);
|
||||
Serial.println("** Starting AP");
|
||||
WiFi.softAP(AP_SSID);
|
||||
break;
|
||||
case STEP_AP_STA://AP+STA
|
||||
Serial.println("** Starting STA");
|
||||
WiFi.begin(STA_SSID, STA_PASS);
|
||||
break;
|
||||
case STEP_OFF://All Off
|
||||
Serial.println("** Stopping WiFi");
|
||||
WiFi.mode(WIFI_OFF);
|
||||
break;
|
||||
case STEP_BT_STA://BT+STA
|
||||
Serial.println("** Starting STA+BT");
|
||||
WiFi.begin(STA_SSID, STA_PASS);
|
||||
btStart();
|
||||
break;
|
||||
case STEP_END://All Off
|
||||
Serial.println("** Stopping WiFi+BT");
|
||||
WiFi.mode(WIFI_OFF);
|
||||
btStop();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(step == STEP_END){
|
||||
step = STEP_BTON;
|
||||
} else {
|
||||
step++;
|
||||
}
|
||||
//little debounce
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// WARNING: WiFiEvent is called from a separate FreeRTOS task (thread)!
|
||||
void WiFiEvent(WiFiEvent_t event){
|
||||
switch(event) {
|
||||
case ARDUINO_EVENT_WIFI_AP_START:
|
||||
Serial.println("AP Started");
|
||||
WiFi.softAPsetHostname(AP_SSID);
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STOP:
|
||||
Serial.println("AP Stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
Serial.println("STA Started");
|
||||
WiFi.setHostname(AP_SSID);
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
Serial.println("STA Connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||
Serial.print("STA IPv6: ");
|
||||
Serial.println(WiFi.localIPv6());
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
Serial.print("STA IPv4: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Serial.println("STA Disconnected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_STOP:
|
||||
Serial.println("STA Stopped");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(0, INPUT_PULLUP);
|
||||
WiFi.onEvent(WiFiEvent); // Will call WiFiEvent() from another thread.
|
||||
WiFi.enableIPv6();
|
||||
Serial.print("ESP32 SDK: ");
|
||||
Serial.println(ESP.getSdkVersion());
|
||||
Serial.println("Press the button to select the next mode");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint8_t lastPinState = 1;
|
||||
uint8_t pinState = digitalRead(0);
|
||||
if(!pinState && lastPinState){
|
||||
onButton();
|
||||
}
|
||||
lastPinState = pinState;
|
||||
}
|
0
libs/WiFi/examples/WiFiClient/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiClient/.skip.esp32h2
Normal file
165
libs/WiFi/examples/WiFiClient/README.md
Normal file
165
libs/WiFi/examples/WiFiClient/README.md
Normal file
|
@ -0,0 +1,165 @@
|
|||
# WiFiClient
|
||||
|
||||
This example demonstrates reading and writing data from and to a web service which can be used for logging data, creating insights and taking actions based on those data.
|
||||
|
||||
# Supported Targets
|
||||
|
||||
Currently, this example supports all SoC with WiFi.
|
||||
|
||||
|
||||
| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 |
|
||||
|
||||
|
||||
## How to Use Example
|
||||
|
||||
Flash this example and observe the serial output. You can also take a look at the values at [https://thingspeak.com/channels/2005329](https://thingspeak.com/channels/2005329)
|
||||
|
||||
Please note that this public channel can be accessed by anyone and it is possible that more people will write their values.
|
||||
|
||||
### Configure the Project
|
||||
|
||||
Change `SSID` and `password` to connect to your WiFi.
|
||||
Default values will allow you to use this example without any changes. If you want to use your own channel and you don't have one already follow these steps:
|
||||
|
||||
* Create an account on [thingspeak.com](https://www.thingspeak.com).
|
||||
* After logging in, click on the "New Channel" button to create a new channel for your data. This is where your data will be stored and displayed.
|
||||
* Fill in the Name, Description, and other fields for your channel as desired, then click the "Save Channel" button.
|
||||
* Take note of the "Write API Key" located in the "API keys" tab, this is the key you will use to send data to your channel.
|
||||
* Replace the channelID from tab "Channel Settings" and privateKey with "Read API Keys" from "API Keys" tab.
|
||||
* Replace the host variable with the thingspeak server hostname "api.thingspeak.com"
|
||||
* Upload the sketch to your ESP32 board and make sure that the board is connected to the internet. The ESP32 should now send data to your Thingspeak channel at the intervals specified by the loop function.
|
||||
* Go to the channel view page on thingspeak and check the "Field1" for the new incoming data.
|
||||
* You can use the data visualization and analysis tools provided by Thingspeak to display and process your data in various ways.
|
||||
* Please note, that Thingspeak accepts only integer values.
|
||||
|
||||
#### Config example:
|
||||
|
||||
You can find the data to be changed at the top of the file:
|
||||
|
||||
```cpp
|
||||
const char* ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||
const char* password = "your-password"; // Change this to your WiFi password
|
||||
|
||||
const char* host = "api.thingspeak.com"; // This should not be changed
|
||||
const int httpPort = 80; // This should not be changed
|
||||
const String channelID = "2005329"; // Change this to your channel ID
|
||||
const String writeApiKey = "V6YOTILH9I7D51F9"; // Change this to your Write API key
|
||||
const String readApiKey = "34W6LGLIFXD56MPM"; // Change this to your Read API key
|
||||
|
||||
// The default example accepts one data filed named "field1"
|
||||
// For your own server you can ofcourse create more of them.
|
||||
int field1 = 0;
|
||||
|
||||
int numberOfResults = 3; // Number of results to be read
|
||||
int fieldNumber = 1; // Field number which will be read out
|
||||
```
|
||||
|
||||
#### Using Arduino IDE
|
||||
|
||||
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
|
||||
|
||||
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||
|
||||
#### Using Platform IO
|
||||
|
||||
* Select the COM port: `Devices` or set the `upload_port` option on the `platformio.ini` file.
|
||||
|
||||
## Example Log Output
|
||||
|
||||
The initial output which is common for all examples can be ignored:
|
||||
```
|
||||
SP-ROM:esp32c3-api1-20210207
|
||||
Build:Feb 7 2021
|
||||
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
|
||||
SPIWP:0xee
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fcd5810,len:0x438
|
||||
load:0x403cc710,len:0x918
|
||||
load:0x403ce710,len:0x24e4
|
||||
entry 0x403cc710
|
||||
```
|
||||
Follows the setup output where connection to your WiFi happens:
|
||||
```
|
||||
******************************************************
|
||||
Connecting to your-ssid
|
||||
.
|
||||
WiFi connected
|
||||
IP address:
|
||||
192.168.1.2
|
||||
```
|
||||
Then you can see the write log:
|
||||
```
|
||||
HTTP/1.1 200 OK
|
||||
Date: Fri, 13 Jan 2023 13:12:31 GMT
|
||||
Content-Type: text/plain; charset=utf-8
|
||||
Content-Length: 1
|
||||
Connection: close
|
||||
Status: 200 OK
|
||||
Cache-Control: max-age=0, private, must-revalidate
|
||||
Access-Control-Allow-Origin: *
|
||||
Access-Control-Max-Age: 1800
|
||||
X-Request-Id: 188e3464-f155-44b0-96f6-0f3614170bb0
|
||||
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
|
||||
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
|
||||
ETag: W/"5feceb66ffc86f38d952786c6d696c79"
|
||||
X-Frame-Options: SAMEORIGIN
|
||||
|
||||
0
|
||||
Closing connection
|
||||
```
|
||||
Last portion is the read log:
|
||||
```
|
||||
HTTP/1.1 200 OK
|
||||
Date: Fri, 13 Jan 2023 13:12:32 GMT
|
||||
Content-Type: application/json; charset=utf-8
|
||||
Transfer-Encoding: chunked
|
||||
Connection: close
|
||||
Status: 200 OK
|
||||
Cache-Control: max-age=7, private
|
||||
Access-Control-Allow-Origin: *
|
||||
Access-Control-Max-Age: 1800
|
||||
X-Request-Id: 91b97016-7625-44f6-9797-1b2973aa57b7
|
||||
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
|
||||
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
|
||||
ETag: W/"8e9c308fe2c50309f991586be1aff28d"
|
||||
X-Frame-Options: SAMEORIGIN
|
||||
|
||||
1e3
|
||||
{"channel":{"id":2005329,"name":"WiFiCLient example","description":"Default setup for Arduino ESP32 WiFiClient example","latitude":"0.0","longitude":"0.0","field1":"data0","created_at":"2023-01-11T15:56:08Z","updated_at":"2023-01-13T08:13:58Z","last_entry_id":2871},"feeds":[{"created_at":"2023-01-13T13:11:30Z","entry_id":2869,"field1":"359"},{"created_at":"2023-01-13T13:11:57Z","entry_id":2870,"field1":"361"},{"created_at":"2023-01-13T13:12:23Z","entry_id":2871,"field1":"363"}]}
|
||||
0
|
||||
|
||||
|
||||
Closing connection
|
||||
```
|
||||
After this the write+read log repeat every 10 seconds.
|
||||
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
|
||||
|
||||
* **WiFi not connected:** Check the SSID and password and also that the signal has sufficient strength.
|
||||
* **400 Bad Request:** Check the writeApiKey.
|
||||
* **404 Not Found:** Check the channel ID.
|
||||
* **No data on chart / reading NULL:** Data must be sent as an integer, without commas.
|
||||
|
||||
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||
|
||||
## Contribute
|
||||
|
||||
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
|
||||
|
||||
Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else.
|
||||
|
||||
## Resources
|
||||
|
||||
* Official ESP32 Forum: [Link](https://esp32.com)
|
||||
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
|
||||
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
|
||||
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
|
||||
* ESP32-S3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf)
|
||||
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
|
108
libs/WiFi/examples/WiFiClient/WiFiClient.ino
Normal file
108
libs/WiFi/examples/WiFiClient/WiFiClient.ino
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
Go to thingspeak.com and create an account if you don't have one already.
|
||||
After logging in, click on the "New Channel" button to create a new channel for your data. This is where your data will be stored and displayed.
|
||||
Fill in the Name, Description, and other fields for your channel as desired, then click the "Save Channel" button.
|
||||
Take note of the "Write API Key" located in the "API keys" tab, this is the key you will use to send data to your channel.
|
||||
Replace the channelID from tab "Channel Settings" and privateKey with "Read API Keys" from "API Keys" tab.
|
||||
Replace the host variable with the thingspeak server hostname "api.thingspeak.com"
|
||||
Upload the sketch to your ESP32 board and make sure that the board is connected to the internet. The ESP32 should now send data to your Thingspeak channel at the intervals specified by the loop function.
|
||||
Go to the channel view page on thingspeak and check the "Field1" for the new incoming data.
|
||||
You can use the data visualization and analysis tools provided by Thingspeak to display and process your data in various ways.
|
||||
Please note, that Thingspeak accepts only integer values.
|
||||
|
||||
You can later check the values at https://thingspeak.com/channels/2005329
|
||||
Please note that this public channel can be accessed by anyone and it is possible that more people will write their values.
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
const char* ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||
const char* password = "your-password"; // Change this to your WiFi password
|
||||
|
||||
const char* host = "api.thingspeak.com"; // This should not be changed
|
||||
const int httpPort = 80; // This should not be changed
|
||||
const String channelID = "2005329"; // Change this to your channel ID
|
||||
const String writeApiKey = "V6YOTILH9I7D51F9"; // Change this to your Write API key
|
||||
const String readApiKey = "34W6LGLIFXD56MPM"; // Change this to your Read API key
|
||||
|
||||
// The default example accepts one data filed named "field1"
|
||||
// For your own server you can ofcourse create more of them.
|
||||
int field1 = 0;
|
||||
|
||||
int numberOfResults = 3; // Number of results to be read
|
||||
int fieldNumber = 1; // Field number which will be read out
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial){delay(100);}
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
|
||||
Serial.println();
|
||||
Serial.println("******************************************************");
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void readResponse(WiFiClient *client){
|
||||
unsigned long timeout = millis();
|
||||
while(client->available() == 0){
|
||||
if(millis() - timeout > 5000){
|
||||
Serial.println(">>> Client Timeout !");
|
||||
client->stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Read all the lines of the reply from server and print them to Serial
|
||||
while(client->available()) {
|
||||
String line = client->readStringUntil('\r');
|
||||
Serial.print(line);
|
||||
}
|
||||
|
||||
Serial.printf("\nClosing connection\n\n");
|
||||
}
|
||||
|
||||
void loop(){
|
||||
WiFiClient client;
|
||||
String footer = String(" HTTP/1.1\r\n") + "Host: " + String(host) + "\r\n" + "Connection: close\r\n\r\n";
|
||||
|
||||
// WRITE --------------------------------------------------------------------------------------------
|
||||
if (!client.connect(host, httpPort)) {
|
||||
return;
|
||||
}
|
||||
|
||||
client.print("GET /update?api_key=" + writeApiKey + "&field1=" + field1 + footer);
|
||||
readResponse(&client);
|
||||
|
||||
// READ --------------------------------------------------------------------------------------------
|
||||
|
||||
String readRequest = "GET /channels/" + channelID + "/fields/" + fieldNumber + ".json?results=" + numberOfResults + " HTTP/1.1\r\n" +
|
||||
"Host: " + host + "\r\n" +
|
||||
"Connection: close\r\n\r\n";
|
||||
|
||||
if (!client.connect(host, httpPort)) {
|
||||
return;
|
||||
}
|
||||
|
||||
client.print(readRequest);
|
||||
readResponse(&client);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
++field1;
|
||||
delay(10000);
|
||||
}
|
0
libs/WiFi/examples/WiFiClientBasic/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiClientBasic/.skip.esp32h2
Normal file
87
libs/WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino
Normal file
87
libs/WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* This sketch sends a message to a TCP server
|
||||
*
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
|
||||
WiFiMulti WiFiMulti;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
WiFiMulti.addAP("SSID", "passpasspass");
|
||||
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Waiting for WiFi... ");
|
||||
|
||||
while(WiFiMulti.run() != WL_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// const uint16_t port = 80;
|
||||
// const char * host = "192.168.1.1"; // ip or dns
|
||||
const uint16_t port = 1337;
|
||||
const char * host = "192.168.1.10"; // ip or dns
|
||||
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(host);
|
||||
|
||||
// Use WiFiClient class to create TCP connections
|
||||
WiFiClient client;
|
||||
|
||||
if (!client.connect(host, port)) {
|
||||
Serial.println("Connection failed.");
|
||||
Serial.println("Waiting 5 seconds before retrying...");
|
||||
delay(5000);
|
||||
return;
|
||||
}
|
||||
|
||||
// This will send a request to the server
|
||||
//uncomment this line to send an arbitrary string to the server
|
||||
//client.print("Send this data to the server");
|
||||
//uncomment this line to send a basic document request to the server
|
||||
client.print("GET /index.html HTTP/1.1\n\n");
|
||||
|
||||
int maxloops = 0;
|
||||
|
||||
//wait for the server's reply to become available
|
||||
while (!client.available() && maxloops < 1000)
|
||||
{
|
||||
maxloops++;
|
||||
delay(1); //delay 1 msec
|
||||
}
|
||||
if (client.available() > 0)
|
||||
{
|
||||
//read back one line from the server
|
||||
String line = client.readStringUntil('\r');
|
||||
Serial.println(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("client.available() timed out ");
|
||||
}
|
||||
|
||||
Serial.println("Closing connection.");
|
||||
client.stop();
|
||||
|
||||
Serial.println("Waiting 5 seconds before restarting...");
|
||||
delay(5000);
|
||||
}
|
0
libs/WiFi/examples/WiFiClientConnect/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiClientConnect/.skip.esp32h2
Normal file
75
libs/WiFi/examples/WiFiClientConnect/README.md
Normal file
75
libs/WiFi/examples/WiFiClientConnect/README.md
Normal file
|
@ -0,0 +1,75 @@
|
|||
# WiFiClientConnect Example
|
||||
|
||||
This example demonstrates how to connect to the WiFi and manage the status and disconnection from STA.
|
||||
|
||||
# Supported Targets
|
||||
|
||||
Currently, this example supports the following targets.
|
||||
|
||||
| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 |
|
||||
| ----------------- | ----- | -------- | -------- |
|
||||
|
||||
## How to Use Example
|
||||
|
||||
* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide).
|
||||
|
||||
#### Using Arduino IDE
|
||||
|
||||
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||
|
||||
#### Using Platform IO
|
||||
|
||||
* Select the COM port: `Devices` or set the `upload_port`` option on the `platformio.ini` file.
|
||||
|
||||
## Example/Log Output
|
||||
|
||||
```
|
||||
[WiFi] Connecting to MyWiFiNetwork
|
||||
[ 66][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
|
||||
[ 150][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
|
||||
[ 151][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
|
||||
[ 151][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
|
||||
[WiFi] WiFi is disconnected
|
||||
[ 234][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: MyWiFiNetwork, BSSID: xx:xx:xx:xx:xx:xx, Channel: 8, Auth: WPA2_PSK
|
||||
[ 235][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
|
||||
[ 560][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got New IP:192.168.68.114
|
||||
[ 561][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
|
||||
[ 564][D][WiFiGeneric.cpp:1004] _eventCallback(): STA IP: 192.168.68.114, MASK: 255.255.255.0, GW: 192.168.68.1
|
||||
[WiFi] WiFi is connected!
|
||||
[WiFi] IP address: 192.168.68.114
|
||||
[WiFi] Disconnecting from WiFi!
|
||||
[ 2633][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MyWiFiNetwork, BSSID: xx:xx:xx:xx:xx:xx, Reason: 8
|
||||
[ 2634][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
|
||||
[ 2635][V][WiFiGeneric.cpp:341] _arduino_event_cb(): STA Stopped
|
||||
[ 2641][W][WiFiGeneric.cpp:953] _eventCallback(): Reason: 8 - ASSOC_LEAVE
|
||||
[ 2654][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi the station is disconnected
|
||||
[ 2661][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 3 - STA_STOP
|
||||
[WiFi] Disconnected from WiFi!
|
||||
...
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
***Important: Be sure you're using a good quality USB cable that has enough power for your project.***
|
||||
|
||||
* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed.
|
||||
* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation.
|
||||
|
||||
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||
|
||||
## Contribute
|
||||
|
||||
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
|
||||
|
||||
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
|
||||
|
||||
## Resources
|
||||
|
||||
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
|
||||
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
|
||||
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
|
||||
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
|
100
libs/WiFi/examples/WiFiClientConnect/WiFiClientConnect.ino
Normal file
100
libs/WiFi/examples/WiFiClientConnect/WiFiClientConnect.ino
Normal file
|
@ -0,0 +1,100 @@
|
|||
/* Wi-Fi STA Connect and Disconnect Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
*/
|
||||
#include <WiFi.h>
|
||||
|
||||
const char* ssid = "your-ssid";
|
||||
const char* password = "your-password";
|
||||
|
||||
int btnGPIO = 0;
|
||||
int btnState = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GPIO0 Boot button as input
|
||||
pinMode(btnGPIO, INPUT);
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
// To debug, please enable Core Debug Level to Verbose
|
||||
|
||||
Serial.println();
|
||||
Serial.print("[WiFi] Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
// Auto reconnect is set true as default
|
||||
// To set auto connect off, use the following function
|
||||
// WiFi.setAutoReconnect(false);
|
||||
|
||||
// Will try for about 10 seconds (20x 500ms)
|
||||
int tryDelay = 500;
|
||||
int numberOfTries = 20;
|
||||
|
||||
// Wait for the WiFi event
|
||||
while (true) {
|
||||
|
||||
switch(WiFi.status()) {
|
||||
case WL_NO_SSID_AVAIL:
|
||||
Serial.println("[WiFi] SSID not found");
|
||||
break;
|
||||
case WL_CONNECT_FAILED:
|
||||
Serial.print("[WiFi] Failed - WiFi not connected! Reason: ");
|
||||
return;
|
||||
break;
|
||||
case WL_CONNECTION_LOST:
|
||||
Serial.println("[WiFi] Connection was lost");
|
||||
break;
|
||||
case WL_SCAN_COMPLETED:
|
||||
Serial.println("[WiFi] Scan is completed");
|
||||
break;
|
||||
case WL_DISCONNECTED:
|
||||
Serial.println("[WiFi] WiFi is disconnected");
|
||||
break;
|
||||
case WL_CONNECTED:
|
||||
Serial.println("[WiFi] WiFi is connected!");
|
||||
Serial.print("[WiFi] IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
Serial.print("[WiFi] WiFi Status: ");
|
||||
Serial.println(WiFi.status());
|
||||
break;
|
||||
}
|
||||
delay(tryDelay);
|
||||
|
||||
if(numberOfTries <= 0){
|
||||
Serial.print("[WiFi] Failed to connect to WiFi!");
|
||||
// Use disconnect function to force stop trying to connect
|
||||
WiFi.disconnect();
|
||||
return;
|
||||
} else {
|
||||
numberOfTries--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Read the button state
|
||||
btnState = digitalRead(btnGPIO);
|
||||
|
||||
if (btnState == LOW) {
|
||||
// Disconnect from WiFi
|
||||
Serial.println("[WiFi] Disconnecting from WiFi!");
|
||||
// This function will disconnect and turn off the WiFi (NVS WiFi data is kept)
|
||||
if(WiFi.disconnect(true, false)){
|
||||
Serial.println("[WiFi] Disconnected from WiFi!");
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
}
|
0
libs/WiFi/examples/WiFiClientEnterprise/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiClientEnterprise/.skip.esp32h2
Normal file
43
libs/WiFi/examples/WiFiClientEnterprise/README.md
Normal file
43
libs/WiFi/examples/WiFiClientEnterprise/README.md
Normal file
|
@ -0,0 +1,43 @@
|
|||
# ESP32-Eduroam
|
||||
* Eduroam wifi connection with university login identity
|
||||
* Working under Eduroam networks worldwide
|
||||
* Methods: PEAP + MsCHAPv2
|
||||
|
||||
# Format
|
||||
* IDENTITY = youridentity --> if connecting from different university, use youridentity@youruniversity.domain format
|
||||
* PASSWORD = yourpassword
|
||||
|
||||
# Usage
|
||||
* Change IDENTITY
|
||||
* Change password
|
||||
* Upload sketch and enjoy!
|
||||
* After sucessful assign of IP address, board will connect to HTTP page on internet to verify your authentification
|
||||
* Board will auto reconnect to Eduroam if it lost connection
|
||||
|
||||
# Tested locations
|
||||
|University|Board|Method|Result|
|
||||
|-------------|-------------| -----|------|
|
||||
|Technical University in Košice (Slovakia)|ESP32 Devkit v1|PEAP + MsCHAPv2|Working|
|
||||
|Technical University in Košice (Slovakia)|ESP32 Devmodule v4|PEAP + MsCHAPv2|Working on 6th attempt in loop|
|
||||
|Slovak Technical University in Bratislava (Slovakia)|ESP32 Devkit v1|PEAP + MsCHAPv2|Working|
|
||||
|University of Antwerp (Belgium)|Lolin32|PEAP + MsCHAPv2|Working|
|
||||
|UPV Universitat Politècnica de València (Spain)|ESP32 Devmodule v4|PEAP + MsCHAPv2|Working|
|
||||
|Local Zeroshell powered network|ESP32 Devkit v1|PEAP + MsCHAPv2|*Not working*|
|
||||
|Hasselt University (Belgium)|xxx|PEAP + MsCHAPv2|Working with fix sketch|
|
||||
|Universidad de Granada (Spain)|Lolin D32 Pro|PEAP + MsCHAPv2|Working|
|
||||
|Universidad de Granada (Spain)|Lolin D32|PEAP + MsCHAPv2|Working|
|
||||
|Universidade Federal de Santa Catarina (Brazil)|xxx|EAP-TTLS + MsCHAPv2|Working|
|
||||
|University of Central Florida (Orlando, Florida)|ESP32 Built-in OLED – Heltec WiFi Kit 32|PEAP + MsCHAPv2|Working|
|
||||
|Université de Montpellier (France)|NodeMCU-32S|PEAP + MsCHAPv2|Working|
|
||||
|
||||
# Common errors - Switch to Debug mode for Serial monitor prints
|
||||
|Error|Appearance|Solution|
|
||||
|-------------|-------------|-------------|
|
||||
|wifi: Set status to INIT|Frequent|Hold EN button for few seconds|
|
||||
|HANDSHAKE_TIMEOUT|Rare|Bug was found under Zeroshell RADIUS authentization - Unsucessful connection|
|
||||
|AUTH_EXPIRE|Common|In the case of weak wifi network signal, this error is quite common, bring your device closer to AP|
|
||||
|ASSOC_EXPIRE|Rare|-|
|
||||
# Sucessful connection example
|
||||

|
||||
# Unsucessful connection example
|
||||

|
|
@ -0,0 +1,85 @@
|
|||
#include <WiFi.h> //Wifi library
|
||||
#define EAP_IDENTITY "login" //if connecting from another corporation, use identity@organisation.domain in Eduroam
|
||||
#define EAP_USERNAME "login" //oftentimes just a repeat of the identity
|
||||
#define EAP_PASSWORD "password" //your Eduroam password
|
||||
const char* ssid = "eduroam"; // Eduroam SSID
|
||||
const char* host = "arduino.php5.sk"; //external server domain for HTTP connection after authentification
|
||||
int counter = 0;
|
||||
|
||||
// NOTE: For some systems, various certification keys are required to connect to the wifi system.
|
||||
// Usually you are provided these by the IT department of your organization when certs are required
|
||||
// and you can't connect with just an identity and password.
|
||||
// Most eduroam setups we have seen do not require this level of authentication, but you should contact
|
||||
// your IT department to verify.
|
||||
// You should uncomment these and populate with the contents of the files if this is required for your scenario (See Example 2 and Example 3 below).
|
||||
//const char *ca_pem = "insert your CA cert from your .pem file here";
|
||||
//const char *client_cert = "insert your client cert from your .crt file here";
|
||||
//const char *client_key = "insert your client key from your .key file here";
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
Serial.println();
|
||||
Serial.print("Connecting to network: ");
|
||||
Serial.println(ssid);
|
||||
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
|
||||
WiFi.mode(WIFI_STA); //init wifi mode
|
||||
|
||||
// Example1 (most common): a cert-file-free eduroam with PEAP (or TTLS)
|
||||
WiFi.begin(ssid, WPA2_AUTH_PEAP, EAP_IDENTITY, EAP_USERNAME, EAP_PASSWORD);
|
||||
|
||||
// Example 2: a cert-file WPA2 Enterprise with PEAP
|
||||
//WiFi.begin(ssid, WPA2_AUTH_PEAP, EAP_IDENTITY, EAP_USERNAME, EAP_PASSWORD, ca_pem, client_cert, client_key);
|
||||
|
||||
// Example 3: TLS with cert-files and no password
|
||||
//WiFi.begin(ssid, WPA2_AUTH_TLS, EAP_IDENTITY, NULL, NULL, ca_pem, client_cert, client_key);
|
||||
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
counter++;
|
||||
if(counter>=60){ //after 30 seconds timeout - reset board
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address set: ");
|
||||
Serial.println(WiFi.localIP()); //print LAN IP
|
||||
}
|
||||
void loop() {
|
||||
if (WiFi.status() == WL_CONNECTED) { //if we are connected to Eduroam network
|
||||
counter = 0; //reset counter
|
||||
Serial.println("Wifi is still connected with IP: ");
|
||||
Serial.println(WiFi.localIP()); //inform user about his IP address
|
||||
}else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry
|
||||
WiFi.begin(ssid);
|
||||
}
|
||||
while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
counter++;
|
||||
if(counter>=60){ //30 seconds timeout - reset board
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
Serial.print("Connecting to website: ");
|
||||
Serial.println(host);
|
||||
WiFiClient client;
|
||||
if (client.connect(host, 80)) {
|
||||
String url = "/rele/rele1.txt";
|
||||
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: ESP32\r\n" + "Connection: close\r\n\r\n");
|
||||
|
||||
while (client.connected()) {
|
||||
String line = client.readStringUntil('\n');
|
||||
if (line == "\r") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
String line = client.readStringUntil('\n');
|
||||
Serial.println(line);
|
||||
}else{
|
||||
Serial.println("Connection unsucessful");
|
||||
}
|
||||
}
|
0
libs/WiFi/examples/WiFiClientEvents/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiClientEvents/.skip.esp32h2
Normal file
176
libs/WiFi/examples/WiFiClientEvents/WiFiClientEvents.ino
Normal file
176
libs/WiFi/examples/WiFiClientEvents/WiFiClientEvents.ino
Normal file
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* This sketch shows the WiFi event usage
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* WiFi Events
|
||||
|
||||
0 ARDUINO_EVENT_WIFI_READY < ESP32 WiFi ready
|
||||
1 ARDUINO_EVENT_WIFI_SCAN_DONE < ESP32 finish scanning AP
|
||||
2 ARDUINO_EVENT_WIFI_STA_START < ESP32 station start
|
||||
3 ARDUINO_EVENT_WIFI_STA_STOP < ESP32 station stop
|
||||
4 ARDUINO_EVENT_WIFI_STA_CONNECTED < ESP32 station connected to AP
|
||||
5 ARDUINO_EVENT_WIFI_STA_DISCONNECTED < ESP32 station disconnected from AP
|
||||
6 ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE < the auth mode of AP connected by ESP32 station changed
|
||||
7 ARDUINO_EVENT_WIFI_STA_GOT_IP < ESP32 station got IP from connected AP
|
||||
8 ARDUINO_EVENT_WIFI_STA_LOST_IP < ESP32 station lost IP and the IP is reset to 0
|
||||
9 ARDUINO_EVENT_WPS_ER_SUCCESS < ESP32 station wps succeeds in enrollee mode
|
||||
10 ARDUINO_EVENT_WPS_ER_FAILED < ESP32 station wps fails in enrollee mode
|
||||
11 ARDUINO_EVENT_WPS_ER_TIMEOUT < ESP32 station wps timeout in enrollee mode
|
||||
12 ARDUINO_EVENT_WPS_ER_PIN < ESP32 station wps pin code in enrollee mode
|
||||
13 ARDUINO_EVENT_WIFI_AP_START < ESP32 soft-AP start
|
||||
14 ARDUINO_EVENT_WIFI_AP_STOP < ESP32 soft-AP stop
|
||||
15 ARDUINO_EVENT_WIFI_AP_STACONNECTED < a station connected to ESP32 soft-AP
|
||||
16 ARDUINO_EVENT_WIFI_AP_STADISCONNECTED < a station disconnected from ESP32 soft-AP
|
||||
17 ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED < ESP32 soft-AP assign an IP to a connected station
|
||||
18 ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED < Receive probe request packet in soft-AP interface
|
||||
19 ARDUINO_EVENT_WIFI_AP_GOT_IP6 < ESP32 ap interface v6IP addr is preferred
|
||||
19 ARDUINO_EVENT_WIFI_STA_GOT_IP6 < ESP32 station interface v6IP addr is preferred
|
||||
20 ARDUINO_EVENT_ETH_START < ESP32 ethernet start
|
||||
21 ARDUINO_EVENT_ETH_STOP < ESP32 ethernet stop
|
||||
22 ARDUINO_EVENT_ETH_CONNECTED < ESP32 ethernet phy link up
|
||||
23 ARDUINO_EVENT_ETH_DISCONNECTED < ESP32 ethernet phy link down
|
||||
24 ARDUINO_EVENT_ETH_GOT_IP < ESP32 ethernet got IP from connected AP
|
||||
19 ARDUINO_EVENT_ETH_GOT_IP6 < ESP32 ethernet interface v6IP addr is preferred
|
||||
25 ARDUINO_EVENT_MAX
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
const char* ssid = "your-ssid";
|
||||
const char* password = "your-password";
|
||||
|
||||
// WARNING: This function is called from a separate FreeRTOS task (thread)!
|
||||
void WiFiEvent(WiFiEvent_t event)
|
||||
{
|
||||
Serial.printf("[WiFi-event] event: %d\n", event);
|
||||
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_WIFI_READY:
|
||||
Serial.println("WiFi interface ready");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_SCAN_DONE:
|
||||
Serial.println("Completed scan for access points");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
Serial.println("WiFi client started");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_STOP:
|
||||
Serial.println("WiFi clients stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
Serial.println("Connected to access point");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Serial.println("Disconnected from WiFi access point");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
|
||||
Serial.println("Authentication mode of access point has changed");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
Serial.print("Obtained IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||
Serial.println("Lost IP address and IP address is reset to 0");
|
||||
break;
|
||||
case ARDUINO_EVENT_WPS_ER_SUCCESS:
|
||||
Serial.println("WiFi Protected Setup (WPS): succeeded in enrollee mode");
|
||||
break;
|
||||
case ARDUINO_EVENT_WPS_ER_FAILED:
|
||||
Serial.println("WiFi Protected Setup (WPS): failed in enrollee mode");
|
||||
break;
|
||||
case ARDUINO_EVENT_WPS_ER_TIMEOUT:
|
||||
Serial.println("WiFi Protected Setup (WPS): timeout in enrollee mode");
|
||||
break;
|
||||
case ARDUINO_EVENT_WPS_ER_PIN:
|
||||
Serial.println("WiFi Protected Setup (WPS): pin code in enrollee mode");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_START:
|
||||
Serial.println("WiFi access point started");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STOP:
|
||||
Serial.println("WiFi access point stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
||||
Serial.println("Client connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
||||
Serial.println("Client disconnected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
|
||||
Serial.println("Assigned IP address to client");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED:
|
||||
Serial.println("Received probe request");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
|
||||
Serial.println("AP IPv6 is preferred");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||
Serial.println("STA IPv6 is preferred");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP6:
|
||||
Serial.println("Ethernet IPv6 is preferred");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Serial.println("Ethernet started");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Serial.println("Ethernet stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Serial.println("Ethernet connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Serial.println("Ethernet disconnected");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Serial.println("Obtained IP address");
|
||||
break;
|
||||
default: break;
|
||||
}}
|
||||
|
||||
// WARNING: This function is called from a separate FreeRTOS task (thread)!
|
||||
void WiFiGotIP(WiFiEvent_t event, WiFiEventInfo_t info)
|
||||
{
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(IPAddress(info.got_ip.ip_info.ip.addr));
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
// delete old config
|
||||
WiFi.disconnect(true);
|
||||
|
||||
delay(1000);
|
||||
|
||||
// Examples of different ways to register wifi events;
|
||||
// these handlers will be called from another thread.
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
WiFi.onEvent(WiFiGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
|
||||
WiFiEventId_t eventID = WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info){
|
||||
Serial.print("WiFi lost connection. Reason: ");
|
||||
Serial.println(info.wifi_sta_disconnected.reason);
|
||||
}, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
|
||||
|
||||
// Remove WiFi event
|
||||
Serial.print("WiFi Event ID: ");
|
||||
Serial.println(eventID);
|
||||
// WiFi.removeEvent(eventID);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println("Wait for WiFi... ");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
}
|
0
libs/WiFi/examples/WiFiClientStaticIP/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiClientStaticIP/.skip.esp32h2
Normal file
92
libs/WiFi/examples/WiFiClientStaticIP/WiFiClientStaticIP.ino
Normal file
92
libs/WiFi/examples/WiFiClientStaticIP/WiFiClientStaticIP.ino
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
Example of connection using Static IP
|
||||
by Evandro Luis Copercini
|
||||
Public domain - 2017
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
const char* ssid = "your_network_name";
|
||||
const char* password = "your_network_password";
|
||||
const char* host = "example.com";
|
||||
const char* url = "/index.html";
|
||||
|
||||
IPAddress local_IP(192, 168, 31, 115);
|
||||
IPAddress gateway(192, 168, 31, 1);
|
||||
IPAddress subnet(255, 255, 0, 0);
|
||||
IPAddress primaryDNS(8, 8, 8, 8); //optional
|
||||
IPAddress secondaryDNS(8, 8, 4, 4); //optional
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
|
||||
Serial.println("STA Failed to configure");
|
||||
}
|
||||
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected!");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.print("ESP Mac Address: ");
|
||||
Serial.println(WiFi.macAddress());
|
||||
Serial.print("Subnet Mask: ");
|
||||
Serial.println(WiFi.subnetMask());
|
||||
Serial.print("Gateway IP: ");
|
||||
Serial.println(WiFi.gatewayIP());
|
||||
Serial.print("DNS: ");
|
||||
Serial.println(WiFi.dnsIP());
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(5000);
|
||||
|
||||
Serial.print("connecting to ");
|
||||
Serial.println(host);
|
||||
|
||||
// Use WiFiClient class to create TCP connections
|
||||
WiFiClient client;
|
||||
const int httpPort = 80;
|
||||
if (!client.connect(host, httpPort)) {
|
||||
Serial.println("connection failed");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("Requesting URL: ");
|
||||
Serial.println(url);
|
||||
|
||||
// This will send the request to the server
|
||||
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
|
||||
"Host: " + host + "\r\n" +
|
||||
"Connection: close\r\n\r\n");
|
||||
unsigned long timeout = millis();
|
||||
while (client.available() == 0) {
|
||||
if (millis() - timeout > 5000) {
|
||||
Serial.println(">>> Client Timeout !");
|
||||
client.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Read all the lines of the reply from server and print them to Serial
|
||||
while (client.available()) {
|
||||
String line = client.readStringUntil('\r');
|
||||
Serial.print(line);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
Serial.println("closing connection");
|
||||
}
|
||||
|
0
libs/WiFi/examples/WiFiIPv6/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiIPv6/.skip.esp32h2
Normal file
119
libs/WiFi/examples/WiFiIPv6/WiFiIPv6.ino
Normal file
119
libs/WiFi/examples/WiFiIPv6/WiFiIPv6.ino
Normal file
|
@ -0,0 +1,119 @@
|
|||
#include "WiFi.h"
|
||||
|
||||
#define STA_SSID "**********"
|
||||
#define STA_PASS "**********"
|
||||
#define AP_SSID "esp32-v6"
|
||||
|
||||
static volatile bool wifi_connected = false;
|
||||
|
||||
WiFiUDP ntpClient;
|
||||
|
||||
void wifiOnConnect(){
|
||||
Serial.println("STA Connected");
|
||||
Serial.print("STA IPv4: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
ntpClient.begin(2390);
|
||||
}
|
||||
|
||||
void wifiOnDisconnect(){
|
||||
Serial.println("STA Disconnected");
|
||||
delay(1000);
|
||||
WiFi.begin(STA_SSID, STA_PASS);
|
||||
}
|
||||
|
||||
void wifiConnectedLoop(){
|
||||
//lets check the time
|
||||
const int NTP_PACKET_SIZE = 48;
|
||||
byte ntpPacketBuffer[NTP_PACKET_SIZE];
|
||||
|
||||
IPAddress address;
|
||||
WiFi.hostByName("time.nist.gov", address);
|
||||
memset(ntpPacketBuffer, 0, NTP_PACKET_SIZE);
|
||||
ntpPacketBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
ntpPacketBuffer[1] = 0; // Stratum, or type of clock
|
||||
ntpPacketBuffer[2] = 6; // Polling Interval
|
||||
ntpPacketBuffer[3] = 0xEC; // Peer Clock Precision
|
||||
// 8 bytes of zero for Root Delay & Root Dispersion
|
||||
ntpPacketBuffer[12] = 49;
|
||||
ntpPacketBuffer[13] = 0x4E;
|
||||
ntpPacketBuffer[14] = 49;
|
||||
ntpPacketBuffer[15] = 52;
|
||||
ntpClient.beginPacket(address, 123); //NTP requests are to port 123
|
||||
ntpClient.write(ntpPacketBuffer, NTP_PACKET_SIZE);
|
||||
ntpClient.endPacket();
|
||||
|
||||
delay(1000);
|
||||
|
||||
int packetLength = ntpClient.parsePacket();
|
||||
if (packetLength){
|
||||
if(packetLength >= NTP_PACKET_SIZE){
|
||||
ntpClient.read(ntpPacketBuffer, NTP_PACKET_SIZE);
|
||||
}
|
||||
ntpClient.flush();
|
||||
uint32_t secsSince1900 = (uint32_t)ntpPacketBuffer[40] << 24 | (uint32_t)ntpPacketBuffer[41] << 16 | (uint32_t)ntpPacketBuffer[42] << 8 | ntpPacketBuffer[43];
|
||||
//Serial.printf("Seconds since Jan 1 1900: %u\n", secsSince1900);
|
||||
uint32_t epoch = secsSince1900 - 2208988800UL;
|
||||
//Serial.printf("EPOCH: %u\n", epoch);
|
||||
uint8_t h = (epoch % 86400L) / 3600;
|
||||
uint8_t m = (epoch % 3600) / 60;
|
||||
uint8_t s = (epoch % 60);
|
||||
Serial.printf("UTC: %02u:%02u:%02u (GMT)\n", h, m, s);
|
||||
}
|
||||
|
||||
delay(9000);
|
||||
}
|
||||
|
||||
// WARNING: WiFiEvent is called from a separate FreeRTOS task (thread)!
|
||||
void WiFiEvent(WiFiEvent_t event){
|
||||
switch(event) {
|
||||
case ARDUINO_EVENT_WIFI_AP_START:
|
||||
//can set ap hostname here
|
||||
WiFi.softAPsetHostname(AP_SSID);
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
//set sta hostname here
|
||||
WiFi.setHostname(AP_SSID);
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||
Serial.print("STA IPv6: ");
|
||||
Serial.println(WiFi.localIPv6());
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
|
||||
Serial.print("AP IPv6: ");
|
||||
Serial.println(WiFi.softAPIPv6());
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
wifiOnConnect();
|
||||
wifi_connected = true;
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
wifi_connected = false;
|
||||
wifiOnDisconnect();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
WiFi.disconnect(true);
|
||||
WiFi.onEvent(WiFiEvent); // Will call WiFiEvent() from another thread.
|
||||
WiFi.mode(WIFI_MODE_APSTA);
|
||||
//enable ap ipv6 here
|
||||
WiFi.softAPenableIPv6();
|
||||
WiFi.softAP(AP_SSID);
|
||||
//enable sta ipv6 here
|
||||
WiFi.enableIPv6();
|
||||
WiFi.begin(STA_SSID, STA_PASS);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
if(wifi_connected){
|
||||
wifiConnectedLoop();
|
||||
}
|
||||
while(Serial.available()) Serial.write(Serial.read());
|
||||
}
|
0
libs/WiFi/examples/WiFiMulti/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiMulti/.skip.esp32h2
Normal file
35
libs/WiFi/examples/WiFiMulti/WiFiMulti.ino
Normal file
35
libs/WiFi/examples/WiFiMulti/WiFiMulti.ino
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This sketch trys to Connect to the best AP based on a given list
|
||||
*
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
|
||||
WiFiMulti wifiMulti;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
wifiMulti.addAP("ssid_from_AP_1", "your_password_for_AP_1");
|
||||
wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2");
|
||||
wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");
|
||||
|
||||
Serial.println("Connecting Wifi...");
|
||||
if(wifiMulti.run() == WL_CONNECTED) {
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if(wifiMulti.run() != WL_CONNECTED) {
|
||||
Serial.println("WiFi not connected!");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
0
libs/WiFi/examples/WiFiMultiAdvanced/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiMultiAdvanced/.skip.esp32h2
Normal file
64
libs/WiFi/examples/WiFiMultiAdvanced/WiFiMultiAdvanced.ino
Normal file
64
libs/WiFi/examples/WiFiMultiAdvanced/WiFiMultiAdvanced.ino
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This sketch tries to connect to the best AP available
|
||||
* and tests for captive portals on open networks
|
||||
*
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <HTTPClient.h>
|
||||
|
||||
WiFiMulti wifiMulti;
|
||||
|
||||
// callback used to check Internet connectivity
|
||||
bool testConnection(){
|
||||
HTTPClient http;
|
||||
http.begin("http://www.espressif.com");
|
||||
int httpCode = http.GET();
|
||||
// we expect to get a 301 because it will ask to use HTTPS instead of HTTP
|
||||
if (httpCode == HTTP_CODE_MOVED_PERMANENTLY) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
wifiMulti.addAP("ssid_from_AP_1", "your_password_for_AP_1");
|
||||
wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2");
|
||||
wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");
|
||||
|
||||
// These options can help when you need ANY kind of wifi connection to get a config file, report errors, etc.
|
||||
wifiMulti.setStrictMode(false); // Default is true. Library will disconnect and forget currently connected AP if it's not in the AP list.
|
||||
wifiMulti.setAllowOpenAP(true); // Default is false. True adds open APs to the AP list.
|
||||
wifiMulti.setConnectionTestCallbackFunc(testConnection); // Attempts to connect to a remote webserver in case of captive portals.
|
||||
|
||||
Serial.println("Connecting Wifi...");
|
||||
if(wifiMulti.run() == WL_CONNECTED) {
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static bool isConnected = false;
|
||||
uint8_t WiFiStatus = wifiMulti.run();
|
||||
|
||||
if (WiFiStatus == WL_CONNECTED) {
|
||||
if (!isConnected) {
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
isConnected = true;
|
||||
} else {
|
||||
Serial.println("WiFi not connected!");
|
||||
isConnected = false;
|
||||
delay(5000);
|
||||
}
|
||||
}
|
0
libs/WiFi/examples/WiFiScan/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiScan/.skip.esp32h2
Normal file
65
libs/WiFi/examples/WiFiScan/README.md
Normal file
65
libs/WiFi/examples/WiFiScan/README.md
Normal file
|
@ -0,0 +1,65 @@
|
|||
# WiFiScan Example
|
||||
|
||||
This example demonstrates how to use the WiFi library to scan available WiFi networks and print the results.
|
||||
|
||||
## Supported Targets
|
||||
|
||||
Currently this example supports the following targets.
|
||||
|
||||
| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 | ESP32-C6 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- |
|
||||
|
||||
## How to Use Example
|
||||
|
||||
* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide).
|
||||
|
||||
#### Using Arduino IDE
|
||||
|
||||
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||
|
||||
#### Using Platform IO
|
||||
|
||||
* Select the COM port: `Devices` or setting the `upload_port` option on the `platformio.ini` file.
|
||||
|
||||
## Example/Log Output
|
||||
|
||||
```
|
||||
Setup done
|
||||
Scan start
|
||||
Scan done
|
||||
17 networks found
|
||||
Nr | SSID | RSSI | CH | Encryption
|
||||
1 | IoTNetwork | -62 | 1 | WPA2
|
||||
2 | WiFiSSID | -62 | 1 | WPA2-EAP
|
||||
3 | B3A7992 | -63 | 6 | WPA+WPA2
|
||||
4 | WiFi | -63 | 6 | WPA3
|
||||
5 | IoTNetwork2 | -64 | 11 | WPA2+WPA3
|
||||
...
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
***Important: Be sure you're using a good quality USB cable and you have enought power source for your project.***
|
||||
|
||||
* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed.
|
||||
* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation.
|
||||
|
||||
If the error persist, you can ask help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||
|
||||
## Contribute
|
||||
|
||||
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
|
||||
|
||||
Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else.
|
||||
|
||||
## Resources
|
||||
|
||||
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
|
||||
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
|
||||
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
|
||||
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
|
||||
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
|
86
libs/WiFi/examples/WiFiScan/WiFiScan.ino
Normal file
86
libs/WiFi/examples/WiFiScan/WiFiScan.ino
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* This sketch demonstrates how to scan WiFi networks.
|
||||
* The API is based on the Arduino WiFi Shield library, but has significant changes as newer WiFi functions are supported.
|
||||
* E.g. the return value of `encryptionType()` different because more modern encryption is supported.
|
||||
*/
|
||||
#include "WiFi.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
// Set WiFi to station mode and disconnect from an AP if it was previously connected.
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(100);
|
||||
|
||||
Serial.println("Setup done");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Scan start");
|
||||
|
||||
// WiFi.scanNetworks will return the number of networks found.
|
||||
int n = WiFi.scanNetworks();
|
||||
Serial.println("Scan done");
|
||||
if (n == 0) {
|
||||
Serial.println("no networks found");
|
||||
} else {
|
||||
Serial.print(n);
|
||||
Serial.println(" networks found");
|
||||
Serial.println("Nr | SSID | RSSI | CH | Encryption");
|
||||
for (int i = 0; i < n; ++i) {
|
||||
// Print SSID and RSSI for each network found
|
||||
Serial.printf("%2d",i + 1);
|
||||
Serial.print(" | ");
|
||||
Serial.printf("%-32.32s", WiFi.SSID(i).c_str());
|
||||
Serial.print(" | ");
|
||||
Serial.printf("%4ld", WiFi.RSSI(i));
|
||||
Serial.print(" | ");
|
||||
Serial.printf("%2ld", WiFi.channel(i));
|
||||
Serial.print(" | ");
|
||||
switch (WiFi.encryptionType(i))
|
||||
{
|
||||
case WIFI_AUTH_OPEN:
|
||||
Serial.print("open");
|
||||
break;
|
||||
case WIFI_AUTH_WEP:
|
||||
Serial.print("WEP");
|
||||
break;
|
||||
case WIFI_AUTH_WPA_PSK:
|
||||
Serial.print("WPA");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_PSK:
|
||||
Serial.print("WPA2");
|
||||
break;
|
||||
case WIFI_AUTH_WPA_WPA2_PSK:
|
||||
Serial.print("WPA+WPA2");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_ENTERPRISE:
|
||||
Serial.print("WPA2-EAP");
|
||||
break;
|
||||
case WIFI_AUTH_WPA3_PSK:
|
||||
Serial.print("WPA3");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_WPA3_PSK:
|
||||
Serial.print("WPA2+WPA3");
|
||||
break;
|
||||
case WIFI_AUTH_WAPI_PSK:
|
||||
Serial.print("WAPI");
|
||||
break;
|
||||
default:
|
||||
Serial.print("unknown");
|
||||
}
|
||||
Serial.println();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
Serial.println("");
|
||||
|
||||
// Delete the scan result to free memory for code below.
|
||||
WiFi.scanDelete();
|
||||
|
||||
// Wait a bit before scanning again.
|
||||
delay(5000);
|
||||
}
|
1
libs/WiFi/examples/WiFiScanAsync/.skip.esp32h2
Normal file
1
libs/WiFi/examples/WiFiScanAsync/.skip.esp32h2
Normal file
|
@ -0,0 +1 @@
|
|||
|
75
libs/WiFi/examples/WiFiScanAsync/README.md
Normal file
75
libs/WiFi/examples/WiFiScanAsync/README.md
Normal file
|
@ -0,0 +1,75 @@
|
|||
# WiFiScanAsync Example
|
||||
|
||||
This example demonstrates how to use the WiFi library to scan available WiFi networks in asynchronous mode and print the results.
|
||||
|
||||
## Supported Targets
|
||||
|
||||
Currently this example supports the following targets.
|
||||
|
||||
| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 | ESP32-C6 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- |
|
||||
|
||||
## How to Use Example
|
||||
|
||||
* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide).
|
||||
|
||||
#### Using Arduino IDE
|
||||
|
||||
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||
|
||||
#### Using Platform IO
|
||||
|
||||
* Select the COM port: `Devices` or setting the `upload_port` option on the `platformio.ini` file.
|
||||
|
||||
## Example/Log Output
|
||||
|
||||
```
|
||||
Setup done
|
||||
Scan start
|
||||
Loop running...
|
||||
Loop running...
|
||||
Loop running...
|
||||
Loop running...
|
||||
Loop running...
|
||||
Loop running...
|
||||
Loop running...
|
||||
Loop running...
|
||||
Loop running...
|
||||
|
||||
Scan done
|
||||
17 networks found
|
||||
Nr | SSID | RSSI | CH | Encryption
|
||||
1 | IoTNetwork | -62 | 1 | WPA2
|
||||
2 | WiFiSSID | -62 | 1 | WPA2-EAP
|
||||
3 | B3A7992 | -63 | 6 | WPA+WPA2
|
||||
4 | WiFi | -63 | 6 | WPA3
|
||||
5 | IoTNetwork2 | -64 | 11 | WPA2+WPA3
|
||||
...
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
***Important: Be sure you're using a good quality USB cable and you have enought power source for your project.***
|
||||
|
||||
* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed.
|
||||
* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation.
|
||||
|
||||
If the error persist, you can ask help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||
|
||||
## Contribute
|
||||
|
||||
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
|
||||
|
||||
Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else.
|
||||
|
||||
## Resources
|
||||
|
||||
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
|
||||
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
|
||||
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
|
||||
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
|
||||
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
|
102
libs/WiFi/examples/WiFiScanAsync/WiFiScanAsync.ino
Normal file
102
libs/WiFi/examples/WiFiScanAsync/WiFiScanAsync.ino
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
This sketch demonstrates how to scan WiFi networks in Async Mode.
|
||||
The API is based on the Arduino WiFi Shield library, but has significant changes as newer WiFi functions are supported.
|
||||
E.g. the return value of `encryptionType()` different because more modern encryption is supported.
|
||||
*/
|
||||
#include "WiFi.h"
|
||||
|
||||
void startWiFiScan() {
|
||||
Serial.println("Scan start");
|
||||
// WiFi.scanNetworks will return immediately in Async Mode.
|
||||
WiFi.scanNetworks(true); // 'true' turns Async Mode ON
|
||||
}
|
||||
|
||||
void printScannedNetworks(uint16_t networksFound) {
|
||||
if (networksFound == 0) {
|
||||
Serial.println("no networks found");
|
||||
} else {
|
||||
Serial.println("\nScan done");
|
||||
Serial.print(networksFound);
|
||||
Serial.println(" networks found");
|
||||
Serial.println("Nr | SSID | RSSI | CH | Encryption");
|
||||
for (int i = 0; i < networksFound; ++i) {
|
||||
// Print SSID and RSSI for each network found
|
||||
Serial.printf("%2d", i + 1);
|
||||
Serial.print(" | ");
|
||||
Serial.printf("%-32.32s", WiFi.SSID(i).c_str());
|
||||
Serial.print(" | ");
|
||||
Serial.printf("%4ld", WiFi.RSSI(i));
|
||||
Serial.print(" | ");
|
||||
Serial.printf("%2ld", WiFi.channel(i));
|
||||
Serial.print(" | ");
|
||||
switch (WiFi.encryptionType(i))
|
||||
{
|
||||
case WIFI_AUTH_OPEN:
|
||||
Serial.print("open");
|
||||
break;
|
||||
case WIFI_AUTH_WEP:
|
||||
Serial.print("WEP");
|
||||
break;
|
||||
case WIFI_AUTH_WPA_PSK:
|
||||
Serial.print("WPA");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_PSK:
|
||||
Serial.print("WPA2");
|
||||
break;
|
||||
case WIFI_AUTH_WPA_WPA2_PSK:
|
||||
Serial.print("WPA+WPA2");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_ENTERPRISE:
|
||||
Serial.print("WPA2-EAP");
|
||||
break;
|
||||
case WIFI_AUTH_WPA3_PSK:
|
||||
Serial.print("WPA3");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_WPA3_PSK:
|
||||
Serial.print("WPA2+WPA3");
|
||||
break;
|
||||
case WIFI_AUTH_WAPI_PSK:
|
||||
Serial.print("WAPI");
|
||||
break;
|
||||
default:
|
||||
Serial.print("unknown");
|
||||
}
|
||||
Serial.println();
|
||||
delay(10);
|
||||
}
|
||||
Serial.println("");
|
||||
// Delete the scan result to free memory for code below.
|
||||
WiFi.scanDelete();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Set WiFi to station mode and disconnect from an AP if it was previously connected.
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(100);
|
||||
|
||||
Serial.println("Setup done");
|
||||
startWiFiScan();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check WiFi Scan Async process
|
||||
int16_t WiFiScanStatus = WiFi.scanComplete();
|
||||
if (WiFiScanStatus < 0) { // it is busy scanning or got an error
|
||||
if (WiFiScanStatus == WIFI_SCAN_FAILED) {
|
||||
Serial.println("WiFi Scan has failed. Starting again.");
|
||||
startWiFiScan();
|
||||
}
|
||||
// other option is status WIFI_SCAN_RUNNING - just wait.
|
||||
} else { // Found Zero or more Wireless Networks
|
||||
printScannedNetworks(WiFiScanStatus);
|
||||
startWiFiScan(); // start over...
|
||||
}
|
||||
|
||||
// Loop can do something else...
|
||||
delay(250);
|
||||
Serial.println("Loop running...");
|
||||
}
|
0
libs/WiFi/examples/WiFiScanDualAntenna/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiScanDualAntenna/.skip.esp32h2
Normal file
70
libs/WiFi/examples/WiFiScanDualAntenna/README.md
Normal file
70
libs/WiFi/examples/WiFiScanDualAntenna/README.md
Normal file
|
@ -0,0 +1,70 @@
|
|||
# WiFiScan Example
|
||||
|
||||
This example demonstrates how to use the WiFi library to scan available WiFi networks and print the results.
|
||||
|
||||
This example shows the basic functionality of the dual antenna capability.
|
||||
|
||||
# Supported Targets
|
||||
|
||||
This example is compatible with the ESP32-WROOM-DA.
|
||||
|
||||
## How to Use Example
|
||||
|
||||
* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide).
|
||||
|
||||
#### Using Arduino IDE
|
||||
|
||||
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||
|
||||
#### Using Platform IO
|
||||
|
||||
* Select the COM port: `Devices` or set the `upload_port` option on the `platformio.ini` file.
|
||||
|
||||
## Example/Log Output
|
||||
|
||||
```
|
||||
ets Jul 29 2019 12:21:46
|
||||
|
||||
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0xee
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fff0030,len:1412
|
||||
load:0x40078000,len:13400
|
||||
load:0x40080400,len:3672
|
||||
entry 0x400805f8
|
||||
Setup done
|
||||
scan start
|
||||
scan done
|
||||
17 networks found
|
||||
1: IoTNetwork (-62)*
|
||||
2: WiFiSSID (-62)*
|
||||
3: B3A7992 (-63)*
|
||||
4: WiFi (-63)
|
||||
5: IoTNetwork2 (-64)*
|
||||
...
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
***Important: Be sure you're using a good quality USB cable and you have enough power source for your project.***
|
||||
|
||||
* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed.
|
||||
* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation.
|
||||
|
||||
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||
|
||||
## Contribute
|
||||
|
||||
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
|
||||
|
||||
Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else.
|
||||
|
||||
## Resources
|
||||
|
||||
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
|
||||
* ESP32-WROOM-DA Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-wroom-da_datasheet_en.pdf)
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This sketch demonstrates how to scan WiFi networks.
|
||||
* The API is almost the same as with the WiFi Shield library,
|
||||
* the most obvious difference being the different file you need to include:
|
||||
*/
|
||||
#include "WiFi.h"
|
||||
|
||||
/* These are the GPIOs connected to the antenna switch on the ESP32-WROOM-DA.
|
||||
* Both GPIOs are not exposed to the module pins and cannot be used except to
|
||||
* control the antnnas switch.
|
||||
*
|
||||
* For more details, see the datashhet at:
|
||||
* https://www.espressif.com/sites/default/files/documentation/esp32-wroom-da_datasheet_en.pdf
|
||||
*/
|
||||
|
||||
#define GPIO_ANT1 2 // GPIO for antenna 1
|
||||
#define GPIO_ANT2 25 // GPIO for antenna 2 (default)
|
||||
|
||||
void setup()
|
||||
{
|
||||
bool err = false;
|
||||
Serial.begin(115200);
|
||||
|
||||
// Set WiFi to station mode and disconnect from an AP if it was previously connected
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
/* Attention: This is the manual prodecure for the dual antenna configuration.
|
||||
* If you choose the ESP32-WROOM-DA module from the Tools -> Board, this configuration
|
||||
* is not necessary!
|
||||
*
|
||||
* Set WiFi dual antenna configuration by passing the GPIO and antenna mode for RX ant TX
|
||||
*/
|
||||
err = WiFi.setDualAntennaConfig(GPIO_ANT1, GPIO_ANT2, WIFI_RX_ANT_AUTO, WIFI_TX_ANT_AUTO);
|
||||
|
||||
/* For more details on how to use this feature, see our docs:
|
||||
* https://docs.espressif.com/projects/arduino-esp32/en/latest/api/wifi.html
|
||||
*/
|
||||
|
||||
if(err == false) {
|
||||
Serial.println("Dual Antenna configuration failed!");
|
||||
} else {
|
||||
Serial.println("Dual Antenna configuration successfuly done!");
|
||||
}
|
||||
|
||||
WiFi.disconnect();
|
||||
delay(100);
|
||||
|
||||
Serial.println("Setup done");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("scan start");
|
||||
|
||||
// WiFi.scanNetworks will return the number of networks found
|
||||
int n = WiFi.scanNetworks();
|
||||
Serial.println("scan done");
|
||||
if (n == 0) {
|
||||
Serial.println("no networks found");
|
||||
} else {
|
||||
Serial.print(n);
|
||||
Serial.println(" networks found");
|
||||
for (int i = 0; i < n; ++i) {
|
||||
// Print SSID and RSSI for each network found
|
||||
Serial.print(i + 1);
|
||||
Serial.print(": ");
|
||||
Serial.print(WiFi.SSID(i));
|
||||
Serial.print(" (");
|
||||
Serial.print(WiFi.RSSI(i));
|
||||
Serial.print(")");
|
||||
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
Serial.println("");
|
||||
|
||||
// Wait a bit before scanning again
|
||||
delay(5000);
|
||||
}
|
0
libs/WiFi/examples/WiFiSmartConfig/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiSmartConfig/.skip.esp32h2
Normal file
36
libs/WiFi/examples/WiFiSmartConfig/WiFiSmartConfig.ino
Normal file
36
libs/WiFi/examples/WiFiSmartConfig/WiFiSmartConfig.ino
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "WiFi.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
//Init WiFi as Station, start SmartConfig
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
WiFi.beginSmartConfig();
|
||||
|
||||
//Wait for SmartConfig packet from mobile
|
||||
Serial.println("Waiting for SmartConfig.");
|
||||
while (!WiFi.smartConfigDone()) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("SmartConfig received.");
|
||||
|
||||
//Wait for WiFi to connect to AP
|
||||
Serial.println("Waiting for WiFi");
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("WiFi Connected.");
|
||||
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
0
libs/WiFi/examples/WiFiTelnetToSerial/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiTelnetToSerial/.skip.esp32h2
Normal file
129
libs/WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino
Normal file
129
libs/WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino
Normal file
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
WiFiTelnetToSerial - Example Transparent UART to Telnet Server for ESP32
|
||||
|
||||
Copyright (c) 2017 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the ESP32 WiFi library for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
|
||||
WiFiMulti wifiMulti;
|
||||
|
||||
//how many clients should be able to telnet to this ESP32
|
||||
#define MAX_SRV_CLIENTS 1
|
||||
const char* ssid = "**********";
|
||||
const char* password = "**********";
|
||||
|
||||
WiFiServer server(23);
|
||||
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("\nConnecting");
|
||||
|
||||
wifiMulti.addAP(ssid, password);
|
||||
wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2");
|
||||
wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");
|
||||
|
||||
Serial.println("Connecting Wifi ");
|
||||
for (int loops = 10; loops > 0; loops--) {
|
||||
if (wifiMulti.run() == WL_CONNECTED) {
|
||||
Serial.println("");
|
||||
Serial.print("WiFi connected ");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
break;
|
||||
}
|
||||
else {
|
||||
Serial.println(loops);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
if (wifiMulti.run() != WL_CONNECTED) {
|
||||
Serial.println("WiFi connect failed");
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
//start UART and the server
|
||||
Serial1.begin(9600);
|
||||
server.begin();
|
||||
server.setNoDelay(true);
|
||||
|
||||
Serial.print("Ready! Use 'telnet ");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.println(" 23' to connect");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uint8_t i;
|
||||
if (wifiMulti.run() == WL_CONNECTED) {
|
||||
//check if there are any new clients
|
||||
if (server.hasClient()){
|
||||
for(i = 0; i < MAX_SRV_CLIENTS; i++){
|
||||
//find free/disconnected spot
|
||||
if (!serverClients[i] || !serverClients[i].connected()){
|
||||
if(serverClients[i]) serverClients[i].stop();
|
||||
serverClients[i] = server.accept();
|
||||
if (!serverClients[i]) Serial.println("available broken");
|
||||
Serial.print("New client: ");
|
||||
Serial.print(i); Serial.print(' ');
|
||||
Serial.println(serverClients[i].remoteIP());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= MAX_SRV_CLIENTS) {
|
||||
//no free/disconnected spot so reject
|
||||
server.accept().stop();
|
||||
}
|
||||
}
|
||||
//check clients for data
|
||||
for(i = 0; i < MAX_SRV_CLIENTS; i++){
|
||||
if (serverClients[i] && serverClients[i].connected()){
|
||||
if(serverClients[i].available()){
|
||||
//get data from the telnet client and push it to the UART
|
||||
while(serverClients[i].available()) Serial1.write(serverClients[i].read());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (serverClients[i]) {
|
||||
serverClients[i].stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
//check UART for data
|
||||
if(Serial1.available()){
|
||||
size_t len = Serial1.available();
|
||||
uint8_t sbuf[len];
|
||||
Serial1.readBytes(sbuf, len);
|
||||
//push UART data to all connected telnet clients
|
||||
for(i = 0; i < MAX_SRV_CLIENTS; i++){
|
||||
if (serverClients[i] && serverClients[i].connected()){
|
||||
serverClients[i].write(sbuf, len);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.println("WiFi not connected!");
|
||||
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
||||
if (serverClients[i]) serverClients[i].stop();
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
}
|
0
libs/WiFi/examples/WiFiUDPClient/.skip.esp32h2
Normal file
0
libs/WiFi/examples/WiFiUDPClient/.skip.esp32h2
Normal file
76
libs/WiFi/examples/WiFiUDPClient/WiFiUDPClient.ino
Normal file
76
libs/WiFi/examples/WiFiUDPClient/WiFiUDPClient.ino
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* This sketch sends random data over UDP on a ESP32 device
|
||||
*
|
||||
*/
|
||||
#include <WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
// WiFi network name and password:
|
||||
const char * networkName = "your-ssid";
|
||||
const char * networkPswd = "your-password";
|
||||
|
||||
//IP address to send UDP data to:
|
||||
// either use the ip address of the server or
|
||||
// a network broadcast address
|
||||
const char * udpAddress = "192.168.0.255";
|
||||
const int udpPort = 3333;
|
||||
|
||||
//Are we currently connected?
|
||||
boolean connected = false;
|
||||
|
||||
//The udp library class
|
||||
WiFiUDP udp;
|
||||
|
||||
void setup(){
|
||||
// Initilize hardware serial:
|
||||
Serial.begin(115200);
|
||||
|
||||
//Connect to the WiFi network
|
||||
connectToWiFi(networkName, networkPswd);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
//only send data when connected
|
||||
if(connected){
|
||||
//Send a packet
|
||||
udp.beginPacket(udpAddress,udpPort);
|
||||
udp.printf("Seconds since boot: %lu", millis()/1000);
|
||||
udp.endPacket();
|
||||
}
|
||||
//Wait for 1 second
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void connectToWiFi(const char * ssid, const char * pwd){
|
||||
Serial.println("Connecting to WiFi network: " + String(ssid));
|
||||
|
||||
// delete old config
|
||||
WiFi.disconnect(true);
|
||||
//register event handler
|
||||
WiFi.onEvent(WiFiEvent); // Will call WiFiEvent() from another thread.
|
||||
|
||||
//Initiate connection
|
||||
WiFi.begin(ssid, pwd);
|
||||
|
||||
Serial.println("Waiting for WIFI connection...");
|
||||
}
|
||||
|
||||
// WARNING: WiFiEvent is called from a separate FreeRTOS task (thread)!
|
||||
void WiFiEvent(WiFiEvent_t event){
|
||||
switch(event) {
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
//When connected set
|
||||
Serial.print("WiFi connected! IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
//initializes the UDP state
|
||||
//This initializes the transfer buffer
|
||||
udp.begin(WiFi.localIP(),udpPort);
|
||||
connected = true;
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Serial.println("WiFi lost connection");
|
||||
connected = false;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
30
libs/WiFi/examples/WiFiUDPClient/udp_server.py
Normal file
30
libs/WiFi/examples/WiFiUDPClient/udp_server.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# This python script listens on UDP port 3333
|
||||
# for messages from the ESP32 board and prints them
|
||||
import socket
|
||||
import sys
|
||||
|
||||
try :
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
except socket.error, msg :
|
||||
print 'Failed to create socket. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
s.bind(('', 3333))
|
||||
except socket.error , msg:
|
||||
print 'Bind failed. Error: ' + str(msg[0]) + ': ' + msg[1]
|
||||
sys.exit()
|
||||
|
||||
print 'Server listening'
|
||||
|
||||
while 1:
|
||||
d = s.recvfrom(1024)
|
||||
data = d[0]
|
||||
|
||||
if not data:
|
||||
break
|
||||
|
||||
print data.strip()
|
||||
|
||||
s.close()
|
16
libs/WiFi/examples/WiFiUDPClient/udp_server.rb
Normal file
16
libs/WiFi/examples/WiFiUDPClient/udp_server.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# This ruby script listens on UDP port 3333
|
||||
# for messages from the ESP32 board and prints them
|
||||
|
||||
require 'socket'
|
||||
include Socket::Constants
|
||||
|
||||
udp_socket = UDPSocket.new(AF_INET)
|
||||
|
||||
#bind
|
||||
udp_socket.bind("", 3333)
|
||||
puts 'Server listening'
|
||||
|
||||
while true do
|
||||
message, sender = udp_socket.recvfrom(1024)
|
||||
puts message
|
||||
end
|
68
libs/WiFi/keywords.txt
Normal file
68
libs/WiFi/keywords.txt
Normal file
|
@ -0,0 +1,68 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For WiFi
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Library (KEYWORD3)
|
||||
#######################################
|
||||
|
||||
WiFi KEYWORD3
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
WiFi KEYWORD1
|
||||
WiFiClient KEYWORD1
|
||||
WiFiServer KEYWORD1
|
||||
WiFiUDP KEYWORD1
|
||||
WiFiClientSecure KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
status KEYWORD2
|
||||
mode KEYWORD2
|
||||
connect KEYWORD2
|
||||
write KEYWORD2
|
||||
available KEYWORD2
|
||||
config KEYWORD2
|
||||
setDNS KEYWORD2
|
||||
read KEYWORD2
|
||||
flush KEYWORD2
|
||||
stop KEYWORD2
|
||||
connected KEYWORD2
|
||||
begin KEYWORD2
|
||||
beginMulticast KEYWORD2
|
||||
disconnect KEYWORD2
|
||||
macAddress KEYWORD2
|
||||
localIP KEYWORD2
|
||||
subnetMask KEYWORD2
|
||||
gatewayIP KEYWORD2
|
||||
SSID KEYWORD2
|
||||
psk KEYWORD2
|
||||
BSSID KEYWORD2
|
||||
RSSI KEYWORD2
|
||||
encryptionType KEYWORD2
|
||||
beginPacket KEYWORD2
|
||||
beginPacketMulticast KEYWORD2
|
||||
endPacket KEYWORD2
|
||||
parsePacket KEYWORD2
|
||||
destinationIP KEYWORD2
|
||||
remoteIP KEYWORD2
|
||||
remotePort KEYWORD2
|
||||
softAP KEYWORD2
|
||||
softAPIP KEYWORD2
|
||||
softAPmacAddress KEYWORD2
|
||||
softAPConfig KEYWORD2
|
||||
printDiag KEYWORD2
|
||||
hostByName KEYWORD2
|
||||
scanNetworks KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
WIFI_AP LITERAL1
|
||||
WIFI_STA LITERAL1
|
||||
WIFI_AP_STA LITERAL1
|
9
libs/WiFi/library.properties
Normal file
9
libs/WiFi/library.properties
Normal file
|
@ -0,0 +1,9 @@
|
|||
name=WiFi
|
||||
version=2.0.0
|
||||
author=Hristo Gochkov
|
||||
maintainer=Hristo Gochkov <hristo@espressif.com>
|
||||
sentence=Enables network connection (local and Internet) using the ESP32 built-in WiFi.
|
||||
paragraph=With this library you can instantiate Servers, Clients and send/receive UDP packets through WiFi. The shield can connect either to open or encrypted networks. The IP address can be assigned statically or through a DHCP. The library can also manage DNS.
|
||||
category=Communication
|
||||
url=
|
||||
architectures=esp32
|
101
libs/WiFi/src/WiFi.cpp
Normal file
101
libs/WiFi/src/WiFi.cpp
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
ESP8266WiFi.cpp - WiFi library for esp8266
|
||||
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Reworked on 28 Dec 2015 by Markus Sattler
|
||||
|
||||
*/
|
||||
#include "WiFi.h"
|
||||
|
||||
extern "C" {
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_event.h>
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------- Debug ------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Output WiFi settings to an object derived from Print interface (like Serial).
|
||||
* @param p Print interface
|
||||
*/
|
||||
void WiFiClass::printDiag(Print& p)
|
||||
{
|
||||
const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };
|
||||
|
||||
wifi_mode_t mode;
|
||||
esp_wifi_get_mode(&mode);
|
||||
|
||||
uint8_t primaryChan;
|
||||
wifi_second_chan_t secondChan;
|
||||
esp_wifi_get_channel(&primaryChan, &secondChan);
|
||||
|
||||
p.print("Mode: ");
|
||||
p.println(modes[mode]);
|
||||
|
||||
p.print("Channel: ");
|
||||
p.println(primaryChan);
|
||||
/*
|
||||
p.print("AP id: ");
|
||||
p.println(wifi_station_get_current_ap_id());
|
||||
|
||||
p.print("Status: ");
|
||||
p.println(wifi_station_get_connect_status());
|
||||
*/
|
||||
|
||||
wifi_config_t conf;
|
||||
esp_wifi_get_config((wifi_interface_t)WIFI_IF_STA, &conf);
|
||||
|
||||
const char* ssid = reinterpret_cast<const char*>(conf.sta.ssid);
|
||||
p.print("SSID (");
|
||||
p.print(strlen(ssid));
|
||||
p.print("): ");
|
||||
p.println(ssid);
|
||||
|
||||
const char* passphrase = reinterpret_cast<const char*>(conf.sta.password);
|
||||
p.print("Passphrase (");
|
||||
p.print(strlen(passphrase));
|
||||
p.print("): ");
|
||||
p.println(passphrase);
|
||||
|
||||
p.print("BSSID set: ");
|
||||
p.println(conf.sta.bssid_set);
|
||||
}
|
||||
|
||||
void WiFiClass::enableProv(bool status)
|
||||
{
|
||||
prov_enable = status;
|
||||
}
|
||||
|
||||
bool WiFiClass::isProvEnabled()
|
||||
{
|
||||
return prov_enable;
|
||||
}
|
||||
|
||||
WiFiClass WiFi;
|
74
libs/WiFi/src/WiFi.h
Normal file
74
libs/WiFi/src/WiFi.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
WiFi.h - esp32 Wifi support.
|
||||
Based on WiFi.h from Arduino WiFi shield library.
|
||||
Copyright (c) 2011-2014 Arduino. All right reserved.
|
||||
Modified by Ivan Grokhotkov, December 2014
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef WiFi_h
|
||||
#define WiFi_h
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Print.h"
|
||||
#include "IPAddress.h"
|
||||
|
||||
#include "WiFiType.h"
|
||||
#include "WiFiSTA.h"
|
||||
#include "WiFiAP.h"
|
||||
#include "WiFiScan.h"
|
||||
#include "WiFiGeneric.h"
|
||||
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
#include "WiFiUdp.h"
|
||||
|
||||
class WiFiClass : public WiFiGenericClass, public WiFiSTAClass, public WiFiScanClass, public WiFiAPClass
|
||||
{
|
||||
private:
|
||||
bool prov_enable;
|
||||
public:
|
||||
WiFiClass()
|
||||
{
|
||||
prov_enable = false;
|
||||
}
|
||||
|
||||
using WiFiGenericClass::channel;
|
||||
|
||||
using WiFiSTAClass::SSID;
|
||||
using WiFiSTAClass::RSSI;
|
||||
using WiFiSTAClass::BSSID;
|
||||
using WiFiSTAClass::BSSIDstr;
|
||||
|
||||
using WiFiScanClass::SSID;
|
||||
using WiFiScanClass::encryptionType;
|
||||
using WiFiScanClass::RSSI;
|
||||
using WiFiScanClass::BSSID;
|
||||
using WiFiScanClass::BSSIDstr;
|
||||
using WiFiScanClass::channel;
|
||||
public:
|
||||
void printDiag(Print& dest);
|
||||
friend class WiFiClient;
|
||||
friend class WiFiServer;
|
||||
friend class WiFiUDP;
|
||||
void enableProv(bool status);
|
||||
bool isProvEnabled();
|
||||
};
|
||||
|
||||
extern WiFiClass WiFi;
|
||||
|
||||
#endif
|
445
libs/WiFi/src/WiFiAP.cpp
Normal file
445
libs/WiFi/src/WiFiAP.cpp
Normal file
|
@ -0,0 +1,445 @@
|
|||
/*
|
||||
ESP8266WiFiSTA.cpp - WiFi library for esp8266
|
||||
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Reworked on 28 Dec 2015 by Markus Sattler
|
||||
|
||||
*/
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "WiFiGeneric.h"
|
||||
#include "WiFiAP.h"
|
||||
|
||||
extern "C" {
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_event.h>
|
||||
#include <lwip/ip_addr.h>
|
||||
#include "dhcpserver/dhcpserver_options.h"
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
// ---------------------------------------------------- Private functions ------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
esp_netif_t* get_esp_interface_netif(esp_interface_t interface);
|
||||
esp_err_t set_esp_interface_ip(esp_interface_t interface, IPAddress local_ip=INADDR_NONE, IPAddress gateway=INADDR_NONE, IPAddress subnet=INADDR_NONE, IPAddress dhcp_lease_start=INADDR_NONE);
|
||||
static bool softap_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs);
|
||||
|
||||
static size_t _wifi_strncpy(char * dst, const char * src, size_t dst_len){
|
||||
if(!dst || !src || !dst_len){
|
||||
return 0;
|
||||
}
|
||||
size_t src_len = strlen(src);
|
||||
if(src_len >= dst_len){
|
||||
src_len = dst_len;
|
||||
} else {
|
||||
src_len += 1;
|
||||
}
|
||||
memcpy(dst, src, src_len);
|
||||
return src_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* compare two AP configurations
|
||||
* @param lhs softap_config
|
||||
* @param rhs softap_config
|
||||
* @return equal
|
||||
*/
|
||||
static bool softap_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs)
|
||||
{
|
||||
if(strncmp(reinterpret_cast<const char*>(lhs.ap.ssid), reinterpret_cast<const char*>(rhs.ap.ssid), 32) != 0) {
|
||||
return false;
|
||||
}
|
||||
if(strncmp(reinterpret_cast<const char*>(lhs.ap.password), reinterpret_cast<const char*>(rhs.ap.password), 64) != 0) {
|
||||
return false;
|
||||
}
|
||||
if(lhs.ap.channel != rhs.ap.channel) {
|
||||
return false;
|
||||
}
|
||||
if(lhs.ap.authmode != rhs.ap.authmode) {
|
||||
return false;
|
||||
}
|
||||
if(lhs.ap.ssid_hidden != rhs.ap.ssid_hidden) {
|
||||
return false;
|
||||
}
|
||||
if(lhs.ap.max_connection != rhs.ap.max_connection) {
|
||||
return false;
|
||||
}
|
||||
if(lhs.ap.pairwise_cipher != rhs.ap.pairwise_cipher) {
|
||||
return false;
|
||||
}
|
||||
if(lhs.ap.ftm_responder != rhs.ap.ftm_responder) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void wifi_softap_config(wifi_config_t *wifi_config, const char * ssid=NULL, const char * password=NULL, uint8_t channel=6, wifi_auth_mode_t authmode=WIFI_AUTH_WPA2_PSK, uint8_t ssid_hidden=0, uint8_t max_connections=4, bool ftm_responder=false, uint16_t beacon_interval=100){
|
||||
wifi_config->ap.channel = channel;
|
||||
wifi_config->ap.max_connection = max_connections;
|
||||
wifi_config->ap.beacon_interval = beacon_interval;
|
||||
wifi_config->ap.ssid_hidden = ssid_hidden;
|
||||
wifi_config->ap.authmode = WIFI_AUTH_OPEN;
|
||||
wifi_config->ap.ssid_len = 0;
|
||||
wifi_config->ap.ssid[0] = 0;
|
||||
wifi_config->ap.password[0] = 0;
|
||||
wifi_config->ap.ftm_responder = ftm_responder;
|
||||
if(ssid != NULL && ssid[0] != 0){
|
||||
_wifi_strncpy((char*)wifi_config->ap.ssid, ssid, 32);
|
||||
wifi_config->ap.ssid_len = strlen(ssid);
|
||||
if(password != NULL && password[0] != 0){
|
||||
wifi_config->ap.authmode = authmode;
|
||||
wifi_config->ap.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP; // Disable by default enabled insecure TKIP and use just CCMP.
|
||||
_wifi_strncpy((char*)wifi_config->ap.password, password, 64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------- AP function -----------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Set up an access point
|
||||
* @param ssid Pointer to the SSID (max 63 char).
|
||||
* @param passphrase (for WPA2 min 8 char, for open use NULL)
|
||||
* @param channel WiFi channel number, 1 - 13.
|
||||
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
|
||||
* @param max_connection Max simultaneous connected clients, 1 - 4.
|
||||
*/
|
||||
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder)
|
||||
{
|
||||
|
||||
if(!ssid || *ssid == 0) {
|
||||
// fail SSID missing
|
||||
log_e("SSID missing!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(passphrase && (strlen(passphrase) > 0 && strlen(passphrase) < 8)) {
|
||||
// fail passphrase too short
|
||||
log_e("passphrase too short!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// last step after checking the SSID and password
|
||||
if(!WiFi.enableAP(true)) {
|
||||
// enable AP failed
|
||||
log_e("enable AP first!");
|
||||
return false;
|
||||
}
|
||||
|
||||
wifi_config_t conf;
|
||||
wifi_config_t conf_current;
|
||||
wifi_softap_config(&conf, ssid, passphrase, channel, WIFI_AUTH_WPA2_PSK, ssid_hidden, max_connection, ftm_responder);
|
||||
esp_err_t err = esp_wifi_get_config((wifi_interface_t)WIFI_IF_AP, &conf_current);
|
||||
if(err){
|
||||
log_e("get AP config failed");
|
||||
return false;
|
||||
}
|
||||
if(!softap_config_equal(conf, conf_current)) {
|
||||
err = esp_wifi_set_config((wifi_interface_t)WIFI_IF_AP, &conf);
|
||||
if(err){
|
||||
log_e("set AP config failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current SSID associated with the network
|
||||
* @return SSID
|
||||
*/
|
||||
String WiFiAPClass::softAPSSID() const
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return String();
|
||||
}
|
||||
wifi_config_t info;
|
||||
if(!esp_wifi_get_config(WIFI_IF_AP, &info)) {
|
||||
return String(reinterpret_cast<char*>(info.ap.ssid));
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure access point
|
||||
* @param local_ip access point IP
|
||||
* @param gateway gateway IP
|
||||
* @param subnet subnet mask
|
||||
*/
|
||||
bool WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
if(!WiFi.enableAP(true)) {
|
||||
// enable AP failed
|
||||
return false;
|
||||
}
|
||||
|
||||
err = set_esp_interface_ip(ESP_IF_WIFI_AP, local_ip, gateway, subnet, dhcp_lease_start);
|
||||
return err == ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disconnect from the network (close AP)
|
||||
* @param wifioff disable mode?
|
||||
* @return one value of wl_status_t enum
|
||||
*/
|
||||
bool WiFiAPClass::softAPdisconnect(bool wifioff)
|
||||
{
|
||||
bool ret;
|
||||
wifi_config_t conf;
|
||||
wifi_softap_config(&conf);
|
||||
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = esp_wifi_set_config((wifi_interface_t)WIFI_IF_AP, &conf) == ESP_OK;
|
||||
|
||||
if(ret && wifioff) {
|
||||
ret = WiFi.enableAP(false) == ESP_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the working bandwidth of the AP mode
|
||||
* @param m wifi_bandwidth_t
|
||||
*/
|
||||
bool WiFiAPClass::softAPbandwidth(wifi_bandwidth_t bandwidth) {
|
||||
if(!WiFi.enableAP(true)) {
|
||||
log_e("AP enable failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_err_t err;
|
||||
err = esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_AP, bandwidth);
|
||||
if(err){
|
||||
log_e("Could not set AP bandwidth!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count of the Station / client that are connected to the softAP interface
|
||||
* @return Stations count
|
||||
*/
|
||||
uint8_t WiFiAPClass::softAPgetStationNum()
|
||||
{
|
||||
wifi_sta_list_t clients;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return 0;
|
||||
}
|
||||
if(esp_wifi_ap_get_sta_list(&clients) == ESP_OK) {
|
||||
return clients.num;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP interface IP address.
|
||||
* @return IPAddress softAP IP
|
||||
*/
|
||||
IPAddress WiFiAPClass::softAPIP()
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
esp_netif_ip_info_t ip;
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_AP), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(ip.ip.addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP broadcast IP address.
|
||||
* @return IPAddress softAP broadcastIP
|
||||
*/
|
||||
IPAddress WiFiAPClass::softAPBroadcastIP()
|
||||
{
|
||||
esp_netif_ip_info_t ip;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_AP), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return WiFiGenericClass::calculateBroadcast(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP network ID.
|
||||
* @return IPAddress softAP networkID
|
||||
*/
|
||||
IPAddress WiFiAPClass::softAPNetworkID()
|
||||
{
|
||||
esp_netif_ip_info_t ip;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_AP), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return WiFiGenericClass::calculateNetworkID(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP subnet mask.
|
||||
* @return IPAddress subnetMask
|
||||
*/
|
||||
IPAddress WiFiAPClass::softAPSubnetMask()
|
||||
{
|
||||
esp_netif_ip_info_t ip;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_AP), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(ip.netmask.addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP subnet CIDR.
|
||||
* @return uint8_t softAP subnetCIDR
|
||||
*/
|
||||
uint8_t WiFiAPClass::softAPSubnetCIDR()
|
||||
{
|
||||
return WiFiGenericClass::calculateSubnetCIDR(softAPSubnetMask());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP interface MAC address.
|
||||
* @param mac pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
* @return pointer to uint8_t*
|
||||
*/
|
||||
uint8_t* WiFiAPClass::softAPmacAddress(uint8_t* mac)
|
||||
{
|
||||
if(WiFiGenericClass::getMode() != WIFI_MODE_NULL){
|
||||
esp_wifi_get_mac((wifi_interface_t)WIFI_IF_AP, mac);
|
||||
}
|
||||
return mac;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP interface MAC address.
|
||||
* @return String mac
|
||||
*/
|
||||
String WiFiAPClass::softAPmacAddress(void)
|
||||
{
|
||||
uint8_t mac[6];
|
||||
char macStr[18] = { 0 };
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return String();
|
||||
}
|
||||
esp_wifi_get_mac((wifi_interface_t)WIFI_IF_AP, mac);
|
||||
|
||||
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
return String(macStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP interface Host name.
|
||||
* @return char array hostname
|
||||
*/
|
||||
const char * WiFiAPClass::softAPgetHostname()
|
||||
{
|
||||
const char * hostname = NULL;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return hostname;
|
||||
}
|
||||
if(esp_netif_get_hostname(get_esp_interface_netif(ESP_IF_WIFI_AP), &hostname) != ESP_OK){
|
||||
log_e("Netif Get Hostname Failed!");
|
||||
}
|
||||
return hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the softAP interface Host name.
|
||||
* @param hostname pointer to const string
|
||||
* @return true on success
|
||||
*/
|
||||
bool WiFiAPClass::softAPsetHostname(const char * hostname)
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return false;
|
||||
}
|
||||
return esp_netif_set_hostname(get_esp_interface_netif(ESP_IF_WIFI_AP), hostname) == ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable IPv6 on the softAP interface.
|
||||
* @return true on success
|
||||
*/
|
||||
bool WiFiAPClass::softAPenableIPv6(bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
WiFiGenericClass::setStatusBits(AP_WANT_IP6_BIT);
|
||||
} else {
|
||||
WiFiGenericClass::clearStatusBits(AP_WANT_IP6_BIT);
|
||||
}
|
||||
return true;
|
||||
// if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
// return false;
|
||||
// }
|
||||
// return esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_AP)) == ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the softAP interface IPv6 address.
|
||||
* @return IPAddress softAP IPv6
|
||||
*/
|
||||
|
||||
IPAddress WiFiAPClass::softAPIPv6()
|
||||
{
|
||||
static esp_ip6_addr_t addr;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
|
||||
if(esp_netif_get_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_STA), &addr)){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
return IPAddress(IPv6, (const uint8_t *)addr.addr, addr.zone);
|
||||
}
|
||||
|
74
libs/WiFi/src/WiFiAP.h
Normal file
74
libs/WiFi/src/WiFiAP.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
ESP8266WiFiAP.h - esp8266 Wifi support.
|
||||
Based on WiFi.h from Arduino WiFi shield library.
|
||||
Copyright (c) 2011-2014 Arduino. All right reserved.
|
||||
Modified by Ivan Grokhotkov, December 2014
|
||||
Reworked by Markus Sattler, December 2015
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef ESP32WIFIAP_H_
|
||||
#define ESP32WIFIAP_H_
|
||||
|
||||
|
||||
#include "WiFiType.h"
|
||||
#include "WiFiGeneric.h"
|
||||
|
||||
|
||||
class WiFiAPClass
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// ----------------------------------------- AP function ----------------------------------------
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
|
||||
bool softAP(const String& ssid, const String& passphrase = emptyString, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false) {
|
||||
return softAP(ssid.c_str(), passphrase.c_str(), channel, ssid_hidden, max_connection, ftm_responder);
|
||||
}
|
||||
|
||||
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = (uint32_t) 0);
|
||||
bool softAPdisconnect(bool wifioff = false);
|
||||
|
||||
bool softAPbandwidth(wifi_bandwidth_t bandwidth);
|
||||
|
||||
uint8_t softAPgetStationNum();
|
||||
|
||||
IPAddress softAPIP();
|
||||
|
||||
IPAddress softAPBroadcastIP();
|
||||
IPAddress softAPNetworkID();
|
||||
IPAddress softAPSubnetMask();
|
||||
uint8_t softAPSubnetCIDR();
|
||||
|
||||
bool softAPenableIPv6(bool enable=true);
|
||||
IPAddress softAPIPv6();
|
||||
|
||||
const char * softAPgetHostname();
|
||||
bool softAPsetHostname(const char * hostname);
|
||||
|
||||
uint8_t* softAPmacAddress(uint8_t* mac);
|
||||
String softAPmacAddress(void);
|
||||
|
||||
String softAPSSID(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
#endif /* ESP32WIFIAP_H_*/
|
663
libs/WiFi/src/WiFiClient.cpp
Normal file
663
libs/WiFi/src/WiFiClient.cpp
Normal file
|
@ -0,0 +1,663 @@
|
|||
/*
|
||||
Client.h - Client class for Raspberry Pi
|
||||
Copyright (c) 2016 Hristo Gochkov All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFi.h"
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/netdb.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define IN6_IS_ADDR_V4MAPPED(a) \
|
||||
((((__const uint32_t *) (a))[0] == 0) \
|
||||
&& (((__const uint32_t *) (a))[1] == 0) \
|
||||
&& (((__const uint32_t *) (a))[2] == htonl (0xffff)))
|
||||
|
||||
#define WIFI_CLIENT_DEF_CONN_TIMEOUT_MS (3000)
|
||||
#define WIFI_CLIENT_MAX_WRITE_RETRY (10)
|
||||
#define WIFI_CLIENT_SELECT_TIMEOUT_US (1000000)
|
||||
#define WIFI_CLIENT_FLUSH_BUFFER_SIZE (1024)
|
||||
|
||||
#undef connect
|
||||
#undef write
|
||||
#undef read
|
||||
|
||||
class WiFiClientRxBuffer {
|
||||
private:
|
||||
size_t _size;
|
||||
uint8_t *_buffer;
|
||||
size_t _pos;
|
||||
size_t _fill;
|
||||
int _fd;
|
||||
bool _failed;
|
||||
|
||||
size_t r_available()
|
||||
{
|
||||
if(_fd < 0){
|
||||
return 0;
|
||||
}
|
||||
int count;
|
||||
#ifdef ESP_IDF_VERSION_MAJOR
|
||||
int res = lwip_ioctl(_fd, FIONREAD, &count);
|
||||
#else
|
||||
int res = lwip_ioctl_r(_fd, FIONREAD, &count);
|
||||
#endif
|
||||
if(res < 0) {
|
||||
_failed = true;
|
||||
return 0;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t fillBuffer()
|
||||
{
|
||||
if(!_buffer){
|
||||
_buffer = (uint8_t *)malloc(_size);
|
||||
if(!_buffer) {
|
||||
log_e("Not enough memory to allocate buffer");
|
||||
_failed = true;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(_fill && _pos == _fill){
|
||||
_fill = 0;
|
||||
_pos = 0;
|
||||
}
|
||||
if(!_buffer || _size <= _fill || !r_available()) {
|
||||
return 0;
|
||||
}
|
||||
int res = recv(_fd, _buffer + _fill, _size - _fill, MSG_DONTWAIT);
|
||||
if(res < 0) {
|
||||
if(errno != EWOULDBLOCK) {
|
||||
_failed = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
_fill += res;
|
||||
return res;
|
||||
}
|
||||
|
||||
public:
|
||||
WiFiClientRxBuffer(int fd, size_t size=1436)
|
||||
:_size(size)
|
||||
,_buffer(NULL)
|
||||
,_pos(0)
|
||||
,_fill(0)
|
||||
,_fd(fd)
|
||||
,_failed(false)
|
||||
{
|
||||
//_buffer = (uint8_t *)malloc(_size);
|
||||
}
|
||||
|
||||
~WiFiClientRxBuffer()
|
||||
{
|
||||
free(_buffer);
|
||||
}
|
||||
|
||||
bool failed(){
|
||||
return _failed;
|
||||
}
|
||||
|
||||
int read(uint8_t * dst, size_t len){
|
||||
if(!dst || !len || (_pos == _fill && !fillBuffer())){
|
||||
return _failed ? -1 : 0;
|
||||
}
|
||||
size_t a = _fill - _pos;
|
||||
if(len <= a || ((len - a) <= (_size - _fill) && fillBuffer() >= (len - a))){
|
||||
if(len == 1){
|
||||
*dst = _buffer[_pos];
|
||||
} else {
|
||||
memcpy(dst, _buffer + _pos, len);
|
||||
}
|
||||
_pos += len;
|
||||
return len;
|
||||
}
|
||||
size_t left = len;
|
||||
size_t toRead = a;
|
||||
uint8_t * buf = dst;
|
||||
memcpy(buf, _buffer + _pos, toRead);
|
||||
_pos += toRead;
|
||||
left -= toRead;
|
||||
buf += toRead;
|
||||
while(left){
|
||||
if(!fillBuffer()){
|
||||
return len - left;
|
||||
}
|
||||
a = _fill - _pos;
|
||||
toRead = (a > left)?left:a;
|
||||
memcpy(buf, _buffer + _pos, toRead);
|
||||
_pos += toRead;
|
||||
left -= toRead;
|
||||
buf += toRead;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int peek(){
|
||||
if(_pos == _fill && !fillBuffer()){
|
||||
return -1;
|
||||
}
|
||||
return _buffer[_pos];
|
||||
}
|
||||
|
||||
size_t available(){
|
||||
return _fill - _pos + r_available();
|
||||
}
|
||||
|
||||
void flush(){
|
||||
if(r_available()){
|
||||
fillBuffer();
|
||||
}
|
||||
_pos = _fill;
|
||||
}
|
||||
};
|
||||
|
||||
class WiFiClientSocketHandle {
|
||||
private:
|
||||
int sockfd;
|
||||
|
||||
public:
|
||||
WiFiClientSocketHandle(int fd):sockfd(fd)
|
||||
{
|
||||
}
|
||||
|
||||
~WiFiClientSocketHandle()
|
||||
{
|
||||
close(sockfd);
|
||||
}
|
||||
|
||||
int fd()
|
||||
{
|
||||
return sockfd;
|
||||
}
|
||||
};
|
||||
|
||||
WiFiClient::WiFiClient():_rxBuffer(nullptr),_connected(false),_timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS),next(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
WiFiClient::WiFiClient(int fd):_connected(true),_timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS),next(NULL)
|
||||
{
|
||||
clientSocketHandle.reset(new WiFiClientSocketHandle(fd));
|
||||
_rxBuffer.reset(new WiFiClientRxBuffer(fd));
|
||||
}
|
||||
|
||||
WiFiClient::~WiFiClient()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void WiFiClient::stop()
|
||||
{
|
||||
clientSocketHandle = NULL;
|
||||
_rxBuffer = NULL;
|
||||
_connected = false;
|
||||
_lastReadTimeout = 0;
|
||||
_lastWriteTimeout = 0;
|
||||
}
|
||||
|
||||
int WiFiClient::connect(IPAddress ip, uint16_t port)
|
||||
{
|
||||
return connect(ip,port,_timeout);
|
||||
}
|
||||
|
||||
int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout_ms)
|
||||
{
|
||||
struct sockaddr_storage serveraddr = {};
|
||||
_timeout = timeout_ms;
|
||||
int sockfd = -1;
|
||||
|
||||
if (ip.type() == IPv6) {
|
||||
struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serveraddr;
|
||||
sockfd = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
tmpaddr->sin6_family = AF_INET6;
|
||||
memcpy(tmpaddr->sin6_addr.un.u8_addr, &ip[0], 16);
|
||||
tmpaddr->sin6_port = htons(port);
|
||||
tmpaddr->sin6_scope_id = ip.zone();
|
||||
} else {
|
||||
struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serveraddr;
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
tmpaddr->sin_family = AF_INET;
|
||||
tmpaddr->sin_addr.s_addr = ip;
|
||||
tmpaddr->sin_port = htons(port);
|
||||
}
|
||||
if (sockfd < 0) {
|
||||
log_e("socket: %d", errno);
|
||||
return 0;
|
||||
}
|
||||
fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) | O_NONBLOCK );
|
||||
|
||||
fd_set fdset;
|
||||
struct timeval tv;
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(sockfd, &fdset);
|
||||
tv.tv_sec = _timeout / 1000;
|
||||
tv.tv_usec = (_timeout % 1000) * 1000;
|
||||
|
||||
#ifdef ESP_IDF_VERSION_MAJOR
|
||||
int res = lwip_connect(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
|
||||
#else
|
||||
int res = lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
|
||||
#endif
|
||||
if (res < 0 && errno != EINPROGRESS) {
|
||||
log_e("connect on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno));
|
||||
close(sockfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = select(sockfd + 1, nullptr, &fdset, nullptr, _timeout<0 ? nullptr : &tv);
|
||||
if (res < 0) {
|
||||
log_e("select on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno));
|
||||
close(sockfd);
|
||||
return 0;
|
||||
} else if (res == 0) {
|
||||
log_i("select returned due to timeout %d ms for fd %d", _timeout, sockfd);
|
||||
close(sockfd);
|
||||
return 0;
|
||||
} else {
|
||||
int sockerr;
|
||||
socklen_t len = (socklen_t)sizeof(int);
|
||||
res = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &sockerr, &len);
|
||||
|
||||
if (res < 0) {
|
||||
log_e("getsockopt on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno));
|
||||
close(sockfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sockerr != 0) {
|
||||
log_e("socket error on fd %d, errno: %d, \"%s\"", sockfd, sockerr, strerror(sockerr));
|
||||
close(sockfd);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define ROE_WIFICLIENT(x,msg) { if (((x)<0)) { log_e("Setsockopt '" msg "'' on fd %d failed. errno: %d, \"%s\"", sockfd, errno, strerror(errno)); return 0; }}
|
||||
ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)),"SO_SNDTIMEO");
|
||||
ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)),"SO_RCVTIMEO");
|
||||
|
||||
// These are also set in WiFiClientSecure, should be set here too?
|
||||
//ROE_WIFICLIENT(setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)),"TCP_NODELAY");
|
||||
//ROE_WIFICLIENT (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)),"SO_KEEPALIVE");
|
||||
|
||||
fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) & (~O_NONBLOCK) );
|
||||
clientSocketHandle.reset(new WiFiClientSocketHandle(sockfd));
|
||||
_rxBuffer.reset(new WiFiClientRxBuffer(sockfd));
|
||||
|
||||
_connected = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WiFiClient::connect(const char *host, uint16_t port)
|
||||
{
|
||||
return connect(host,port,_timeout);
|
||||
}
|
||||
|
||||
int WiFiClient::connect(const char *host, uint16_t port, int32_t timeout_ms)
|
||||
{
|
||||
IPAddress srv((uint32_t)0);
|
||||
if(!WiFiGenericClass::hostByName(host, srv)){
|
||||
return 0;
|
||||
}
|
||||
return connect(srv, port, timeout_ms);
|
||||
}
|
||||
|
||||
int WiFiClient::setSocketOption(int option, char* value, size_t len)
|
||||
{
|
||||
return setSocketOption(SOL_SOCKET, option, (const void*)value, len);
|
||||
}
|
||||
|
||||
int WiFiClient::setSocketOption(int level, int option, const void* value, size_t len)
|
||||
{
|
||||
int res = setsockopt(fd(), level, option, value, len);
|
||||
if(res < 0) {
|
||||
log_e("fail on %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int WiFiClient::getSocketOption(int level, int option, const void* value, size_t size)
|
||||
{
|
||||
int res = getsockopt(fd(), level, option, (char *)value, (socklen_t*)&size);
|
||||
if(res < 0) {
|
||||
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int WiFiClient::setOption(int option, int *value)
|
||||
{
|
||||
return setSocketOption(IPPROTO_TCP, option, (const void*)value, sizeof(int));
|
||||
}
|
||||
|
||||
int WiFiClient::getOption(int option, int *value)
|
||||
{
|
||||
socklen_t size = sizeof(int);
|
||||
int res = getsockopt(fd(), IPPROTO_TCP, option, (char *)value, &size);
|
||||
if(res < 0) {
|
||||
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void WiFiClient::setConnectionTimeout(uint32_t milliseconds)
|
||||
{
|
||||
_timeout = milliseconds;
|
||||
}
|
||||
|
||||
int WiFiClient::setNoDelay(bool nodelay)
|
||||
{
|
||||
int flag = nodelay;
|
||||
return setOption(TCP_NODELAY, &flag);
|
||||
}
|
||||
|
||||
bool WiFiClient::getNoDelay()
|
||||
{
|
||||
int flag = 0;
|
||||
getOption(TCP_NODELAY, &flag);
|
||||
return flag;
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(uint8_t data)
|
||||
{
|
||||
return write(&data, 1);
|
||||
}
|
||||
|
||||
int WiFiClient::read()
|
||||
{
|
||||
uint8_t data = 0;
|
||||
int res = read(&data, 1);
|
||||
if(res < 0) {
|
||||
return res;
|
||||
}
|
||||
if (res == 0) { // No data available.
|
||||
return -1;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(const uint8_t *buf, size_t size)
|
||||
{
|
||||
int res =0;
|
||||
int retry = WIFI_CLIENT_MAX_WRITE_RETRY;
|
||||
int socketFileDescriptor = fd();
|
||||
size_t totalBytesSent = 0;
|
||||
size_t bytesRemaining = size;
|
||||
|
||||
if(!_connected || (socketFileDescriptor < 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while(retry) {
|
||||
//use select to make sure the socket is ready for writing
|
||||
fd_set set;
|
||||
struct timeval tv;
|
||||
FD_ZERO(&set); // empties the set
|
||||
FD_SET(socketFileDescriptor, &set); // adds FD to the set
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = WIFI_CLIENT_SELECT_TIMEOUT_US;
|
||||
retry--;
|
||||
|
||||
if(_lastWriteTimeout != _timeout){
|
||||
if(fd() >= 0){
|
||||
struct timeval timeout_tv;
|
||||
timeout_tv.tv_sec = _timeout / 1000;
|
||||
timeout_tv.tv_usec = (_timeout % 1000) * 1000;
|
||||
if(setSocketOption(SO_SNDTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0)
|
||||
{
|
||||
_lastWriteTimeout = _timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(select(socketFileDescriptor + 1, NULL, &set, NULL, &tv) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(FD_ISSET(socketFileDescriptor, &set)) {
|
||||
res = send(socketFileDescriptor, (void*) buf, bytesRemaining, MSG_DONTWAIT);
|
||||
if(res > 0) {
|
||||
totalBytesSent += res;
|
||||
if (totalBytesSent >= size) {
|
||||
//completed successfully
|
||||
retry = 0;
|
||||
} else {
|
||||
buf += res;
|
||||
bytesRemaining -= res;
|
||||
retry = WIFI_CLIENT_MAX_WRITE_RETRY;
|
||||
}
|
||||
}
|
||||
else if(res < 0) {
|
||||
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
|
||||
if(errno != EAGAIN) {
|
||||
//if resource was busy, can try again, otherwise give up
|
||||
stop();
|
||||
res = 0;
|
||||
retry = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Try again
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalBytesSent;
|
||||
}
|
||||
|
||||
size_t WiFiClient::write_P(PGM_P buf, size_t size)
|
||||
{
|
||||
return write(buf, size);
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(Stream &stream)
|
||||
{
|
||||
uint8_t * buf = (uint8_t *)malloc(1360);
|
||||
if(!buf){
|
||||
return 0;
|
||||
}
|
||||
size_t toRead = 0, toWrite = 0, written = 0;
|
||||
size_t available = stream.available();
|
||||
while(available){
|
||||
toRead = (available > 1360)?1360:available;
|
||||
toWrite = stream.readBytes(buf, toRead);
|
||||
written += write(buf, toWrite);
|
||||
available = stream.available();
|
||||
}
|
||||
free(buf);
|
||||
return written;
|
||||
}
|
||||
|
||||
int WiFiClient::read(uint8_t *buf, size_t size)
|
||||
{
|
||||
if(_lastReadTimeout != _timeout){
|
||||
if(fd() >= 0){
|
||||
struct timeval timeout_tv;
|
||||
timeout_tv.tv_sec = _timeout / 1000;
|
||||
timeout_tv.tv_usec = (_timeout % 1000) * 1000;
|
||||
if(setSocketOption(SO_RCVTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0)
|
||||
{
|
||||
_lastReadTimeout = _timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int res = -1;
|
||||
if (_rxBuffer) {
|
||||
res = _rxBuffer->read(buf, size);
|
||||
if(_rxBuffer->failed()) {
|
||||
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
|
||||
stop();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int WiFiClient::peek()
|
||||
{
|
||||
int res = -1;
|
||||
if (_rxBuffer) {
|
||||
res = _rxBuffer->peek();
|
||||
if(_rxBuffer->failed()) {
|
||||
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
|
||||
stop();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int WiFiClient::available()
|
||||
{
|
||||
if(!_rxBuffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int res = _rxBuffer->available();
|
||||
if(_rxBuffer->failed()) {
|
||||
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
|
||||
stop();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Though flushing means to send all pending data,
|
||||
// seems that in Arduino it also means to clear RX
|
||||
void WiFiClient::flush() {
|
||||
if (_rxBuffer != nullptr) {
|
||||
_rxBuffer->flush();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t WiFiClient::connected()
|
||||
{
|
||||
if (_connected) {
|
||||
uint8_t dummy;
|
||||
int res = recv(fd(), &dummy, 0, MSG_DONTWAIT);
|
||||
// avoid unused var warning by gcc
|
||||
(void)res;
|
||||
// recv only sets errno if res is <= 0
|
||||
if (res <= 0){
|
||||
switch (errno) {
|
||||
case EWOULDBLOCK:
|
||||
case ENOENT: //caused by vfs
|
||||
_connected = true;
|
||||
break;
|
||||
case ENOTCONN:
|
||||
case EPIPE:
|
||||
case ECONNRESET:
|
||||
case ECONNREFUSED:
|
||||
case ECONNABORTED:
|
||||
_connected = false;
|
||||
log_d("Disconnected: RES: %d, ERR: %d", res, errno);
|
||||
break;
|
||||
default:
|
||||
log_i("Unexpected: RES: %d, ERR: %d", res, errno);
|
||||
_connected = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
_connected = true;
|
||||
}
|
||||
}
|
||||
return _connected;
|
||||
}
|
||||
|
||||
IPAddress WiFiClient::remoteIP(int fd) const
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t len = sizeof addr;
|
||||
getpeername(fd, (struct sockaddr*)&addr, &len);
|
||||
|
||||
// IPv4 socket, old way
|
||||
if (((struct sockaddr*)&addr)->sa_family == AF_INET) {
|
||||
struct sockaddr_in *s = (struct sockaddr_in *)&addr;
|
||||
return IPAddress((uint32_t)(s->sin_addr.s_addr));
|
||||
}
|
||||
|
||||
// IPv6, but it might be IPv4 mapped address
|
||||
if (((struct sockaddr*)&addr)->sa_family == AF_INET6) {
|
||||
struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)&addr;
|
||||
if (IN6_IS_ADDR_V4MAPPED(saddr6->sin6_addr.un.u32_addr)) {
|
||||
return IPAddress(IPv4, (uint8_t*)saddr6->sin6_addr.s6_addr+IPADDRESS_V4_BYTES_INDEX);
|
||||
} else {
|
||||
return IPAddress(IPv6, (uint8_t*)(saddr6->sin6_addr.s6_addr), saddr6->sin6_scope_id);
|
||||
}
|
||||
}
|
||||
log_e("WiFiClient::remoteIP Not AF_INET or AF_INET6?");
|
||||
return (IPAddress(0,0,0,0));
|
||||
}
|
||||
|
||||
uint16_t WiFiClient::remotePort(int fd) const
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t len = sizeof addr;
|
||||
getpeername(fd, (struct sockaddr*)&addr, &len);
|
||||
struct sockaddr_in *s = (struct sockaddr_in *)&addr;
|
||||
return ntohs(s->sin_port);
|
||||
}
|
||||
|
||||
IPAddress WiFiClient::remoteIP() const
|
||||
{
|
||||
return remoteIP(fd());
|
||||
}
|
||||
|
||||
uint16_t WiFiClient::remotePort() const
|
||||
{
|
||||
return remotePort(fd());
|
||||
}
|
||||
|
||||
IPAddress WiFiClient::localIP(int fd) const
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t len = sizeof addr;
|
||||
getsockname(fd, (struct sockaddr*)&addr, &len);
|
||||
struct sockaddr_in *s = (struct sockaddr_in *)&addr;
|
||||
return IPAddress((uint32_t)(s->sin_addr.s_addr));
|
||||
}
|
||||
|
||||
uint16_t WiFiClient::localPort(int fd) const
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t len = sizeof addr;
|
||||
getsockname(fd, (struct sockaddr*)&addr, &len);
|
||||
struct sockaddr_in *s = (struct sockaddr_in *)&addr;
|
||||
return ntohs(s->sin_port);
|
||||
}
|
||||
|
||||
IPAddress WiFiClient::localIP() const
|
||||
{
|
||||
return localIP(fd());
|
||||
}
|
||||
|
||||
uint16_t WiFiClient::localPort() const
|
||||
{
|
||||
return localPort(fd());
|
||||
}
|
||||
|
||||
bool WiFiClient::operator==(const WiFiClient& rhs)
|
||||
{
|
||||
return clientSocketHandle == rhs.clientSocketHandle && remotePort() == rhs.remotePort() && remoteIP() == rhs.remoteIP();
|
||||
}
|
||||
|
||||
int WiFiClient::fd() const
|
||||
{
|
||||
if (clientSocketHandle == NULL) {
|
||||
return -1;
|
||||
} else {
|
||||
return clientSocketHandle->fd();
|
||||
}
|
||||
}
|
112
libs/WiFi/src/WiFiClient.h
Normal file
112
libs/WiFi/src/WiFiClient.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
Client.h - Base class that provides Client
|
||||
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _WIFICLIENT_H_
|
||||
#define _WIFICLIENT_H_
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Client.h"
|
||||
#include <memory>
|
||||
|
||||
class WiFiClientSocketHandle;
|
||||
class WiFiClientRxBuffer;
|
||||
|
||||
class ESPLwIPClient : public Client
|
||||
{
|
||||
public:
|
||||
virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
|
||||
virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
|
||||
virtual void setConnectionTimeout(uint32_t milliseconds) = 0;
|
||||
};
|
||||
|
||||
class WiFiClient : public ESPLwIPClient
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<WiFiClientSocketHandle> clientSocketHandle;
|
||||
std::shared_ptr<WiFiClientRxBuffer> _rxBuffer;
|
||||
bool _connected;
|
||||
int _timeout;
|
||||
int _lastWriteTimeout;
|
||||
int _lastReadTimeout;
|
||||
|
||||
public:
|
||||
WiFiClient *next;
|
||||
WiFiClient();
|
||||
WiFiClient(int fd);
|
||||
~WiFiClient();
|
||||
int connect(IPAddress ip, uint16_t port);
|
||||
int connect(IPAddress ip, uint16_t port, int32_t timeout_ms);
|
||||
int connect(const char *host, uint16_t port);
|
||||
int connect(const char *host, uint16_t port, int32_t timeout_ms);
|
||||
size_t write(uint8_t data);
|
||||
size_t write(const uint8_t *buf, size_t size);
|
||||
size_t write_P(PGM_P buf, size_t size);
|
||||
size_t write(Stream &stream);
|
||||
int available();
|
||||
int read();
|
||||
int read(uint8_t *buf, size_t size);
|
||||
int peek();
|
||||
void flush();
|
||||
void stop();
|
||||
uint8_t connected();
|
||||
|
||||
operator bool()
|
||||
{
|
||||
return connected();
|
||||
}
|
||||
bool operator==(const bool value)
|
||||
{
|
||||
return bool() == value;
|
||||
}
|
||||
bool operator!=(const bool value)
|
||||
{
|
||||
return bool() != value;
|
||||
}
|
||||
bool operator==(const WiFiClient&);
|
||||
bool operator!=(const WiFiClient& rhs)
|
||||
{
|
||||
return !this->operator==(rhs);
|
||||
};
|
||||
|
||||
virtual int fd() const;
|
||||
|
||||
int setSocketOption(int option, char* value, size_t len);
|
||||
int setSocketOption(int level, int option, const void* value, size_t len);
|
||||
int getSocketOption(int level, int option, const void* value, size_t size);
|
||||
int setOption(int option, int *value);
|
||||
int getOption(int option, int *value);
|
||||
void setConnectionTimeout(uint32_t milliseconds);
|
||||
int setNoDelay(bool nodelay);
|
||||
bool getNoDelay();
|
||||
|
||||
IPAddress remoteIP() const;
|
||||
IPAddress remoteIP(int fd) const;
|
||||
uint16_t remotePort() const;
|
||||
uint16_t remotePort(int fd) const;
|
||||
IPAddress localIP() const;
|
||||
IPAddress localIP(int fd) const;
|
||||
uint16_t localPort() const;
|
||||
uint16_t localPort(int fd) const;
|
||||
|
||||
//friend class WiFiServer;
|
||||
using Print::write;
|
||||
};
|
||||
|
||||
#endif /* _WIFICLIENT_H_ */
|
1723
libs/WiFi/src/WiFiGeneric.cpp
Normal file
1723
libs/WiFi/src/WiFiGeneric.cpp
Normal file
File diff suppressed because it is too large
Load diff
245
libs/WiFi/src/WiFiGeneric.h
Normal file
245
libs/WiFi/src/WiFiGeneric.h
Normal file
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
ESP8266WiFiGeneric.h - esp8266 Wifi support.
|
||||
Based on WiFi.h from Ardiono WiFi shield library.
|
||||
Copyright (c) 2011-2014 Arduino. All right reserved.
|
||||
Modified by Ivan Grokhotkov, December 2014
|
||||
Reworked by Markus Sattler, December 2015
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef ESP32WIFIGENERIC_H_
|
||||
#define ESP32WIFIGENERIC_H_
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_event.h"
|
||||
#include <functional>
|
||||
#include "WiFiType.h"
|
||||
#include "IPAddress.h"
|
||||
#include "esp_smartconfig.h"
|
||||
#include "esp_netif_types.h"
|
||||
#include "esp_eth_driver.h"
|
||||
#include "wifi_provisioning/manager.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(ARDUINO_EVENTS);
|
||||
|
||||
typedef enum {
|
||||
ARDUINO_EVENT_WIFI_READY = 0,
|
||||
ARDUINO_EVENT_WIFI_SCAN_DONE,
|
||||
ARDUINO_EVENT_WIFI_STA_START,
|
||||
ARDUINO_EVENT_WIFI_STA_STOP,
|
||||
ARDUINO_EVENT_WIFI_STA_CONNECTED,
|
||||
ARDUINO_EVENT_WIFI_STA_DISCONNECTED,
|
||||
ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE,
|
||||
ARDUINO_EVENT_WIFI_STA_GOT_IP,
|
||||
ARDUINO_EVENT_WIFI_STA_GOT_IP6,
|
||||
ARDUINO_EVENT_WIFI_STA_LOST_IP,
|
||||
ARDUINO_EVENT_WIFI_AP_START,
|
||||
ARDUINO_EVENT_WIFI_AP_STOP,
|
||||
ARDUINO_EVENT_WIFI_AP_STACONNECTED,
|
||||
ARDUINO_EVENT_WIFI_AP_STADISCONNECTED,
|
||||
ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED,
|
||||
ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED,
|
||||
ARDUINO_EVENT_WIFI_AP_GOT_IP6,
|
||||
ARDUINO_EVENT_WIFI_FTM_REPORT,
|
||||
ARDUINO_EVENT_ETH_START,
|
||||
ARDUINO_EVENT_ETH_STOP,
|
||||
ARDUINO_EVENT_ETH_CONNECTED,
|
||||
ARDUINO_EVENT_ETH_DISCONNECTED,
|
||||
ARDUINO_EVENT_ETH_GOT_IP,
|
||||
ARDUINO_EVENT_ETH_LOST_IP,
|
||||
ARDUINO_EVENT_ETH_GOT_IP6,
|
||||
ARDUINO_EVENT_WPS_ER_SUCCESS,
|
||||
ARDUINO_EVENT_WPS_ER_FAILED,
|
||||
ARDUINO_EVENT_WPS_ER_TIMEOUT,
|
||||
ARDUINO_EVENT_WPS_ER_PIN,
|
||||
ARDUINO_EVENT_WPS_ER_PBC_OVERLAP,
|
||||
ARDUINO_EVENT_SC_SCAN_DONE,
|
||||
ARDUINO_EVENT_SC_FOUND_CHANNEL,
|
||||
ARDUINO_EVENT_SC_GOT_SSID_PSWD,
|
||||
ARDUINO_EVENT_SC_SEND_ACK_DONE,
|
||||
ARDUINO_EVENT_PROV_INIT,
|
||||
ARDUINO_EVENT_PROV_DEINIT,
|
||||
ARDUINO_EVENT_PROV_START,
|
||||
ARDUINO_EVENT_PROV_END,
|
||||
ARDUINO_EVENT_PROV_CRED_RECV,
|
||||
ARDUINO_EVENT_PROV_CRED_FAIL,
|
||||
ARDUINO_EVENT_PROV_CRED_SUCCESS,
|
||||
ARDUINO_EVENT_MAX
|
||||
} arduino_event_id_t;
|
||||
|
||||
typedef union {
|
||||
wifi_event_sta_scan_done_t wifi_scan_done;
|
||||
wifi_event_sta_authmode_change_t wifi_sta_authmode_change;
|
||||
wifi_event_sta_connected_t wifi_sta_connected;
|
||||
wifi_event_sta_disconnected_t wifi_sta_disconnected;
|
||||
wifi_event_sta_wps_er_pin_t wps_er_pin;
|
||||
wifi_event_sta_wps_fail_reason_t wps_fail_reason;
|
||||
wifi_event_ap_probe_req_rx_t wifi_ap_probereqrecved;
|
||||
wifi_event_ap_staconnected_t wifi_ap_staconnected;
|
||||
wifi_event_ap_stadisconnected_t wifi_ap_stadisconnected;
|
||||
wifi_event_ftm_report_t wifi_ftm_report;
|
||||
ip_event_ap_staipassigned_t wifi_ap_staipassigned;
|
||||
ip_event_got_ip_t got_ip;
|
||||
ip_event_got_ip6_t got_ip6;
|
||||
smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd;
|
||||
esp_eth_handle_t eth_connected;
|
||||
wifi_sta_config_t prov_cred_recv;
|
||||
wifi_prov_sta_fail_reason_t prov_fail_reason;
|
||||
} arduino_event_info_t;
|
||||
|
||||
typedef struct{
|
||||
arduino_event_id_t event_id;
|
||||
arduino_event_info_t event_info;
|
||||
} arduino_event_t;
|
||||
|
||||
typedef void (*WiFiEventCb)(arduino_event_id_t event);
|
||||
typedef std::function<void(arduino_event_id_t event, arduino_event_info_t info)> WiFiEventFuncCb;
|
||||
typedef void (*WiFiEventSysCb)(arduino_event_t *event);
|
||||
|
||||
typedef size_t wifi_event_id_t;
|
||||
|
||||
// General Flags
|
||||
static const int NET_DNS_IDLE_BIT = BIT0;
|
||||
static const int NET_DNS_DONE_BIT = BIT1;
|
||||
// WiFi Scan Flags
|
||||
static const int WIFI_SCANNING_BIT = BIT2;
|
||||
static const int WIFI_SCAN_DONE_BIT = BIT3;
|
||||
// AP Flags
|
||||
static const int AP_STARTED_BIT = BIT4;
|
||||
static const int AP_HAS_IP6_BIT = BIT5;
|
||||
static const int AP_HAS_CLIENT_BIT = BIT6;
|
||||
static const int AP_WANT_IP6_BIT = BIT7;
|
||||
// STA Flags
|
||||
static const int STA_STARTED_BIT = BIT8;
|
||||
static const int STA_CONNECTED_BIT = BIT9;
|
||||
static const int STA_HAS_IP_BIT = BIT10;
|
||||
static const int STA_HAS_IP6_BIT = BIT11;
|
||||
static const int STA_HAS_IP6_GLOBAL_BIT = BIT12;
|
||||
static const int STA_WANT_IP6_BIT = BIT13;
|
||||
// ETH Flags
|
||||
static const int ETH_STARTED_BIT = BIT14;
|
||||
static const int ETH_CONNECTED_BIT = BIT15;
|
||||
static const int ETH_HAS_IP_BIT = BIT16;
|
||||
static const int ETH_HAS_IP6_BIT = BIT17;
|
||||
static const int ETH_HAS_IP6_GLOBAL_BIT = BIT18;
|
||||
static const int ETH_WANT_IP6_BIT = BIT19;
|
||||
// Masks
|
||||
static const int NET_HAS_IP6_GLOBAL_BIT = STA_HAS_IP6_GLOBAL_BIT | ETH_HAS_IP6_GLOBAL_BIT;
|
||||
|
||||
typedef enum {
|
||||
WIFI_POWER_19_5dBm = 78,// 19.5dBm
|
||||
WIFI_POWER_19dBm = 76,// 19dBm
|
||||
WIFI_POWER_18_5dBm = 74,// 18.5dBm
|
||||
WIFI_POWER_17dBm = 68,// 17dBm
|
||||
WIFI_POWER_15dBm = 60,// 15dBm
|
||||
WIFI_POWER_13dBm = 52,// 13dBm
|
||||
WIFI_POWER_11dBm = 44,// 11dBm
|
||||
WIFI_POWER_8_5dBm = 34,// 8.5dBm
|
||||
WIFI_POWER_7dBm = 28,// 7dBm
|
||||
WIFI_POWER_5dBm = 20,// 5dBm
|
||||
WIFI_POWER_2dBm = 8,// 2dBm
|
||||
WIFI_POWER_MINUS_1dBm = -4// -1dBm
|
||||
} wifi_power_t;
|
||||
|
||||
typedef enum {
|
||||
WIFI_RX_ANT0 = 0,
|
||||
WIFI_RX_ANT1,
|
||||
WIFI_RX_ANT_AUTO
|
||||
} wifi_rx_ant_t;
|
||||
|
||||
typedef enum {
|
||||
WIFI_TX_ANT0 = 0,
|
||||
WIFI_TX_ANT1,
|
||||
WIFI_TX_ANT_AUTO
|
||||
} wifi_tx_ant_t;
|
||||
|
||||
class WiFiGenericClass
|
||||
{
|
||||
public:
|
||||
WiFiGenericClass();
|
||||
|
||||
wifi_event_id_t onEvent(WiFiEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||
wifi_event_id_t onEvent(WiFiEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||
wifi_event_id_t onEvent(WiFiEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||
void removeEvent(WiFiEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||
void removeEvent(WiFiEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX);
|
||||
void removeEvent(wifi_event_id_t id);
|
||||
|
||||
static int getStatusBits();
|
||||
static int waitStatusBits(int bits, uint32_t timeout_ms);
|
||||
|
||||
int32_t channel(void);
|
||||
|
||||
void persistent(bool persistent);
|
||||
void enableLongRange(bool enable);
|
||||
|
||||
static bool mode(wifi_mode_t);
|
||||
static wifi_mode_t getMode();
|
||||
|
||||
bool enableSTA(bool enable);
|
||||
bool enableAP(bool enable);
|
||||
|
||||
bool setSleep(bool enabled);
|
||||
bool setSleep(wifi_ps_type_t sleepType);
|
||||
wifi_ps_type_t getSleep();
|
||||
|
||||
bool setTxPower(wifi_power_t power);
|
||||
wifi_power_t getTxPower();
|
||||
|
||||
bool initiateFTM(uint8_t frm_count=16, uint16_t burst_period=2, uint8_t channel=1, const uint8_t * mac=NULL);
|
||||
|
||||
static bool setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode);
|
||||
|
||||
const char * disconnectReasonName(wifi_err_reason_t reason);
|
||||
const char * eventName(arduino_event_id_t id);
|
||||
static const char * getHostname();
|
||||
static bool setHostname(const char * hostname);
|
||||
static bool hostname(const String& aHostname) { return setHostname(aHostname.c_str()); }
|
||||
|
||||
static esp_err_t _eventCallback(arduino_event_t *event);
|
||||
|
||||
static void useStaticBuffers(bool bufferMode);
|
||||
static bool useStaticBuffers();
|
||||
|
||||
protected:
|
||||
static bool _persistent;
|
||||
static bool _long_range;
|
||||
static wifi_mode_t _forceSleepLastMode;
|
||||
static wifi_ps_type_t _sleepEnabled;
|
||||
static bool _wifiUseStaticBuffers;
|
||||
|
||||
static int setStatusBits(int bits);
|
||||
static int clearStatusBits(int bits);
|
||||
|
||||
private:
|
||||
static bool _isReconnectableReason(uint8_t reason);
|
||||
|
||||
public:
|
||||
static int hostByName(const char *aHostname, IPAddress &aResult, bool preferV6=false);
|
||||
|
||||
static IPAddress calculateNetworkID(IPAddress ip, IPAddress subnet);
|
||||
static IPAddress calculateBroadcast(IPAddress ip, IPAddress subnet);
|
||||
static uint8_t calculateSubnetCIDR(IPAddress subnetMask);
|
||||
|
||||
protected:
|
||||
friend class WiFiSTAClass;
|
||||
friend class WiFiScanClass;
|
||||
friend class WiFiAPClass;
|
||||
friend class ETHClass;
|
||||
};
|
||||
|
||||
#endif /* ESP32WIFIGENERIC_H_ */
|
305
libs/WiFi/src/WiFiMulti.cpp
Normal file
305
libs/WiFi/src/WiFiMulti.cpp
Normal file
|
@ -0,0 +1,305 @@
|
|||
/**
|
||||
*
|
||||
* @file WiFiMulti.cpp
|
||||
* @date 16.05.2015
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
* This file is part of the esp8266 core for Arduino environment.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "WiFiMulti.h"
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <esp32-hal.h>
|
||||
|
||||
WiFiMulti::WiFiMulti()
|
||||
{
|
||||
ipv6_support = false;
|
||||
}
|
||||
|
||||
void WiFiMulti::APlistClean(void)
|
||||
{
|
||||
for(auto entry : APlist) {
|
||||
if(entry.ssid) {
|
||||
free(entry.ssid);
|
||||
}
|
||||
if(entry.passphrase) {
|
||||
free(entry.passphrase);
|
||||
}
|
||||
}
|
||||
APlist.clear();
|
||||
}
|
||||
|
||||
WiFiMulti::~WiFiMulti()
|
||||
{
|
||||
APlistClean();
|
||||
}
|
||||
|
||||
bool WiFiMulti::addAP(const char* ssid, const char *passphrase)
|
||||
{
|
||||
WifiAPlist_t newAP;
|
||||
|
||||
if(!ssid || *ssid == '\0' || strlen(ssid) > 31) {
|
||||
// fail SSID too long or missing!
|
||||
log_e("[WIFI][APlistAdd] no ssid or ssid too long");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(passphrase && strlen(passphrase) > 63) {
|
||||
// fail passphrase too long!
|
||||
log_e("[WIFI][APlistAdd] passphrase too long");
|
||||
return false;
|
||||
}
|
||||
|
||||
newAP.ssid = strdup(ssid);
|
||||
|
||||
if(!newAP.ssid) {
|
||||
log_e("[WIFI][APlistAdd] fail newAP.ssid == 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(passphrase && *passphrase != '\0') {
|
||||
newAP.passphrase = strdup(passphrase);
|
||||
if(!newAP.passphrase) {
|
||||
log_e("[WIFI][APlistAdd] fail newAP.passphrase == 0");
|
||||
free(newAP.ssid);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
newAP.passphrase = NULL;
|
||||
}
|
||||
newAP.hasFailed = false;
|
||||
APlist.push_back(newAP);
|
||||
log_i("[WIFI][APlistAdd] add SSID: %s", newAP.ssid);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t WiFiMulti::run(uint32_t connectTimeout)
|
||||
{
|
||||
int8_t scanResult;
|
||||
uint8_t status = WiFi.status();
|
||||
if(status == WL_CONNECTED) {
|
||||
if (!_bWFMInit && _connectionTestCBFunc != NULL){
|
||||
if (_connectionTestCBFunc() == true) {
|
||||
_bWFMInit = true;
|
||||
return status;
|
||||
}
|
||||
} else {
|
||||
if (!_bStrict) {
|
||||
return status;
|
||||
} else {
|
||||
for(auto ap : APlist) {
|
||||
if(WiFi.SSID() == ap.ssid) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
WiFi.disconnect(false,false);
|
||||
delay(10);
|
||||
status = WiFi.status();
|
||||
}
|
||||
|
||||
scanResult = WiFi.scanNetworks();
|
||||
if (scanResult == WIFI_SCAN_RUNNING) {
|
||||
// scan is running
|
||||
return WL_NO_SSID_AVAIL;
|
||||
} else if (scanResult >= 0) {
|
||||
// scan done analyze
|
||||
int32_t bestIndex = 0;
|
||||
WifiAPlist_t bestNetwork { NULL, NULL, false };
|
||||
int bestNetworkDb = INT_MIN;
|
||||
int bestNetworkSec = WIFI_AUTH_MAX;
|
||||
uint8_t bestBSSID[6];
|
||||
int32_t bestChannel = 0;
|
||||
|
||||
log_i("[WIFI] scan done");
|
||||
|
||||
if (scanResult == 0) {
|
||||
log_e("[WIFI] no networks found");
|
||||
} else {
|
||||
log_i("[WIFI] %d networks found", scanResult);
|
||||
|
||||
int8_t failCount = 0;
|
||||
int8_t foundCount = 0;
|
||||
for(int8_t i = 0; i < scanResult; ++i) {
|
||||
|
||||
String ssid_scan;
|
||||
int32_t rssi_scan;
|
||||
uint8_t sec_scan;
|
||||
uint8_t* BSSID_scan;
|
||||
int32_t chan_scan;
|
||||
|
||||
WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan);
|
||||
// add any Open WiFi AP to the list, if allowed with setAllowOpenAP(true)
|
||||
if (_bAllowOpenAP && sec_scan == WIFI_AUTH_OPEN){
|
||||
bool found = false;
|
||||
for(auto check : APlist) {
|
||||
if (ssid_scan == check.ssid){
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If we didn't find it, add this Open WiFi AP to the list
|
||||
if (!found){
|
||||
log_i("[WIFI][APlistAdd] adding Open WiFi SSID: %s", ssid_scan.c_str());
|
||||
addAP(ssid_scan.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool known = false;
|
||||
for(uint32_t x = 0; x < APlist.size(); x++) {
|
||||
WifiAPlist_t entry = APlist[x];
|
||||
|
||||
if(ssid_scan == entry.ssid) { // SSID match
|
||||
log_v("known ssid: %s, has failed: %s", entry.ssid, entry.hasFailed ? "yes" : "no");
|
||||
foundCount++;
|
||||
if (!entry.hasFailed){
|
||||
known = true;
|
||||
log_v("rssi_scan: %d, bestNetworkDb: %d", rssi_scan, bestNetworkDb);
|
||||
if(rssi_scan > bestNetworkDb) { // best network
|
||||
if(_bAllowOpenAP || (sec_scan == WIFI_AUTH_OPEN || entry.passphrase)) { // check for passphrase if not open wlan
|
||||
log_v("best network is now: %s", ssid_scan);
|
||||
bestIndex = x;
|
||||
bestNetworkSec = sec_scan;
|
||||
bestNetworkDb = rssi_scan;
|
||||
bestChannel = chan_scan;
|
||||
memcpy((void*) &bestNetwork, (void*) &entry, sizeof(bestNetwork));
|
||||
memcpy((void*) &bestBSSID, (void*) BSSID_scan, sizeof(bestBSSID));
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(known) {
|
||||
log_d(" ---> %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c", i, chan_scan, BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], ssid_scan.c_str(), rssi_scan, (sec_scan == WIFI_AUTH_OPEN) ? ' ' : '*');
|
||||
} else {
|
||||
log_d(" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c", i, chan_scan, BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], ssid_scan.c_str(), rssi_scan, (sec_scan == WIFI_AUTH_OPEN) ? ' ' : '*');
|
||||
}
|
||||
}
|
||||
log_v("foundCount = %d, failCount = %d", foundCount, failCount);
|
||||
// if all the APs in the list have failed, reset the failure flags
|
||||
if (foundCount == failCount) {
|
||||
resetFails(); // keeps trying the APs in the list
|
||||
}
|
||||
}
|
||||
// clean up ram
|
||||
WiFi.scanDelete();
|
||||
|
||||
if(bestNetwork.ssid) {
|
||||
log_i("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channel: %d (%d)", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb);
|
||||
|
||||
if (ipv6_support == true) {
|
||||
WiFi.enableIPv6();
|
||||
}
|
||||
WiFi.disconnect();
|
||||
delay(10);
|
||||
WiFi.begin(bestNetwork.ssid, (_bAllowOpenAP && bestNetworkSec == WIFI_AUTH_OPEN) ? NULL : bestNetwork.passphrase, bestChannel, bestBSSID);
|
||||
status = WiFi.status();
|
||||
_bWFMInit = true;
|
||||
|
||||
auto startTime = millis();
|
||||
// wait for connection, fail, or timeout
|
||||
while(status != WL_CONNECTED && (millis() - startTime) <= connectTimeout) { // && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED
|
||||
delay(10);
|
||||
status = WiFi.status();
|
||||
}
|
||||
|
||||
switch(status) {
|
||||
case WL_CONNECTED:
|
||||
log_i("[WIFI] Connecting done.");
|
||||
log_d("[WIFI] SSID: %s", WiFi.SSID().c_str());
|
||||
log_d("[WIFI] IP: %s", WiFi.localIP().toString().c_str());
|
||||
log_d("[WIFI] MAC: %s", WiFi.BSSIDstr().c_str());
|
||||
log_d("[WIFI] Channel: %d", WiFi.channel());
|
||||
|
||||
if (_connectionTestCBFunc != NULL) {
|
||||
// We connected to an AP but if it's a captive portal we're not going anywhere. Test it.
|
||||
if (_connectionTestCBFunc()) {
|
||||
resetFails();
|
||||
} else {
|
||||
markAsFailed(bestIndex);
|
||||
WiFi.disconnect();
|
||||
delay(10);
|
||||
status = WiFi.status();
|
||||
}
|
||||
} else {
|
||||
resetFails();
|
||||
}
|
||||
break;
|
||||
case WL_NO_SSID_AVAIL:
|
||||
log_e("[WIFI] Connecting Failed AP not found.");
|
||||
markAsFailed(bestIndex);
|
||||
break;
|
||||
case WL_CONNECT_FAILED:
|
||||
log_e("[WIFI] Connecting Failed.");
|
||||
markAsFailed(bestIndex);
|
||||
break;
|
||||
default:
|
||||
log_e("[WIFI] Connecting Failed (%d).", status);
|
||||
markAsFailed(bestIndex);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log_e("[WIFI] no matching wifi found!");
|
||||
}
|
||||
} else {
|
||||
// start scan
|
||||
log_d("[WIFI] delete old wifi config...");
|
||||
WiFi.disconnect();
|
||||
|
||||
log_d("[WIFI] start scan");
|
||||
// scan wifi async mode
|
||||
WiFi.scanNetworks(true);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void WiFiMulti::enableIPv6(bool state) {
|
||||
ipv6_support = state;
|
||||
}
|
||||
|
||||
void WiFiMulti::markAsFailed(int32_t i) {
|
||||
APlist[i].hasFailed = true;
|
||||
log_d("[WIFI] Marked SSID %s as failed", APlist[i].ssid);
|
||||
}
|
||||
|
||||
void WiFiMulti::resetFails(){
|
||||
for(uint32_t i = 0; i < APlist.size(); i++) {
|
||||
APlist[i].hasFailed = false;
|
||||
}
|
||||
log_d("[WIFI] Resetting failure flags");
|
||||
}
|
||||
|
||||
void WiFiMulti::setStrictMode(bool bStrict) {
|
||||
_bStrict = bStrict;
|
||||
}
|
||||
|
||||
void WiFiMulti::setAllowOpenAP(bool bAllowOpenAP) {
|
||||
_bAllowOpenAP = bAllowOpenAP;
|
||||
}
|
||||
|
||||
void WiFiMulti::setConnectionTestCallbackFunc(ConnectionTestCB_t cbFunc) {
|
||||
_connectionTestCBFunc = cbFunc;
|
||||
}
|
79
libs/WiFi/src/WiFiMulti.h
Normal file
79
libs/WiFi/src/WiFiMulti.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* @file ESP8266WiFiMulti.h
|
||||
* @date 16.05.2015
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
* This file is part of the esp8266 core for Arduino environment.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WIFICLIENTMULTI_H_
|
||||
#define WIFICLIENTMULTI_H_
|
||||
|
||||
#include "WiFi.h"
|
||||
#include <vector>
|
||||
|
||||
typedef struct {
|
||||
char * ssid;
|
||||
char * passphrase;
|
||||
bool hasFailed;
|
||||
} WifiAPlist_t;
|
||||
|
||||
typedef std::function<bool(void)> ConnectionTestCB_t;
|
||||
|
||||
class WiFiMulti
|
||||
{
|
||||
public:
|
||||
WiFiMulti();
|
||||
~WiFiMulti();
|
||||
|
||||
bool addAP(const char* ssid, const char *passphrase = NULL);
|
||||
uint8_t run(uint32_t connectTimeout=5000);
|
||||
void enableIPv6(bool state);
|
||||
|
||||
// Force (default: true) to only keep connected or to connect to an AP from the provided WiFiMulti list.
|
||||
// When bStrict is false, it will keep the last/current connected AP even if not in the WiFiMulti List.
|
||||
void setStrictMode(bool bStrict = true);
|
||||
|
||||
// allows (true) to connect to ANY open AP, even if not in the user list
|
||||
// default false (do not connect to an open AP that has not been explicitaly added by the user to list)
|
||||
void setAllowOpenAP(bool bAllowOpenAP = false);
|
||||
|
||||
// clears the current list of Multi APs and frees the memory
|
||||
void APlistClean(void);
|
||||
|
||||
// allow the user to define a callback function that will validate the connection to the Internet.
|
||||
// if the callback returns true, the connection is considered valid and the AP will added to the validated AP list.
|
||||
// set the callback to NULL to disable the feature and validate any SSID that is in the list.
|
||||
void setConnectionTestCallbackFunc(ConnectionTestCB_t cbFunc);
|
||||
|
||||
private:
|
||||
std::vector<WifiAPlist_t> APlist;
|
||||
bool ipv6_support;
|
||||
|
||||
bool _bStrict = true;
|
||||
bool _bAllowOpenAP = false;
|
||||
ConnectionTestCB_t _connectionTestCBFunc = NULL;
|
||||
bool _bWFMInit = false;
|
||||
|
||||
void markAsFailed(int32_t i);
|
||||
void resetFails();
|
||||
};
|
||||
|
||||
#endif /* WIFICLIENTMULTI_H_ */
|
943
libs/WiFi/src/WiFiSTA.cpp
Normal file
943
libs/WiFi/src/WiFiSTA.cpp
Normal file
|
@ -0,0 +1,943 @@
|
|||
/*
|
||||
WiFiSTA.cpp - WiFi library for esp32
|
||||
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Reworked on 28 Dec 2015 by Markus Sattler
|
||||
|
||||
*/
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "WiFiGeneric.h"
|
||||
#include "WiFiSTA.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_event.h>
|
||||
#include <esp32-hal.h>
|
||||
#include <lwip/ip_addr.h>
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/dns.h"
|
||||
#include <esp_smartconfig.h>
|
||||
#include <esp_netif.h>
|
||||
#include "esp_mac.h"
|
||||
|
||||
#if __has_include ("esp_eap_client.h")
|
||||
#include "esp_eap_client.h"
|
||||
#else
|
||||
#include "esp_wpa2.h"
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
// ---------------------------------------------------- Private functions ------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
esp_netif_t* get_esp_interface_netif(esp_interface_t interface);
|
||||
esp_err_t set_esp_interface_dns(esp_interface_t interface, IPAddress main_dns=IPAddress(), IPAddress backup_dns=IPAddress(), IPAddress fallback_dns=IPAddress());
|
||||
esp_err_t set_esp_interface_ip(esp_interface_t interface, IPAddress local_ip=INADDR_NONE, IPAddress gateway=INADDR_NONE, IPAddress subnet=INADDR_NONE, IPAddress dhcp_lease_start=INADDR_NONE);
|
||||
static bool sta_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs);
|
||||
|
||||
static size_t _wifi_strncpy(char * dst, const char * src, size_t dst_len){
|
||||
if(!dst || !src || !dst_len){
|
||||
return 0;
|
||||
}
|
||||
size_t src_len = strlen(src);
|
||||
if(src_len >= dst_len){
|
||||
src_len = dst_len;
|
||||
} else {
|
||||
src_len += 1;
|
||||
}
|
||||
memcpy(dst, src, src_len);
|
||||
return src_len;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* compare two STA configurations
|
||||
* @param lhs station_config
|
||||
* @param rhs station_config
|
||||
* @return equal
|
||||
*/
|
||||
static bool sta_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs)
|
||||
{
|
||||
if(memcmp(&lhs, &rhs, sizeof(wifi_config_t)) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL, const char * password=NULL, const uint8_t * bssid=NULL, uint8_t channel=0, wifi_auth_mode_t min_security=WIFI_AUTH_WPA2_PSK, wifi_scan_method_t scan_method=WIFI_ALL_CHANNEL_SCAN, wifi_sort_method_t sort_method=WIFI_CONNECT_AP_BY_SIGNAL, uint16_t listen_interval=0, bool pmf_required=false){
|
||||
wifi_config->sta.channel = channel;
|
||||
wifi_config->sta.listen_interval = listen_interval;
|
||||
wifi_config->sta.scan_method = scan_method;//WIFI_ALL_CHANNEL_SCAN or WIFI_FAST_SCAN
|
||||
wifi_config->sta.sort_method = sort_method;//WIFI_CONNECT_AP_BY_SIGNAL or WIFI_CONNECT_AP_BY_SECURITY
|
||||
wifi_config->sta.threshold.rssi = -127;
|
||||
wifi_config->sta.pmf_cfg.capable = true;
|
||||
wifi_config->sta.pmf_cfg.required = pmf_required;
|
||||
wifi_config->sta.bssid_set = 0;
|
||||
memset(wifi_config->sta.bssid, 0, 6);
|
||||
wifi_config->sta.threshold.authmode = WIFI_AUTH_OPEN;
|
||||
wifi_config->sta.ssid[0] = 0;
|
||||
wifi_config->sta.password[0] = 0;
|
||||
if(ssid != NULL && ssid[0] != 0){
|
||||
_wifi_strncpy((char*)wifi_config->sta.ssid, ssid, 32);
|
||||
if(password != NULL && password[0] != 0){
|
||||
wifi_config->sta.threshold.authmode = min_security;
|
||||
_wifi_strncpy((char*)wifi_config->sta.password, password, 64);
|
||||
}
|
||||
if(bssid != NULL){
|
||||
wifi_config->sta.bssid_set = 1;
|
||||
memcpy(wifi_config->sta.bssid, bssid, 6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
// ---------------------------------------------------- STA function -----------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
bool WiFiSTAClass::_autoReconnect = true;
|
||||
bool WiFiSTAClass::_useStaticIp = false;
|
||||
wifi_auth_mode_t WiFiSTAClass::_minSecurity = WIFI_AUTH_WPA2_PSK;
|
||||
wifi_scan_method_t WiFiSTAClass::_scanMethod = WIFI_FAST_SCAN;
|
||||
wifi_sort_method_t WiFiSTAClass::_sortMethod = WIFI_CONNECT_AP_BY_SIGNAL;
|
||||
|
||||
static wl_status_t _sta_status = WL_STOPPED;
|
||||
static EventGroupHandle_t _sta_status_group = NULL;
|
||||
|
||||
void WiFiSTAClass::_setStatus(wl_status_t status)
|
||||
{
|
||||
if(!_sta_status_group){
|
||||
_sta_status_group = xEventGroupCreate();
|
||||
if(!_sta_status_group){
|
||||
log_e("STA Status Group Create Failed!");
|
||||
_sta_status = status;
|
||||
return;
|
||||
}
|
||||
}
|
||||
xEventGroupClearBits(_sta_status_group, 0x00FFFFFF);
|
||||
xEventGroupSetBits(_sta_status_group, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Connection status.
|
||||
* @return one of the value defined in wl_status_t
|
||||
*
|
||||
*/
|
||||
wl_status_t WiFiSTAClass::status()
|
||||
{
|
||||
if(!_sta_status_group){
|
||||
return _sta_status;
|
||||
}
|
||||
return (wl_status_t)xEventGroupClearBits(_sta_status_group, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Wifi connection with a WPA2 Enterprise AP
|
||||
* if passphrase is set the most secure supported mode will be automatically selected
|
||||
* @param ssid const char* Pointer to the SSID string.
|
||||
* @param method wpa2_method_t The authentication method of WPA2 (WPA2_AUTH_TLS, WPA2_AUTH_PEAP, WPA2_AUTH_TTLS)
|
||||
* @param wpa2_identity const char* Pointer to the entity
|
||||
* @param wpa2_username const char* Pointer to the username
|
||||
* @param password const char * Pointer to the password.
|
||||
* @param ca_pem const char* Pointer to a string with the contents of a .pem file with CA cert
|
||||
* @param client_crt const char* Pointer to a string with the contents of a .crt file with client cert
|
||||
* @param client_key const char* Pointer to a string with the contants of a .key file with client key
|
||||
* @param bssid uint8_t[6] Optional. BSSID / MAC of AP
|
||||
* @param channel Optional. Channel of AP
|
||||
* @param connect Optional. call connect
|
||||
* @return
|
||||
*/
|
||||
wl_status_t WiFiSTAClass::begin(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity, const char* wpa2_username, const char *wpa2_password, const char* ca_pem, const char* client_crt, const char* client_key, int32_t channel, const uint8_t* bssid, bool connect)
|
||||
{
|
||||
if(!WiFi.enableSTA(true)) {
|
||||
log_e("STA enable failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(!wpa2_ssid || *wpa2_ssid == 0x00 || strlen(wpa2_ssid) > 32) {
|
||||
log_e("SSID too long or missing!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(wpa2_identity && strlen(wpa2_identity) > 64) {
|
||||
log_e("identity too long!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(wpa2_username && strlen(wpa2_username) > 64) {
|
||||
log_e("username too long!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(wpa2_password && strlen(wpa2_password) > 64) {
|
||||
log_e("password too long!");
|
||||
}
|
||||
|
||||
if(ca_pem) {
|
||||
#if __has_include ("esp_eap_client.h")
|
||||
esp_eap_client_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem));
|
||||
#else
|
||||
esp_wifi_sta_wpa2_ent_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem));
|
||||
#endif
|
||||
}
|
||||
|
||||
if(client_crt) {
|
||||
#if __has_include ("esp_eap_client.h")
|
||||
esp_eap_client_set_certificate_and_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0);
|
||||
#else
|
||||
esp_wifi_sta_wpa2_ent_set_cert_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if __has_include ("esp_eap_client.h")
|
||||
esp_eap_client_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity));
|
||||
#else
|
||||
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity));
|
||||
#endif
|
||||
if(method == WPA2_AUTH_PEAP || method == WPA2_AUTH_TTLS) {
|
||||
#if __has_include ("esp_eap_client.h")
|
||||
esp_eap_client_set_username((uint8_t *)wpa2_username, strlen(wpa2_username));
|
||||
esp_eap_client_set_password((uint8_t *)wpa2_password, strlen(wpa2_password));
|
||||
#else
|
||||
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)wpa2_username, strlen(wpa2_username));
|
||||
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)wpa2_password, strlen(wpa2_password));
|
||||
#endif
|
||||
}
|
||||
#if __has_include ("esp_eap_client.h")
|
||||
esp_wifi_sta_enterprise_enable(); //set config settings to enable function
|
||||
#else
|
||||
esp_wifi_sta_wpa2_ent_enable(); //set config settings to enable function
|
||||
#endif
|
||||
WiFi.begin(wpa2_ssid); //connect to wifi
|
||||
|
||||
return status();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Wifi connection
|
||||
* if passphrase is set the most secure supported mode will be automatically selected
|
||||
* @param ssid const char* Pointer to the SSID string.
|
||||
* @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal).
|
||||
* @param bssid uint8_t[6] Optional. BSSID / MAC of AP
|
||||
* @param channel Optional. Channel of AP
|
||||
* @param connect Optional. call connect
|
||||
* @return
|
||||
*/
|
||||
wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_t channel, const uint8_t* bssid, bool connect)
|
||||
{
|
||||
|
||||
if(!WiFi.enableSTA(true)) {
|
||||
log_e("STA enable failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
|
||||
log_e("SSID too long or missing!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(passphrase && strlen(passphrase) > 64) {
|
||||
log_e("passphrase too long!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
wifi_config_t conf;
|
||||
memset(&conf, 0, sizeof(wifi_config_t));
|
||||
|
||||
wifi_sta_config(&conf, ssid, passphrase, bssid, channel, _minSecurity, _scanMethod, _sortMethod);
|
||||
|
||||
wifi_config_t current_conf;
|
||||
if(esp_wifi_get_config((wifi_interface_t)ESP_IF_WIFI_STA, ¤t_conf) != ESP_OK){
|
||||
log_e("get current config failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
if(!sta_config_equal(current_conf, conf)) {
|
||||
if(esp_wifi_disconnect()){
|
||||
log_e("disconnect failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(esp_wifi_set_config((wifi_interface_t)ESP_IF_WIFI_STA, &conf) != ESP_OK){
|
||||
log_e("set config failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
} else if(status() == WL_CONNECTED){
|
||||
return WL_CONNECTED;
|
||||
} else {
|
||||
if(esp_wifi_set_config((wifi_interface_t)ESP_IF_WIFI_STA, &conf) != ESP_OK){
|
||||
log_e("set config failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if(!_useStaticIp){
|
||||
if(set_esp_interface_ip(ESP_IF_WIFI_STA) != ESP_OK) {
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if(connect){
|
||||
if(esp_wifi_connect() != ESP_OK) {
|
||||
log_e("connect failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return status();
|
||||
}
|
||||
|
||||
wl_status_t WiFiSTAClass::begin(char* ssid, char *passphrase, int32_t channel, const uint8_t* bssid, bool connect)
|
||||
{
|
||||
return begin((const char*) ssid, (const char*) passphrase, channel, bssid, connect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to connect to SDK config.
|
||||
* @return wl_status_t
|
||||
*/
|
||||
wl_status_t WiFiSTAClass::begin()
|
||||
{
|
||||
|
||||
if(!WiFi.enableSTA(true)) {
|
||||
log_e("STA enable failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
wifi_config_t current_conf;
|
||||
if(esp_wifi_get_config((wifi_interface_t)ESP_IF_WIFI_STA, ¤t_conf) != ESP_OK || esp_wifi_set_config((wifi_interface_t)ESP_IF_WIFI_STA, ¤t_conf) != ESP_OK) {
|
||||
log_e("config failed");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(!_useStaticIp && set_esp_interface_ip(ESP_IF_WIFI_STA) != ESP_OK) {
|
||||
log_e("set ip failed!");
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(status() != WL_CONNECTED){
|
||||
esp_err_t err = esp_wifi_connect();
|
||||
if(err){
|
||||
log_e("connect failed! 0x%x", err);
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return status();
|
||||
}
|
||||
|
||||
/**
|
||||
* will force a disconnect and then start reconnecting to AP
|
||||
* @return true when successful
|
||||
*/
|
||||
bool WiFiSTAClass::reconnect()
|
||||
{
|
||||
if(WiFi.getMode() & WIFI_MODE_STA) {
|
||||
if(esp_wifi_disconnect() == ESP_OK) {
|
||||
return esp_wifi_connect() == ESP_OK;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the network.
|
||||
* @param wifioff `true` to turn the Wi-Fi radio off.
|
||||
* @param eraseap `true` to erase the AP configuration from the NVS memory.
|
||||
* @return `true` when successful.
|
||||
*/
|
||||
bool WiFiSTAClass::disconnectAsync(bool wifioff, bool eraseap)
|
||||
{
|
||||
wifi_config_t conf;
|
||||
wifi_sta_config(&conf);
|
||||
|
||||
if(WiFi.getMode() & WIFI_MODE_STA){
|
||||
if(eraseap){
|
||||
if(esp_wifi_set_config((wifi_interface_t)ESP_IF_WIFI_STA, &conf)){
|
||||
log_e("clear config failed!");
|
||||
}
|
||||
}
|
||||
if(esp_wifi_disconnect()){
|
||||
log_e("disconnect failed!");
|
||||
return false;
|
||||
}
|
||||
if(wifioff) {
|
||||
return WiFi.enableSTA(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the network.
|
||||
* @param wifioff `true` to turn the Wi-Fi radio off.
|
||||
* @param eraseap `true` to erase the AP configuration from the NVS memory.
|
||||
* @param timeoutLength timeout to wait for status change
|
||||
* @return `true` when successful.
|
||||
*/
|
||||
bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap, unsigned long timeoutLength)
|
||||
{
|
||||
if (!disconnectAsync(wifioff, eraseap)) {
|
||||
return false;
|
||||
}
|
||||
if (!timeoutLength) {
|
||||
return true;
|
||||
}
|
||||
const unsigned long start = millis();
|
||||
while ((WiFiGenericClass::getStatusBits() & STA_CONNECTED_BIT) != 0) {
|
||||
if((millis() - start) >= timeoutLength){
|
||||
return false;
|
||||
}
|
||||
delay(2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset WiFi settings in NVS to default values.
|
||||
* @return true if erase succeeded
|
||||
* @note: Resets SSID, password, protocol, mode, etc.
|
||||
* These settings are maintained by WiFi driver in IDF.
|
||||
* WiFi driver must be initialized.
|
||||
*/
|
||||
bool WiFiSTAClass::eraseAP(void) {
|
||||
if(WiFi.getMode()==WIFI_MODE_NULL) {
|
||||
if(!WiFi.enableSTA(true))
|
||||
return false;
|
||||
}
|
||||
|
||||
return esp_wifi_restore()==ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change IP configuration settings disabling the dhcp client
|
||||
* @param local_ip Static ip configuration
|
||||
* @param gateway Static gateway configuration
|
||||
* @param subnet Static Subnet mask
|
||||
* @param dns1 Static DNS server 1
|
||||
* @param dns2 Static DNS server 2
|
||||
*/
|
||||
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
if(!WiFi.enableSTA(true)) {
|
||||
return false;
|
||||
}
|
||||
err = set_esp_interface_ip(ESP_IF_WIFI_STA, local_ip, gateway, subnet);
|
||||
if(err == ESP_OK){
|
||||
err = set_esp_interface_dns(ESP_IF_WIFI_STA, dns1, dns2);
|
||||
}
|
||||
_useStaticIp = err == ESP_OK;
|
||||
return err == ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the working bandwidth of the STA mode
|
||||
* @param m wifi_bandwidth_t
|
||||
*/
|
||||
bool WiFiSTAClass::bandwidth(wifi_bandwidth_t bandwidth) {
|
||||
if(!WiFi.enableSTA(true)) {
|
||||
log_e("STA enable failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_err_t err;
|
||||
err = esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, bandwidth);
|
||||
if(err){
|
||||
log_e("Could not set STA bandwidth!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change DNS server for static IP configuration
|
||||
* @param dns1 Static DNS server 1
|
||||
* @param dns2 Static DNS server 2 (optional)
|
||||
*/
|
||||
bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2)
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL)
|
||||
return false;
|
||||
esp_err_t err = set_esp_interface_dns(ESP_IF_WIFI_STA, dns1, dns2);
|
||||
return err == ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* is STA interface connected?
|
||||
* @return true if STA is connected to an AP
|
||||
*/
|
||||
bool WiFiSTAClass::isConnected()
|
||||
{
|
||||
return (status() == WL_CONNECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum security for AP to be considered connectable.
|
||||
* Must be called before WiFi.begin().
|
||||
* @param minSecurity wifi_auth_mode_t
|
||||
*/
|
||||
void WiFiSTAClass::setMinSecurity(wifi_auth_mode_t minSecurity)
|
||||
{
|
||||
_minSecurity = minSecurity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the way that AP is chosen.
|
||||
* First SSID match[WIFI_FAST_SCAN] or Sorted[WIFI_ALL_CHANNEL_SCAN] (RSSI or Security)
|
||||
* Must be called before WiFi.begin()
|
||||
* @param scanMethod wifi_scan_method_t
|
||||
*/
|
||||
void WiFiSTAClass::setScanMethod(wifi_scan_method_t scanMethod)
|
||||
{
|
||||
_scanMethod = scanMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the way that AP is sorted. (requires scanMethod WIFI_ALL_CHANNEL_SCAN)
|
||||
* By SSID[WIFI_CONNECT_AP_BY_SIGNAL] or Security[WIFI_CONNECT_AP_BY_SECURITY]
|
||||
* Must be called before WiFi.begin()
|
||||
* @param sortMethod wifi_sort_method_t
|
||||
*/
|
||||
void WiFiSTAClass::setSortMethod(wifi_sort_method_t sortMethod)
|
||||
{
|
||||
_sortMethod = sortMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated. Setting the ESP32 station to connect to the AP (which is recorded)
|
||||
* automatically or not when powered on. Enable auto-connect by default.
|
||||
* @deprecated use `setAutoReconnect`
|
||||
* @param autoConnect bool
|
||||
* @return if saved
|
||||
*/
|
||||
bool WiFiSTAClass::setAutoConnect(bool autoConnect)
|
||||
{
|
||||
return false;//now deprecated
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated. Checks if ESP32 station mode will connect to AP
|
||||
* automatically or not when it is powered on.
|
||||
* @deprecated use `getAutoReconnect`
|
||||
* @return auto connect
|
||||
*/
|
||||
bool WiFiSTAClass::getAutoConnect()
|
||||
{
|
||||
return false;//now deprecated
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to set the automatic reconnection if the connection is lost.
|
||||
* @param autoReconnect `true` to enable this option.
|
||||
* @return true
|
||||
*/
|
||||
bool WiFiSTAClass::setAutoReconnect(bool autoReconnect)
|
||||
{
|
||||
_autoReconnect = autoReconnect;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Function used to get the automatic reconnection if the connection is lost.
|
||||
* @return The function will return `true` if this setting is enabled.
|
||||
*/
|
||||
bool WiFiSTAClass::getAutoReconnect()
|
||||
{
|
||||
return _autoReconnect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for WiFi connection to reach a result
|
||||
* returns the status reached or disconnect if STA is off
|
||||
* @return wl_status_t
|
||||
*/
|
||||
uint8_t WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength)
|
||||
{
|
||||
//1 and 3 have STA enabled
|
||||
if((WiFiGenericClass::getMode() & WIFI_MODE_STA) == 0) {
|
||||
return WL_DISCONNECTED;
|
||||
}
|
||||
unsigned long start = millis();
|
||||
while((!status() || status() >= WL_DISCONNECTED) && (millis() - start) < timeoutLength) {
|
||||
delay(100);
|
||||
}
|
||||
return status();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the station interface IP address.
|
||||
* @return IPAddress station IP
|
||||
*/
|
||||
IPAddress WiFiSTAClass::localIP()
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
esp_netif_ip_info_t ip;
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(ip.ip.addr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the station interface MAC address.
|
||||
* @param mac pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
* @return pointer to uint8_t *
|
||||
*/
|
||||
uint8_t* WiFiSTAClass::macAddress(uint8_t* mac)
|
||||
{
|
||||
if(WiFiGenericClass::getMode() != WIFI_MODE_NULL){
|
||||
esp_wifi_get_mac((wifi_interface_t)ESP_IF_WIFI_STA, mac);
|
||||
}
|
||||
else{
|
||||
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
||||
}
|
||||
return mac;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the station interface MAC address.
|
||||
* @return String mac
|
||||
*/
|
||||
String WiFiSTAClass::macAddress(void)
|
||||
{
|
||||
uint8_t mac[6];
|
||||
char macStr[18] = { 0 };
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
||||
}
|
||||
else{
|
||||
esp_wifi_get_mac((wifi_interface_t)ESP_IF_WIFI_STA, mac);
|
||||
}
|
||||
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
return String(macStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the interface subnet mask address.
|
||||
* @return IPAddress subnetMask
|
||||
*/
|
||||
IPAddress WiFiSTAClass::subnetMask()
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
esp_netif_ip_info_t ip;
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(ip.netmask.addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the gateway ip address.
|
||||
* @return IPAddress gatewayIP
|
||||
*/
|
||||
IPAddress WiFiSTAClass::gatewayIP()
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
esp_netif_ip_info_t ip;
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(ip.gw.addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DNS ip address.
|
||||
* @param dns_no
|
||||
* @return IPAddress DNS Server IP
|
||||
*/
|
||||
IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no)
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
const ip_addr_t * dns_ip = dns_getserver(dns_no);
|
||||
return IPAddress(dns_ip->u_addr.ip4.addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the broadcast ip address.
|
||||
* @return IPAddress broadcastIP
|
||||
*/
|
||||
IPAddress WiFiSTAClass::broadcastIP()
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
esp_netif_ip_info_t ip;
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return WiFiGenericClass::calculateBroadcast(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the network id.
|
||||
* @return IPAddress networkID
|
||||
*/
|
||||
IPAddress WiFiSTAClass::networkID()
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress();
|
||||
}
|
||||
esp_netif_ip_info_t ip;
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return WiFiGenericClass::calculateNetworkID(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subnet CIDR.
|
||||
* @return uint8_t subnetCIDR
|
||||
*/
|
||||
uint8_t WiFiSTAClass::subnetCIDR()
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return (uint8_t)0;
|
||||
}
|
||||
esp_netif_ip_info_t ip;
|
||||
if(esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip) != ESP_OK){
|
||||
log_e("Netif Get IP Failed!");
|
||||
return IPAddress();
|
||||
}
|
||||
return WiFiGenericClass::calculateSubnetCIDR(IPAddress(ip.netmask.addr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current SSID associated with the network
|
||||
* @return SSID
|
||||
*/
|
||||
String WiFiSTAClass::SSID() const
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return String();
|
||||
}
|
||||
wifi_ap_record_t info;
|
||||
if(!esp_wifi_sta_get_ap_info(&info)) {
|
||||
return String(reinterpret_cast<char*>(info.ssid));
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current pre shared key associated with the network
|
||||
* @return psk string
|
||||
*/
|
||||
String WiFiSTAClass::psk() const
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return String();
|
||||
}
|
||||
wifi_config_t conf;
|
||||
esp_wifi_get_config((wifi_interface_t)ESP_IF_WIFI_STA, &conf);
|
||||
return String(reinterpret_cast<char*>(conf.sta.password));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current bssid / mac associated with the network if configured
|
||||
* @return bssid uint8_t *
|
||||
*/
|
||||
uint8_t* WiFiSTAClass::BSSID(uint8_t* buff)
|
||||
{
|
||||
static uint8_t bssid[6];
|
||||
wifi_ap_record_t info;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return NULL;
|
||||
}
|
||||
esp_err_t err = esp_wifi_sta_get_ap_info(&info);
|
||||
if (buff != NULL) {
|
||||
if(err) {
|
||||
memset(buff, 0, 6);
|
||||
} else {
|
||||
memcpy(buff, info.bssid, 6);
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
if(!err) {
|
||||
memcpy(bssid, info.bssid, 6);
|
||||
return reinterpret_cast<uint8_t*>(bssid);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current bssid / mac associated with the network if configured
|
||||
* @return String bssid mac
|
||||
*/
|
||||
String WiFiSTAClass::BSSIDstr(void)
|
||||
{
|
||||
uint8_t* bssid = BSSID();
|
||||
if(!bssid){
|
||||
return String();
|
||||
}
|
||||
char mac[18] = { 0 };
|
||||
sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
|
||||
return String(mac);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current network RSSI.
|
||||
* @return RSSI value
|
||||
*/
|
||||
int8_t WiFiSTAClass::RSSI(void)
|
||||
{
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return 0;
|
||||
}
|
||||
wifi_ap_record_t info;
|
||||
if(!esp_wifi_sta_get_ap_info(&info)) {
|
||||
return info.rssi;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable IPv6 on the station interface.
|
||||
* Should be called before WiFi.begin()
|
||||
*
|
||||
* @return true on success
|
||||
*/
|
||||
bool WiFiSTAClass::enableIPv6(bool en)
|
||||
{
|
||||
if (en) {
|
||||
WiFiGenericClass::setStatusBits(STA_WANT_IP6_BIT);
|
||||
} else {
|
||||
WiFiGenericClass::clearStatusBits(STA_WANT_IP6_BIT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the station interface link-local IPv6 address.
|
||||
* @return IPAddress
|
||||
*/
|
||||
IPAddress WiFiSTAClass::localIPv6()
|
||||
{
|
||||
static esp_ip6_addr_t addr;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
if(esp_netif_get_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_STA), &addr)){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
return IPAddress(IPv6, (const uint8_t *)addr.addr, addr.zone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the station interface global IPv6 address.
|
||||
* @return IPAddress
|
||||
*/
|
||||
IPAddress WiFiSTAClass::globalIPv6()
|
||||
{
|
||||
static esp_ip6_addr_t addr;
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
if(esp_netif_get_ip6_global(get_esp_interface_netif(ESP_IF_WIFI_STA), &addr)){
|
||||
return IPAddress(IPv6);
|
||||
}
|
||||
return IPAddress(IPv6, (const uint8_t *)addr.addr, addr.zone);
|
||||
}
|
||||
|
||||
|
||||
bool WiFiSTAClass::_smartConfigStarted = false;
|
||||
bool WiFiSTAClass::_smartConfigDone = false;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param type Select type of SmartConfig. Default type is SC_TYPE_ESPTOUCH
|
||||
* @param crypt_key When using type SC_TYPE_ESPTOUTCH_V2 crypt key needed, else ignored. Lenght should be 16 chars.
|
||||
* @return true if configuration is successful.
|
||||
* @return false if configuration fails.
|
||||
*/
|
||||
bool WiFiSTAClass::beginSmartConfig(smartconfig_type_t type, char* crypt_key) {
|
||||
esp_err_t err;
|
||||
if (_smartConfigStarted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WiFi.mode(WIFI_STA)) {
|
||||
return false;
|
||||
}
|
||||
esp_wifi_disconnect();
|
||||
|
||||
smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT();
|
||||
|
||||
if (type == SC_TYPE_ESPTOUCH_V2){
|
||||
conf.esp_touch_v2_enable_crypt = true;
|
||||
conf.esp_touch_v2_key = crypt_key;
|
||||
}
|
||||
|
||||
err = esp_smartconfig_set_type(type);
|
||||
if (err != ESP_OK) {
|
||||
log_e("SmartConfig Set Type Failed!");
|
||||
return false;
|
||||
}
|
||||
err = esp_smartconfig_start(&conf);
|
||||
if (err != ESP_OK) {
|
||||
log_e("SmartConfig Start Failed!");
|
||||
return false;
|
||||
}
|
||||
_smartConfigStarted = true;
|
||||
_smartConfigDone = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WiFiSTAClass::stopSmartConfig() {
|
||||
if (!_smartConfigStarted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (esp_smartconfig_stop() == ESP_OK) {
|
||||
_smartConfigStarted = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WiFiSTAClass::smartConfigDone() {
|
||||
if (!_smartConfigStarted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _smartConfigDone;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue