2025-08-15 21:14:12 +02:00
2018-10-04 00:09:57 +02:00
2018-09-28 10:38:31 +02:00
2018-11-15 12:46:13 +01:00
2025-08-14 19:39:26 +02:00
2018-08-03 11:01:42 +00:00
2025-08-14 19:39:26 +02:00
2025-08-14 19:48:19 +02: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
2025-08-14 19:39:26 +02:00
2025-08-15 21:14:12 +02:00

Sprocket-Core

A lightweight Arduino framework for event-driven programming on ESP8266 devices, featuring a plugin architecture and task scheduling capabilities.

Overview

Sprocket-Core provides a modular foundation for building IoT applications with:

  • Event-driven architecture using a topic-based publish/subscribe pattern
  • Plugin system for extensible functionality
  • Task scheduling with priority support
  • Network abstraction layer for communication
  • JSON-based messaging system

Core Concepts

Event Channel

The framework implements a publish/subscribe event system where components can:

  • Subscribe to topics with callback handlers
  • Publish messages to specific topics
  • Handle events asynchronously

Plugin Architecture

Plugins extend the core functionality and can:

  • Subscribe to and publish events
  • Integrate with the task scheduler
  • Access network capabilities
  • Be dynamically activated/deactivated

Task Scheduler

Built on TaskScheduler library with support for:

  • Priority-based task execution
  • Sleep-on-idle power management
  • Standard function callbacks
  • Layered scheduling priorities

Network Layer

Abstract network interface supporting:

  • Connection management
  • Message broadcasting
  • Point-to-point communication
  • Scheduler integration

Architecture

Sprocket (EventChannel)
├── TaskScheduler
├── Network
├── Plugins[]
└── Configuration

Key Components

  • Sprocket: Main framework class inheriting from EventChannel
  • EventChannel: Core pub/sub messaging system
  • Plugin: Base class for all framework extensions
  • Network: Abstract network communication layer
  • SprocketMessage: JSON-structured message format
  • TaskScheduler: Task management and execution

Usage Example

#include <Sprocket.h>

class MyApp : public Sprocket {
public:
    Task periodicTask;
    
    MyApp(SprocketConfig cfg) : Sprocket(cfg) {}
    
    Sprocket* activate(Scheduler* scheduler) {
        // Set up periodic task
        periodicTask.set(TASK_SECOND, TASK_FOREVER, [](){
            Serial.println("Periodic task executed");
        });
        
        scheduler->addTask(periodicTask);
        periodicTask.enable();
        
        return this;
    }
};

// Configuration
SprocketConfig config = { 3000, 115200 }; // startup delay, baud rate
MyApp app(config);

void setup() {
    app.activate();
}

void loop() {
    app.loop();
    yield();
}

Message Format

Messages use a structured JSON format:

{
    "domain": "app",
    "from": "device1",
    "to": "device2",
    "payload": "message content",
    "topic": "sensor/data",
    "type": 1,
    "broadcast": 0
}

Plugin Development

Create custom plugins by extending the Plugin class:

class MyPlugin : public Plugin {
public:
    void activate(Scheduler* scheduler) override {
        // Plugin initialization
        subscribe("my/topic", [](String msg) {
            // Handle incoming messages
        });
    }
    
    void onMessage(SprocketMessage msg) override {
        // Process framework messages
    }
};

Dependencies

  • Arduino framework
  • TaskScheduler library
  • ArduinoJson library
  • ESP8266 platform support

Platform Support

Currently supports ESP8266 devices with Arduino framework.

Useful Commands

# Erase flash memory
esptool --port /dev/ttyUSB0 erase_flash

# Over-the-air (OTA) update
~/.platformio/packages/tool-espotapy/espota.py -i <espIP> -p 8266 -a <authPW> -f .pioenvs/ota/firmware.bin

License

See LICENSE file for details.

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%