Patrick Balsiger 3b191c997a docs
2019-02-17 11:29:23 +01:00
2019-02-17 11:29:23 +01:00
2018-09-28 10:38:31 +02:00
2018-11-15 12:46:13 +01:00
2018-12-28 20:18:42 +01:00
2018-08-03 11:01:42 +00:00
2018-08-30 00:16:33 +02:00
ci
2018-11-16 19:28:22 +01:00
2018-06-02 12:08:04 +02:00
2018-09-01 19:42:12 +02:00
2018-06-02 10:08:33 +00:00
2019-02-17 11:29:23 +01:00
2019-02-17 11:29:23 +01:00

Sprocket-Core

A lightweight Arduino framework for event driven programming.

Getting Started

Install sprocket-lib on your favorite dev environment. Either by cloning this repository into the Arduino library path or by adding it as a dependency to your platformio.ini file.
Additionally, sprocket-lib depends on following libraries:

Hash
TaskScheduler
SPIFFS
ArduinoJson

Example platformio.ini:

[env:build]
framework = arduino
platform = espressif8266
board = esp12e
upload_speed = 921600
monitor_baud = 115200
lib_deps = 
    Hash
    TaskScheduler
    SPIFFS
    ArduinoJson
    https://gitlab.com/wirelos/sprocket-lib.git#develop

Example main.cpp:

#include <Sprocket.h>
#include <MyPlugin.h>

Sprocket *sprocket;

void setup()
{
    sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE});
    sprocket->addPlugin(new MyPlugin());
    sprocket->activate();
}

void loop()
{
    sprocket->loop();
    yield();
}

Concepts

... topic based event channel / pubsub-pattern
... plugin system

Lifecycle

As the initialization order of core components is critical on embedded devices, it has been split up into different phases of a lifecycle.
In most cases a Sprocket is bootstraped in the setup() method. Addidional plugins are hooked into the Sprocket after initialisation. During loop, the internal Scheduler needs to be updated by calling the corresponding method.
See the "Getting Started" section for an example of skeleton Sprocket.

Phase Purpose
init Setup Serial and SPIFFS
activation Activate all plugins
loop Update the scheduler

Plugins

To extend the functionality of a Sprocket, plugins can be hooked into the activation phase with the addPlugin method. They are activated on the order the've been added.
The Sprocket internal scheduler is passed into the activation method of the plugin in order to add tasks.
Plugins can communicate with each other over the EvenChannel by a simple publish-subscribe mechanism.

Example plugin:

#include "Arduino.h"
#include "TaskSchedulerDeclarations.h"
#include "Plugin.h"

class MyPlugin : public Plugin
{
  public:
    MyPlugin() {}
    void activate(Scheduler *userScheduler)
    {
        subscribe("someTopic", [](String msg){
            Serial.println(msg);
        });
        publish("someTopic", "calling someTopic");
    }
};

Useful tools and commands

Commands:

# erase flash  
esptool --port /dev/ttyUSB0 erase_flash

# build environment esp32 and upload the binary
pio run -e esp32 -t upload

# build environment esp32 and upload the filesystem
pio run -e esp32 -t uploadfs
  
# OTA
~/.platformio/packages/tool-espotapy/espota.py -i <espIP> -p 8266 -a <authPW> -f .pioenvs/ota/firmware.bin 

Description
Arduino based library for event driven applications.
Readme MIT 312 KiB
Languages
C++ 43.5%
C 31.6%
JavaScript 22.7%
HTML 2.2%