Difference between revisions of "IEdge NodeRED iAlarm Sample"
Line 2: | Line 2: | ||
== Introduction == | == Introduction == | ||
− | This document will introduce a NodeRed sample code for user define their own alarm flow and message in iEdge. In this example, | + | This document will introduce a NodeRed sample code for user define their own alarm flow and message in iEdge. In this example, iEdge use Modbus-Master plugin to collect sensor data, and if the status sensor returns 0 which means device does not any abnormal, other wise, sensor returns error code. We use NodeRed to design a work flow that will send corresponding error message which depends on the error code. |
[[File:IEdge NodeRed 1 Example Code.png|center|IEdge NodeRed 1 Example Code.png]] | [[File:IEdge NodeRed 1 Example Code.png|center|IEdge NodeRed 1 Example Code.png]] | ||
− | + | == == | |
== Set Global Variable == | == Set Global Variable == | ||
Line 12: | Line 12: | ||
To avoid a large number of notifications in a short period of time, this sample code adds a variable to record previous error code. If sensor returns error code, NodeRed will send alarm once and will not notify again if getting the same code with previous time again. | To avoid a large number of notifications in a short period of time, this sample code adds a variable to record previous error code. If sensor returns error code, NodeRed will send alarm once and will not notify again if getting the same code with previous time again. | ||
− | Get a inject node and enable Inject once at start for initialing, get a function node and | + | Get a inject node and enable Inject once at start for initialing, get a function node and declare a global variable with initial value 0 for recording previous error code. |
− | <pre>context.global.ex_Err_Code=0;</pre> | + | <pre>context.global.ex_Err_Code = 0;</pre> |
[[File:IEdge NodeRed 2 Set Golbal Variable.png|center|IEdge NodeRed 2 Set Golbal Variable.png]] | [[File:IEdge NodeRed 2 Set Golbal Variable.png|center|IEdge NodeRed 2 Set Golbal Variable.png]] | ||
+ | |||
+ | == == | ||
== Get Data From MQTT == | == Get Data From MQTT == | ||
− | + | At the begining, NodeRed has to get status sensor data, due to Modbus-Master plugin will collect sensor data to MQTT Broker on gateway, therefore, NodeRed can subscribe corresponding topics from MQTT to get the raw data of specific plugin. | |
+ | |||
+ | Get a MQTT Node then set Topic to '''/cagent/admin/# '''and QoS to 1, click edit icon and set Server IP to gateway IP with 1883 port number. | ||
+ | |||
+ | [[File:IEdge NodeRed 3 Get Data from MQTT.png|center]] | ||
== Filter Modbus-Master Data == | == Filter Modbus-Master Data == | ||
+ | |||
+ | | ||
== Filter Sensor Data == | == Filter Sensor Data == |
Revision as of 09:10, 26 December 2022
Contents
Introduction
This document will introduce a NodeRed sample code for user define their own alarm flow and message in iEdge. In this example, iEdge use Modbus-Master plugin to collect sensor data, and if the status sensor returns 0 which means device does not any abnormal, other wise, sensor returns error code. We use NodeRed to design a work flow that will send corresponding error message which depends on the error code.
Set Global Variable
To avoid a large number of notifications in a short period of time, this sample code adds a variable to record previous error code. If sensor returns error code, NodeRed will send alarm once and will not notify again if getting the same code with previous time again.
Get a inject node and enable Inject once at start for initialing, get a function node and declare a global variable with initial value 0 for recording previous error code.
context.global.ex_Err_Code = 0;
Get Data From MQTT
At the begining, NodeRed has to get status sensor data, due to Modbus-Master plugin will collect sensor data to MQTT Broker on gateway, therefore, NodeRed can subscribe corresponding topics from MQTT to get the raw data of specific plugin.
Get a MQTT Node then set Topic to /cagent/admin/# and QoS to 1, click edit icon and set Server IP to gateway IP with 1883 port number.
Filter Modbus-Master Data
Filter Sensor Data
Define Alarm Message
Publish Alarm to MQTT