In this tutorial, you will learn how to create your custom nodes, namely:
We assume you have completed the following guides and reviewed the articles listed below:
In order to create new rule node, you should implement the TbNode interface:
package org.thingsboard.rule.engine.api;
...
public interface TbNode {
void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException;
void onMsg(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException, TbNodeException;
void destroy();
}
and annotate your implementation with the following multi-value annotation that refers to the runtime:
org.thingsboard.rule.engine.api.RuleNode
Also each rule node may have a configuration class that implement NodeConfiguration interface.
package org.thingsboard.rule.engine.api;
public interface NodeConfiguration<T extends NodeConfiguration> {
T defaultConfiguration();
}
Configuration classes defines in Rule node classes.
In this section, we explain the purpose of each implemented method from TbNode interface:
Method to initialize rule node after its creation. Body of init method for each above mention rule node is almost the same. We convert the incoming JSON configuration to the specific NodeConfiguration implementation.
It is invoked only after rule node creation or updating and takes two input parameters:
Method for processing received messages. It is invoked each time when messages arrive in the node. and also takes two input parameters:
TbMsg is a final serialized class that gives access to fields from the message and also allows you to copy the message, convert the message to ByteBuffer and other way round.
gives access to fields:
copy message:
true & false:
failure:
tellSelf and updateSelf methods:
Also, TbContext allow to create new message:
and transform message:
This method that invoked only after rule node stops or update and don’t have input parameters.
git clone git@github.com:thingsboard/rule-node-examples.git
Execute the following command from the rule-node-examples folder to build the project:
mvn clean install
Import jar-file to your Thingsboard project as dependency library, that should be here:
./target/rule-engine-1.0.0-custom-nodes.jar
NOTE if you have changed the package name from org.thingsboard.rule.engine to your company package name, e.g. com.example.rule.engine, you need also to add your package name in thingsboard.yml file in plugins section:
# Plugins configuration parameters
plugins:
# Comma separated package list used during classpath scanning for plugins
scan_packages: "${PLUGINS_SCAN_PACKAGES:org.thingsboard.server.extensions,org.thingsboard.rule.engine,com.example.rule.engine}"
Restart ThingsBoard server-side container. Please, refer to the following link to see how to do this: Running server-side container.
**Once ThingsBoard was restarted you need to clear browser cache and refresh the web page to reload UI of Rule Nodes**
sudo mv rule-engine-1.0.0-custom-nodes.jar /usr/share/thingsboard/extensions/
sudo chown thingsboard:thingsboard /usr/share/thingsboard/extensions/*
Restart Thingsboard service:
sudo service thingsboard restart
**Once ThingsBoard was restarted you need to clear browser cache and refresh the web page to reload UI of Rule Nodes**
The ThingsBoard rule nodes UI is configured with another project in the official github repo. Please, refer to the following link to see build instructions.
To run Rule Node UI container in hot redeploy mode:
cd ${TB_WORK_DIR}/ui-ngx/proxy.conf.js
second, you need to run UI container in hot redeploy mode. Please, refer to the following link to see how to do this: Running UI container in hot redeploy mode.
last step is to execute the following command from your local directory TB_RULE_NODE_UI_WORK_DIR:
npm start
Getting started guides - These guides provide quick overview of main ThingsBoard features. Designed to be completed in 15-30 minutes.
Installation guides - Learn how to setup ThingsBoard on various available operating systems.
Connect your device - Learn how to connect devices based on your connectivity technology or solution.
Data visualization - These guides contain instructions how to configure complex ThingsBoard dashboards.
Data processing & actions - Learn how to use ThingsBoard Rule Engine.
IoT Data analytics - Learn how to use rule engine to perform basic analytics tasks.
Hardware samples - Learn how to connect various hardware platforms to ThingsBoard.
Advanced features - Learn about advanced ThingsBoard features.