Node-RED Complete / Status ノードガイド

☁️ クラウドOK 環境とは?

目次

1. 概要

Complete ノードとStatus ノードは、他のノードの動作状況を監視するためのノードです。Catch ノード(エラー監視)と合わせて、フローの監視に使用します。

✅ Complete ノード

Complete

役割: 指定ノードの処理完了を検知

用途:

  • 非同期処理の完了検知
  • 処理時間の計測
  • 後続処理のトリガー

📊 Status ノード

Status

役割: 指定ノードのステータス変化を検知

用途:

  • 接続状態の監視(MQTT等)
  • 処理状況の表示
  • エラー状態の早期検知

工場のラインに例えると:Complete ノードは「作業完了」のランプ、Status ノードは機械の「状態表示パネル」のようなものです。作業が終わったか、今どんな状態かをリアルタイムで把握できます。

動作を図で見る

2 つのノードは、どちらも入力の端子を持たず、別のノードを見張っていて、何かが起きたときに msg を送り出します。

msghttp request…✓ 処理が終わったcomplete見張る出ていく msgpayload: (処理した msg)
complete は、見張っているノードが処理を終えた msg を送り出す
mqtt in接続済みstatus見張る出ていく msgstatus.text: "接続済み"status.fill: "green"status.shape: "dot"status.source.type: "mqtt in"
status は、見張っているノードのステータス表示の内容を msg.status に入れて送り出す

2. Complete ノード詳細

プロパティ

設定項目説明
対象ノード(「ノードを選択...」)完了を監視するノードを選ぶ。「ノードを選択...」ボタンを押し、フロー上のノードを複数選択する。Complete ノードには固定ラベルの入力欄はなく、この選択リストが本体となる
名前エディター上のノード表示名

出力メッセージ

{ "payload": /* 完了したノードが処理した msg の payload */, "_msgid": "元のメッセージID", /* 元のメッセージの全プロパティを継承 */ "complete": { "source": { // 処理を終えたノード "id": "ノードID", "type": "debug", "name": "ノードの名前" } } }

Complete が発火するタイミング

ポイント:

Complete に対応するのは一部のノードです。主に非同期処理を行うノード(HTTP Request、Exec、File など)で有効です。

3. Status ノード詳細

プロパティ

設定項目説明
ステータス取得元ステータスを監視する範囲を選ぶセレクト。「全てのノード」「同一グループ内」「選択したノード」の3つから選ぶ
名前エディター上のノード表示名

「ステータス取得元」で「選択したノード」を選ぶと「ノードを選択...」ボタンが現れ、監視するノードを個別に指定できる。3つの選択肢の意味は次のとおり。

選択肢説明
全てのノード同じフロー(タブ)上の全ノードのステータスを監視する
同一グループ内Status ノードが置かれたグループ内のノードだけを監視する
選択したノード「ノードを選択...」ボタンで個別に選んだノードだけを監視する

出力メッセージ

{ "status": { "fill": "green", // 色: red, green, yellow, blue, grey "shape": "dot", // 形状: dot, ring "text": "connected", // テキスト "source": { // ステータスを変えたノード "id": "ノードID", "type": "mqtt in", "name": "MQTT購読" } } }

よくあるステータスパターン

fill(色)shape(形状)意味
greendot(塗りつぶし)正常・接続中
yellowring(輪)待機中・処理中
reddotエラー・切断
bluedot情報・アクティブ
greyring無効・停止

4. Catch ノードとの違い

ノード検知するもの発火タイミング
Complete処理完了ノードがメッセージ処理を完了したとき
Status状態変化ノードがステータスを更新したとき
Catchエラーノードがエラーを投げたとき
HTTP Request - - -正常完了- - -Complete - - -ステータス変化- - -Status - - -エラー発生- - -Catch

5. サンプルフロー

公式サンプルフロー

最初のサンプルフローは、Node-RED本体に同梱されている公式サンプル(complete の「Handle completion of node execution」と、status の「Handle status message output」)を1つのタブにまとめ、名前の無かった inject ノードと debug ノードに日本語の名前を付けたものです。エディタの メニュー → 読み込み → サンプル → node-red → common → complete(または status)からも、元のフローを開けます。

📥 公式サンプルフローJSON(クリックで展開)
[ { "id": "a2046c0f338a6a59", "type": "tab", "label": "complete / status", "disabled": false, "info": "", "env": [] }, { "id": "9df3290f.c6d2e8", "type": "inject", "z": "a2046c0f338a6a59", "name": "実行: complete の例", "topic": "", "payload": "Hello, World!", "payloadType": "str", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 210, "y": 140, "wires": [ [ "96f1096b.2f82a8" ] ] }, { "id": "96f1096b.2f82a8", "type": "debug", "z": "a2046c0f338a6a59", "name": "表示(完了を見張られる)", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 390, "y": 140, "wires": [] }, { "id": "23811105.474c6e", "type": "complete", "z": "a2046c0f338a6a59", "name": "", "scope": [ "96f1096b.2f82a8" ], "uncaught": false, "x": 390, "y": 180, "wires": [ [ "f06a3fc9.6bab7" ] ] }, { "id": "f06a3fc9.6bab7", "type": "debug", "z": "a2046c0f338a6a59", "name": "完了の通知", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 580, "y": 180, "wires": [] }, { "id": "34d5ef47.79e72", "type": "comment", "z": "a2046c0f338a6a59", "name": "Example: Complete Node", "info": "Complete node can catch completion of specified nodes. It receives input of target node.", "x": 150, "y": 40, "wires": [] }, { "id": "6ed443a1.a0c3cc", "type": "comment", "z": "a2046c0f338a6a59", "name": "Catch completion of a node", "info": "", "x": 200, "y": 100, "wires": [] }, { "id": "70b28e37.84edd", "type": "comment", "z": "a2046c0f338a6a59", "name": "Catch completion of 1st debug node", "info": "", "x": 460, "y": 220, "wires": [] }, { "id": "cf27351f.392d88", "type": "inject", "z": "a2046c0f338a6a59", "name": "実行: status の例", "topic": "", "payload": "Hello, World!", "payloadType": "str", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 270, "y": 420, "wires": [ [ "75eaadfb.bed014" ] ] }, { "id": "cd1ac74a.a149a8", "type": "debug", "z": "a2046c0f338a6a59", "name": "ステータスの通知", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "x": 590, "y": 480, "wires": [] }, { "id": "fc2e6dfc.2b0e9", "type": "comment", "z": "a2046c0f338a6a59", "name": "Example: Status Node", "info": "Status node can catch change of status message of specified nodes or all nodes in a flow. It receives metadata of status message.", "x": 200, "y": 320, "wires": [] }, { "id": "d97b97d0.c4cfe8", "type": "comment", "z": "a2046c0f338a6a59", "name": "Catch status message", "info": "", "x": 240, "y": 380, "wires": [] }, { "id": "a1914d09.e7ba2", "type": "comment", "z": "a2046c0f338a6a59", "name": "Catch status message of 1st debug node", "info": "", "x": 540, "y": 520, "wires": [] }, { "id": "75fefe32.3e47d", "type": "status", "z": "a2046c0f338a6a59", "name": "", "scope": [ "cf27351f.392d88", "75eaadfb.bed014" ], "x": 440, "y": 480, "wires": [ [ "cd1ac74a.a149a8" ] ] }, { "id": "75eaadfb.bed014", "type": "debug", "z": "a2046c0f338a6a59", "name": "表示(ステータスを見張られる)", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "x": 450, "y": 420, "wires": [] } ]

フローの読み解き

フローは、上の complete の例と、下の status の例の、2つの部分に分かれています。それぞれの先頭に、「Example:」で始まる comment ノードがあります。どちらの部分も2行でできていて、上の行が inject → debug のふつうの流れ、下の行がそれを見張る流れです。complete ノードと status ノードには名前が付いていないので、ここでは種類の名前で呼びます。

部分(comment ノードの見出しと、その意味) ノードの並び 設定と、その理由
Example: Complete Node
Catch completion of a node(1つのノードの完了を捕まえる)
上の行:「実行: complete の例」(inject)→「表示(完了を見張られる)」(debug)
下の行: complete →「完了の通知」(debug)
complete の対象は「表示(完了を見張られる)」だけ。下の comment ノード「Catch completion of 1st debug node」(1つ目の debug ノードの完了を捕まえる)が、このことを示している。complete は、対象のノードが処理し終えた msg に、完了したノードを表す msg.complete を足して出す。msg.payload は元のままなので、「完了の通知」は msg.payload を表示する設定にしてある
Example: Status Node
Catch status message(ステータスの表示を捕まえる)
上の行:「実行: status の例」(inject)→「表示(ステータスを見張られる)」(debug)
下の行: status →「ステータスの通知」(debug)
上の行の debug は、「出力先」の「ノードステータス(32 文字)」をオンにしてある。msg が届くたびに、ノードの下に msg.payload の内容がステータスとして表示される。status の「ステータス取得元」は「選択したノード」で、対象は上の行の inject と debug の2つ。「ステータスの通知」は、「対象」を「msgオブジェクト全体」にしてある(status ノードが出す msg には msg.payload が無いため)

ボタンを押すと出るもの:

押すボタン デバッグサイドバーに出るもの
「実行: complete の例」 「表示(完了を見張られる)」に Hello, World!、続いて「完了の通知」にも Hello, World! が出る。2つ目は、debug ノードが表示を終えたことを complete が捕まえて送った msg で、msg.payload は debug ノードが受け取ったものと同じ
「実行: status の例」 「表示(ステータスを見張られる)」に Hello, World! が出て、そのノードの下にも灰色の丸と Hello, World! が表示される。続いて「ステータスの通知」に、そのステータスの内容が出る(下の例)。続けてもう一度押すと、「表示(ステータスを見張られる)」には出るが、「ステータスの通知」には出ない。debug ノードは、ステータスの文字が前と同じときは、ステータスを出し直さないため。もう一度確かめるときは、デプロイし直す
// 「ステータスの通知」に出る msg {"status":{"fill":"grey","shape":"dot","text":"Hello, World!", "source":{"id":"75eaadfb.bed014","type":"debug","name":"表示(ステータスを見張られる)"}}, "_msgid":"9f6b41b08aef6cb3"}

status.text が、ノードの下に表示された文字です。status.source で、どのノードのステータスかが分かります。status の対象には inject も入っていますが、inject ノードはステータスを表示しないので、届くのは debug のステータスだけです。各項目の意味は、3章の「出力メッセージ」と、下の応用フローの読み解きの表を見てください。

2つの例は、見張る相手がどちらも debug ノードです。complete は「処理が終わった」ことを、status は「ノードの下の表示が変わった」ことを捕まえます。処理が終わってもステータスを変えないノードは complete でしか分からず、接続の状態のように処理の完了と関係なく変わるものは status でしか分かりません。

応用(サイト独自): 完了・ステータス・エラーを使い分ける

ここから先は公式サンプルではなく、本サイトが用意した応用教材です。処理にかかった時間の計測、function ノードが自分で変えるステータスの監視、エラーの検知を、1つのタブにまとめています。

💼 使いどころ: 処理の完了・状態変化・エラーを、それぞれ別のノードで検知して使い分ける場面で使います。

📥 応用フローJSON(クリックで展開)
[ { "id": "complete_status_tab", "type": "tab", "label": "Complete/Status サンプル", "disabled": false, "info": "" }, { "id": "cs_comment1", "type": "comment", "z": "complete_status_tab", "name": "━━━ Complete ノード:処理完了の検知 ━━━", "info": "", "x": 210, "y": 40, "wires": [] }, { "id": "cs_inject1", "type": "inject", "z": "complete_status_tab", "name": "開始", "props": [{"p": "payload"}, {"p": "startTime", "v": "", "vt": "date"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "処理開始", "payloadType": "str", "x": 130, "y": 100, "wires": [["cs_delay"]] }, { "id": "cs_delay", "type": "delay", "z": "complete_status_tab", "name": "2秒待機", "pauseType": "delay", "timeout": "2", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 280, "y": 100, "wires": [["cs_debug1"]] }, { "id": "cs_debug1", "type": "debug", "z": "complete_status_tab", "name": "メイン出力", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 450, "y": 100, "wires": [] }, { "id": "cs_complete", "type": "complete", "z": "complete_status_tab", "name": "Delay完了検知", "scope": ["cs_delay"], "x": 300, "y": 160, "wires": [["cs_func_time"]] }, { "id": "cs_func_time", "type": "function", "z": "complete_status_tab", "name": "処理時間計算", "func": "const elapsed = Date.now() - msg.startTime;\nmsg.payload = \"処理完了! 経過時間: \" + elapsed + \"ms\";\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 500, "y": 160, "wires": [["cs_debug2"]] }, { "id": "cs_debug2", "type": "debug", "z": "complete_status_tab", "name": "完了通知", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 680, "y": 160, "wires": [] }, { "id": "cs_comment2", "type": "comment", "z": "complete_status_tab", "name": "━━━ Status ノード:ステータス監視 ━━━", "info": "", "x": 200, "y": 240, "wires": [] }, { "id": "cs_inject2", "type": "inject", "z": "complete_status_tab", "name": "ステータス更新", "props": [{"p": "payload"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "テストデータ", "payloadType": "str", "x": 160, "y": 300, "wires": [["cs_func_status"]] }, { "id": "cs_func_status", "type": "function", "z": "complete_status_tab", "name": "処理中表示", "func": "// ステータスを「処理中」に設定\nnode.status({fill:\"yellow\", shape:\"ring\", text:\"処理中...\"});\n\n// 1秒後に「完了」に変更\nsetTimeout(function() {\n node.status({fill:\"green\", shape:\"dot\", text:\"完了\"});\n}, 1000);\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 360, "y": 300, "wires": [["cs_debug3"]] }, { "id": "cs_debug3", "type": "debug", "z": "complete_status_tab", "name": "出力", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 530, "y": 300, "wires": [] }, { "id": "cs_status", "type": "status", "z": "complete_status_tab", "name": "ステータス監視", "scope": ["cs_func_status"], "x": 300, "y": 360, "wires": [["cs_debug4"]] }, { "id": "cs_debug4", "type": "debug", "z": "complete_status_tab", "name": "ステータス出力", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "status", "targetType": "msg", "statusVal": "status.text", "statusType": "msg", "x": 500, "y": 360, "wires": [] }, { "id": "cs_comment3", "type": "comment", "z": "complete_status_tab", "name": "━━━ Catch ノード:エラーの検知 ━━━", "info": "", "x": 190, "y": 440, "wires": [] }, { "id": "cs_inject3", "type": "inject", "z": "complete_status_tab", "name": "実行", "props": [{"p": "payload"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "5", "payloadType": "num", "x": 130, "y": 500, "wires": [["cs_func_error"]] }, { "id": "cs_func_error", "type": "function", "z": "complete_status_tab", "name": "ランダムエラー", "func": "node.status({fill:\"blue\", shape:\"dot\", text:\"実行中\"});\n\nif (Math.random() < 0.5) {\n node.status({fill:\"red\", shape:\"dot\", text:\"エラー\"});\n node.error(\"ランダムエラー発生\", msg);\n return null;\n}\n\nnode.status({fill:\"green\", shape:\"dot\", text:\"成功\"});\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 300, "y": 500, "wires": [["cs_debug5"]] }, { "id": "cs_debug5", "type": "debug", "z": "complete_status_tab", "name": "成功", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 470, "y": 500, "wires": [] }, { "id": "cs_catch", "type": "catch", "z": "complete_status_tab", "name": "エラー捕捉", "scope": ["cs_func_error"], "uncaught": false, "x": 290, "y": 560, "wires": [["cs_debug6"]] }, { "id": "cs_debug6", "type": "debug", "z": "complete_status_tab", "name": "エラー内容", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "error", "targetType": "msg", "x": 490, "y": 560, "wires": [] } ]

フローの読み解き

フローは3つの部分に分かれています。各部分の先頭にある comment ノードの名前が、下の表の「部分」に当たります。どの部分も2行でできていて、上の行がふつうの流れ、下の行がそれを見張る流れです。見張るノード(complete・status・catch)は、相手のノードと配線でつながっていません。見張る相手は、それぞれの設定で選んであります。

部分 ノードの並び 設定と、その理由
Complete ノード:処理完了の検知 上の行:「開始」(inject)→「2秒待機」(delay)→「メイン出力」(debug)
下の行:「Delay完了検知」(complete)→「処理時間計算」(function)→「完了通知」(debug)
complete の対象は「2秒待機」だけ。「開始」は、msg.payload の「処理開始」のほかに、ボタンを押した時刻を msg.startTime に入れて送る。complete は、「2秒待機」が処理し終えた msg を出す(完了したノードを表す msg.complete が足されるほかは、元のまま)ので、msg.startTime が残っている。function は、今の時刻から msg.startTime を引いて、かかった時間を求める
Status ノード:ステータス監視 上の行:「ステータス更新」(inject)→「処理中表示」(function)→「出力」(debug)
下の行:「ステータス監視」(status)→「ステータス出力」(debug)
status の「ステータス取得元」は「選択したノード」で、対象は「処理中表示」だけ。function は、node.status() で自分のステータスを黄色の「処理中...」にし、1秒後に緑の「完了」に変える。msg は1秒待たずに、すぐ次へ渡す。「ステータス出力」は、msg.payload ではなく msg.status を表示する設定にしてある(status ノードが出す msg には msg.payload が無いため)
Catch ノード:エラーの検知 上の行:「実行」(inject)→「ランダムエラー」(function)→「成功」(debug)
下の行:「エラー捕捉」(catch)→「エラー内容」(debug)
function は、2回に1回の割合で node.error() を呼んでエラーにし、msg を次へ渡さない。残りは msg をそのまま渡す。catch の「エラー取得元」は「選択したノード」で、対象は「ランダムエラー」だけ。「エラー内容」は、msg.error を表示する設定にしてある。4章の表のうち、Catch の行に当たる

3つ目の部分の「ランダムエラー」は、自分のステータスも「エラー」「成功」に変えます。ただし、この部分に status ノードは無いので、ステータスはノードの下に表示されるだけで、msg にはなりません。1つのノードを complete・status・catch の3つで同時に見張る例は、演習3で作ります。

ボタンを押すと出るもの:

押すボタン デバッグサイドバーに出るもの
「開始」 約2秒後に、「メイン出力」に 処理開始、「完了通知」に 処理完了! 経過時間: 2006ms が出る(数字は押すたびに少し変わる)。「完了通知」のノードの下にも、同じ文字が出る
「ステータス更新」 すぐに、「出力」に テストデータ、「ステータス出力」に黄色のステータス("text":"処理中...")が出る。1秒後に、「ステータス出力」に緑のステータス("text":"完了")が出る。status ノードは、ステータスが変わるたびに msg を1つ出すので、1回押すと「ステータス出力」には2つ届く
「実行」 「成功」に 5 が出るか、「エラー内容」にエラーの内容が出るかの、どちらか。どちらになるかは押すたびに変わるので、何回か押して両方を確かめる

「ステータス出力」と「エラー内容」に出るオブジェクトは、次の形をしています。source は、ステータスを変えたノード、またはエラーを起こしたノードを表します。見張る相手が複数あるときに、どのノードのことかを見分けるのに使います。

// 「ステータス出力」(msg.status) {"fill":"yellow","shape":"ring","text":"処理中...", "source":{"id":"cs_func_status","type":"function","name":"処理中表示"}} // 「エラー内容」(msg.error) {"message":"ランダムエラー発生", "source":{"id":"cs_func_error","type":"function","name":"ランダムエラー","count":1}}
項目 意味
fill、shape、text ステータスの色、形(dot は塗りつぶした丸、ring は輪)、文字。node.status() に渡した値がそのまま入る
message エラーの文。node.error() の1つ目に渡した文字が入る
source.id、source.type、source.name ステータスを変えた、またはエラーを起こしたノードの ID、種類、名前
source.count 同じ msg が、同じノードで続けてエラーになった回数(エラーのときだけ入る)。ふつうは 1 で、catch で受けた msg を同じノードへ戻す作りにしたときに増える

6. 演習問題

演習1: Complete で処理時間を計測 初級

課題: Delay ノードの処理完了を Complete ノードで検知し、開始から完了までの時間を表示してください。

💼 使いどころ: 処理の開始から完了までにかかった時間を計測する場面で使います。

成功の条件:

💡 ヒント

1. Inject ノードで msg.startTime に現在時刻を設定

2. Complete ノードで Delay の完了を検知

3. Change ノードの「値の代入」で、msg.payload に「JSONata式」型の "経過時間: " & ($millis() - startTime) & "ms" を設定する。$millis() は現在時刻のミリ秒で、そこから開始時刻を引くと経過時間になる。& は文字列をつなぐ演算子

✅ 解答例フロー
[ {"id": "ex1_tab", "type": "tab", "label": "演習1"}, {"id": "ex1_inject", "type": "inject", "z": "ex1_tab", "name": "開始", "props": [{"p": "payload"}, {"p": "startTime", "v": "", "vt": "date"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "開始", "payloadType": "str", "x": 130, "y": 100, "wires": [["ex1_delay"]]}, {"id": "ex1_delay", "type": "delay", "z": "ex1_tab", "name": "3秒待機", "pauseType": "delay", "timeout": "3", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 280, "y": 100, "wires": [[]]}, {"id": "ex1_complete", "type": "complete", "z": "ex1_tab", "name": "完了検知", "scope": ["ex1_delay"], "x": 290, "y": 160, "wires": [["ex1_change"]]}, {"id": "ex1_change", "type": "change", "z": "ex1_tab", "name": "経過時間", "rules": [{"t": "set", "p": "payload", "pt": "msg", "to": "\"経過時間: \" & ($millis() - startTime) & \"ms\"", "tot": "jsonata"}], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 460, "y": 160, "wires": [["ex1_debug"]]}, {"id": "ex1_debug", "type": "debug", "z": "ex1_tab", "name": "結果", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 610, "y": 160, "wires": []} ]

演習2: Status でノード状態を監視 中級

課題: Function ノードでステータスを更新し、Status ノードでその変化を検知してください。

💼 使いどころ: ノードの処理状況の変化を、別のノードで捕捉して確認する場面で使います。

成功の条件:

💡 ヒント

Function 内で node.status({fill:"色", shape:"形状", text:"テキスト"}) を使用します。

✅ 解答例フロー
[ {"id": "ex2_tab", "type": "tab", "label": "演習2"}, {"id": "ex2_inject", "type": "inject", "z": "ex2_tab", "name": "実行", "props": [{"p": "payload"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "test", "payloadType": "str", "x": 130, "y": 100, "wires": [["ex2_func"]]}, {"id": "ex2_func", "type": "function", "z": "ex2_tab", "name": "状態変化", "func": "// 処理を始めたことを、ノードの下に黄色のステータスで表示する\nnode.status({fill:\"yellow\", shape:\"ring\", text:\"処理中\"});\n// 1.5秒後に、緑の「完了」へ切り替える(時間のかかる処理の代わり)\nsetTimeout(function(){\n node.status({fill:\"green\", shape:\"dot\", text:\"完了\"});\n}, 1500);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 300, "y": 100, "wires": [[]]}, {"id": "ex2_status", "type": "status", "z": "ex2_tab", "name": "監視", "scope": ["ex2_func"], "x": 270, "y": 160, "wires": [["ex2_debug"]]}, {"id": "ex2_debug", "type": "debug", "z": "ex2_tab", "name": "状態", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "status", "targetType": "msg", "statusVal": "status.text", "statusType": "msg", "x": 430, "y": 160, "wires": []} ]

演習3: 3種類の監視ノード組み合わせ 上級

課題: Complete、Status、Catch を組み合わせて、処理の成功/失敗を監視するフローを作成してください。

💼 使いどころ: 処理の成功・失敗と状態変化を、それぞれ別々に捕捉して確認する場面で使います。

成功の条件:

💡 ヒント

Function ノードで node.error() を使うとエラーを発生させ、Catch で捕捉できます。

✅ 解答例フロー
[ {"id": "ex3_tab", "type": "tab", "label": "演習3"}, {"id": "ex3_inject", "type": "inject", "z": "ex3_tab", "name": "実行", "props": [{"p": "payload"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "test", "payloadType": "str", "x": 130, "y": 120, "wires": [["ex3_func"]]}, {"id": "ex3_func", "type": "function", "z": "ex3_tab", "name": "ランダム処理", "func": "// 実行を始めたことをステータスで表示する\nnode.status({fill:\"blue\", shape:\"dot\", text:\"実行中\"});\n// 約30%の確率で失敗させる(失敗する処理の代わり)\nif (Math.random() < 0.3) {\n node.status({fill:\"red\", shape:\"dot\", text:\"エラー\"});\n // msg を付けて node.error を呼ぶと、Catch ノードで捕まえられる\n node.error(\"失敗\", msg);\n // 失敗したときは、通常の出力には何も送らない\n return null;\n}\nnode.status({fill:\"green\", shape:\"dot\", text:\"成功\"});\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 310, "y": 120, "wires": [["ex3_debug1"]]}, {"id": "ex3_debug1", "type": "debug", "z": "ex3_tab", "name": "成功", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 490, "y": 120, "wires": []}, {"id": "ex3_catch", "type": "catch", "z": "ex3_tab", "name": "エラー捕捉", "scope": ["ex3_func"], "uncaught": false, "x": 290, "y": 180, "wires": [["ex3_debug2"]]}, {"id": "ex3_debug2", "type": "debug", "z": "ex3_tab", "name": "エラー", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "error", "targetType": "msg", "x": 490, "y": 180, "wires": []}, {"id": "ex3_status", "type": "status", "z": "ex3_tab", "name": "状態監視", "scope": ["ex3_func"], "x": 280, "y": 240, "wires": [["ex3_debug3"]]}, {"id": "ex3_debug3", "type": "debug", "z": "ex3_tab", "name": "状態", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "status.text", "targetType": "msg", "statusVal": "status.text", "statusType": "msg", "x": 490, "y": 240, "wires": []} ]

7. まとめ

ポイント:

注意事項:

8. 実務活用例

ケース1: HTTP Request の完了監視

外部API呼び出しの完了をComplete で検知し、後続処理をトリガー。

ケース2: MQTT接続状態の監視

Status ノードでMQTTブローカーへの接続状態を監視し、切断時にアラート。

ケース3: 処理時間の計測

開始時刻を記録し、Complete で完了を検知して処理時間をログ。

ケース4: バッチ処理の進捗監視

各処理ステップの Status を監視してダッシュボードに進捗を表示。

📚 Node-RED 公式ドキュメント

🏠