📋 サンプルフロー(クリックで展開)
参照元:NodeREDエディター内サンプルフロー
[
{
"id": "4172066d80ce08eb",
"type": "tab",
"label": "debug",
"disabled": false,
"info": "",
"env": []
},
{
"id": "f1a1990e6cf1bdad",
"type": "comment",
"z": "4172066d80ce08eb",
"name": "Output payload value to debug sidebar",
"info": "Debug node can be used to output payload value to debug sidebar.",
"x": 270,
"y": 60,
"wires": []
},
{
"id": "a325a0b5fbc66ec5",
"type": "inject",
"z": "4172066d80ce08eb",
"name": "",
"props": [
{
"p": "payload",
"v": "Hello, World!",
"vt": "str"
},
{
"p": "topic",
"v": "",
"vt": "string"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "Hello, World!",
"payloadType": "str",
"x": 250,
"y": 100,
"wires": [
[
"095465ec1455c239"
]
]
},
{
"id": "095465ec1455c239",
"type": "debug",
"z": "4172066d80ce08eb",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 490,
"y": 100,
"wires": []
},
{
"id": "8c66d039.44465",
"type": "comment",
"z": "4172066d80ce08eb",
"name": "Output complete object",
"info": "Debug node can be used to output whole object value to debug sidebar.",
"x": 220,
"y": 180,
"wires": []
},
{
"id": "dac87e40.90376",
"type": "inject",
"z": "4172066d80ce08eb",
"name": "",
"props": [
{
"p": "payload",
"v": "Hello, World!",
"vt": "str"
},
{
"p": "topic",
"v": "Sample",
"vt": "string"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "Sample",
"payload": "Hello, World!",
"payloadType": "str",
"x": 280,
"y": 220,
"wires": [
[
"a77fa5e3.fac248"
]
]
},
{
"id": "a77fa5e3.fac248",
"type": "debug",
"z": "4172066d80ce08eb",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 470,
"y": 220,
"wires": []
},
{
"id": "fb1c3ce9.c29ee",
"type": "comment",
"z": "4172066d80ce08eb",
"name": "Output to console",
"info": "Debug node can be used to output values to console.",
"x": 210,
"y": 300,
"wires": []
},
{
"id": "3c24e746.9ff6a8",
"type": "inject",
"z": "4172066d80ce08eb",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "Hello, World!",
"payloadType": "str",
"x": 250,
"y": 340,
"wires": [
[
"66cc7b44.82ba74"
]
]
},
{
"id": "66cc7b44.82ba74",
"type": "debug",
"z": "4172066d80ce08eb",
"name": "",
"active": true,
"tosidebar": false,
"console": true,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 500,
"y": 340,
"wires": []
},
{
"id": "33791e6a.973502",
"type": "comment",
"z": "4172066d80ce08eb",
"name": "Output to node status area",
"info": "Debug node can be used to output values to status area below the node.",
"x": 230,
"y": 420,
"wires": []
},
{
"id": "a5d8e744.a034e8",
"type": "inject",
"z": "4172066d80ce08eb",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "Hello, World!",
"payloadType": "str",
"x": 250,
"y": 460,
"wires": [
[
"b0646a4d.db4bc8"
]
]
},
{
"id": "b0646a4d.db4bc8",
"type": "debug",
"z": "4172066d80ce08eb",
"name": "",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 490,
"y": 460,
"wires": []
},
{
"id": "30ed0a73.fcef86",
"type": "comment",
"z": "4172066d80ce08eb",
"name": "Formatting output using JSONata",
"info": "Debug node can format output value using JSONata expression.",
"x": 260,
"y": 540,
"wires": []
},
{
"id": "6f477e7d.3a8da",
"type": "inject",
"z": "4172066d80ce08eb",
"name": "",
"props": [
{
"p": "payload",
"v": "Hello, World!",
"vt": "str"
},
{
"p": "topic",
"v": "Sample",
"vt": "string"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "Sample",
"payload": "Hello, World!",
"payloadType": "str",
"x": 280,
"y": 580,
"wires": [
[
"19c9408d.ac6d4f"
]
]
},
{
"id": "19c9408d.ac6d4f",
"type": "debug",
"z": "4172066d80ce08eb",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "\"[\" & topic & \"] \" & payload",
"targetType": "jsonata",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 580,
"wires": []
}
]
出力対象: 完全なmsgオブジェクト
出力先: デバッグサイドバー ✓
表示されるプロパティ:
- payload: メインデータ
- topic: トピック
- _msgid: メッセージID
- その他: 前のノードで追加されたプロパティ
出力対象: msg.payload
出力先: デバッグサイドバー ✗
システムコンソール ✓
ノードステータス ✗
コンソール出力例:
16 Dec 10:30:45 - [info] [debug:debug 1] Hello, World!
出力対象: msg.payload
出力先: デバッグサイドバー ✗
システムコンソール ✗
ノードステータス ✓
注意: 32文字を超えると切り詰められる
出力対象: JSONata式
式: "[" & topic & "] " & payload
入力:
msg.payload = "Hello, World!"
msg.topic = "Sample"
出力: "[Sample] Hello, World!"
演習4: 条件付きデバッグ出力上級
📝 課題:
センサー値が閾値を超えた場合のみ警告表示を行い、それ以外は通常表示するフローを作成してください。
🎯 要求仕様:
- 温度が30度以上: "⚠️ 警告: [温度]°C - 高温注意!"
- 温度が30度未満: "✓ 正常: [温度]°C"
- Switchノードで条件分岐、それぞれ別のDebugノードで出力
📊 期待される動作:
- 35を入力 → "⚠️ 警告: 35°C - 高温注意!"
- 25を入力 → "✓ 正常: 25°C"
✅ 成功の条件:
- 「高温テスト (35°C)」ボタンをクリックすると、「警告出力」ノードのサイドバーに
"⚠️ 警告: 35°C - 高温注意!" が表示される
- 「正常テスト (25°C)」ボタンをクリックすると、「正常出力」ノードのサイドバーに
"✓ 正常: 25°C" が表示される
- 高温テスト時には「正常出力」には何も表示されず、正常テスト時には「警告出力」には何も表示されない(条件分岐が正しく機能している)
- それぞれのDebugノードのステータス欄にも出力内容が表示される
💡 ヒント
Injectノードの設定(高温テスト):
Injectノードの設定(正常テスト):
Switchノードの設定:
- プロパティ: msg.payload
- 条件1: >= 30 → 出力1
- 条件2: その他(otherwise)→ 出力2
Debug 1(警告)の設定:
- 出力対象: JSONata式
- 式:
"⚠️ 警告: " & $string(payload) & "°C - 高温注意!"
Debug 2(正常)の設定:
- 出力対象: JSONata式
- 式:
"✓ 正常: " & $string(payload) & "°C"
✅ 解答例フロー
[
{
"id": "ex4_inject_high",
"type": "inject",
"name": "高温テスト (35°C)",
"props": [{"p": "payload"}],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "35",
"payloadType": "num",
"x": 160,
"y": 80,
"wires": [["ex4_switch"]]
},
{
"id": "ex4_inject_normal",
"type": "inject",
"name": "正常テスト (25°C)",
"props": [{"p": "payload"}],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "25",
"payloadType": "num",
"x": 160,
"y": 140,
"wires": [["ex4_switch"]]
},
{
"id": "ex4_switch",
"type": "switch",
"name": "温度判定",
"property": "payload",
"propertyType": "msg",
"rules": [
{"t": "gte", "v": "30", "vt": "num"},
{"t": "else"}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 360,
"y": 110,
"wires": [["ex4_debug_warn"], ["ex4_debug_ok"]]
},
{
"id": "ex4_debug_warn",
"type": "debug",
"name": "警告出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "\"⚠️ 警告: \" & $string(payload) & \"°C - 高温注意!\"",
"targetType": "jsonata",
"statusVal": "",
"statusType": "auto",
"x": 540,
"y": 80,
"wires": []
},
{
"id": "ex4_debug_ok",
"type": "debug",
"name": "正常出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "\"✓ 正常: \" & $string(payload) & \"°C\"",
"targetType": "jsonata",
"statusVal": "",
"statusType": "auto",
"x": 540,
"y": 140,
"wires": []
}
]
HTTP Request前: リクエスト内容を確認
↓
HTTP Request → API呼び出し
↓
HTTP Request後: レスポンス内容を確認
↓
JSONパース後: 変換結果を確認
各段階でDebugノードを配置して
データの流れを可視化
MQTT受信 → センサーデータ
↓
Debug (ステータス): 最新値をノード下に表示
↓
Debug (コンソール): 全データをログファイルに記録
↓
処理継続...
本番環境ではサイドバー出力を無効化して
コンソールログのみ残す
問題発生時:
1. 疑わしい箇所の前後にDebugを追加
2. 完全なmsgオブジェクトを出力
3. 各プロパティの値を確認
4. 問題箇所を特定
5. 修正後、Debugを無効化または削除
開発時:
- サイドバー出力を有効
- ブラウザで確認しながら開発
本番運用時:
- サイドバー出力を無効
- コンソール出力のみ有効
- journalctl でログを確認
sudo journalctl -u nodered -f | grep "debug"