Starting point for ESP32 projects based on ESP-IDF (FreeRTOS), WiFi, NTP and MQTT.
Provide a foundation for future projects that run on an ESP32 using the ESP-IDF platform (which includes Espressif's version of FreeRTOS), WiFi access, NTP time keeping and an MQTT client. Many of my projects start with this combination.
This combination is proving to be a bit more difficult to get going than some of the Arduino examples but should prove more useful in the long run. Or not.
Everything desired for this project is complete, working and tested.
- LED task blinking
- WiFi associates
- MQTT working
- NTP gets time
Rework the example code for MQTT to do something more useful (than just subscribe and publish to itself.)Determine how to publish from other threads and provide an internal API for that.- Test the WiFi and MQTT code to provide error recovery on disconnect.
AP restartMQTT broker restart- Test SNTP through ntp server restart. Will test next time edge router (NTP server) is restarted.
The following functional tests have been performed.
- Turn AP off, leave off for a minute or so and restart. (Modified code to perform infinite WiFi reconnect attempts.)
- Shut down and restart MQTT broker.
Development will be using PlatformIO driven by VS Code. There are ready made examples that share a lot of code in connect.c
(and perhaps other files) and it will be my task to extract what is needed for this specific project. General steps will include
-
Copy the files from
.../examples/get-started/sample_project
to this repo and build (except theREADME.md)
. (blink
andhello_world
projects in the same directory may be useful references as well.) -
Open with PlatformIO. No Joy. Wants a
platformio.ini
. -
Create with PlatformIO. Still not so good. Created the inside the git directory. I guess I can merge my
README.md
into the PlatformIO project, destroy the Guitrhub project and then create a bare gitbub project and import Platform IO project. -
Abandon this and start from scratch.
-
Create bare Github project.
-
Create PlatformIO project with same name.
-
Follow instructions from Github bare project redirect to import the project into Github.
-
project builds, ready to roll!
Given a buildable project...
- Add a (FreeRTOS) task to blink an LED. Always fun to blink an LED and can be used as an indicator later.
- Associate with a WiFi AP and identify by host name.
- Add MQTT client to publish messages.
- Add NTP client so we know time. (Does anyboey really know what time it is? - CTA)
- Full PlatformIO and tool chain installation, and using VS Code.
- User provided
include/secrets.h
that has definitions for
#define SSID "your_SSID"
#define PWD "your_password"
#define sntp_server "your_ntp_server"
The sample project was pretty much abandoned. I should read the link below from "How to use example"
The boot_count in main.c
is not counting up.
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This is the simplest buildable example. The example is used by command idf.py create-project
that copies the project to user specified path and set it's name. For more information follow the docs page
We encourage the users to use the example as a template for the new projects. A recommended way is to follow the instructions on a docs page.
The project sample_project contains one source file in C language main.c. The file is located in folder main.
ESP-IDF projects are built using CMake. The project build configuration is contained in CMakeLists.txt
files that provide set of directives and instructions describing the project's source files and targets
(executable, library, or both).
Below is short explanation of remaining files in the project folder.
├── CMakeLists.txt
├── main
│ ├── CMakeLists.txt
│ └── main.c
└── README.md This is the file you are currently reading
Additionally, the sample project contains Makefile and component.mk files, used for the legacy Make based build system. They are not used or needed when building with CMake and idf.py.