This section elaborates about setting up control path, Wi-Fi and Bluetooth/BLE connectivity on Linux host using ESP-Hosted solution.
Wi-Fi can be configured as either as STATION mode or SOFTAP mode or STATION+SOFTAP mode.
Python App is placed in esp_hosted_fg/host/linux/host_control/python_support/ directory. Use below command to navigate to this directory.
$ cd esp_hosted_fg/host/linux/host_control/python_support/
get_connected_ap_info command initiates Wi-Fi scan and displays list of available APs in the vicinity. The output contains SSID, channel number, RSSI, MAC address and authentication mode of AP.
$ sudo python3 test.py get_connected_ap_info
Connect to external access point
connect_ap command configures ESP peripheral in Wi-Fi station mode and connects to an external AP with user-provided credentials.The command accepts arguments such as SSID, password, optionally BSSID of an external AP, wpa3 support and listen interval (AP beacon intervals). For example:
$ sudo python3 test.py connect_ap --ssid SaveEarth PlantMoreTrees123
or
$ sudo python3 test.py connect_ap --bssid 'e5:6c:67:3c:cf:65' \
--use_wpa3 True --listen_interval 3 --set_dhcp True
As an end result of this command:
ethsta0 interface will be up and ESP's MAC address will be assigned to ituse_wpa3 option will be useful if target AP supports WPA3 security protocolset_dhcp option is only included for user convenience. If DHCP software different than dhclient, User can set this option to False and use DHCP software shipped with Linuxdisconnect_ap command disconnects ESP peripheral station from an external AP.
$ sudo python3 test.py disconnect_ap
As an end result of this command:
ethsta0 interface will be in down stateSetup and start softAP
start_softap command configures ESP peripheral to work in softAP mode. The following parameters should be provided:
ssid : SSIDpwd : password, should be 8 ~ 64 bytes ASCIIchannel : Optional field, Wi-Fi channel ID, 1 ~ 11. Default: 1sec_prot : Optional field, security protocol is string one of 'open' or 'wpa_psk' or 'wpa2_psk' or 'wpa_wpa2_psk'. Default: 'wpa_wpa2_psk'max_conn : Optional field, maximum number of stations, in range of 1 ~ 10. Default: 4hide_ssid : Optional field, whether SSID is hidden (True if the softAP shouldn't broadcast its SSID, else False)bw : Optional field, bandwidth, 20 (represents 20MHz) or 40 (represents 40MHz)). Default: 20For example:
$ sudo python3 test.py start_softap --ssid ESP_WiFi --pwd ESP_WiFi@123 \
--channel 6 --sec_prot wpa_wpa2_psk --max_conn 9 --hide_ssid False --bw 40
As an end result of this command:
ethap0 interface will be in up stateTo start data connection, set up a static IP address for AP interface (ethap0) or set up DHCP server on the Raspberry Pi similar to example as below:
$ sudo dnsmasq --no-daemon --no-resolv --no-poll \
--dhcp-script=/system/bin/dhcp_announce \
--dhcp-range=192.168.4.1,192.168.4.20,1h
$ sudo ifconfig ethap0 192.168.4.5
stop_softap command disables Wi-Fi softAP mode on ESP peripheral.
$ sudo python3 ./test.py stop_softap
As an end result of this command:
ethap0 interface will be in down state
---List external stations connected to softAP
softap_connected_clients_info command displays list of MAC addresses of stations connected to softAP.
$ sudo python3 ./test.py softap_connected_clients_info
There are many more commands which are supported for Wi-Fi related operation like Set/Get transmit power, Set/Get power save mode etc.
Please Check All supported commands
Ensure that hci0 interface is visible. To check that, run hciconfig.
hci0: Type: Primary Bus: SDIO
BD Address: 3C:71:BF:9A:C2:46 ACL MTU: 1021:9 SCO MTU: 255:4
UP RUNNING PSCAN
RX bytes:8801 acl:1000 sco:0 events:406 errors:0
TX bytes:5097 acl:147 sco:0 commands:52 errors:0
This interface supports all standard HCI commands. Use standard hci tools to control and configure this interface.
bluez 5.50+.
Whereas BLE 5.X functionalities are tested with bluez 5.45+.bluez version to be used. Any other bluetooth stack instead of bluez also could be used.bluez for particular version, follow this link. Replace bluez older version to expected version while following mentioned link.Steps:
sudo bluetoothctl.list to get MAC address of ESP.menu advertise. Then name <enter_any_name>.back.advertise on.
Perform below steps on Mobile Phone:SCANNER tab as a result of scan.Generic Attribute option.Generic Attribute service.
To disconnet:disconnect <MAC_ADDRESS_of_gatt_client> on linux host's bluetoothctrl OR click on DISCONNECT in nRF connect application's GATT client screen.sudo bluetoothctl.power on.discoverable on.pairable on.default-agent.agent on.scan on.scan off.sudo btmon &.trust <MAC address of mobile phone>.pair <MAC address of mobile phone>.connect <MAC address of mobile phone>.discoverable off.menu gatt.list-attributes.select-attribute <characteristic_of_service>.disconnect <MAC_ADDRESS_of_gatt_server>.Run hcitool scan for BT device scanning.
Run hcitool lescan for BLE device scanning.
ESP32-C2/C3/S3 HCI controller supports BLE 5.0. ESP32-C6 supports BLE 5.3. Some of the BLE 5.x features are:
To test BLE 5.X on Raspberry Pi, minimum bluez version 5.45 and above required. If bluez version is less than 5.45 ,then upgrade bluez version.
Check current bluez version by running following command on Raspberry Pi:
$ bluetoothctl -v
:warning: hcitool lescan is deprecated. Please dont use it.
Execute following steps on linux host. Steps:
sudo bluetoothctl.power on.discoverable on.pairable on.default-agent.agent on.sudo btmon &.scan on in bluetoothctl window.scan off.trust <MAC address of your device>.pair <MAC address of your device>.connect <MAC address of your device>.discoverable off.BLE 5.X has backword compability. It can connect with BLE4.2 devices.
Below example demonstrate linux host as GATT server and mobile phone as GATT client. We are using nRF connect application for GATT client operartion.
Follow section 3.1.1 for GATT server connections.
BLE 5.X has backword compability. It can connect with BLE4.2 devices.
Below example demonstrate linux host as GATT client and mobile phone as GATT server. We are using nRF connect application for GATT server operartion.
Follow section 3.1.2 for GATT client connections.
BLE5.X supports 1M, 2M and CODED phy. To use 2M and CODED phy for gatt read/write procedure as follow:
Note:
Default selected phy is 1M. To perform gatt read/write with BLE5.X peripheral, both host and peripheral must have same phy configuration.
'PHY' feature in BLE 5.X is verified with btmgmt tool from bluez version 5.56+.
If bluez version is less than 5.56 ,then upgrade bluez version.
1M phy is default phy for BLE5.X. Follow above mentioned steps in section 3.2.1 for connection. After connection follow gatt read/write from gatt menu in bluetoothctl.
2M phy can not use for connection in BLE5.X . So configure phy as 1M and 2M both, make connection with other BLE5.X device and then set phy as 2M. On peripheral side make primary phy as 1M and secondary phy as 2M.
Steps:
sudo hcitool cmd 08 31 03 03 03.bluez-5.56 directory. Run sudo ./tools/btmgmt --index hci0 and run phy.LE Enhanced Connection Complete event in btmon log. Note down handle value.exit in bluetoothctl.sudo hcitool cmd 08 32 <handle value in two bytes in little endian format > 03 02 02 00 00.
ex. For handle 1 -> sudo hcitool cmd 08 32 01 00 03 02 02 00 00menu gatt in bluetoothctl.Configure CODED phy on host and peripheral side.
Steps:
sudo hcitool cmd 08 31 03 04 04.bluez-5.56 directory. Run sudo ./tools/btmgmt --index hci0 and run phy.menu gatt in bluetoothctl.OTA (Over The Air) update performs following operations.
Please follow OTA update documentation for further details.
Please refer following for troubleshoot instructions if something goes wrong.