MQTT 使用 <MQTTPubSubClient.h> 發行 led 狀態 dht22 溫度濕度 暨 訂閱 led控制
WOKWI程式
#include <WiFi.h>
#include <MQTTPubSubClient.h>
#include <Adafruit_Sensor.h>
#include <DHT_U.h>
extern "C" {
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
}
#define Relay1 15 //D15 LED-Orangs = Water-1
#define Relay2 2 //D2 LED-Blue = Water-2
#define Relay3 19 //D19 LED-Blue = Motor
#define Relay4 23 //D23 LED-RED = Fan
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define MQTT_HOST "test.mosquitto.org"
#define MQTT_PORT 1883
#define DHTPIN 12
// DHT parameters
#define DHTTYPE DHT22 // DHT 11
DHT_Unified dht(DHTPIN, DHTTYPE);
WiFiClient client;
MQTTPubSubClient mqtt;
int count;
float temp, hum;
bool Send= false;
String json="";
//=============================================================================
void connect() {
connect_to_wifi:
Serial.print("connecting to wifi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.println(" connected!");
connect_to_host:
Serial.print("connecting to host...");
client.stop();
while (!client.connect(MQTT_HOST, 1883)) {//while (!client.connect("public.cloud.shiftr.io", 1883)) {
Serial.print(".");
delay(1000);
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi disconnected");
goto connect_to_wifi;
}
}
Serial.println(" connected!");
Serial.print("connecting to mqtt broker...");
mqtt.disconnect();
while (!mqtt.connect("arduino", "", "")) {
Serial.print(".");
delay(1000);
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi disconnected");
goto connect_to_wifi;
}
if (client.connected() != 1) {
Serial.println("WiFiClient disconnected");
goto connect_to_host;
}
}
Serial.println(" connected!");
}
//=============================================================================
void Publish_message() {
if (Send){
mqtt.publish("alex9ufo/esp32/led/status", json);
Serial.println();
Serial.print("publish message to MQTT ---");
Serial.println(json);
Send= false;
json="";
}
}
//=============================================================================
void setup() {
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
Serial.begin(115200);
dht.begin();
// Get temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD, 6);
mqtt.begin(client);
connect();
mqtt.subscribe([](const String& topic, const String& payload, const size_t size) {
Serial.println("mqtt received: " + topic + " - " + payload);
});
mqtt.subscribe("alex9ufo/esp32/led/control", [] (const String& payload, const size_t size) {
Serial.print("alex9ufo/esp32/led/control");
Serial.println(payload);
String message=payload;
message.trim();
Serial.print(message);
if ( message == "1on" ) {
digitalWrite(Relay1, HIGH); // Turn on the LED
Send = true;
json="Relay1on";
}
if ( message == "1off" ) {
digitalWrite(Relay1, LOW); // Turn off the LED
Send = true;
json="Relay1off";
}
if ( message == "2on" ) {
digitalWrite(Relay2, HIGH); // Turn on the LED
Send = true;
json="Relay2on";
}
if ( message == "2off" ) {
digitalWrite(Relay2, LOW); // Turn off the LED
Send = true;
json="Relay2off";
}
if ( message == "3on" ) {
digitalWrite(Relay3, HIGH); // Turn on the LED
Send = true;
json="Relay3on";
}
if ( message == "3off" ) {
digitalWrite(Relay3, LOW); // Turn off the LED
Send = true;
json="Relay3off";
}
if ( message == "4on" ) {
digitalWrite(Relay4, HIGH); // Turn on the LED
Send = true;
json="Relay4on";
}
if ( message == "4off" ) {
digitalWrite(Relay4, LOW); // Turn off the LED
Send = true;
json="Relay4off";
}
});
/***
mqtt.subscribe("alex9ufo/esp32/dht/temp", [](const String& payload, const size_t size) {
Serial.print("alex9ufo/esp32/dht/temp");
Serial.println(payload);
});
mqtt.subscribe("alex9ufo/esp32/dht/humi", [](const String& payload, const size_t size) {
Serial.print("alex9ufo/esp32/dht/humi");
Serial.println(payload);
});
***/
}
//=============================================================================
void loop() {
mqtt.update();
Publish_message();
if (!mqtt.isConnected()) {
connect();
}
// publish message
static uint32_t prev_ms = millis();
if (millis() > prev_ms + 2500) {
prev_ms = millis();
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature: "));
temp = event.temperature;
Serial.print(temp);
Serial.println(F("°C"));
}
// Get humidity event and print its value
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity: "));
hum = event.relative_humidity;
Serial.print(hum);
Serial.println(F("%"));
}
String msgStr = String(temp) + "," + String(hum) + ",";
//mqtt.publish("alex9ufo/esp32/dht/temp", String(temp));
//delay(100);
//mqtt.publish("alex9ufo/esp32/dht/humi", String(hum));
delay(100);
mqtt.publish("alex9ufo/esp32/dht/temphumi", msgStr);
}
}
Node-Red程式
[
{
"id": "32cc6fb06dc59026",
"type": "mqtt out",
"z": "7f568cf7f029073b",
"name": "RELAY Publish",
"topic": "alex9ufo/esp32/led/control",
"qos": "1",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "21957383cfd8785a",
"x": 340,
"y": 180,
"wires": []
},
{
"id": "18aeb56f5dee63f7",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 3,
"width": 2,
"height": 1,
"passthru": false,
"label": "1:ON",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "1on",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 70,
"y": 40,
"wires": [
[
"32cc6fb06dc59026",
"3024d1f03808997b"
]
]
},
{
"id": "8acddacbdf4a2fd4",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 4,
"width": 2,
"height": 1,
"passthru": false,
"label": "1:OFF",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "1off",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 70,
"y": 80,
"wires": [
[
"32cc6fb06dc59026",
"3024d1f03808997b"
]
]
},
{
"id": "0156ce1b70861af9",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 7,
"width": 2,
"height": 1,
"passthru": false,
"label": "2:ON",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "2on",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 70,
"y": 140,
"wires": [
[
"32cc6fb06dc59026",
"3024d1f03808997b"
]
]
},
{
"id": "900f6596119f932e",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 8,
"width": 2,
"height": 1,
"passthru": false,
"label": "2:OFF",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "2off",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 70,
"y": 180,
"wires": [
[
"32cc6fb06dc59026",
"3024d1f03808997b"
]
]
},
{
"id": "a9b967f452c7a121",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 11,
"width": 2,
"height": 1,
"passthru": false,
"label": "3:ON",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "3on",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 70,
"y": 240,
"wires": [
[
"32cc6fb06dc59026",
"3024d1f03808997b"
]
]
},
{
"id": "3c3e60270287be00",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 12,
"width": 2,
"height": 1,
"passthru": false,
"label": "3:OFF",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "3off",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 70,
"y": 280,
"wires": [
[
"32cc6fb06dc59026",
"3024d1f03808997b"
]
]
},
{
"id": "be7ea477b63b6dd4",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 15,
"width": 2,
"height": 1,
"passthru": false,
"label": "4:ON",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "4on",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 70,
"y": 340,
"wires": [
[
"32cc6fb06dc59026",
"3024d1f03808997b"
]
]
},
{
"id": "f806f83415320b34",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 16,
"width": 2,
"height": 1,
"passthru": false,
"label": "4:OFF",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "4off",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 70,
"y": 380,
"wires": [
[
"32cc6fb06dc59026",
"3024d1f03808997b"
]
]
},
{
"id": "3024d1f03808997b",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 310,
"y": 260,
"wires": []
},
{
"id": "64103c69ecb8762c",
"type": "mqtt in",
"z": "7f568cf7f029073b",
"name": "RELAY_Status Subscribe",
"topic": "alex9ufo/esp32/led/status",
"qos": "1",
"datatype": "auto-detect",
"broker": "21957383cfd8785a",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 850,
"y": 80,
"wires": [
[
"07b9f01ae0ad5a72",
"6baa58d970ba957e",
"e5caffc44bd438a7",
"9f4e70d369707a36"
]
]
},
{
"id": "33fe88a4e04e3bed",
"type": "inject",
"z": "7f568cf7f029073b",
"name": "CREATE建立",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));",
"payload": "",
"payloadType": "date",
"x": 110,
"y": 640,
"wires": [
[
"3c8f2f9047a675be"
]
]
},
{
"id": "f0efdfea5dbc649e",
"type": "inject",
"z": "7f568cf7f029073b",
"name": "SELECT檢視",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "SELECT * FROM LEDSTATUS",
"payload": "",
"payloadType": "date",
"x": 110,
"y": 720,
"wires": [
[
"3c8f2f9047a675be"
]
]
},
{
"id": "687fafdb43ae553d",
"type": "inject",
"z": "7f568cf7f029073b",
"name": "INSERT新增",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "INSERT INTO LEDSTATUS (STATUS , Date , Time )values(\"off\", \"11/22\" , \"21:05\") ",
"payload": "",
"payloadType": "date",
"x": 110,
"y": 680,
"wires": [
[
"3c8f2f9047a675be"
]
]
},
{
"id": "02dcc2c37568c669",
"type": "inject",
"z": "7f568cf7f029073b",
"name": "DELETE刪除所有資料",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "DELETE from LEDSTATUS",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 760,
"wires": [
[
"3c8f2f9047a675be"
]
]
},
{
"id": "6098f0057cfb75c1",
"type": "inject",
"z": "7f568cf7f029073b",
"name": "DROP TABLE刪除資料庫",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "DROP TABLE LEDSTATUS",
"payload": "",
"payloadType": "date",
"x": 150,
"y": 800,
"wires": [
[
"3c8f2f9047a675be"
]
]
},
{
"id": "3c8f2f9047a675be",
"type": "sqlite",
"z": "7f568cf7f029073b",
"mydb": "46923bc412125a9e",
"sqlquery": "msg.topic",
"sql": "",
"name": "LED_STATUS",
"x": 380,
"y": 720,
"wires": [
[
"7e8a8349e9a22c15"
]
]
},
{
"id": "7e8a8349e9a22c15",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 570,
"y": 720,
"wires": []
},
{
"id": "a221b786682796c5",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "資料表 :TABLE LEDSTATUS",
"info": "CREATE TABLE LEDSTATUS (\nid INTEGER,\nSTATUS TEXT,\nDate DATE,\nTime TIME,\nPRIMARY KEY (id)\n);\n\n",
"x": 140,
"y": 600,
"wires": []
},
{
"id": "b904ffe34491964a",
"type": "sqlite",
"z": "7f568cf7f029073b",
"mydb": "46923bc412125a9e",
"sqlquery": "msg.topic",
"sql": "",
"name": "LED_STATUS",
"x": 1360,
"y": 320,
"wires": [
[
"912a2c18da3a3a15"
]
]
},
{
"id": "656c3f4674b31679",
"type": "function",
"z": "7f568cf7f029073b",
"name": "CREATE DATABASE",
"func": "//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id))\";\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1100,
"y": 340,
"wires": [
[
"b904ffe34491964a"
]
]
},
{
"id": "8ff0c6770c8d8d59",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"order": 2,
"width": 2,
"height": 1,
"passthru": false,
"label": "建立資料庫",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "建立資料庫",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 810,
"y": 320,
"wires": [
[
"656c3f4674b31679",
"2d4378b8e19ad196"
]
]
},
{
"id": "07b9f01ae0ad5a72",
"type": "function",
"z": "7f568cf7f029073b",
"name": "INSERT",
"func": "var Today = new Date();\nvar yyyy = Today.getFullYear(); //年\nvar MM = Today.getMonth()+1; //月\nvar dd = Today.getDate(); //日\nvar h = Today.getHours(); //時\nvar m = Today.getMinutes(); //分\nvar s = Today.getSeconds(); //秒\nif(MM<10)\n{\n MM = '0'+MM;\n}\n\nif(dd<10)\n{\n dd = '0'+dd;\n}\n\nif(h<10)\n{\n h = '0'+h;\n}\n\nif(m<10)\n{\n m = '0' + m;\n}\n\nif(s<10)\n{\n s = '0' + s;\n}\nvar var_date = yyyy+'/'+MM+'/'+dd;\nvar var_time = h+':'+m+':'+s;\n\nvar myLED = msg.payload;\n\n\nmsg.topic = \"INSERT INTO LEDSTATUS ( STATUS , Date , Time ) VALUES ($myLED, $var_date , $var_time ) \" ;\nmsg.payload = [myLED, var_date , var_time ]\nreturn msg;\n\n\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1080,
"y": 80,
"wires": [
[
"ec85147569fc2b11"
]
]
},
{
"id": "6baa58d970ba957e",
"type": "ui_audio",
"z": "7f568cf7f029073b",
"name": "",
"group": "3a18026dc181f483",
"voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)",
"always": true,
"x": 1035,
"y": 40,
"wires": [],
"l": false
},
{
"id": "ec85147569fc2b11",
"type": "sqlite",
"z": "7f568cf7f029073b",
"mydb": "46923bc412125a9e",
"sqlquery": "msg.topic",
"sql": "",
"name": "LED_STATUS",
"x": 1260,
"y": 80,
"wires": [
[
"a9fa315671d24bf8",
"7b4e5f12d74e0b7b"
]
]
},
{
"id": "912a2c18da3a3a15",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1550,
"y": 320,
"wires": []
},
{
"id": "a9fa315671d24bf8",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1530,
"y": 80,
"wires": []
},
{
"id": "04c573b6f187fede",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"order": 10,
"width": 4,
"height": 1,
"passthru": false,
"label": "檢視資料庫資料",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "檢視資料",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 820,
"y": 380,
"wires": [
[
"7b4e5f12d74e0b7b",
"2d4378b8e19ad196"
]
]
},
{
"id": "7b4e5f12d74e0b7b",
"type": "function",
"z": "7f568cf7f029073b",
"name": "檢視資料",
"func": "//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50;\n\nmsg.topic = \"SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1120,
"y": 380,
"wires": [
[
"c432df8b65715fe6"
]
]
},
{
"id": "9b4b3471e4446539",
"type": "ui_table",
"z": "7f568cf7f029073b",
"group": "3a18026dc181f483",
"name": "",
"order": 3,
"width": 10,
"height": 10,
"columns": [],
"outputs": 0,
"cts": false,
"x": 1650,
"y": 380,
"wires": []
},
{
"id": "c432df8b65715fe6",
"type": "sqlite",
"z": "7f568cf7f029073b",
"mydb": "46923bc412125a9e",
"sqlquery": "msg.topic",
"sql": "",
"name": "LED_STATUS",
"x": 1360,
"y": 380,
"wires": [
[
"9b4b3471e4446539"
]
]
},
{
"id": "2e507eecaa0dad8c",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"order": 6,
"width": 2,
"height": 1,
"passthru": false,
"label": "刪除資料庫 ",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "刪除資料庫 ",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 810,
"y": 580,
"wires": [
[
"e57dd6531727f298",
"af1bd2d7d6f53e7e"
]
]
},
{
"id": "d204b6118eee4678",
"type": "function",
"z": "7f568cf7f029073b",
"name": "DROP DATABASE",
"func": "//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"DROP TABLE LEDSTATUS\";\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1480,
"y": 580,
"wires": [
[
"eaff192c7bb76731"
]
]
},
{
"id": "eaff192c7bb76731",
"type": "sqlite",
"z": "7f568cf7f029073b",
"mydb": "46923bc412125a9e",
"sqlquery": "msg.topic",
"sql": "",
"name": "LED_STATUS",
"x": 1680,
"y": 560,
"wires": [
[
"7404688e15a5f1fb"
]
]
},
{
"id": "7d41677359df049e",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"order": 4,
"width": 2,
"height": 1,
"passthru": false,
"label": "刪除所有資料 ",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "刪除所有資料 ",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 820,
"y": 520,
"wires": [
[
"af1bd2d7d6f53e7e",
"d60cab41ba66fe22"
]
]
},
{
"id": "e2d8a5c13e249e3f",
"type": "function",
"z": "7f568cf7f029073b",
"name": "DELETE ALL DATA",
"func": "//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"DELETE from LEDSTATUS\";\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1470,
"y": 520,
"wires": [
[
"eaff192c7bb76731"
]
]
},
{
"id": "e57dd6531727f298",
"type": "ui_toast",
"z": "7f568cf7f029073b",
"position": "prompt",
"displayTime": "3",
"highlight": "",
"sendall": true,
"outputs": 1,
"ok": "OK",
"cancel": "Cancel",
"raw": true,
"className": "",
"topic": "",
"name": "",
"x": 1070,
"y": 580,
"wires": [
[
"9a0f68ce200e4546"
]
]
},
{
"id": "9a0f68ce200e4546",
"type": "function",
"z": "7f568cf7f029073b",
"name": "OK or Cancel",
"func": "var topic=msg.payload;\nif (topic==\"\"){\n return [msg,null];\n \n}\nif (topic==\"Cancel\"){\n return [null,msg];\n \n}\nreturn msg;",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1260,
"y": 580,
"wires": [
[
"d204b6118eee4678"
],
[]
]
},
{
"id": "af1bd2d7d6f53e7e",
"type": "ui_audio",
"z": "7f568cf7f029073b",
"name": "",
"group": "3a18026dc181f483",
"voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)",
"always": true,
"x": 955,
"y": 560,
"wires": [],
"l": false
},
{
"id": "d60cab41ba66fe22",
"type": "ui_toast",
"z": "7f568cf7f029073b",
"position": "prompt",
"displayTime": "3",
"highlight": "",
"sendall": true,
"outputs": 1,
"ok": "OK",
"cancel": "Cancel",
"raw": true,
"className": "",
"topic": "",
"name": "",
"x": 1090,
"y": 520,
"wires": [
[
"23b18c68d24e3ebe"
]
]
},
{
"id": "23b18c68d24e3ebe",
"type": "function",
"z": "7f568cf7f029073b",
"name": "OK or Cancel",
"func": "var topic=msg.payload;\nif (topic==\"\"){\n return [msg,null];\n \n}\nif (topic==\"Cancel\"){\n return [null,msg];\n \n}\nreturn msg;",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1260,
"y": 520,
"wires": [
[
"e2d8a5c13e249e3f"
],
[]
]
},
{
"id": "2d4378b8e19ad196",
"type": "ui_audio",
"z": "7f568cf7f029073b",
"name": "",
"group": "3a18026dc181f483",
"voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)",
"always": true,
"x": 955,
"y": 360,
"wires": [],
"l": false
},
{
"id": "7404688e15a5f1fb",
"type": "link out",
"z": "7f568cf7f029073b",
"name": "link out 64",
"mode": "link",
"links": [
"fbd4208d2ebd1ce2"
],
"x": 1815,
"y": 520,
"wires": []
},
{
"id": "fbd4208d2ebd1ce2",
"type": "link in",
"z": "7f568cf7f029073b",
"name": "link in 62",
"links": [
"7404688e15a5f1fb"
],
"x": 1065,
"y": 460,
"wires": [
[
"7b4e5f12d74e0b7b"
]
]
},
{
"id": "4c6dfad4de41ec77",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "資料庫位置 2025LED.db",
"info": "",
"x": 390,
"y": 680,
"wires": []
},
{
"id": "d6429c2e67f1ae4b",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "CREATE建立",
"info": "CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));",
"x": 370,
"y": 780,
"wires": []
},
{
"id": "ae727104af2e93bf",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "INSERT新增",
"info": "INSERT INTO LEDSTATUS (STATUS , Date , Time )values(\"on\", \"11/01\" , \"21:05\") ",
"x": 530,
"y": 760,
"wires": []
},
{
"id": "76279219e89bb86e",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "SELECT檢視",
"info": "SELECT * FROM LEDSTATUS",
"x": 370,
"y": 820,
"wires": []
},
{
"id": "850f4f93281748bf",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "DELETE刪除所有資料",
"info": "DELETE from LEDSTATUS",
"x": 560,
"y": 800,
"wires": []
},
{
"id": "2595fb5a4d591f6a",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "DROP TABLE 刪除資料庫",
"info": "DROP TABLE LEDSTATUS",
"x": 570,
"y": 840,
"wires": []
},
{
"id": "e5caffc44bd438a7",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1010,
"y": 200,
"wires": []
},
{
"id": "9f4e70d369707a36",
"type": "function",
"z": "7f568cf7f029073b",
"name": "function ",
"func": "var temp=msg.payload;\n\nif (temp==\"Relay1on\")\n{\n msg.payload=true;\n return [msg, null, null, null] ;\n}\n\nif (temp == \"Relay1off\")\n{\n msg.payload = false;\n return [msg, null, null, null];\n}\n\nif (temp == \"Relay2on\")\n{\n msg.payload = true;\n return [null, msg, null, null];\n}\n\nif (temp == \"Relay2off\")\n{\n msg.payload = false;\n return [null, msg, null, null]; \n}\n\nif (temp == \"Relay3on\") {\n msg.payload = true;\n return [null, null, msg, null];\n}\n\nif (temp == \"Relay3off\") {\n msg.payload = false;\n return [null, null, msg, null];\n}\nif (temp == \"Relay4on\") {\n msg.payload = true;\n return [null, null, null, msg];\n}\n\nif (temp == \"Relay4off\") {\n msg.payload = false;\n return [null, null, null, msg];\n}\n\n\nreturn msg;",
"outputs": 4,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1340,
"y": 200,
"wires": [
[
"d5d173f638890b30"
],
[
"f29187c3551cbbaf"
],
[
"a3b29f1f2cccc0eb"
],
[
"f62ed4b22c0271df"
]
]
},
{
"id": "d5d173f638890b30",
"type": "ui_led",
"z": "7f568cf7f029073b",
"order": 22,
"group": "a4d2ace4206ad2ca",
"width": 2,
"height": 1,
"label": "LED1",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "#ff0000",
"value": "false",
"valueType": "bool"
},
{
"color": "#008000",
"value": "true",
"valueType": "bool"
}
],
"allowColorForValueInMessage": false,
"shape": "circle",
"showGlow": true,
"name": "",
"x": 1530,
"y": 140,
"wires": []
},
{
"id": "f29187c3551cbbaf",
"type": "ui_led",
"z": "7f568cf7f029073b",
"order": 24,
"group": "a4d2ace4206ad2ca",
"width": 2,
"height": 1,
"label": "LED2",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "#ff0000",
"value": "false",
"valueType": "bool"
},
{
"color": "#008000",
"value": "true",
"valueType": "bool"
}
],
"allowColorForValueInMessage": false,
"shape": "circle",
"showGlow": true,
"name": "",
"x": 1530,
"y": 180,
"wires": []
},
{
"id": "a3b29f1f2cccc0eb",
"type": "ui_led",
"z": "7f568cf7f029073b",
"order": 26,
"group": "a4d2ace4206ad2ca",
"width": 2,
"height": 1,
"label": "LED3",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "#ff0000",
"value": "false",
"valueType": "bool"
},
{
"color": "#008000",
"value": "true",
"valueType": "bool"
}
],
"allowColorForValueInMessage": false,
"shape": "circle",
"showGlow": true,
"name": "",
"x": 1530,
"y": 220,
"wires": []
},
{
"id": "f62ed4b22c0271df",
"type": "ui_led",
"z": "7f568cf7f029073b",
"order": 28,
"group": "a4d2ace4206ad2ca",
"width": 2,
"height": 1,
"label": "LED4",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "#ff0000",
"value": "false",
"valueType": "bool"
},
{
"color": "#008000",
"value": "true",
"valueType": "bool"
}
],
"allowColorForValueInMessage": false,
"shape": "circle",
"showGlow": true,
"name": "",
"x": 1530,
"y": 260,
"wires": []
},
{
"id": "d1ba7b908b8e04a2",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"order": 8,
"width": 2,
"height": 1,
"passthru": false,
"label": "查詢一筆資料",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "查詢一筆資料",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 820,
"y": 660,
"wires": [
[
"b8a90cae646cf5c9",
"4f48a178a9c4ecf3"
]
]
},
{
"id": "0e2e04ac9704eaf0",
"type": "function",
"z": "7f568cf7f029073b",
"name": "查詢一筆資料",
"func": "//\nvar id = msg.payload.id;\nvar s=global.get(\"SEL1\")\nmsg.topic=\"\";\nvar temp=\"\";\n\nif (s==1)\n{\n temp =\"SELECT * FROM LEDSTATUS\";\n temp=temp+\" WHERE id LIKE '\"+ id +\"'\";\n}\nmsg.topic=temp;\nglobal.set(\"SEL1\",0);\n\nreturn msg;\n\n//SELECT * FROM COMPANY WHERE AGE LIKE 'XXX%';\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1360,
"y": 660,
"wires": [
[
"371eb07d99bf6318"
]
]
},
{
"id": "9146f1de0d6535dc",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"order": 12,
"width": 2,
"height": 1,
"passthru": false,
"label": "刪除一筆資料",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "刪除一筆資料",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 820,
"y": 720,
"wires": [
[
"4f48a178a9c4ecf3",
"b11361a1a77554c1"
]
]
},
{
"id": "4f48a178a9c4ecf3",
"type": "ui_audio",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)",
"always": true,
"x": 955,
"y": 760,
"wires": [],
"l": false
},
{
"id": "ffd8f3a338bc1454",
"type": "ui_form",
"z": "7f568cf7f029073b",
"name": "",
"label": "輸入id",
"group": "92ed45c1ead25706",
"order": 18,
"width": 0,
"height": 0,
"options": [
{
"label": "ID",
"value": "id",
"type": "number",
"required": true,
"rows": null
}
],
"formValue": {
"id": ""
},
"payload": "",
"submit": "Submit",
"cancel": "Cancle",
"topic": "Form",
"topicType": "str",
"splitLayout": false,
"className": "",
"x": 1210,
"y": 720,
"wires": [
[
"0e2e04ac9704eaf0",
"e3e6086c7a7db607",
"55b28065da2fe7b9"
]
]
},
{
"id": "e3e6086c7a7db607",
"type": "function",
"z": "7f568cf7f029073b",
"name": "刪除一筆資料",
"func": "//\nvar id = msg.payload.id;\nvar s=global.get(\"SEL2\")\nmsg.topic=\"\";\nvar temp=\"\";\n\nif (s==2)\n{\n temp =\"DELETE FROM LEDSTATUS\";\n temp=temp+\" WHERE id LIKE '\"+ id +\"'\";\n}\n\nmsg.topic=temp;\nglobal.set(\"SEL2\",0)\nreturn msg;\n\n//SELECT * FROM COMPANY WHERE AGE LIKE 'XXX%';\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//DELETE FROM COMPANY WHERE ID = 7;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1380,
"y": 720,
"wires": [
[
"114ec6672d669474",
"e8d7494ca434eacd"
]
]
},
{
"id": "114ec6672d669474",
"type": "sqlite",
"z": "7f568cf7f029073b",
"mydb": "46923bc412125a9e",
"sqlquery": "msg.topic",
"sql": "",
"name": "LED_STATUS",
"x": 1720,
"y": 720,
"wires": [
[
"7404688e15a5f1fb"
]
]
},
{
"id": "b0f3921db12efc98",
"type": "ui_button",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"order": 14,
"width": 2,
"height": 1,
"passthru": false,
"label": "更正一筆資料",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "更正一筆資料",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 820,
"y": 800,
"wires": [
[
"4f48a178a9c4ecf3",
"30c6d0e5032a8bf6"
]
]
},
{
"id": "62d096cced7157f3",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "UPDATE查詢的WHERE",
"info": "UPDATE查詢的WHERE子句的基本語法如下:\n\nUPDATE table_name\nSET column1 = value1, column2 = value2...., columnN = valueN\nWHERE [condition];",
"x": 840,
"y": 840,
"wires": []
},
{
"id": "a972d6f23b3a215c",
"type": "function",
"z": "7f568cf7f029073b",
"name": "更正一筆資料",
"func": "//\nvar id = global.get(\"ID\");\nvar status = msg.payload.Status;\nvar date = msg.payload.date;\nvar time = msg.payload.time;\n\nvar s=global.get(\"SEL3\")\nmsg.topic=\"\";\nvar temp=\"\";\n\nif (s==3)\n{\n temp =\"update LEDSTATUS set \";\n temp=temp+\" STATUS= '\" + status +\"'\";\n temp=temp+\" , Date= '\" + date +\"'\";\n temp=temp+\" , Time= '\" + time +\"'\";\n temp=temp+\" WHERE id=\" + id;\n \n //msg.topic = \"update LEDSTATUS set ( id , STATUS , Date , Time ) VALUES ($id, $status , $date , $time ) \" ;\n //msg.payload = [id,status,date,time]\n}\nmsg.topic=temp;\n\nreturn msg;\n\n//msg.topic = \"INSERT INTO LEDSTATUS ( STATUS , Date , Time ) VALUES ($myLED, $var_date , $var_time ) \" ;\n//msg.payload = [myLED, var_date , var_time ]\n\n\n//SELECT * FROM COMPANY WHERE AGE LIKE 'XXX%';\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//DELETE FROM COMPANY WHERE ID = 7;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1480,
"y": 840,
"wires": [
[
"114ec6672d669474",
"ddaf0d8c00082905"
]
]
},
{
"id": "b8a90cae646cf5c9",
"type": "function",
"z": "7f568cf7f029073b",
"name": "function flow set1",
"func": "var s1=1;\nglobal.set(\"SEL1\",s1);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1030,
"y": 660,
"wires": [
[
"ffd8f3a338bc1454"
]
]
},
{
"id": "b11361a1a77554c1",
"type": "function",
"z": "7f568cf7f029073b",
"name": "function flow set2",
"func": "var s1=2;\nglobal.set(\"SEL2\",s1);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1030,
"y": 720,
"wires": [
[
"ffd8f3a338bc1454"
]
]
},
{
"id": "30c6d0e5032a8bf6",
"type": "function",
"z": "7f568cf7f029073b",
"name": "function flow set3",
"func": "var s1=3;\nglobal.set(\"SEL3\",s1);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1030,
"y": 800,
"wires": [
[
"ffd8f3a338bc1454"
]
]
},
{
"id": "44184ebeea5cb2cb",
"type": "ui_form",
"z": "7f568cf7f029073b",
"name": "",
"label": "更正欄位",
"group": "92ed45c1ead25706",
"order": 16,
"width": 0,
"height": 0,
"options": [
{
"label": "STATUS",
"value": "Status",
"type": "text",
"required": true,
"rows": null
},
{
"label": "DATE",
"value": "date",
"type": "text",
"required": true,
"rows": null
},
{
"label": "TIME",
"value": "time",
"type": "text",
"required": true,
"rows": null
}
],
"formValue": {
"Status": "",
"date": "",
"time": ""
},
"payload": "",
"submit": "Submit",
"cancel": "Cancle",
"topic": "Form",
"topicType": "str",
"splitLayout": false,
"className": "",
"x": 1300,
"y": 840,
"wires": [
[
"a972d6f23b3a215c"
]
]
},
{
"id": "e8d7494ca434eacd",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug 332",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "topic",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1570,
"y": 700,
"wires": []
},
{
"id": "55b28065da2fe7b9",
"type": "function",
"z": "7f568cf7f029073b",
"name": "Store ID資料",
"func": "//\nvar id = msg.payload.id;\nglobal.set(\"ID\",id)\nreturn msg;\n\n//SELECT * FROM COMPANY WHERE AGE LIKE 'XXX%';\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//DELETE FROM COMPANY WHERE ID = 7;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1310,
"y": 780,
"wires": [
[
"44184ebeea5cb2cb",
"4902db512c1335d5"
]
]
},
{
"id": "4902db512c1335d5",
"type": "function",
"z": "7f568cf7f029073b",
"name": "查詢一筆資料",
"func": "//\nvar id = global.get(\"ID\");\nmsg.topic=\"\";\nvar temp=\"\";\ntemp =\"SELECT * FROM LEDSTATUS\";\ntemp=temp+\" WHERE id LIKE '\"+ id +\"'\";\n\nmsg.topic=temp;\n\nreturn msg;\n\n//SELECT * FROM COMPANY WHERE AGE LIKE 'XXX%';\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1500,
"y": 780,
"wires": [
[
"371eb07d99bf6318"
]
]
},
{
"id": "ddaf0d8c00082905",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug 333",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "topic",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1670,
"y": 840,
"wires": []
},
{
"id": "50062c5f7d34d449",
"type": "function",
"z": "7f568cf7f029073b",
"name": "function ",
"func": "msg.payload=\" ---ESP32回來資料---\" +msg.payload;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 980,
"y": 960,
"wires": [
[
"4ab59d366402d061",
"8a5ea74b9b7e1c79",
"26ea7bcb9967c1b8"
]
]
},
{
"id": "4ab59d366402d061",
"type": "function",
"z": "7f568cf7f029073b",
"name": "Set Line API ",
"func": "msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB7dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;\n\n//oR7KdXvK1eobRr2sRRgsl4PMq23DjDlhfUs96SyUBZu",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1170,
"y": 960,
"wires": [
[
"49718f96288f67f4"
]
]
},
{
"id": "49718f96288f67f4",
"type": "http request",
"z": "7f568cf7f029073b",
"name": "",
"method": "POST",
"ret": "txt",
"paytoqs": false,
"url": "https://notify-api.line.me/api/notify",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 1340,
"y": 960,
"wires": [
[
"947da7bd498147af"
]
]
},
{
"id": "947da7bd498147af",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug 334",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1510,
"y": 960,
"wires": []
},
{
"id": "bf5775a352413c1b",
"type": "comment",
"z": "7f568cf7f029073b",
"name": "Line Notify Message ",
"info": "",
"x": 1190,
"y": 920,
"wires": []
},
{
"id": "26ea7bcb9967c1b8",
"type": "ui_text",
"z": "7f568cf7f029073b",
"group": "a4d2ace4206ad2ca",
"order": 18,
"width": 4,
"height": 1,
"name": "",
"label": "Node-RED 訂閱MQTT的資料 : ",
"format": "{{msg.payload}}",
"layout": "row-left",
"className": "",
"x": 1230,
"y": 1040,
"wires": []
},
{
"id": "01e18a8367d319fb",
"type": "ui_audio",
"z": "7f568cf7f029073b",
"name": "",
"group": "92ed45c1ead25706",
"voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)",
"always": "",
"x": 1340,
"y": 1000,
"wires": []
},
{
"id": "8a5ea74b9b7e1c79",
"type": "delay",
"z": "7f568cf7f029073b",
"name": "",
"pauseType": "delay",
"timeout": "1",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 1160,
"y": 1000,
"wires": [
[
"01e18a8367d319fb"
]
]
},
{
"id": "9f648d461ae619b5",
"type": "mqtt in",
"z": "7f568cf7f029073b",
"name": "RELAY_Status Subscribe",
"topic": "alex9ufo/esp32/led/status",
"qos": "1",
"datatype": "auto-detect",
"broker": "21957383cfd8785a",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 770,
"y": 960,
"wires": [
[
"50062c5f7d34d449"
]
]
},
{
"id": "371eb07d99bf6318",
"type": "sqlite",
"z": "7f568cf7f029073b",
"mydb": "46923bc412125a9e",
"sqlquery": "msg.topic",
"sql": "",
"name": "LED_STATUS",
"x": 1560,
"y": 660,
"wires": [
[
"9b4b3471e4446539"
]
]
},
{
"id": "a5f4acf3b9eee1e5",
"type": "ui_gauge",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 19,
"width": 4,
"height": 3,
"gtype": "gage",
"title": "溫度",
"label": "°C",
"format": "{{value}}",
"min": "-40",
"max": "80",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "20",
"seg2": "40",
"className": "",
"x": 550,
"y": 480,
"wires": []
},
{
"id": "f50a7d9e2b2a9a85",
"type": "function",
"z": "7f568cf7f029073b",
"name": "get 濕度",
"func": "msg.payload=msg.payload[1];\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 580,
"wires": [
[
"dd0938ed6509c41f",
"68eb6e5cda3d191a"
]
]
},
{
"id": "333fb02249d57239",
"type": "mqtt in",
"z": "7f568cf7f029073b",
"name": "DHT22 Subscribe",
"topic": "alex9ufo/esp32/dht/temphumi",
"qos": "1",
"datatype": "auto-detect",
"broker": "21957383cfd8785a",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 110,
"y": 440,
"wires": [
[
"f1b583f0b17e8566",
"e1abf12ed03a2277"
]
]
},
{
"id": "f1b583f0b17e8566",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug 335",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 330,
"y": 420,
"wires": []
},
{
"id": "e1abf12ed03a2277",
"type": "function",
"z": "7f568cf7f029073b",
"name": "分離",
"func": "msg.payload = msg.payload.split(\",\");\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 210,
"y": 540,
"wires": [
[
"5d73ae1fe7833bf2",
"f50a7d9e2b2a9a85"
]
]
},
{
"id": "5d73ae1fe7833bf2",
"type": "function",
"z": "7f568cf7f029073b",
"name": "get 溫度",
"func": "msg.payload=msg.payload[0];\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 480,
"wires": [
[
"ed3a43baaa1ee5c7",
"a5f4acf3b9eee1e5"
]
]
},
{
"id": "ed3a43baaa1ee5c7",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug 336",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 570,
"y": 520,
"wires": []
},
{
"id": "dd0938ed6509c41f",
"type": "debug",
"z": "7f568cf7f029073b",
"name": "debug 337",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 570,
"y": 560,
"wires": []
},
{
"id": "68eb6e5cda3d191a",
"type": "ui_gauge",
"z": "7f568cf7f029073b",
"name": "",
"group": "a4d2ace4206ad2ca",
"order": 20,
"width": 4,
"height": 3,
"gtype": "gage",
"title": "濕度",
"label": "%",
"format": "{{value}}",
"min": 0,
"max": "100",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "40",
"seg2": "60",
"className": "",
"x": 550,
"y": 600,
"wires": []
},
{
"id": "21957383cfd8785a",
"type": "mqtt-broker",
"name": "test.mosquitto.org",
"broker": "test.mosquitto.org",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "a4d2ace4206ad2ca",
"type": "ui_group",
"name": "LED控制",
"tab": "62b7557c711185f0",
"order": 1,
"disp": true,
"width": "4",
"collapse": false,
"className": ""
},
{
"id": "46923bc412125a9e",
"type": "sqlitedb",
"db": "2025LED.db",
"mode": "RWC"
},
{
"id": "92ed45c1ead25706",
"type": "ui_group",
"name": "LED 資料庫命令區",
"tab": "62b7557c711185f0",
"order": 3,
"disp": true,
"width": "4",
"collapse": false,
"className": ""
},
{
"id": "3a18026dc181f483",
"type": "ui_group",
"name": "LED 資料庫顯示區",
"tab": "62b7557c711185f0",
"order": 2,
"disp": true,
"width": "10",
"collapse": false,
"className": ""
},
{
"id": "62b7557c711185f0",
"type": "ui_tab",
"name": "WOKWI LED SQLite ",
"icon": "dashboard",
"order": 136,
"disabled": false,
"hidden": false
}
]
沒有留言:
張貼留言