Git Product home page Git Product logo

bleeper's Introduction

Bleeper is a library to manage your firmware configurations written in C++ for ESP8266 and ESP32 Arduino Platforms.

Features

  • Fully customizable hierarchical configuration structure
  • Generic property types
  • Automatic storage with property granularity (EEPROM & SPIFFS)
  • Wifi & AP connections
  • Configuration interfaces (web panel by default)
  • Observe any configuration property change through the observer API

Why Bleeper

In the scenario of prototyping with hardware devices you will likely end up with a bunch of configuration settings like pin numbers, sensor thresholds, device ids, connection credentials, port numbers, and so many others.
As a good programmer you decide to define these configurations in a "configuration file" with a lot of #define macros or constants.

But... what if you want to change those values? Downloading the firmware each time is tedious. Think about the cases where you have multiple devices to configure or even worst you don't have close physical access to them.

At the end you realize that you actually need some sort of "Configuration Manager" with high level features like exposing those variables on a web panel (or another type of interface), persisting some of them (usually your Wifi credentials) and so on.

Usage

Suppose that you have this configuration:

The above tree structure speaks by its own, what's worth to mention here is that we want wifi.ssid and wifi.passwrod to be persistent using the Bleeper storage.

The C++ code will look like this:

#include "Bleeper.h"

class Config: public RootConfiguration {
public:
  stringVar(name, "Default Device Name");
  subconfig(WifiConfig, wifi);
  subconfig(LedsConfig, leds);
};

class WifiConfig: public Configuration {
public:
  persistentStringVar(ssid, "MySSID");
  persistentStringVar(password, "MyPassword");
};

class LedsConfig: public Configuration {
public:
  floatVar(calibration, 1.5);
  subconfig(SPIConfig, spi);
};

class SPIConfig: public Configuration {
public:
  intVar(speed, 1000000);
};

Basically, per each configuration node you have to implement a subclass of Configuration and a RootConfiguration subclass for the especial root node (i.e the top level entry).

For a full documentation on how properties are defined read here.

Once we completed our configuration structure we can use it like this:

// Your Config instance
Config C;

void loop() {
  // access to your spi speed config
  int speed = C.leds.spi.speed
}

Note that all variables are type-safe. You are not accessing to a generic wrapper and casting its type.

The final step is to setup the Bleeper singleton instance with your RootConfiguration instance and specify your connections, interfaces, storage and observers.

#include "Bleeper.h"

class CalibrationObserver: public ConfigurationObserver {
public:
  void onConfigurationChanged(const ConfigurationPropertyChange value) {
    Serial.println("Configuration " + value.key + " changed from " + value.oldValue + " to " + value.newValue);
  }
};

Config C;

void setup() {

  Bleeper
    .verbose(115200)
    .configuration
      .set(&C)
      .addObserver(new CalibrationObserver(), {&C.leds.calibration})
      .done()
    .configurationInterface
      .addDefaultWebServer()
      .done()
    .connection
      .setSingleConnectionFromPriorityList({
          new Wifi(&C.wifi.ssid, &C.wifi.password),
          new AP() // fallback
      })
      .done()
    .storage
      .setDefault() // EEPROM
      // .set(new SPIFFSStorage()) // SPIFFS
      .done()
    .init();
}

void loop() {

  Bleeper.handle();

}

Basically Bleeper exposes four entry points:

  1. Bleeper.configuration

Lets you set your RootConfiguration instance and add observers to changes on it. In this example we are setting the CalibrationObserver instance that will be only notified about changes on the C.leds.calibration property.

  1. Bleeper.configurationInterface

Here you can add as many ConfigurationInterface instances as you want. Bleeper provides a default web panel when calling addDefaultWebServer.

  1. Bleeper.connection

Under connection we can call setMultipleConnections or setSingleConnectionFromPriorityList (in which only one connection will be active) and provide a list of Connection instances. By default the Wifi class will observe changes on the provided credentials and retry the connection accordingly.

  1. Bleeper.storage

Lets you specify the Storage instance to use when saving your persistent variables. Calling setDefault will use the default EEPROM storage automatically. You can also use SPIFFSStorage or create your own instead.

Installation

Arduino IDE

Go to Sketch > Include Library > Manage Libraries...
Search for Bleeper and click on Install

PlatformIO IDE

Go to your platformio.ini file and add the following lines:

lib_deps = Bleeper
lib_ldf_mode = deep

Future Work

  • Add support for other boards.
  • Improve documentation & examples.
  • Add CI server & tests.

Author

bleeper's People

Contributors

dernster avatar einstweilenhier avatar grocky avatar per1234 avatar sidoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bleeper's Issues

Question - use of std::vector in esp8266 environment

Thanks so much for this library. It looks like a really beautiful interface, and I'm eager to use it in my projects.

I think pulling in std::vector causes conflicts because the macros min and max, which are defined here, are also defined elsewhere in the ESP8266 Arduino SDK. (Or, at least, that's my understanding).

Reference: esp8266/Arduino#2549

I've tried stuffing Arduino.h before Bleeper.h in my main, which solves the original issue, but then I get other wacky compile errors in a different library I'm using (GxEPD).

Wondering if this is something you've ran into before, and if you have a suggested workaround? Is there a way to make Bleeper robust to header inclusion ordering?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.