Plugin System

Plugin System

The plugins are an essential part of the Gateway, they allow users to:

  • Publish/Subscribe to datapoints
  • Query information from the realtime database
  • Preform any action with the previous information

So far they can be written in Rust and C, the Rust plugins serve as the recommended way to write plugins. The C plugins are used mostly for support of complex libraries that are not available in Rust.
Depending on the language, the implementation of a plugin may vary widely, but the general structure is the same. The core only supports the C ABI and every other language follows this ABI by implementing their own wrappers.
The SDK for each plugin can be found in the sdk directory.

What exactly can plugins do

Plugins may provide additional data sources, data sinks, or just data processing. The simple interface allow for a wide range of possibilities, here are some examples:

  • Data source: A plugin that reads data from a serial port and publishes it to the Gateway.
  • Data sink: A plugin that subscribes to data and writes it to a file.
  • Data processing: A plugin that subscribes to a datapoint containing voltage information, and calculates the Root Mean Square average over a certain period of time and publishes the result to a different datapoint.

High-Level Workflow

  1. Plugin Development: Developers create plugins by implementing the necessary traits and functions defined in the specific SDK.
  2. Plugin Loading: The runtime loads the plugin shared libraries using libloading and initializes the plugin instances.
  3. Interaction: The runtime Gateway interacts with the plugins through the defined ABI, allowing plugins to communicate using datapoints.
  4. Configuration: Plugins can access their configuration data using the provided JSON callbacks, ensuring they can be easily configured by users.
  5. Shutdown: When a plugin instance is no longer needed, the runtime Gateway calls the shutdown function to release resources and ensure a clean termination.

How to create a plugin

Each plugin should import it’s corresponding SDK and implement the required functions. In each plugin directory there is a script create_new_plugin.sh that can and should be used to create new plugins, this script will create the necessary files and directories for the plugin to be built.
This is an example of how to create a Rust plugin but all the other languages follow the same convention:

⚠️

If creating a C plugin manually, do to not copy the SDK directly and link it instead.

ln -s ../../sdk/c <plugin_name>/gridcore

This will ensure that changes to the ABI are reflected in the plugin and thus tests can be run to ensure compatibility.

SDK Documentations