NODE-REDでIoT インストール編

三菱のPLCのデータをオンラインで収集する目的で、いろいろ探していたところ、NODE -REDでmodbusプロトコルとMCプロトコルが使用できるということで、色々試してみました。

まずは、テストとして、手持ちのラズパイ02Wに入れてみました。インストールは公式に準じて、入れています。

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

インストールには若干時間がかかりますが、焦らずに待ちます。

Running Node-RED install for user **** at /home/**** on debian


This can take 20-30 minutes on the slower Pi versions - please wait.

  Stop Node-RED                       ✔
  Remove old version of Node-RED      ✔
  Remove old version of Node.js       ✔   
  Install Node v22.22.2               ✔   v22.22.2   Npm 10.9.7
  Clean npm cache                     ✔
  Install Node-RED core               ✔   4.1.8
  Move global nodes to local          -
  Npm rebuild existing nodes          ✔
  Install extra Pi nodes              ✔
  Add shortcut commands               ✔
  Update systemd script               ✔
                                      

Any errors will be logged to   /var/log/nodered-install.log
All done.
You can now start Node-RED with the command  node-red-start
  or using the icon under   Menu / Programming / Node-RED
Then point your browser to localhost:1880 or http://{your_pi_ip-address}:1880

Started :  2026年  4月 10日 金曜日 17:59:35 JST 
Finished:  2026年  4月 10日 金曜日 18:16:22 JST
 
**********************************************************************************
 ### WARNING ###
 DO NOT EXPOSE NODE-RED TO THE OPEN INTERNET WITHOUT SECURING IT FIRST
 
 Even if your Node-RED doesn't have anything valuable, (automated) attacks will
 happen and could provide a foothold in your local network
 
 Follow the guide at https://nodered.org/docs/user-guide/runtime/securing-node-red
 to setup security.
 
 ### ADDITIONAL RECOMMENDATIONS ###
  - Remove the /etc/sudoers.d/010_pi-nopasswd file to require entering your password
    when performing any sudo/root commands:
 
      sudo rm -f /etc/sudoers.d/010_pi-nopasswd
 
  - You can customise the initial settings by running:
 
      node-red admin init
 
**********************************************************************************
 

Node-RED Settings File initialisation
=====================================
This tool will help you create a Node-RED settings file.

✔ Settings file · /home/****/.node-red/settings.js

Share Anonymouse Usage Information
==================================
✔ Node-RED can notify you when there is a new version available.
This ensures you keep up to date with the latest features and fixes.
This requires sending anonymised data back to the Node-RED team.
It does not include any details of your flows or users.
For full information on what information is collected and how it is used,
please see https://nodered.org/docs/telemetry
 · No, do not send my usage data

User Security
=============
✔ Do you want to setup user security? · Yes
✔ Username · ****
✔ Password · ********
✔ User permissions · full access
✔ Add another user? · No

Projects
========
The Projects feature allows you to version control your flow using a local git repository.

✔ Do you want to enable the Projects feature? · No

Flow File settings
==================
✔ Enter a name for your flows file · flows.json
✔ Provide a passphrase to encrypt your credentials file · 

Editor settings
===============
✔ Select a theme for the editor. To use any theme other than "default", you will need to install @node-red-contrib-themes/theme-collection in your Node-RED user directory. · default


✔ Select the text editor component to use in the Node-RED Editor · monaco (default)

Node settings
=============
✔ Allow Function nodes to load external modules? (functionExternalModules) · Yes


Settings file written to /home/****/.node-red/settings.js

今回はインストールには、ログにある通り約20分かかりました。途中ハングアップしてるかと思うくらいです。

では起動してみましょう

node-red-pi --max-old-space-size=256
10 Apr 18:22:50 - [info] 

Welcome to Node-RED
===================

10 Apr 18:22:50 - [info] Node-RED バージョン: v4.1.8
10 Apr 18:22:50 - [info] Node.js  バージョン: v22.22.2
10 Apr 18:22:50 - [info] Linux 6.12.75+rpt-rpi-v8 arm64 LE
10 Apr 18:22:51 - [info] パレットノードのロード
10 Apr 18:22:58 - [info] 設定ファイル: /home/****/.node-red/settings.js
10 Apr 18:22:58 - [info] コンテキストストア : 'default' [module=memory]
10 Apr 18:22:58 - [info] ユーザディレクトリ : /home/****/.node-red
10 Apr 18:22:58 - [warn] プロジェクトは無効化されています : editorTheme.projects.enabled=false
10 Apr 18:22:58 - [info] フローファイル     : /home/****/.node-red/flows.json
10 Apr 18:22:58 - [info] flow ファイルを作成します
10 Apr 18:22:58 - [warn] 暗号化されていないクレデンシャルを使用
10 Apr 18:22:58 - [info] サーバは http://127.0.0.1:1880/ で実行中です
10 Apr 18:22:58 - [info] フローを開始します
10 Apr 18:22:58 - [info] フローを開始しました

ブラウザでhttp://127.0.0.1:1880/にアクセスすると、ログイン画面が出ます。

先に登録したユーザー名とパスワードを入力すると、本体の画面が出てきます。

左の列にノード欄、真ん中がフローシート、右の列が情報欄になります。
今後、簡単なプログラムを通して、解説していきたいと思います。