1.9. Next Steps with the Dev Kit: Using your own Flow

Once you’re comfortable with the Node-RED example flow that ships with the Gateway, you may want to replace it with your own flow. This section will detail how to remove the Dev Kit flow and configure your own flow.

This section starts with an overview of how Node-RED is organized and run on the Gateway. After that, we will discuss removal of the example flow and configuration of a custom flow from two perspectives:

  • working directly with a Gateway with commands like ssh and scp, and
  • building an image with Yocto that has the flows baked in as layers.

1.9.1. Organization of Node-RED

Out of the box, a Vesta Gateway will run Node-RED when it boots up. This service is run out of the file /etc/init.d/node-red. To start or stop the service manually, log in to the Gateway and run the command

# /etc/init.d/node-red COMMAND

(replacing COMMAND with start, stop or restart)

This service runs Node-RED with a settings file located at /usr/share/node-red/settings.js, a log file at /var/log/node-red/node-red.log, and a flow file at /usr/share/node-red/dev-kit.json.

1.9.2. Removing Node-RED completely

1.9.2.1. Direct Perspective

To remove the Node-RED service from the startup sequence, first log in to the Gateway, then run the command

root@B014012917-00065:~# update-rc.d -f node-red remove
update-rc.d: /etc/init.d/node-red exists during rc.d purge (continuing)
 Removing any system startup links for node-red ...
  /etc/rc0.d/K20node-red
  /etc/rc1.d/K20node-red
  /etc/rc2.d/S99node-red
  /etc/rc3.d/S99node-red
  /etc/rc4.d/S99node-red
  /etc/rc5.d/S99node-red
  /etc/rc6.d/K20node-red

To replace the service in the runlevels, run the command

root@B014012917-00065:~# update-rc.d -v node-red stop 20 0 1 6 . start 99 2 3 4 5 .
 Adding system startup for /etc/init.d/node-red.
  /etc/rc2.d/S99node-red -> ../init.d/node-red
  /etc/rc3.d/S99node-red -> ../init.d/node-red
  /etc/rc4.d/S99node-red -> ../init.d/node-red
  /etc/rc5.d/S99node-red -> ../init.d/node-red
  /etc/rc0.d/K20node-red -> ../init.d/node-red
  /etc/rc1.d/K20node-red -> ../init.d/node-red
  /etc/rc6.d/K20node-red -> ../init.d/node-red

1.9.2.2. Yocto Perspective

These instructions will demonstrate how to remove the Node-Red init script from starting on boot in the vesta-developer-image. To create a custom layer, follow the instructions under the section Creating a Custom Yocto Layer in the following document Build Your Own Image. Once this step has been completed, follow the instructions below to remove the startup script from the build.

To begin, remove the recipes-vesta-custom folder. The changes being made will only affect the vesta-developer-image and not the vesta-custom-image. Execute the following command:

user@ubuntu:~/vesta-gateway-bsp/sources# rm -rf meta-vesta-custom/recipes-vesta-custom/

The folder structure should look like this:

meta-vesta-custom/
└── conf
    └── layer.conf

Create the following folder structure executing the make directory command below:

user@ubuntu:~/vesta-gateway-bsp/sources# mkdir -p meta-vesta-custom/recipes-core/node-red-init

Inside of this folder, create a file named node-red-init-script_1.0.bbappend and add the following line to it. This line will disable the node-red startup script:

INITSCRIPT_PARAMS = ""

The folder structure should now look like this:

meta-vesta-custom/
├── conf
│   └── layer.conf
└── recipes-core
    └── node-red-init
        └── node-red-init-script_1.0.bbappend
To create the modified image, execute the following:
user@ubuntu:~/vesta-gateway-bsp/build# bitbake vesta-image-developer

To install this new image on the Rigado Gateway, follow the instruction outlined in Installing a Development Build using USB.

1.9.3. Replacing the Flow file

1.9.3.1. Direct Perspective

To remove the existing flow, open the Node-RED instance in your browser, select the nodes and delete them. Pres Deploy to make sure the change is saved to the flow file on disk.

If you already have a flow file in JSON format that you’d like the Gateway to run, open the Node-RED instance in your browser and import the flow JSON using the Clipboard feature:

../_images/devkit-clipboard.png

Figure 1.11 Opening the Clipboard import feature

../_images/devkit-import-paste.png

Figure 1.12 The dialog in which to paste your JSON flow code

Alternately, you could send your flow file to the Node-RED library on disk. This would enable you to select that flow from the Library feature any time you want.

Save your flow JSON file to the directory /var/node-red/lib/flows/. Reload the page and you should see your flow files in the Library menu:

../_images/devkit-library.png

Note

The directory /var/node-red/ is the “Node-RED user directory”, and this value was configured in the Node-RED settings file at /usr/share/node-red/settings.js.

To Export flows, select the nodes you’d like to export, and use the menu to select either Clipboard or Library.

Note

Remember to click Deploy after importing changes to your flow, to make sure the changes get saved to the flow file on disk!

1.9.3.2. Yocto Perspective

These instructions will demonstrate how to replace the dev-kit.json flow from the vesta-developer-image and replace it with a Node-Red custom flow called my_custom_flow.json. To create a custom layer, follow the instructions under the section Creating a Custom Yocto Layer in the following document Build Your Own Image. Once this step has been completed, follow the instructions below to to replace the dev-kit.json with a file called my_custom_flow.json.

To begin, remove the recipes-vesta-custom folder. The changes being made will only affect the vesta-developer-image and not the vesta-custom-image. Execute the following command:

user@ubuntu:~/vesta-gateway-bsp/sources# rm -rf meta-vesta-custom/recipes-vesta-custom/

The folder structure should look like this:

meta-vesta-custom/
└── conf
    └── layer.conf

Create the following folder structure executing the make directory command below:

user@ubuntu:~/vesta-gateway-bsp/sources# mkdir -p meta-vesta-custom/recipes-nodered-addons/node-red-noble/files

Inside of the folder meta-vesta-custom/recipes-nodered-addons/node-red-noble, create a file named rigado-devkit.bbappend and add the following lines to it. This will remove the dev-kit.json file and add the file my_custom_flow.json:

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += "file://my_custom_flow.json"

do_install_append() {
    rm ${D}${datadir}/node-red/dev-kit.json
    install -m 644 ${WORKDIR}/my_custom_flow.json ${D}${datadir}/node-red
    chown -R ${NODERED_USER}:${NODERED_GROUP} ${D}${datadir}/node-red/my_custom_flow.json
}

Next copy the file my_custom_flow.json into the folder meta-vesta-custom/recipes-nodered-addons/node-red-noble/files.

The folder structure should look like this:

meta-vesta-custom/
├── conf
│   └── layer.conf
└── recipes-nodered-addons
    └── node-red-noble
        ├── files
        │   └── my_custom_flow.json
        └── rigado-devkit.bbappend
To create the modified image, execute the following:
user@ubuntu:~/vesta-gateway-bsp/build# bitbake vesta-image-developer

To install this new image on the Rigado Gateway, follow the instruction outlined in Installing a Development Build using USB.

1.9.4. Adding Nodes to Node-RED

1.9.4.1. How to Add a Node to Node-RED from the Command Line

To install a Node-RED node from the command line, issue the command npm install --global package-name. For example, to install node-red-aws-tools issue the following commands:

root@B013012517-00005:~# npm install --global node-red-aws-tools
root@B013012517-00005:~# /etc/init.d/node-red restart

After Node-RED has restarted, redirect your browser to the Node-RED server running on the Rigado Gateway. To view the newly installed node, select the Manage palette from the menu icon on the top right hand corner of the web page. Under the Nodes tab of the Manage palette, node-red-aws-tools will now show up in the list of installed nodes.

1.9.4.2. How to Enable Installing Nodes from the Node-RED Web Page

In order to install nodes from the Node-RED web interface, the user will need to change the permissions on how Node-RED is started up on the gateway. The developer image for the gateway has the user for Node-RED set to nobody. This prevents users of the Node-RED web interface from installing nodes. In order for the user to install nodes from the web interfaces, the Node-RED server will need to be started as the root user. It is bad practice to run web-facing interfaces as the root user. However, to enable this ability for rapid prototyping, change the USER=nobody to USER=root in the file /etc/init.d/node-red and reboot the gateway. After the gateway has rebooted, redirect your web browser to the Node-RED web page and select Manage palette from the menu button in the top right hand corner of the web page. From the Manage palette side bar, the user will now be able to install new nodes. Again, running the Node-RED server as a root user should only be used for rapid prototyping.