Integrated Agent: ESP32 v1.3.8
The Ayla ESP32 solution includes example host application source code, an Ayla Wi-Fi Integrated Agent, and Ayla extensions to the Espressif IoT Development Framework (IDF). These pieces link together to provide an Ayla edge solution for the ESP32 board. Learn more about Ayla Integrated Agents.
First steps
-
Obtain an Espressif ESP32-DevKitC board.
-
Create an Ayla user account. You will probably need to have your Ayla Customer Account admin or Ayla support create a user account for you with admin or developer access rights.
-
Reserve a DSN. Browse to Ayla Dashboard Portal. On the sidebar, navigate to Factory Actions. Click the Reserve DSN button. For Model, select AY008ESP1. Click Submit, and then download the associated XML file. You will need DSN value and the key from the file.
-
Browse to the Ayla Developer Portal, and create a template with the following details.
Visibility: oem Name: ADA ESP v1.3.8 Description: ADA ESP v1.3.8 Registration: Dsn Model: ledevb Version: ada-esp-idf-src-1.3.8 Type: Wifi -
After creating the template, copy & paste the following properties into a text file, and import the file.
base_type,direction,name,scope
boolean,output,Blue_button,user
boolean,input,Blue_LED,user
string,input,cmd,user
decimal,input,decimal_in,user
decimal,output,decimal_out,user
boolean,input,Green_LED,user
integer,input,input,user
string,output,log,user
integer,output,output,user
string,output,version,user -
Finally, click the new version property, check Host SW Version, and click OK.
Build and Run
GCC/Ubuntu/Docker
This section provides directions for building an Ayla ESP32 Solution v1.5-beta using a GCC/Ubuntu/Docker development environment.
-
Download Ayla source code (ada-esp-idf-src-1.3.8.tgz).
-
Determine the computer-to-ESP32 serial port:
-
List the serial ports on your computer (e.g.
ls /dev/tty*
). -
Connect an ESP32 board to your computer using a serial cable.
-
List the serial ports again. The new serial port on the list is the one to use (e.g.
/dev/ttyUSB0
).
-
-
Install a Docker Engine on your Windows, Mac, and/or Linux host OS.
-
Create a Docker ubuntu container:
$ docker run --net=host --name=esp -w /root -it --device=/dev/ttyUSB0 ubuntu bash
You are root, and the current working directory is
/root
. -
Prepare your development environment:
-
Update package list:
# apt update
-
Install miscellaneous packages:
# apt install nano screen iputils-ping
-
Install prerequisites for Espressif Standard Setup of Toolchain v3.2.2 for Linux.
# apt install gcc git wget make libncurses-dev flex bison gperf \ python python-pip python-setuptools python-serial python-cryptography python-future
-
Create an
esp
directory, and change directory:# mkdir esp # cd esp
-
Download ESP32 toolchain for Linux:
# wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
-
Extract the archive file:
# tar -xzf xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
-
Add to the PATH environment variable:
# export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH
-
Clone the Espressif IoT Development Framework:
# git clone -b v3.1-beta1 --recursive https://github.com/espressif/esp-idf.git esp-idf-v3.1-beta1
-
Create the
IDF_PATH
environment variable:# export IDF_PATH=$HOME/esp/esp-idf-v3.1-beta1
-
-
Test the development environment with the hello_world example:
-
Change directory:
# cd $IDF_PATH/examples/get-started/hello_world
-
Customize configuration. (Defaults should be fine.)
# make menuconfig
-
Build, flash, and monitor:
# make # make flash # make monitor
Output appears similar to this:
Toolchain path: /root/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc Toolchain version: esp32-2019r1 Compiler version: 8.2.0 ... ... Hello world! This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash Restarting in 10 seconds... Restarting in 9 seconds... ... ...
Press
Ctl
+]
to exit the monitor.
-
-
Install Ayla source code:
-
In a host terminal, copy
ada-esp-idf-src-1.3.8.tgz
to your Docker container:$ docker cp /home/matt/Downloads/ada-esp-idf-src-1.3.8.tgz esp:/root/esp
-
In your Docker terminal, extract the archive file:
# cd /root/esp # tar zxvf ada-esp-idf-src-1.3.8.tgz
-
Copy the
ada-esp-idf-src-1.3.8
directory on top of theesp-idf-v3.1-beta1
directory:# cp -R ada-esp-idf-src-1.3.8/* ./esp-idf-v3.1-beta1
This diagram gives you an idea of where the Ayla files are copied:
-
-
Configure and build the Ayla agent and host application:
-
Change directory:
# cd $IDF_PATH/examples/ayla_demo
-
Edit
./main/conf.h
. Set the following:#define DEMO_OEM_ID "00000000" /* replace with your Ayla OEM ID */ #define DEMO_TEMPLATE_VERSION "ada-esp-idf-src-1.3.8"
-
Build, flash, and monitor:
# make # make erase_flash # make flash # make monitor
-
Configure networking and security (use
log debug all
for maximum visibility):# nvs-set ada.f.wifi/profile/0/ssid <ssid> # nvs-set ada.f.wifi/profile/0/security <security_type> # 0=none, 3=wpa, 4=wpa2 # nvs-set ada.f.wifi/profile/0/key <passphrase> # nvs-set ada.f.wifi/profile/0/enable 1 # nvs-set "ada.f.id/dev_id" AC000W000000001 # nvs-set "ada.f.id/key" MIIB... (long number) # nvs-set ada.f.client/server/default 1 # esp-reboot
# oem key 0123456789abcdef0123456789abcdef ledevb # save
-
NOTE: Setting "ada.f.client/server/default" to 1 will force your devices to use the development servers. For production, please set this value to 0: "ada.f.client/server/default 0".
GCC/Windows
This page provides directions for building an Ayla ESP32 Solution v1.3.8 using a GCC/Windows development environment.
-
Download Ayla source code (ada-esp-idf-src-1.3.8.tgz).
-
Determine the computer-to-ESP32 COM port:
-
Run Windows Device Manager, and expand
Ports
. -
Connect an ESP32 board to your computer using a serial cable.
-
Note the new COM port (e.g. "
Silicon Labs CP210x USB to UART Bridge (COM3)
") on the list.
-
-
Browse to Standard Setup of Toolchain for Windows, and complete "Toolchain Setup" and "Check it Out" only.
-
Clone the Espressif IoT Development Framework:
$ cd ~/esp $ git clone -b v3.1-beta1 --recursive https://github.com/espressif/esp-idf.git esp-idf-v3.1-beta1
-
Add IDF_PATH to user profile.
-
Create a script file named
export_idf_path.sh
inC:/msys32/etc/profile.d/
. -
Identify the path to ESP-IDF directory. It is specific to your system configuration and may look something like
C:\msys32\home\user-name\esp\esp-idf-v3.1-beta1
. -
Add the export command to the script file replacing backslashes with forward slashes, e.g.:
$ export IDF_PATH="C:/msys32/home/user-name/esp/esp-idf-v3.1-beta1"
-
Save the file, close the MSYS2 window, re-open it, and verify the IDF_PATH:
$ printenv IDF_PATH
-
-
Install Patching with MSYS2 run:
$ pacman -S patch
-
Test the development environment with the hello_world example:
-
Change directory:
# cd $IDF_PATH/examples/get-started/hello_world
-
Customize configuration. (Defaults should be fine.)
# make menuconfig
-
Build, flash, and monitor:
# make # make flash # make monitor
Output appears similar to this:
Toolchain path: /root/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc Toolchain version: esp32-2019r1 Compiler version: 8.2.0 ... ... Hello world! This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash Restarting in 10 seconds... Restarting in 9 seconds... ... ...
Press
Ctl
+]
to exit the monitor.
-
-
Install Ayla source code:
-
Extract the archive file:
# cd ~/esp # tar zxvf ada-esp-idf-src-1.3.8.tgz
-
Copy the
ada-esp-idf-src-1.3.8
directory on top of theesp-idf-v3.1-beta1
directory:# cp -R ada-esp-idf-src-1.3.8/* ./esp-idf-v3.1-beta1
This diagram gives you an idea of where the Ayla files are copied:
-
-
Configure and build the Ayla agent and host application:
-
Change directory:
# cd $IDF_PATH/examples/ayla_demo
-
Edit
./main/conf.h
. Set the following:#define DEMO_OEM_ID "00000000" /* replace with your Ayla OEM ID */ #define DEMO_TEMPLATE_VERSION "ada-esp-idf-src-1.3.8"
-
Run
make menuconfig
to setSerial flasher config > Default serial port
to the correct COM port. -
Build, flash, and monitor:
# make # make erase_flash # make flash # make monitor
-
Configure networking and security (use
log debug all
for maximum visibility):# nvs-set ada.f.wifi/profile/0/ssid <ssid> # nvs-set ada.f.wifi/profile/0/security <security_type> # 0=none, 3=wpa, 4=wpa2 # nvs-set ada.f.wifi/profile/0/key <passphrase> # nvs-set ada.f.wifi/profile/0/enable 1 # nvs-set "ada.f.id/dev_id" AC000W000000001 # nvs-set "ada.f.id/key" MIIB... (long number) # nvs-set ada.f.client/server/default 1 # esp-reboot
# oem key 0123456789abcdef0123456789abcdef ledevb # save
-
Register your device
-
Browse to the Ayla Dashboard Portal, click OEM Users in the sidebar, click your account, and copy your UUID (e.g.
a0000000-0000-0000-0000-000000000000
). -
Click Devices in the sidebar, and find the new device on the list:
-
Click the device row. Then, in the Device > Settings table, paste your UUID, and click Register:
-
View the device on the Devices list again. Note that the device is registered to you.
-
View the device in the Ayla Developer Portal:
-
View the device in the Aura Mobile App:
Updated over 2 years ago