Build simple and ready to use applications on ESP devices, focusing only on the application logic. This is a battery-included library, with connection management capabilities (using the EspWifiManager lib by antima.it), and a simple REST HTTP interface.
This library is part of the Moody project.
You can build sensor and actuator applications by exploiting the MoodySensor and MoodyActuator classes.
These classes are generic in the type of data that you acquire (sensor) or receive to actuate(actuator), which must be an arithmetic type. You can use the examples to understand the basic concepts of the library.
The Wifi connection management capabilities included, automatically manage credentials by allowing the user to insert them via a web browser interface. They are then saved to the non -volatile memory available, in order to be retrieved later. This process uses the EspWifiManager antima library.
The device information is exposed through HTTP APIs. You can request a sensor reading, change an actuator state, read its state, request information about the device, all through HTTP endpoints.
Add the library dependency to your platformio.ini. This is the preferred way to use the library, it's that easy!
[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
lib_deps = abathargh/MoodyNodeEsp
# or
lib_deps = https://github.com/antima/MoodyNodeEsp.git
MoodyNodeEsp depends on the following libraries:
- Arduino Json
- ESPAsyncWebServer
- ESPAsyncTcp (Dependency of ESPAsyncWebServer)
- EspWifiManager
- ArxTypeTraits
To install these dependencies, you can clone the repositories in your Arduino/libraries directory:
cd /path/to/Arduino/libraries
git clone https://github.com/bblanchon/ArduinoJson
git clone https://github.com/me-no-dev/ESPAsyncWebServer
git clone https://github.com/me-no-dev/ESPAsyncTCP
git clone https://github.com/antima/EspWifiManager
git clone https://github.com/hideakitai/ArxTypeTraits
You can also install them by downloading the zip archives of the linked projects by clicking on the links, then on the Code button and on the Download ZIP button; you can then add them to your Arduino IDE environment you can add it to your environment by clicking Sketch -> Include Library -> Add -> .ZIP Library... and selecting the zip file you just downloaded.
After installing everything, clone this repository into your Arduino libraries folder,
If you want download the zip version, you can click download zip from the upper right corner of this github page to obtain a release containing the latest features. You can then add it to your environment by clicking Sketch -> Include Library -> Add -> .ZIP Library... and selecting the zip file you just downloaded.
Devices using this library expose a number of HTTP APIs through which an external actor can interact with them.
A sensor node is reachable at the following endpoints:
- /api/conn [GET]: a get to this endpoint returns data regarding the node type, the sensor service and its mac address, in json format.
- /api/data [GET]: a get to this endpoint requests a sensor reading. The result of the operation is returned as a json message, in the payload field.
An actuator node is reachable at the following endpoints:
- /api/conn [GET]: a get to this endpoint returns data regarding the node type and its mac address, in json format.
- /api/data [GET]: a get to this endpoint returns the current state of the actuator. The result of the operation is returned as a json message, in the payload field.
- /api/data [PUT]: a put to this endpoint will result in a change of state inside the actuator, which in turn will actuate the received command. The new state is then returned as a json message, in the payload field.
Basic sensor example:
#include <MoodyNodeEsp.h>
MoodySensor<int> sensor("example");
int acquireFunction()
{
static int i = 0;
return i++;
}
void setup()
{
sensor.setAcquireFunction(acquireFunction);
sensor.begin();
}
void loop()
{
sensor.loop();
}
Basic actuator example:
#include <MoodyNodeEsp.h>
MoodyActuator<int> actuator("example");
void acquireFunction(int payload)
{
Serial.println(payload);
}
void setup()
{
Serial.begin(115200);
actuator.setActuateFunction(acquireFunction);
actuator.begin();
}
void loop()
{
actuator.loop();
}
This library is released under the LGPL 2.1 license.
- The ESP Async WebServer library used by this library is released under the LGPL 2.1 license.
- The EspWifiManager library used by this library is released under the LGPL 2.1 license.
- The ArxTypeTraits library used by this library is released under the MIT license.
For more information regarding the licensing of the Arduino API, ESP8266 Arduino core, Arduino IDE, ecc, you can check out this page.