Krittapon Phacharoen

Krittapon's github web

View My GitHub Profile

Basic Example Node-red


ตัวอย่างการ Configure Node-red เพื่อใช้งานกับ Protocal MQTT

ExpNodered1

    1. Setting Block แรกให้เป็น Timer ในการสั้งให้ Block ต่อไปทำงานเป็นรอบการทำงาน ให้ทำงานทุกๆ 5 วินาที

ExpNodered2

    2. Setting Block ที่สองสำหรับ Function ที่แปลงข้อมูลเวลาให้เป็น String ด้วย code ด้านล่างในภาษา javascript

 // Convert the payload to a String object
 msg.payload = new Date(msg.payload).toString();
 return msg;

ExpNodered2

     3. ตั้งค่า Mosquitto Client ให้ Publish ข้อมูลไปยัง Client ที่ Subscribe ไว้ใน Topic เดียวกัน

ExpNodered3

ExpNodered4

     4. ตั้งค่า Mosquitto Client ให้รอรับข้อมูลจาก ฺBroker จาก Topic ที่ Subscribe ไว้

ExpNodered5

     5. ตั้งค่า Debug Page ให้แสดงผลข้อความที่่รับมาจาก Client

ExpNodered6

     6. เมื่อตั้งค่าทั้งหมดแล้ว ค่าที่ได้จาก Debug Page มีค่าตามรูปด้านล่าง

ExpNodered7

ExpNodered8

     7. สำหรับไฟล์ตัวอย่างสามารถ Export และ Import ได้ด้วยไฟล์ .json

» Homepage