TMCnet Feature Free eNews Subscription
May 13, 2019

IBM Cloud: Creating an IoT App for Monitoring Remote Machines\Servers



It is not as difficult to create an IoT application for IoT as you might think. This post describes how you can set up an IBM (News - Alert) Cloud workspace by creating a sample application for monitoring remote servers or managing a distributed network.



What technologies are required to get started?

  • IBM Cloud
  • Node-RED
  • Twilio (News - Alert) - SMS messaging service
  • Mobile phone number and phone itself for receiving SMS notifications
  • Basic knowledge of JavaScript

Let’s call our app - PingOK. The main function of this application is observing the status of machines by monitoring network and machine ports. If the machine fails, the application notifies the operator via an SMS message. Applications of this type are very useful for a wide range of technical workers, data center operators, engineers who need to remotely control servers or distributed computer networks. I must note that this is going to be a demo version, that is, its goal it to show the capabilities of the system.

Creating an application on the IBM Cloud platform based on Node-RED

1. Log in to the system using your IBM Cloud account or register to create a free account. Make sure the dev section\space is created.

2. Open your profile page and make sure that the active region is configured correctly. You need to deploy your own application in one of the existing IBM Cloud regions, the choice of region does not matter much. In my case, I selected United Kingdom.

3. Look for and choose the Node-RED Starter service in the catalog.

4. Type in a unique name for the application and click Create. Wait for the message: Your application was started. If you get an error message like Lost connection to server, then you should make sure that you are using an HTTPS connection.

Creating a two-node app

Here we start working with Node-RED by creating a simple two-node application.

1. Open the URL for your IBM Cloud application and click Go to your Node-RED flow editor. The flow editor consists of a blank sheet in the center and several available nodes on the left.

2. Find the node called Inject (in the Input section). Drag it to the sheet. This node features a button that is going to send a time stamp to the connected nodes.

3. Then find the Debug node (in the Output section). Put it next to the Inject node. This node will help to show incoming messages on your app's Debug tab.

4. Connect the Inject node (output port) with the Debug node (input port). The timestamp messages of the Inject node will be sent to the Debug node. At the same time, the Debug node displays the text msg.payload (timestamp).

5. Now deploy the Node-RED by clicking the Deploy button in the upper right corner.

Adding a custom node

At this stage, you should add the Ping node to the palette.

1. In the Node-RED editor, select Manage Palette from the upper right menu.

2. Click the Install tab.

3.  Locate the node-red-node-ping.

4. Click the Install button.

5. Press Done and return to the Node-RED editor. The Ping node is now added to your palette.

Adding a Ping node to the flow

1. Drag the Ping node to the sheet.

2. Edit new node settings by double-clicking on it.

3. In the Target (News - Alert) field put in the IP address of the machine, you want to monitor. Specify a short name for this node, for example, PingMyMachine1. After that, click Done.

3. Connect the Debug node with the Ping node output in order to observe its output.

4. Now you can deploy the Node-RED app with all nodes that are currently defined. (You can find Debug messages on the Debug tab in the right pane of the window).

Checking ping replies

If the ping request passes successfully, the Ping node returns the duration of its passing in the msg.payload. If no response is received from the server within 5 seconds, this node returns false. To check the msg.payload value, you can configure the Function node.

1. Locate the Function section in the palette and move the Function node close to the Ping node on the sheet.

2. Connect the Ping node (output) to the Function node (input).

3. Double-tap this node and edit its settings. Change the Name field, to something like Alive?

4. Add the following code:

msg.tripTime = msg.payload; msg.payload = msg.payload! == false? “Server alive”: “Server down”; return msg;

4. Click Done. Now the Function node will get you the Server alive if it receives a response within 5 seconds, and Server down if your server is unavailable.

5. Since you most likely do not want to receive several SMS messages every minute, you can add a node the will handle exceptions.

a. Add the Report by Exception node to the sheet.

b. Double-click this node and click the block unless value changes option. Now messages will not be received until the msg.payload property changes.

c. Put Send once in the Name field for this node.

d. Press Done.

Configure Twilio to send SMS

At this stage, almost everything is ready, all that remains is to add the Twilio node to the application flow.

1. Copy your Twilio number and other credentials from your Twilio account.

a. Open the Twilio page.

b. Click Get your first Twilio Number. Copy this SMS number to a text file.

c. Click Choose this Number.

d. On the right side of the Twilio page, locate and click a link called Show API Credentials. Copy the ACCOUNT SID and AUTH TOKENT to a text file.

3. In your flow editor, select the Twilio node in the Output section and move it to your sheet.

4. Now configure the Twilio node settings by double-clicking it.

a. Select the External Service from the Service field.

b. Open the Add new Twilio-api config node dialog box (by clicking the small Edit button).

c. Add the earlier copied account SID, the auth token, and the SMS phone number into this dialog box.

d. Press Add and return to the Edit dialog box.

e. Add your personal phone number to the SMS to field.

5. Change the Name field to something like Alert Admin and click Done.

6. Press Deploy in the flow editor.

Deploying the Node-RED App

Just click Deploy in the flow editor.

All is done. Now you can use the application to monitor your server.

Summary

You have learned how to use standard and custom nodes in a single flow as well as how to configure them correctly, specifying your mobile phone for SMS-notifications. Now you can create apps with IBM Cloud, Node-RED, and Twilio. Please mind that monitoring remote servers you may also need a VPN service. VPNs secure your connection by tunneling and encrypting all traffic.



» More TMCnet Feature Articles
Get stories like this delivered straight to your inbox. [Free eNews Subscription]
SHARE THIS ARTICLE

LATEST TMCNET ARTICLES

» More TMCnet Feature Articles