Arduino Framework based IoT Skeleton Embedded Application, powered by PlatformIO.
With this project you have a good starting point to create your own application that shall be based on the Arduino Framework.
The project is suitable for the following controller boards:
- LOLIN D32
- DoIt ESP32 DEVKIT V1
- Wemos D1 Mini
- NodeMcu
- Adafruit ESP8266 Huzzah
This project builds up an Arduino Framework based IoT device application skeleton and it comprises of several components helping with debugging and integrating embedded applications on several different contoller modules.
This skeleton application can help you to build up your own Arduino Framework based applications while working with PlatformIO.
This project demonstrates how to integrate the following components:
- SpinTimer: Universal timer with 1 millisecond resolution, supporting OOP principles, providing recurring and non-recurring mode; helps to improve your application's architecture by encapsulating the timers into your components and thus make them active
- Ramutils: helps to determine the free Ram that is currently available
- DbgTrace: debug trace log environment with configurable log levels
- DbgCLI: interactive console environment with command tree that can be built up decentralized (from any different location in your application code and within any component)
- App-Dbg: boilerplate code setting up all the debug environment such as CLI and Tracing and free RAM info printer
- ArduinoJson: C++ JSON library for Arduino and IoT (Internet Of Things)
The command line interface provides the following functionality:
- set the trace level of the free heap monitoring printer
- configure the WiFi access point (SSID & Password) and show the WiFi connection status and the available hotspots around your device
This skeleton application demonstrates how to integrate libraries provided by the PlatformIO ecosystem and also how to use your own libraries and can help you to build up your own Arduino Framework based applications with focus on IoT.
The following components are in focus:
PlatformIO is the ideal foundation when developing IoT devices. It supports cross-platform development for many different controller boards widely used in the maker field and also for industrial applications.
Windows
- download Python 3.7.x or later from: https://www.python.org/downloads/
- select destination directory: keep default
- make sure python.exe is added to path
Linux
Install Python 3.7 or later using your package manager.
Install PlatformIO using the Python Package Manager (see also http://docs.platformio.org/en/latest/installation.html#python-package-manager):
- in a cmd shell enter:
pip install -U platformio
- upgrade pip, in the cmd shell enter:
python -m pip install --upgrade pip
- upgrade PlatformIO, in the cmd shell enter:
pio upgrade
- Create a directory where your code project shall be cloned into. E.g.
C:\git\pio-prj
- Clone this repository into the folder you created before:
git clone [email protected]:ERNICommunity/wiring-iot-skeleton.git
(ssh) orgit clone https://github.com/ERNICommunity/wiring-iot-skeleton.git
(ssl) - Open a command shell in the just cloned project folder, i.e. in
C:\git\pio-prj\wiring-iot-skeleton
- Run the command
pio init --ide vscode
. This prepares the project to be edited using Visual Studio Code.
- Open VSCode
- In menu choose File > Open Folder... and choose the folder you cloned the project into before, i.e
C:\git\pio-prj\wiring-iot-skeleton
- Press F1 to open the command menu
- Enter "platformIO: Switch Project Environment"
- Select the desired target platform. If your platform is not present, it may not be supported.
- Press F1 to open the command menu
- Enter "platformIO: Build"
or:
- On windows, press: ctrl + alt + B
- Press F1 to open the command menu
- Enter "platformIO: Upload"
or:
- On windows, press: ctrl + alt + U
- Click on the PlatformIO on the left bar menu
- In the PROJECT TASKS menu select your target platform name and open the Platform menu
- Click on "Build Filesystem Image"
- Click on "Upload Filesystem Image"
- Create a directory where your Eclipse Workspace will be stored and where this project shall be cloned into. E.g.
C:\git\pio-prj
- Clone this repository into the folder you created before:
git clone [email protected]:ERNICommunity/wiring-iot-skeleton.git
(ssh) orgit clone https://github.com/ERNICommunity/wiring-iot-skeleton.git
(ssl) - Open a command shell in the just cloned project folder, i.e in
C:\git\pio-prj\wiring-iot-skeleton
- Run the command
pio init --ide eclipse
. This prepares the project to be edited using Eclipse CDT. - Run the command
pio run
, this starts the project build
Note: Print a list of all available boards with the command: pio boards
- Open Eclipse CDT, choose the folder you created before as workspace, i.e
C:\git\pio-prj
- Import the project with File > Import > General > Existing Projects into Workspace, choose the
wiring-iot-skeleton
(i.eC:\git\pio-prj\wiring-iot-skeleton
)
In order to test and run the CLI commands, a terminal emulation program shall be used. The one giving you the best experience will be the HTerm.
Load the hterm-com10.cfg file (to be found in the project root directory) to configure HTerm properly. Alter the COM10 accordingly to the one that has been selected on your computer.
dbg Debug CLI root node
tr Debug Trace Port config access
heap Particular Trace Port (heap: see below in chapter Trace Port)
out Trace Output config access for the current trace port
get Show the assigned Trace Output
set <outName> Set a particular Trace Output name
list Show all available Trace Output names (& currently selected)
lvl Trace Level config access for the current trace port
get Show the current trace level
set <level> Set a particular trace level
list Show all available trace levels (& currenntly selected)
wifi WiFi debug commands
mac show WiFi MAC address
nets list available WLAN networks
stat Show WiFi status
dis Disconnect WiFi
con <SSID> <Pass> Connect WiFi
dbg tr heap lvl set debug
Trace Port | default level | functionality |
---|---|---|
heap | info | if set to debug level: automatically print free heap memory [bytes], every 10 seconds |
This chapter lists and explains all the libraries in this project. You can find the libraries under the 'lib' folder.
Libraries are divided in two application libraries and interface libraries.
Application libraries are meant to be agnostic from the platform they are deployed to. No code that bounds these libraries to a platform should be added.
-
AppHandler
- Offers the full functionality of the repo by wrapping all the other application libraries, meaning only this library must be included. It provides an Arduino like interface to setup and loop. It provides wrapper functions to expose required functionality from the application libraries.
-
AzureHAndler
- Offers functionality to register devices to an IoT Hub through a DPS, send telemetry, device twin changes and receive messages from the IoT Hub.
-
ConfigHandler
- Offer functionality to configure the board and other application libraries. Configuration of the WiFi, oft access point, device location, azure credentials and landing page are available.
-
ConfigTypes
- Holds together all the common types shared by all the application libraries.
-
LandingPageHandler
- Offers functionality for a web server that exposes the device's configuration, accessible through the IP address of the device. The landing page can be accessed by either connecting to the device soft access point or to the same WiFi network the device is connected to. Both, the device's soft access point IP or the WiFi IP (if connected) are printed in the log at boot time.
Interface libraries are meant to connect the application libraries to any specific target platform. This way, if the need to support a new platform arises, only these libraries need to be updated.
- FileHandler - Interface for File System handling
- WifiHandler - Interface for board WiFi handling
TODO: Create interface libraries for JSON, MQTT, SNTP and HTTP. Move the direct code used in application libraries to the interface libraries.
This chapter lists all the libraries this project is using.
Name | URL | Description |
---|---|---|
SerialCommand | https://github.com/kroimon/Arduino-SerialCommand | A Wiring/Arduino library to tokenize and parse commands received over a serial port. |
spin-timer | https://github.com/dniklaus/spin-timer | Universal recurring or non-recurring Timer. |
debug-cli | https://github.com/ERNICommunity/debug-cli | Debug CLI for Embedded Applications - Command Line Interface for debugging and testing based on object oriented tree structure. |
dbg-trace | https://github.com/ERNICommunity/dbg-trace | Debug Trace component for Embedded Applications - Debug and Trace Log message system based on trace ports with adjustable levels. |
ArduinoJson | https://github.com/bblanchon/ArduinoJson | An elegant and efficient JSON library for embedded systems |
Name | URL | Description |
---|---|---|
RamUtils | https://github.com/dniklaus/arduino-utils-mem | Arduino Memory Utilities, helps to show free heap space |
App-Debug | https://github.com/dniklaus/wiring-app-debug.git | Wiring application debug setup component |
- On GitHub: create new repository, i.e. my-test
- Within a Git Bash:
git clone --bare [email protected]:ERNICommunity/wiring-iot-skeleton.git
cd ./wiring-iot-skeleton.git
git remote rm origin
git remote add origin [email protected]:your-name/my-test.git
git push --mirror