The Servita project is an embedded system firmware designed for the ESP32 platform. It includes a web interface for controlling and monitoring the device. The project has been refactored to improve readability and maintainability by separating the HTML content into distinct files that can be easily edited and tested independently of the firmware.
ServitaFirmware_InternalTeamOnly/
├── export_html.py
├── html/
│ └── main.html
├── install.sh
├── README.md
└── Servita/
├── button.cpp
├── inc/
│ ├── button.h
│ ├── led.h
│ ├── main_html.h
│ ├── motor.h
│ ├── pour.h
│ ├── serial_cmd.h
│ └── server.h
├── led.cpp
├── motor.cpp
├── pour.cpp
├── serial_cmd.cpp
├── server.cpp
└── Servita.ino
html
DirectoryContains the HTML file for the main application interface:
main.html
: The HTML content for the main application interface.Servita
DirectoryContains the main firmware code and the exported HTML header files:
inc/
: Directory for header files.
button.h
: The header file for button-related functions and definitions.led.h
: The header file for LED-related functions and definitions.main_html.h
: The header file containing the HTML content for the main application interface.motor.h
: The header file for motor-related functions and definitions.pour.h
: The header file for pour-related functions and definitions.serial_cmd.h
: The header file for serial command-related functions and definitions.server.h
: The header file for server-related functions and definitions.button.cpp
: The source file for button-related functions.led.cpp
: The source file for LED-related functions.motor.cpp
: The source file for motor-related functions.pour.cpp
: The source file for pour-related functions.serial_cmd.cpp
: The source file for serial command-related functions.server.cpp
: The source file for server-related functions.Servita.ino
: The main Arduino sketch file.export_html.py
A Python script that converts the HTML files in the html
directory into C header files for inclusion in the Arduino project. This script should be run whenever changes are made to the HTML files to ensure the firmware is up-to-date with the latest HTML content.
install.sh
A shell script for installing dependencies and setting up the project.
To update the header files with the latest HTML content, simply run the following command from the root directory:
python3 export_html.py
This will generate the main_html.h
file in the Servita/inc
directory.
Readability: By maintaining the HTML content in separate files, it becomes much easier to read and edit. This improves the overall readability of the codebase.
Local Testing: The HTML files can be opened directly in a web browser for local testing and debugging. This allows developers to verify the appearance and functionality of the web interface without needing to upload the firmware to the ESP32.
Separation of Concerns: Keeping the HTML, CSS, and JavaScript separate from the C++ code enhances modularity. In the future, maintaining separate CSS and JavaScript files would further improve this separation, making the project easier to maintain and extend.
File
> Preferences
.https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
OK
to close the Preferences window.Tools
> Board
> Boards Manager
.esp32
and install the esp32
by Espressif Systems version 3.0.1
.Tools
> Board
> ESP32 Arduino
> ESP32 Dev Module
.Tools
> Manage Libraries
.FastLED
version 3.7.0
AsyncTCP
version 1.1.4
ArduinoJson
version 7.0.4
WebSockets
version 2.5.1
C:\Users\<YourUsername>\Documents\Arduino\libraries
~/Arduino/libraries
C:\Users\<YourUsername>\Documents\Arduino\libraries
~/Arduino/libraries
SinricPro
.If your ESP32 board uses the CH340 USB-to-Serial chip, you may need to install the CH340 drivers:
When using the Arduino IDE to install the firmware on an ESP32 device, it is important to select the correct partition scheme to ensure that there is enough space for the application.
Tools
> Partition Scheme
.Huge APP (3MB No OTA/1MB SPIFFS)
from the dropdown menu.This partition scheme is recommended for devices with 8 MB of flash space, as it allocates a large portion of the memory for the application, ensuring that it can run without issues related to memory limitations.
Download and install the Arduino CLI:
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
sudo mv bin/arduino-cli /usr/local/bin/
Configure the Arduino CLI:
arduino-cli config init
Add the ESP32 board support:
arduino-cli core update-index
arduino-cli core install esp32:esp32@3.0.1
Install the required Python packages:
pip install pyserial
Install Git if it's not already installed:
sudo apt-get install git
Download the Arduino CLI executable from the Arduino CLI GitHub releases page.
Extract the executable and add it to your system PATH.
Configure the Arduino CLI:
arduino-cli config init
Add the ESP32 board support:
arduino-cli core update-index
arduino-cli core install esp32:esp32@3.0.1
Install the required Python packages:
pip install pyserial
Install Git if it's not already installed: Download and install Git from the official Git website.
Download and install the Arduino CLI:
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
sudo mv bin/arduino-cli /usr/local/bin/
Configure the Arduino CLI:
arduino-cli config init
Add the ESP32 board support:
arduino-cli core update-index
arduino-cli core install esp32:esp32@3.0.1
Install the required Python packages:
pip install pyserial
Install Git if it's not already installed:
brew install git
arduino-cli lib install "FastLED@3.7.0"
arduino-cli lib install "AsyncTCP@1.1.4"
arduino-cli lib install "ArduinoJson@7.0.4"
arduino-cli lib install "WebSockets@2.5.1"
ESPAsyncWebServer
Instead of using the version of ESPAsyncWebServer
that the Arduino CLI automatically installs, clone the repository directly:
Navigate to your Arduino libraries folder. The default locations are:
~/Arduino/libraries
C:\Users\<YourUsername>\Documents\Arduino\libraries
~/Documents/Arduino/libraries
Open a terminal (or command prompt) and navigate to the Arduino libraries folder:
cd ~/Arduino/libraries
# or for Windows
cd C:\Users\<YourUsername>\Documents\Arduino\libraries
Clone the ESPAsyncWebServer
repository and checkout the latest supported version (v3.0.6):
git clone https://github.com/mathieucarbou/ESPAsyncWebServer.git
cd ESPAsyncWebServer
git checkout v3.0.6
SinricPro
Navigate to your Arduino libraries folder. The default locations are:
~/Arduino/libraries
C:\Users\<YourUsername>\Documents\Arduino\libraries
~/Documents/Arduino/libraries
Open a terminal (or command prompt) and navigate to the Arduino libraries folder:
cd ~/Arduino/libraries
# or for Windows
cd C:\Users\<YourUsername>\Documents\Arduino\libraries
Clone the 'SinricPro' repository and checkout the latest supported version (3.2.1):
git clone https://github.com/sinricpro/esp8266-esp32-sdk.git SinricPro
cd SinricPro
git checkout 3.2.1
To compile the firmware using the Arduino CLI, use the following command:
arduino-cli compile --fqbn esp32:esp32:esp32 Servita
To upload the compiled firmware to the ESP32, use the following command, replacing /dev/ttyUSB0
(or the appropriate serial port for your ESP32 device):
arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:esp32 Servita
To monitor the serial output of the ESP32, use the following command:
arduino-cli monitor -p /dev/ttyUSB0 -b esp32:esp32:esp32 -c baudrate=115200
Congratulations! You have successfully set up and integrated Sinric Pro with Alexa and Servita. Enjoy your smart home automation!
manufacturing.py
Install the arduino-cli
tool for your operating system.
Download the desired firmware version from the ServitaFirmware releases.
Place the release files into a folder named build
in the root of the Servita firmware repository.
Run the following command:
python manufacturing.py --port USB_PORT
Replace USB_PORT
with the actual USB port where the device is connected.
The script will provide output as it goes through various stages. The final output color indicates the configuration status of the device:
Color | Description |
---|---|
Cyan | Both the ESP32 and the expansion board have been successfully configured. |
Yellow | Only the ESP32 main board has been configured. |
Red | Neither the main board nor the expansion board were configured properly. |
If you follow these steps and the output colors, you can easily determine the success of the configuration process.
To automate the process of creating a release, you can use GitHub Actions. By tagging a specific commit and pushing to GitHub, a release will be automatically created. To create a release, tag a commit with a version number and push it to GitHub. For example:
git tag v1.0
git push origin v1.0
This will trigger the GitHub Actions workflow, compile the code, and create a release with the compiled binaries attached. All versions should be tagged with a 'v' prefix followed by the version number (e.g., v1.0
, v1.1
, etc.). The automated release process ensures that new versions of the firmware are easily distributed and reduces the manual effort involved in creating releases.