This is part 2 of the article about putting Node-RED on OKI's gateway product called "AI Edge Computer" called AE2100 to make it a low-code IoT platform, ** Docker for low-code IoT platform construction **. I will.
Part 1 Preparation for RS-485 simulator with Python Part 2 Building a low-code IoT platform with Docker ** (this article) ** Part 3 Low Code IoT Practice with Node-RED 1 Dashboard Creation Part 4 Low Code IoT Practice with Node-RED 2 MQTT Pub / Sub
In the previous article, I wrote an RS-485 simulator in Python that runs on a Windows 10 PC. This time, we will finally launch Node-RED on the AE2100. As for the content, it is mostly Docker work.
Create a Dockerfile and hit the Docker command several times to launch Node-RED on the AE2100.
Create a Docker image with Node-RED installed in ❷ in the figure.
Log in to AE2100 with SSH and work on Bash.
Dockerfile
A Dockerfile that creates an image of a Docker container that runs on the AE2100. This is all you need.
Dockerfile
FROM nodered/node-red:1.1.3-minimal
USER root
RUN apk add python3 make g++ linux-headers
RUN npm install node-red-node-serialport node-red-dashboard
Regarding the contents of this file, first specify the base image with the FROM instruction as the minimum image 1.1.3-minimal of nodered / node-red in Docker Hub. Then, as root in this Alpine Linux-based image, ** apk add ** the following four packages needed to build the Node-RED serial communication driver.
Finally, ** npm install ** the following two Node-RED libraries needed for this work.
** node-red-node-serialport ** is a library for using RS-485 with Node-RED on AE2100 this time. As the name implies, this library is a library that adds serial communication functions such as RS-232C / RS-485 / RS-422 to Node-RED. Normally, it is a library often used for RS-232C communication, but it could be used with RS-485 without any problem (I have not tried multi-drop).
** node-red-dashboard ** is a library for creating simple dashboards with Node-RED. It is very popular and is updated frequently. The versions at the time of writing were 3.23.3 and 0.11.0, respectively.
You can install these two libraries after Node-RED starts up, but since it is required this time, it will be included in the image.
Now let's build the image on the AE2100. Execute the following in the directory where the above Dockerfile is located.
AE2100-Shell
# docker build --tag node-red_v1:appf .
:
Successfully built 3691865b0133
Successfully tagged node-red_v1:appf
When the build of the C ++ module of node-red-node-serialport starts, a lot of logs in red are output, but it should be okay if "Successfully build ..." is displayed. You now have an image with the tag name "node-red_v1: appf". Various additions have been made to the official Minimal image of 194MB, bringing the total image to 441MB. .. .. But for the AE2100 with a 32GB eMMC, there's still plenty of room.
It's the launch of the container! Make port 1880 to access Node-RED and port 1883 for MQTT available in the container as they are. The device file for RS-485 on the AE2100 is / dev / ttyRS485. This will also be used in the container as it is. Then volume mount the /home/root/.node-red directory of the AE2100 host to / data of the container so that the Node-RED configuration files and flows are stored in the file system on the AE2100 host side. Node-RED flows and libraries are updated frequently.
# docker run -it -p 1880:1880 -p 1883:1883 --device=/dev/ttyRS485:/dev/ttyRS485 -v /home/root/.node-red:/data --name node-red-1 node-red_v1:appf
> [email protected] start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"
8 Sep 23:27:27 - [info]
Welcome to Node-RED
===================
8 Sep 23:27:27 - [info] Node-RED version: v1.1.3
8 Sep 23:27:27 - [info] Node.js version: v10.22.0
8 Sep 23:27:27 - [info] Linux 4.14.67-intel-pk-standard x64 LE
8 Sep 23:27:27 - [info] Loading palette nodes
8 Sep 23:27:29 - [info] Dashboard version 2.23.3 started at /ui
8 Sep 23:27:29 - [info] Settings file : /data/settings.js
8 Sep 23:27:29 - [info] Context store : 'default' [module=memory]
8 Sep 23:27:29 - [info] User directory : /data
8 Sep 23:27:29 - [warn] Projects disabled : editorTheme.projects.enabled=false
8 Sep 23:27:29 - [info] Flows file : /data/flows.json
8 Sep 23:27:29 - [info] Creating new flow file
8 Sep 23:27:29 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
8 Sep 23:27:29 - [info] Server now running at http://127.0.0.1:1880/
8 Sep 23:27:29 - [info] Starting flows
8 Sep 23:27:29 - [info] Started flows
Did you get up without any errors? Would you like to check with the Docker command?
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
122cd69c5b65 node-red_v1:appf "npm start --cache /…" 15 seconds ago Up 14 seconds (health: starting) 0.0.0.0:1880->1880/tcp, 0.0.0.0:1883->1883/tcp node-red-1
It seems to be working with the name "node-red-1" specified by the "--name" option at runtime.
Now let's connect to this Node-RED with a web browser on your PC. The URL looks like this:
http://IP address of AE2100:1880
You should see the familiar flow editor.
Looking at the network palette, three nodes are added at the bottom: "** serial in ", " serial out ", and " serial request **". The node-red-node-serialport library installed by the RUN instruction described in the Dockerfile.
Even in the Minimal image, there are MQTT and WebSocket nodes, which is truly Node-RED. Is it natural because it is a low-code IoT development platform?
The bottom of the palette ** dashboard ** is also the nodes of the library ** node-red-dashboard ** installed in the Dockerfile.
As I explained a little earlier, this makes it really easy to create a little dashboard, it can also be used for debugging support, and it is an indispensable external library.
This completes the AE2100 low-code IoT development platform! Once Node-RED is launched, I can't explain it to anyone who has experience with Node-RED anymore, but since it's a big deal, I decided to write a simple IoT-like practical article for Node-RED beginners. .. First, create an application that captures sensor data from the RS-485 simulator and displays it on a simple dashboard on a web browser.
Recommended Posts