Uniot Core
0.8.1
Loading...
Searching...
No Matches
UniotCore Class Reference

Main API class for the Uniot IoT platform. More...

#include <Uniot.h>

Public Types

using TimerId = uint32_t
 Type for timer identifiers.
 
using ListenerId = uint32_t
 Type for event listener identifiers.
 

Public Member Functions

 UniotCore ()
 Construct a new UniotCore instance.
 
void configWiFiResetButton (uint8_t pinBtn, uint8_t activeLevelBtn=LOW, bool registerLispBtn=true)
 Configure WiFi reset button.
 
void configWiFiStatusLed (uint8_t pinLed, uint8_t activeLevelLed=HIGH)
 Configure WiFi status LED.
 
void configWiFiResetOnReboot (uint8_t maxRebootCount, uint32_t rebootWindowMs=10000)
 Configure automatic WiFi reset on repeated reboots.
 
void configWiFiCredentials (const String &ssid, const String &password="")
 Configure WiFi network credentials.
 
void configUser (const String &user)
 Configure user identification.
 
void enablePeriodicDateSave (uint32_t periodSeconds=5 *60)
 Enable periodic saving of date/time information.
 
void addLispPrimitive (Primitive *primitive)
 Add a custom primitive to the Lisp interpreter.
 
void setLispEventInterceptor (uniot::LispEventInterceptor interceptor)
 Set event interceptor for Lisp interpreter.
 
void publishLispEvent (const String &eventID, int32_t value)
 Publish an event to the Lisp interpreter.
 
template<typename... Pins>
void registerLispDigitalOutput (uint8_t first, Pins... pins)
 Register GPIO pins as digital outputs for Lisp access.
 
template<typename... Pins>
void registerLispDigitalInput (uint8_t first, Pins... pins)
 Register GPIO pins as digital inputs for Lisp access.
 
template<typename... Pins>
void registerLispAnalogInput (uint8_t first, Pins... pins)
 Register GPIO pins as analog inputs for Lisp access.
 
template<typename... Pins>
void registerLispAnalogOutput (uint8_t first, Pins... pins)
 Register GPIO pins as analog outputs for Lisp access.
 
bool registerLispButton (uniot::Button *button, uint32_t id=FOURCC(_btn))
 Register a button object with the Lisp interpreter.
 
bool registerLispObject (const String &primitiveName, uniot::RecordPtr link, uint32_t id=FOURCC(____))
 Register a generic object with the Lisp interpreter.
 
TimerId setInterval (std::function< void()> callback, uint32_t intervalMs, short times=0)
 Create a repeating timer.
 
TimerId setTimeout (std::function< void()> callback, uint32_t timeoutMs)
 Create a one-shot timer.
 
TimerId setImmediate (std::function< void()> callback)
 Execute a callback on the next scheduler cycle.
 
bool cancelTimer (TimerId id)
 Cancel an active timer.
 
bool isTimerActive (TimerId id)
 Check if a timer is currently active.
 
int getActiveTimersCount () const
 Get the number of active timers.
 
uniot::TaskScheduler::TaskPtr createTask (const char *name, uniot::SchedulerTask::SchedulerTaskCallback callback)
 Create a named task for custom scheduling.
 
template<typename... Topics>
ListenerId addSystemListener (std::function< void(unsigned int, int)> callback, unsigned int firstTopic, Topics... otherTopics)
 Add a system event listener.
 
bool removeSystemListener (ListenerId id)
 Remove a system event listener.
 
template<typename... Topics>
size_t removeSystemListeners (unsigned int firstTopic, Topics... otherTopics)
 Remove all listeners for specific topics.
 
bool isSystemListenerActive (ListenerId id)
 Check if a system listener is active.
 
int getActiveListenersCount () const
 Get the number of active event listeners.
 
void emitSystemEvent (unsigned int topic, int message)
 Emit a system event.
 
ListenerId addWifiStatusLedListener (std::function< void(bool)> callback)
 Add a WiFi status LED listener.
 
void begin (uint32_t eventBusTaskPeriod=10)
 Initialize and start the Uniot platform.
 
void loop ()
 Process scheduled tasks and events.
 
uniot::AppKitgetAppKit ()
 Get access to the application kit.
 
uniot::CoreEventBusgetEventBus ()
 Get access to the event bus.
 
uniot::TaskSchedulergetScheduler ()
 Get access to the task scheduler.
 

Static Public Attributes

static constexpr TimerId INVALID_TIMER_ID = 0
 Invalid timer ID constant.
 
static constexpr ListenerId INVALID_LISTENER_ID = 0
 Invalid listener ID constant.
 

Detailed Description

Main API class for the Uniot IoT platform.

This class provides a comprehensive interface for building IoT applications with minimal boilerplate code. It orchestrates all platform subsystems including networking, scheduling, scripting, and hardware management.

The UniotCore class implements a singleton-like pattern through the global Uniot instance, providing immediate access to platform capabilities without complex initialization procedures.

Architecture overview:

  • Task scheduler: Non-blocking execution of periodic and one-shot tasks
  • Event bus: Decoupled communication between system components
  • Network stack: Automatic WiFi management with fallback mechanisms
  • Lisp interpreter: Dynamic scripting and runtime reconfiguration
  • Hardware abstraction: GPIO management and peripheral control

Member Typedef Documentation

◆ ListenerId

using UniotCore::ListenerId = uint32_t

Type for event listener identifiers.

◆ TimerId

using UniotCore::TimerId = uint32_t

Type for timer identifiers.

Constructor & Destructor Documentation

◆ UniotCore()

UniotCore::UniotCore ( )
inline

Construct a new UniotCore instance.

Initializes the core platform components including the task scheduler and event bus. Network controller configuration is deferred until begin() is called to allow for runtime configuration.

Member Function Documentation

◆ addLispPrimitive()

void UniotCore::addLispPrimitive ( Primitive * primitive)
inline

Add a custom primitive to the Lisp interpreter.

Parameters
primitivePointer to the primitive implementation

Extends the embedded Lisp interpreter with custom functionality. Primitives provide the bridge between Lisp scripts and hardware or application-specific operations.

◆ addSystemListener()

template<typename... Topics>
ListenerId UniotCore::addSystemListener ( std::function< void(unsigned int, int)> callback,
unsigned int firstTopic,
Topics... otherTopics )
inline

Add a system event listener.

Parameters
callbackFunction to call when events occur
firstTopicFirst event topic to listen for
otherTopicsAdditional event topics to listen for
Return values
ListenerIdListener identifier for management operations

Registers a callback function to receive system events from multiple topics. The callback receives the topic and message for event handling.

◆ addWifiStatusLedListener()

ListenerId UniotCore::addWifiStatusLedListener ( std::function< void(bool)> callback)
inline

Add a WiFi status LED listener.

Parameters
callbackFunction to call when LED status changes
Return values
ListenerIdListener identifier for management operations

Convenience method for listening to WiFi status LED events. The callback receives a boolean indicating the desired LED state.

◆ begin()

void UniotCore::begin ( uint32_t eventBusTaskPeriod = 10)
inline

Initialize and start the Uniot platform.

Parameters
eventBusTaskPeriodEvent bus processing interval in milliseconds

Initializes all platform subsystems, applies configuration, and starts the main event loop. This method should be called once during setup.

◆ cancelTimer()

bool UniotCore::cancelTimer ( TimerId id)
inline

Cancel an active timer.

Parameters
idTimer identifier returned by set* functions
Return values
booltrue if timer was found and canceled, false otherwise

Stops and removes an active timer, preventing further executions. Similar to JavaScript's clearInterval() and clearTimeout() functions.

◆ configUser()

void UniotCore::configUser ( const String & user)
inline

Configure user identification.

Parameters
userUser identifier string for device association

Sets the user ID for device identification and association purposes. This identifier is used for device management and tracking within the Uniot ecosystem.

◆ configWiFiCredentials()

void UniotCore::configWiFiCredentials ( const String & ssid,
const String & password = "" )
inline

Configure WiFi network credentials.

Parameters
ssidNetwork SSID to connect to
passwordNetwork password (empty for open networks)

Sets the WiFi credentials for automatic network connection. The credentials are validated and stored persistently for use across device reboots.

◆ configWiFiResetButton()

void UniotCore::configWiFiResetButton ( uint8_t pinBtn,
uint8_t activeLevelBtn = LOW,
bool registerLispBtn = true )
inline

Configure WiFi reset button.

Parameters
pinBtnGPIO pin number for the reset button
activeLevelBtnActive logic level for button (LOW or HIGH)
registerLispBtnWhether to register button with Lisp interpreter

Configures a hardware button for WiFi network reset functionality. The button provides both manual reconnection (single press) and configuration reset (multiple rapid presses followed by long press).

◆ configWiFiResetOnReboot()

void UniotCore::configWiFiResetOnReboot ( uint8_t maxRebootCount,
uint32_t rebootWindowMs = 10000 )
inline

Configure automatic WiFi reset on repeated reboots.

Parameters
maxRebootCountMaximum reboots before triggering configuration reset
rebootWindowMsTime window for counting reboots in milliseconds

Enables automatic configuration reset when the device reboots repeatedly within a specified time window. This provides a recovery mechanism for devices that become unreachable due to network configuration issues.

◆ configWiFiStatusLed()

void UniotCore::configWiFiStatusLed ( uint8_t pinLed,
uint8_t activeLevelLed = HIGH )
inline

Configure WiFi status LED.

Parameters
pinLedGPIO pin number for the status LED
activeLevelLedActive logic level for LED (LOW or HIGH)

Configures a hardware LED for visual indication of WiFi connection status. The LED provides different blinking patterns for various connection states:

  • Fast blink: Error/alarm state
  • Medium blink: Connecting/busy state
  • Slow blink: Waiting/configuration mode
  • Brief flash: Connected/idle state

◆ createTask()

uniot::TaskScheduler::TaskPtr UniotCore::createTask ( const char * name,
uniot::SchedulerTask::SchedulerTaskCallback callback )
inline

Create a named task for custom scheduling.

Parameters
nameOptional name for the task (for debugging)
callbackFunction to execute when task runs
Return values
TaskPtrPointer to the created task for manual management

Creates a task that can be manually scheduled and managed. Provides direct access to the underlying task scheduler for advanced use cases.

◆ emitSystemEvent()

void UniotCore::emitSystemEvent ( unsigned int topic,
int message )
inline

Emit a system event.

Parameters
topicEvent topic identifier
messageEvent message identifier

Broadcasts an event to all registered listeners on the specified topic. Events are processed asynchronously through the event bus.

◆ enablePeriodicDateSave()

void UniotCore::enablePeriodicDateSave ( uint32_t periodSeconds = 5 * 60)
inline

Enable periodic saving of date/time information.

Parameters
periodSecondsInterval between saves in seconds (0 to disable)

Configures automatic persistence of date/time information to prevent time loss during device reboots. Useful for maintaining accurate timestamps when NTP synchronization is not always available.

◆ getActiveListenersCount()

int UniotCore::getActiveListenersCount ( ) const
inline

Get the number of active event listeners.

Return values
intCount of currently active listeners

Returns the current number of active event listeners for monitoring and debugging purposes.

◆ getActiveTimersCount()

int UniotCore::getActiveTimersCount ( ) const
inline

Get the number of active timers.

Return values
intCount of currently active timers

Returns the current number of active timers for monitoring and debugging purposes.

◆ getAppKit()

uniot::AppKit & UniotCore::getAppKit ( )
inline

Get access to the application kit.

Return values
AppKit&Reference to the application kit instance

Provides access to lower-level platform functionality for advanced use cases that require direct subsystem interaction.

◆ getEventBus()

uniot::CoreEventBus & UniotCore::getEventBus ( )
inline

Get access to the event bus.

Return values
CoreEventBus&Reference to the event bus instance

Provides direct access to the event bus for advanced event handling and custom event types.

◆ getScheduler()

uniot::TaskScheduler & UniotCore::getScheduler ( )
inline

Get access to the task scheduler.

Return values
TaskScheduler&Reference to the scheduler instance

Provides direct access to the task scheduler for advanced scheduling requirements and custom task management.

◆ isSystemListenerActive()

bool UniotCore::isSystemListenerActive ( ListenerId id)
inline

Check if a system listener is active.

Parameters
idListener identifier to check
Return values
booltrue if listener exists and is active, false otherwise

Determines whether a system event listener is currently registered and active.

◆ isTimerActive()

bool UniotCore::isTimerActive ( TimerId id)
inline

Check if a timer is currently active.

Parameters
idTimer identifier to check
Return values
booltrue if timer exists and is active, false otherwise

Determines whether a timer is currently scheduled for execution.

◆ loop()

void UniotCore::loop ( )
inline

Process scheduled tasks and events.

Executes one iteration of the main scheduler loop. This method should be called continuously from the main program loop to ensure proper system operation.

◆ publishLispEvent()

void UniotCore::publishLispEvent ( const String & eventID,
int32_t value )
inline

Publish an event to the Lisp interpreter.

Parameters
eventIDUnique identifier for the event
valueNumeric value associated with the event

Sends events from the application to the Lisp interpreter, enabling bidirectional communication and script-driven responses to system events.

◆ registerLispAnalogInput()

template<typename... Pins>
void UniotCore::registerLispAnalogInput ( uint8_t first,
Pins... pins )
inline

Register GPIO pins as analog inputs for Lisp access.

Parameters
firstFirst GPIO pin number
pinsAdditional GPIO pin numbers

Makes specified GPIO pins available to the Lisp interpreter as analog input pins, enabling script-based analog sensor reading.

◆ registerLispAnalogOutput()

template<typename... Pins>
void UniotCore::registerLispAnalogOutput ( uint8_t first,
Pins... pins )
inline

Register GPIO pins as analog outputs for Lisp access.

Parameters
firstFirst GPIO pin number
pinsAdditional GPIO pin numbers

Makes specified GPIO pins available to the Lisp interpreter as analog output pins (PWM), enabling script-based analog control.

◆ registerLispButton()

bool UniotCore::registerLispButton ( uniot::Button * button,
uint32_t id = FOURCC(_btn) )
inline

Register a button object with the Lisp interpreter.

Parameters
buttonPointer to the button instance
idFOURCC identifier for the button (default: _btn)
Return values
booltrue if registration was successful, false otherwise

Makes a button object available to the Lisp interpreter, enabling script-based button event handling and state monitoring.

◆ registerLispDigitalInput()

template<typename... Pins>
void UniotCore::registerLispDigitalInput ( uint8_t first,
Pins... pins )
inline

Register GPIO pins as digital inputs for Lisp access.

Parameters
firstFirst GPIO pin number
pinsAdditional GPIO pin numbers

Makes specified GPIO pins available to the Lisp interpreter as digital input pins, enabling script-based sensor reading.

◆ registerLispDigitalOutput()

template<typename... Pins>
void UniotCore::registerLispDigitalOutput ( uint8_t first,
Pins... pins )
inline

Register GPIO pins as digital outputs for Lisp access.

Parameters
firstFirst GPIO pin number
pinsAdditional GPIO pin numbers

Makes specified GPIO pins available to the Lisp interpreter as digital output pins, enabling script-based hardware control.

◆ registerLispObject()

bool UniotCore::registerLispObject ( const String & primitiveName,
uniot::RecordPtr link,
uint32_t id = FOURCC(____) )
inline

Register a generic object with the Lisp interpreter.

Parameters
primitiveNameName of the primitive to associate with the object
linkPointer to the object to register
idFOURCC identifier for the object
Return values
booltrue if registration was successful, false otherwise

Provides a generic mechanism for making application objects available to the Lisp interpreter through named primitives.

◆ removeSystemListener()

bool UniotCore::removeSystemListener ( ListenerId id)
inline

Remove a system event listener.

Parameters
idListener identifier returned by addSystemListener
Return values
booltrue if listener was found and removed, false otherwise

Unregisters a system event listener and cleans up associated resources.

◆ removeSystemListeners()

template<typename... Topics>
size_t UniotCore::removeSystemListeners ( unsigned int firstTopic,
Topics... otherTopics )
inline

Remove all listeners for specific topics.

Parameters
firstTopicFirst topic to remove listeners from
otherTopicsAdditional topics to remove listeners from
Return values
size_tNumber of listeners removed

Removes all active listeners that are subscribed to any of the specified topics. Useful for bulk cleanup operations.

◆ setImmediate()

TimerId UniotCore::setImmediate ( std::function< void()> callback)
inline

Execute a callback on the next scheduler cycle.

Parameters
callbackFunction to execute immediately
Return values
TimerIdTimer identifier for management operations

Schedules a callback for immediate execution on the next scheduler cycle. Similar to JavaScript's setImmediate() function.

◆ setInterval()

TimerId UniotCore::setInterval ( std::function< void()> callback,
uint32_t intervalMs,
short times = 0 )
inline

Create a repeating timer.

Parameters
callbackFunction to execute on timer expiration
intervalMsInterval between executions in milliseconds
timesNumber of times to execute (0 for infinite)
Return values
TimerIdTimer identifier for management operations

Creates a timer that executes the callback function at regular intervals. Similar to JavaScript's setInterval() function.

◆ setLispEventInterceptor()

void UniotCore::setLispEventInterceptor ( uniot::LispEventInterceptor interceptor)
inline

Set event interceptor for Lisp interpreter.

Parameters
interceptorFunction to intercept and process Lisp events

Configures a callback function to intercept events generated by the Lisp interpreter, enabling custom event processing and application-specific behavior.

◆ setTimeout()

TimerId UniotCore::setTimeout ( std::function< void()> callback,
uint32_t timeoutMs )
inline

Create a one-shot timer.

Parameters
callbackFunction to execute after timeout
timeoutMsDelay before execution in milliseconds
Return values
TimerIdTimer identifier for management operations

Creates a timer that executes the callback function once after the specified delay. Similar to JavaScript's setTimeout() function.

Member Data Documentation

◆ INVALID_LISTENER_ID

ListenerId UniotCore::INVALID_LISTENER_ID = 0
staticconstexpr

Invalid listener ID constant.

◆ INVALID_TIMER_ID

TimerId UniotCore::INVALID_TIMER_ID = 0
staticconstexpr

Invalid timer ID constant.


The documentation for this class was generated from the following file: