Publishing an Alert

Publishing an Alert from Node-RED in Raspberry Pi

In this example, we will show you how to publish an Alert from your Raspberry Pi Node-Red application.

If you have not done so, start at 1. Create a Device Client, if you have, continue to 2. Create an Alert

NOTE: One Node-Red device client is sufficient for cloud communication in Data Streams, Alerts, and Actions.

1.Create a Device Client:

From the side navigation tab of the device page, click on Create Client. Set the name as Node-RED (or any publishing client). Save the Client ID and the Password in a secured location. To learn more go to What is a Client?

2.Create an Alert Channel:

Navigate to the Alerts tab. Tap on Alert Channels and create a channel (to learn more go to Creating an Alert Channel).

Tap on the gear icon next to the alert channel and go to Manage Alert Channel Notifications. Set your personal preferences for receiving an alert from this channel (Go to Managing Alert Channel for details). Note that to receive a text message, you should verify your phone number first, which can be done in the Profile Button on the top right side of the screen.

3.Connect to Node-RED on your Raspberry Pi:

From the side navigation tab of the device page, activate the Node-RED Connection, and connect to Node-RED.

Activate Node-Red Remote Access
Connect to Device Node-Red Remotely

Once you click on the Node-Red Connect, you will be routed to the Node-Red page. The default credentials are:

  • username: admin

  • password: password

IMPORTANT: We strongly recommend that you change the username and password

To change Node-Red credentials, click on the Credentials button on the device page.

4.Configure Alert Channel Node in Node-RED:

From the nodes in the left navigation bar, drag and drop the alert channel out node. Go to Downloading IoTFlows Node-Red Nodes for installing instructions.

Double-click on the alert channel out node, and then double click on the edit button.

Here we will add the device client that will be used to publish your data.

NOTE: If you have previously configured any nodes with your Client Id and Password, your node should already be configured, if not you need to add your Client Id and Password by clicking the edit button in the Server row

For more information on setting up a client go to Creating a Device Client.

Your device client should now be displayed as your server.

Next, we will click the refresh button in the Topic and select the Alert Channel that we will like to publish to.

Once everything is complete, click Done.

Publish an Alert from Node-RED:

  • Drag and drop an inject node.

  • Drag and drop a function node.

  • Connect the inject to function to alert channel out node, respectively.

  • Double-tap the function node and write this code:

msg.payload =
{
"severity_level": "MAJOR",
"subject": "An alert subject",
"description": "Description of the alert",
};
return msg;

Severity levels could be the following

  1. MAJOR

  2. MINOR

  3. INFORMATIVE

Important: Alert severities need to be CAPITALIZED when publishing. Failure to do so will result in you not receiving alert notifications, as well as not being able to filter results properly.

From the top right corner of Node-RED, tap Deploy.

Tap the button of the inject node and you should receive an alert based on your alert channel notification preference!