# First Program

# AquaStorm Module System (Experimental)

The AquaStorm System is modular by design and is based on the DSIS specification. The specification defines the specific way modules in the system are connected to each other.

aquastorm --> <system> --> modules --> <module-name><module-index>

# Libraries

//
// Created by A.P.A. Slaa on 9/17/23.
// Copyright: ProjectSource V.o.F.
//

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>

/* DSIS Specification definitions */
#include "DSIS/DSIS.h"
#include "DSIS/module.h"
#include "DSIS/value/boolean.h"

/* AquaStorm Module definitions */
#include "AquaStorm.h"

After including the required library files, we can use the AquaStorm.h library.

Defining the System Every complete AquaStorm module is built upon a single system. A system can be defined as follows:

AquaStorm aquaStorm("eindmaas" /* System name */, "192.168.2.1" /* MQTT Broker IP */, 1883 /* MQTT broker port, optional */);

# Defining the Module

By defining a module, we can group inputs and outputs together and form known functionality within a module:

Module io("io" /* Module name */, "V0" /* Module version */, 1 /* Module index, default is 0 */);

# Defining the IO

A module is comprised of inputs and outputs that can be of different types. The following types are supported:

  • Boolean (1 or 0)
  • Integer (32-bit)
  • Float
  • String

In the example code, we define an input that can toggle an LED as follows:

Boolean led0("led0" /* Name */, "example led" /* Description */, false /* Initial value */, Value<bool>::MUTABLE /* MUTABLE or READONLY */);

When defining IO, consider whether the IO needs to be writable from external sources (MQTT). The following options are supported:

  • MUTABLE (Writable and Readable from external sources) (INPUT)/(OUTPUT (*ref))
  • READONLY (Readable from external sources) (OUTPUT)

# Handling updates of MUTABLE IO

To handle external mutations on the specified IO, you need to add a listener. This listener needs to listen for the event COMPONENT:UPDATE. This event is triggered when a component's value is updated. The user needs to implement the logic to change the desired states or GPIO port on the hardware module.

led0.on(Component::UPDATE, [](const Event<Value<bool> *> *event) {
    return gpio_set_level(LED0_PIN, event->data->get());
});

# Binding Configured Objects

The defined objects need to be bound together to form the structure needed for operation. This can be done as follows:

This only has to be done once (on startup)

io.add(&led0); // This will automatically select input or output based on `MUTABLE` or `READONLY`

aquaStorm.bind(&io);
aquaStorm.setup();

# Resulting example program

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>

/* DSIS Specification definitions */
#include "DSIS/DSIS.h"
#include "DSIS/module.h"
#include "DSIS/value/boolean.h"

/* AquaStorm Module definitions */
#include "AquaStorm.h"

#include <driver/gpio.h>

/* System definition */
AquaStorm aquaStorm("eindmaas", "192.168.2.1");

/* Module definition */
Module io("io", "V0");

/* IO definition */
Boolean led0("led0", "example led", false, Value<bool>::MUTABLE);

// Main application
extern "C" void app_main(void) {
    io.add(&led0);

    aquaStorm.bind(&io);
    aquaStorm.setup();

    gpio_reset_pin(LED0_PIN);
    gpio_set_direction(LED0_PIN, GPIO_MODE_OUTPUT);

    led0.on(Component::UPDATE, [](const Event<Value<bool> *> *event) {
        return gpio_set_level(LED0_PIN, event->data->get());
    });
}

Use at your own risk

Firmware (GitLab)