WebThing Empty Project is a starting point for building webThing device on ESP32 processor.
This software is prepared for ESP32 CPUs and uses esp-idf environment (current stable version: 4.1).
To build webThing device follow these steps:
- download
WebThing Empty Project
- in
main
folder rename the main project code file fromwebthings_empty_project.c
into appropriate name - in
main/CMakeLists.txt
updateset(COMPONENT_SRCS "webthings_empty_project.c")
according to the new file name - in
CMakeLists.txt
updateproject(empty_project)
according to your project name
- in
- in project directory create
components
folder - into
components
folder downloadweb_thing_server
from webthings-components repository - in the directory
components
put code of your webThing, it should haveinit_the_thing
function which returns pointer (thing_t *
) to the webThing (seeweb_thing_server
documentation and wethings-node-example-project for information about how to create webThing software) - for tests (in the above point) you can download thing_button and/or thing_blinking_led into components and add things to the server using
add_thing_to_server(init_button())
and/oradd_thing_to_server(init_blinking_led())
- include header file (e.g.
thing_button.h
) of your thing in the main code file - if necessary configure project by
idf.py menuconfig
- compile by
idf.py build
- upload into flash memory by
idf.py flash
In order to fully use the potential of IoT, and to have access to webThings from the Internet, it is best to run WebThing Gateway in the same WiFi network.
By the first power-up the node starts in AP mode with SSID: iot-node-ap and password: htqn9Fzv. After logging into this WiFi network load the main page by typing in browser iot-node-ap.local:8080/
(it does not work on Android) or 192.168.4.1:8080/
.
On the page write SSID and password of the WiFi network where the node will work. In the last position enter the local node's name.
Pressing submit causes writing data into flash and restart of the node in station mode. If you want to change the WiFi SSID or password later just connect GPIO27
to GND, this causes node's restart in AP mode as in the previous paragraph.
If WebThings Gateway runs in the same WiFi network go to Things category on gateway and press plus sign. Gateway shoud find new things, press Save and Done.
Now you have 2 new things in your IoT network and you can control them from anywhere you are.
After power-up information about CPU is sent to serial port (e.g. /dev/ttyUSB0 in Linux). Serial port speed is set on 115200 bps.
init_reset_button
- initialization of GPIO27
for restarting in AP mode.
init_things
- things are added here (see things documentation).
init_nvs
- checks if WiFi SSID and password are saved in flash, if so WiFi initialization takes place in station mode (wifi_init_sta
) and the node connects to the WiFi network.
If SSID or pasword were not found node starts in softAP mode (wifi_init_softap
).
In the main loop information about free heap memory is sent every 2 seconds on serial port (for tests only).
Web Thing Server starts running after event IP_EVENT_STA_GOT_IP
. Server runs on port 8080 (more information in Web Thing Server documentation).
After that the SNTP client (init_sntp
) is started.
idf.py menuconfig
In the WebThing Empty Project menu item, you can set the GPIO_A
(default 26) and GPIO_B
(default 22) positions. They will be visible for compiler as CONFIG_GPIO_A
and CONFIG_GPIO_B
constants.
Build: idf.py build
Flash: idf.py flash
and press boot button.
- WebThing Gateway - https://webthings.io/gateway/
- Web Thing API - https://webthings.io/api/
- esp-idf - https://github.com/espressif/esp-idf
This project is licensed under the MIT License.
- Krzysztof Zurek - github