How do I connect my BB-400 to FRED?

FAQs

Cloud computing is the process by which information can be sent back and forth over the Internet using a variety of different “pay-as-you-go” cloud services. The BB-400 is compatible with a number of cloud services, and this FAQ will explore one of these options: FRED.

For more information regarding the other cloud services please refer to the FAQ What Cloud services are available on the BB-400?

What is FRED?

Front End for Node-RED, or FRED, is a cloud service that manages Node-RED instances. It has been independently developed by Sense Tecnic, an IoT solutions provider.

It is possible to connect the BB-400’s Node-RED instance to FRED and as Node-RED is already set up on the BB-400 by default, FRED is a great method to connect your device to the cloud.

FRED Setup

Sign up for a Sense Tecnic account: https://users.sensetecnic.com/app/services.

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-function-account-registration.png

Complete the user registration, select a plan, and create an account.

You will receive an email in order to verify your account, after this you can login to Sense Tecnic.

After verification you will arrive at this screen and clicking on FRED will load up the FRED Node-RED instance.

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-initial-screen.png

Clicking on “Start Instance” will begin FRED.

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-initial-node-red-screen.png

You will be presented with a default flow and a few examples.

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-node-red-default-flow.png

FRED short features

In this example we are using FRED short, the free account on offer. FRED short includes a number of different features that will be explained briefly here.

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-features.png

  1. The timer shows how long you have been running the FRED instance for. There is a 24 hour running time provided and after the 24 hours have been exceeded your flows will stop and you will have to log back in to FRED to restart your flows.
  2. An API key is provided for secure connections.
  3. A maximum of 50 nodes are available to use.
  4. FRED manages the nodes available to users and only allows installation of nodes that have been tested. There are a range of different nodes available, and they can be found by clicking on “Add and Remove nodes”.

BB-400’s Node-RED application

You can open up your Node-RED application by navigating to the webadmin page “https://BB-400-IP-Address:9090”, selecting apps and then opening up your Node-RED application. You will notice the the BB-400’s Node-RED instance comes with a “Cloud Connectors” flow as well as the FRED nodes installed by default: input files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-input-node.png and output files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-output-node.png.

You can use the Cloud Connectors flow to connect to FRED straightaway just by adding your FRED credentials to the FRED nodes and disconnecting the other cloud service nodes.

If you require more information configuring your BB-400’s Node-RED instance then the following sections will explain the setup in greater detail.

Setup BB-400’s Node-RED

Example: sending IO status from BB-400’s Node-RED to FRED using WebSocket

In this example we will set up a Node-RED flow on our BB-400’s Node-RED instance to send the IO status to FRED using WebSocket.

Firstly, within the BB-400’s Node-RED instance, drag a WebSocket input node files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-websocket-input-node.png
and adjust it so the Type is “Connect to” and the URL is “ws://localhost:8989”, where 8989 is the port number of WebSocket. You can give this node a name for example: WS READ IO Lines:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-websocket-input-node-configuration.png

Next, we need to use a JSON node files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-json-node.png (this can be found under function nodes) to convert the IO status to a JSON message. Connect this node to the WebSocket in node.

When dealing with multiple WebSocket nodes, we need to ensure that the msg._session property is removed from the message. This is important with the FRED nodes, as they are WebSocket nodes. So in order to ensure that we send only the required message properties, we need to use a change node files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-change-node.png, found under the function nodes, to delete the msg._session property from the msg.payload.

Without deleting the msg._session property the WebSocket node will not process the message properly and we will not see the message being sent from and/or to the BB-400’s Node-RED instance and FRED.

The change node should be configured as follows:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-change-node-configuration.png

Next, add a FRED output node files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-output-node.png and connect it to the change node. When you double-click on the FRED node the configuration should look like this:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-out-config.png

You can think of the endpoint as being an ID used to connect the FRED node on your BB-400’s Node-RED instance, i.e. the client, to the specified FRED endpoint. When we create the FRED workflow in the next section, you will see that whatever you use as the endpoint on the client’s Node-RED needs to be the same on FRED’s Node-RED so that both instances can communicate with one another.

Click on the pencil next to endpoint to add your username. In order to set up a secure connection you can use the FRED API key (located on the left-hand side of FRED Node-RED) as an endpoint. Connect this node to the JSON node:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-out-config-api.png

Finally, we need to add a debug node files/pages/support/faqs/bb-400-faqs/Node-REDapp-watson-debug-node.png and connect it to the JSON node, so we can read the output from the flow.

Example: Receive events from FRED

Now we also need to set up a flow so that we can receive the events from FRED. We can add these nodes to the same workspace we created above.

We will start with a FRED input node files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-input-node.png and give it the same endpoint as our FRED output node from the previous example. We will then add a JSON node and set the Action to “Always convert to JSON String”, as you can see below:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-json-node-configuration.png

Next, as explained in the previous section, we are required to delete the msg._session property. We can achieve this by using a change node files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-change-node.png and configure it as shown:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-change-node-configuration.png

Then we will use a WebSocket output node to set the IO outputs:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-websocket-output-node-configuration.png

Attach this to the change node, and finally add a debug node files/pages/support/faqs/bb-400-faqs/Node-REDapp-watson-debug-node.png

Complete BB-400 Node-RED flow

Now your workspace should look similar to the BB-400’s Node-RED Cloud Connectors flow:

files/pages/support/faqs/bb-400-faqs/CompleteFlow_updated_with_delete_msg_session.png

You will notice that the default flow above includes nodes for Amazon Web Services and IBM cloud. In order to use just FRED, please delete the other 2 cloud service nodes.

FRED Setup

Now we need to setup FRED so that we can receive the messages being sent from the BB-400’s Node-RED, and also so that we can send messages to the BB-400.
Navigate to your FRED account and create a new flow by clicking on the plus sign at the top of the page.

Receive IO status data from the BB-400

This example will show how we can receive the IO status that is being sent from the BB-400’s Node-RED.

This requires just 2 nodes. First we need to add a FRED input node:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-in-config.png

and use the same endpoint that we gave the FRED output node on the BB-400’s Node-RED.

Finally we will add a debug node so we can read the output and connect the 2 nodes together:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-send-io-status-fred-complete-flow.png

Send data from FRED to the BB-400 to adjust the IO status

Now we will send a message from FRED to adjust the BB-400’s IO state.
Within the same flow you created in the previous example, drag an inject node files/pages/support/faqs/bb-400-faqs/Node-REDapp-watson-inject-node.pngonto the workspace. Edit the node to use a payload. The message will be a JSON array of 8 outputs:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-inject-node-configuration.png

Now we need to send the message using a FRED output node: files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-output-node.png

Click deploy: files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-deploy.png

If you click on the inject node on FRED, you will see the IO LEDs on the front of your device change state.

You will see the message has been sent from FRED’s Node-RED instance and received on your BB-400’s Node-RED instance:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-node-output.png

The FRED in node on FRED has also received the message:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-receive-message-from-bb-400.png

You can also see the change in state on the IO webadmin page:

files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-webadmin-adjusting-io-lines.png

FRED Flow JSON code

Below is the JSON for the flow we created in FRED. You can copy and paste it into your FRED instance by clicking on Import > Clipboard:

files/pages/support/faqs/bb-400-faqs/Node-REDapp-import-flow.png

[
    {"id": "519ae52.0cb781c", "type": "tab", "label": "Flow 1", "disabled": false, "info": ""},
    {"id": "e799ee8f.e7c31", "type": "fred in", "z": "519ae52.0cb781c", "name": "FRED in", "server": "94fcb675.b530b8", "client": "", "x": 140, "y": 120, "wires": [["b5a6b2f9.eb8a5"]]},
    {"id": "b5a6b2f9.eb8a5", "type": "debug", "z": "519ae52.0cb781c", "name": "From BB-400", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 530, "y": 120, "wires": []},
    {"id": "43e449b3.627b08", "type": "fred out", "z": "519ae52.0cb781c", "name": "", "server": "94fcb675.b530b8", "client": "", "x": 560, "y": 260, "wires": []}
    {"id": "aa66b7bf.a70868", "type": "inject", "z": "519ae52.0cb781c", "name": "Adjust IO Status", "topic": "","payload": "[0,1,1,0,1,1,1,0]", "payloadType": "json", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 260, "wires": [["43e449b3.627b08"]]},
    {"id": "94fcb675.b530b8", "type": "fred-server", "z": "", "endpoint": "", "private": true, "wholemsg": "false"}
]

In this FAQ we have learnt how to set up a FRED account, installed FRED nodes on the BB-400’s instance of Node-RED, sent the IO status from the BB-400 to FRED, and sent a message from FRED to toggle the IO state on the BB-400.

FAQs