WOKWI RFID(亂數模擬) + 4 Relay 控制 (2)
WOKWI程式
#define BOTtoken "80231906815:AAE0KApbm51Ng00VCvO57JWA_XKtbx6a4IXM"
// your Bot Token (Get from Botfather)
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
#define CHAT_ID "796152184619"
以上須修改成自己的Telegram Bot Token API , Chat ID
#include <ArduinoMqttClient.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h> // Universal Telegram Bot Library
//MFRC522 程式庫 模擬mfrc522 送出卡號 PB可以控制
int LED1 = 23;
int LED2 = 22;
int LED3 = 21;
int LED4 = 19;
char ssid[]="Wokwi-GUEST";
char pass[]="";
WiFiClient wifiClient;
MqttClient mqttClient(wifiClient);
// Telegram Bot 資訊
// Initialize Telegram BOT
#define BOTtoken "80231906815:AAE0KApbm51Ng00VCvO57JWA_XKtbx6a4IXM"
// your Bot Token (Get from Botfather)
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
#define CHAT_ID "796152184619"
WiFiClientSecure client1;
UniversalTelegramBot bot(BOTtoken, client1);
// Checks for new messages every 1 second.
int botRequestDelay = 1000;
unsigned long lastTimeBotRan;
//const char broker[] = "test.mosquitto.org";
const char broker[] = "broker.mqttgo.io";
//const char broker[] = "broker.mqtt-dashboard.com";
int port = 1883;
const char *SubTopic1 = "alex9ufo/esp32/led";
const char *PubTopic2 = "alex9ufo/esp32/led_status";
const char *PubTopic3 = "alex9ufo/esp32/RFID";
const char willTopic[] = "alex9ufo/esp32/Starting";
int inPin = 12; // pushbutton connected to digital pin
int val = 0; // variable to store the read value
bool create=false;
bool Send = false; //true
bool RFID = false; //true
bool ledState= false;
String LEDjson = "";
String RFIDjson = "";
const long interval = 1000;
unsigned long previousMillis = 0;
//===========================================================
void onMqttMessage(int messageSize) {
// we received a message, print out the topic and contents
Serial.print("Received a message with topic '");
Serial.print(mqttClient.messageTopic());
String Topic= mqttClient.messageTopic();
Serial.print("', duplicate = ");
Serial.print(mqttClient.messageDup() ? "true" : "false");
Serial.print(", QoS = ");
Serial.print(mqttClient.messageQoS());
Serial.print(", retained = ");
Serial.print(mqttClient.messageRetain() ? "true" : "false");
Serial.print("', length ");
Serial.print(messageSize);
Serial.println(" bytes:");
String message="";
// use the Stream interface to print the contents
while (mqttClient.available()) {
//Serial.print((char)mqttClient.read());
message += (char)mqttClient.read();
}
Serial.println(message);
message.trim();
Topic.trim();
if (Topic=="alex9ufo/esp32/led") {
if (message == "led1on") {
digitalWrite(LED1, HIGH); // Turn on the LED
//ledState = true; //ledState = ture HIGH
//設定 各個 旗號
LEDjson ="LED1ON";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "led2on") {
digitalWrite(LED2, HIGH); // Turn on the LED
//ledState = true; //ledState = ture HIGH
//設定 各個 旗號
LEDjson ="LED2ON";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "led3on") {
digitalWrite(LED3, HIGH); // Turn on the LED
//ledState = true; //ledState = ture HIGH
//設定 各個 旗號
LEDjson ="LED3ON";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "led4on") {
digitalWrite(LED4, HIGH); // Turn on the LED
//ledState = true; //ledState = ture HIGH
//設定 各個 旗號
LEDjson ="LED4ON";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "led1off" ) {
digitalWrite(LED1, LOW); // Turn off the LED
//ledState = false; //ledState = false LOW
LEDjson ="LED1OFF";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "led2off" ) {
digitalWrite(LED2, LOW); // Turn off the LED
//ledState = false; //ledState = false LOW
LEDjson ="LED2OFF";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "led3off" ) {
digitalWrite(LED3, LOW); // Turn off the LED
//ledState = false; //ledState = false LOW
LEDjson ="LED3OFF";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "led4off" ) {
digitalWrite(LED4, LOW); // Turn off the LED
//ledState = false; //ledState = false LOW
LEDjson ="LED4OFF";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "ledalloff" ) {
digitalWrite(LED1, LOW); // Turn off the LED
digitalWrite(LED2, LOW); // Turn off the LED
digitalWrite(LED3, LOW); // Turn off the LED
digitalWrite(LED4, LOW); // Turn off the LED
//ledState = false; //ledState = false LOW
LEDjson ="LEDALLOFF";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
if (message == "ledallon") {
digitalWrite(LED1, HIGH); // Turn on the LED
digitalWrite(LED2, HIGH); // Turn on the LED
digitalWrite(LED3, HIGH); // Turn on the LED
digitalWrite(LED4, HIGH); // Turn on the LED
//ledState = true; //ledState = ture HIGH
//設定 各個 旗號
LEDjson ="LEDALLON";
Send = true ;
Serial.println(LEDjson);
bot.sendMessage(CHAT_ID, LEDjson, "");
}
Serial.println();
Serial.println("-----------------------");
}
}
//===========================================================
//判斷 旗號Flash , Timer 是否為真
void LED_Message() {
//判斷 旗號 Flash / timer 是否為真 ? 閃爍 定時
////判斷 旗號 Send 是否為真 回傳MQTT訊息到MQTT Broker
if (Send) {
// Convert JSON string to character array
Serial.print("Publish message: ");
Serial.println(LEDjson);
LEDjson.trim();
bool retained = false;
int qos = 1;
bool dup = false;
// Publish JSON character array to MQTT topic
mqttClient.beginMessage(PubTopic2, LEDjson.length(), retained, qos, dup); //LED Status
mqttClient.print(LEDjson);
mqttClient.endMessage();
Send = false; //處理過後 旗號 Send為假
}
}
//===========================================================
//副程式 setup wifi
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid); //print ssid
WiFi.begin(ssid, pass); //初始化WiFi 函式庫並回傳目前的網路狀態
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
} //假設 wifi 未連接 show ………
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
//==================================================================
void setup() {
Serial.begin(115200); // 初始化序列埠
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW); // Turn off the LED initially
pinMode(LED2, OUTPUT);
digitalWrite(LED2, LOW); // Turn off the LED initially
pinMode(LED3, OUTPUT);
digitalWrite(LED3, LOW); // Turn off the LED initially
pinMode(LED4, OUTPUT);
digitalWrite(LED4, LOW); // Turn off the LED initially
pinMode(inPin, INPUT); // sets the digital pin 12 as input
randomSeed(analogRead(0)); // 設定亂數種子,增加亂數的隨機性
//Initialize serial and wait for port to open:
Serial.begin(115200); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
setup_wifi();
Serial.println("\nWiFi 已連線");
// 啟用不安全連線(略過 SSL 憑證驗證)
client1.setInsecure();
Serial.println("You're connected to the network");
Serial.println();
Serial.print("Attempting to connect to the MQTT broker: ");
Serial.println(broker);
if (!mqttClient.connect(broker, port)) {
Serial.print("MQTT connection failed! Error code = ");
Serial.println(mqttClient.connectError());
while (1);
}
Serial.println("You're connected to the MQTT broker!");
Serial.println();
// set the message receive callback
mqttClient.onMessage(onMqttMessage);
Serial.print("Subscribing to topic: ");
Serial.println(SubTopic1);
// subscribe to a topic
// the second parameter sets the QoS of the subscription,
// the the library supports subscribing at QoS 0, 1, or 2
int subscribeQos = 1;
mqttClient.subscribe(SubTopic1, subscribeQos);
Serial.println();
Serial.println("Start telegram");
bot.sendMessage(CHAT_ID, "Start telegram " , "");
/***
Init SPI bus
Init MFRC522
***/
}
//==================================================================
void loop() {
val = digitalRead(inPin); // read the input pin
if (val==LOW) create= false;
if (val==HIGH) create= true;
// call poll() regularly to allow the library to receive MQTT messages and
// send MQTT keep alives which avoids being disconnected by the broker
mqttClient.poll();
LED_Message();
/*
int subscribeQos = 1;
mqttClient.subscribe(SubTopic1, subscribeQos);
*/
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (create) {
create= false;
// 模擬 RFID UID 結構
struct RFID_UID {
uint8_t uidByte[10]; // UID 位元組陣列,最大長度為 10
uint8_t size; // UID 長度
};
// 建立一個 RFID UID 物件
RFID_UID uid;
// 設定 UID 資料
uid.size = 4;
for (int i = 0; i < uid.size; i++) {
uid.uidByte[i] = random(256); // 生成 0-255 的亂數
}
// 顯示 UID
Serial.print("UID: ");
for (int i = 0; i < uid.size; i++) {
Serial.print(uid.uidByte[i] < 0x10 ? " 0" : " "); // 補零
Serial.print(uid.uidByte[i], HEX); // 以十六進位格式輸出
}
Serial.println();
RFIDjson = "{ \"uid\": \"";
for (int i = 0; i < uid.size; i++) {
RFIDjson += String(uid.uidByte[i], HEX);
}
RFIDjson += "\" }";
RFIDjson.trim();
bool retained = false;
int qos = 1;
bool dup = false;
mqttClient.beginMessage(PubTopic3, RFIDjson.length(), retained, qos, dup);
mqttClient.print(RFIDjson);
mqttClient.endMessage();
Serial.println(RFIDjson);
Serial.println();
bot.sendMessage(CHAT_ID, RFIDjson, "");
}
}
}
Node-Red程式
1) RFID (LED)
[{"id":"fa7252b2482fe261","type":"ui_switch","z":"cc4582ceffac2493","name":"","label":"LED1","tooltip":"","group":"cb4ec225009fc5c7","order":1,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"led1on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"led1off","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":130,"y":260,"wires":[["e2c5085f408d1ea6","3c2b48c75827145c"]]},{"id":"63a07c9442211c48","type":"ui_switch","z":"cc4582ceffac2493","name":"","label":"LED2","tooltip":"","group":"cb4ec225009fc5c7","order":2,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"led2on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"led2off","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":130,"y":300,"wires":[["e2c5085f408d1ea6","3c2b48c75827145c"]]},{"id":"08265db526adab8f","type":"ui_switch","z":"cc4582ceffac2493","name":"","label":"LED3","tooltip":"","group":"cb4ec225009fc5c7","order":3,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"led3on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"led3off","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":130,"y":340,"wires":[["e2c5085f408d1ea6","3c2b48c75827145c"]]},{"id":"a98ae1d8aabe0bcc","type":"ui_switch","z":"cc4582ceffac2493","name":"","label":"LED4","tooltip":"","group":"cb4ec225009fc5c7","order":4,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"led4on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"led4off","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":130,"y":380,"wires":[["e2c5085f408d1ea6","3c2b48c75827145c"]]},{"id":"5c9028e8e0c4e997","type":"ui_switch","z":"cc4582ceffac2493","name":"","label":"allLED","tooltip":"","group":"cb4ec225009fc5c7","order":5,"width":6,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"ledallon","onvalueType":"str","onicon":"","oncolor":"","offvalue":"ledalloff","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":130,"y":420,"wires":[["e2c5085f408d1ea6","3c2b48c75827145c"]]},{"id":"e2c5085f408d1ea6","type":"mqtt out","z":"cc4582ceffac2493","name":"LED控制","topic":"alex9ufo/esp32/led","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"70940176.2b2d3","x":400,"y":320,"wires":[]},{"id":"a3cd416a183e31e4","type":"mqtt in","z":"cc4582ceffac2493","name":"","topic":"alex9ufo/esp32/led_status","qos":"1","datatype":"auto-detect","broker":"70940176.2b2d3","nl":false,"rap":true,"rh":0,"inputs":0,"x":190,"y":500,"wires":[["15d2e78b1d3d6409","2729eaf47eeed79e"]]},{"id":"15d2e78b1d3d6409","type":"debug","z":"cc4582ceffac2493","name":"debug 374","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":500,"wires":[]},{"id":"2729eaf47eeed79e","type":"ui_text","z":"cc4582ceffac2493","group":"cb4ec225009fc5c7","order":7,"width":6,"height":1,"name":"","label":"LED回傳 : ","format":"{{msg.payload}}","layout":"row-center","className":"","x":400,"y":460,"wires":[]},{"id":"3c2b48c75827145c","type":"ui_text","z":"cc4582ceffac2493","group":"cb4ec225009fc5c7","order":6,"width":6,"height":1,"name":"","label":"控制LED : ","format":"{{msg.payload}}","layout":"row-center","className":"","x":400,"y":380,"wires":[]},{"id":"c376b5404e847cfc","type":"ui_button","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","order":8,"width":2,"height":1,"passthru":false,"label":"建立資料庫","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"建立資料庫","payloadType":"str","topic":"topic","topicType":"msg","x":150,"y":600,"wires":[["2cf12db8d006a7b3","6f9be7b0937e46ae"]]},{"id":"6f9be7b0937e46ae","type":"ui_audio","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":295,"y":560,"wires":[],"l":false},{"id":"9f923ffda1b521f1","type":"comment","z":"cc4582ceffac2493","name":"TABLE LEDSTATUS","info":"CREATE TABLE LEDSTATUS (\nid INTEGER,\nSTATUS TEXT,\nDate DATE,\nTime TIME,\nPRIMARY KEY (id)\n);","x":370,"y":640,"wires":[]},{"id":"2cf12db8d006a7b3","type":"function","z":"cc4582ceffac2493","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,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":600,"wires":[["f26c14872ebca2a6"]]},{"id":"f26c14872ebca2a6","type":"sqlite","z":"cc4582ceffac2493","mydb":"a364eb882c401a25","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":580,"y":600,"wires":[["4f562fa3a88f9931"]]},{"id":"4f562fa3a88f9931","type":"debug","z":"cc4582ceffac2493","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":600,"wires":[]},{"id":"77551c67d1fcca42","type":"comment","z":"cc4582ceffac2493","name":"資料庫位置 C:\\Users\\User\\.node-red\\EX4_LED.db","info":"","x":500,"y":560,"wires":[]},{"id":"e7457906753b858c","type":"ui_button","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","order":14,"width":2,"height":1,"passthru":false,"label":"檢視資料庫","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"檢視資料","payloadType":"str","topic":"topic","topicType":"msg","x":130,"y":740,"wires":[["e3fae5cf397b87d8","c31cded87dd34452"]]},{"id":"e3fae5cf397b87d8","type":"function","z":"cc4582ceffac2493","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":400,"y":760,"wires":[["cf3c75dc8981d826"]]},{"id":"b1ef1857cb7ad9fe","type":"ui_table","z":"cc4582ceffac2493","group":"0f721267ca7e6a01","name":"LED 資料庫","order":1,"width":6,"height":8,"columns":[],"outputs":0,"cts":false,"x":790,"y":760,"wires":[]},{"id":"cf3c75dc8981d826","type":"sqlite","z":"cc4582ceffac2493","mydb":"a364eb882c401a25","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":580,"y":760,"wires":[["b1ef1857cb7ad9fe"]]},{"id":"e3d24e44df60ebec","type":"ui_button","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","order":10,"width":2,"height":1,"passthru":false,"label":"刪除資料庫 ","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"刪除資料庫 ","payloadType":"str","topic":"topic","topicType":"msg","x":170,"y":1100,"wires":[["9e6ab6be1de449ec","42d03526e7aa4ec7"]]},{"id":"9a6c5ec2c8de6b6c","type":"function","z":"cc4582ceffac2493","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":580,"y":1040,"wires":[["9315d3541bfedd0a"]]},{"id":"9315d3541bfedd0a","type":"sqlite","z":"cc4582ceffac2493","mydb":"a364eb882c401a25","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":800,"y":960,"wires":[["9db515ea863b3af3"]]},{"id":"9df64b96e32ef295","type":"ui_button","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","order":12,"width":2,"height":1,"passthru":false,"label":"刪除所有資料 ","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"刪除所有資料 ","payloadType":"str","topic":"topic","topicType":"msg","x":180,"y":1000,"wires":[["42d03526e7aa4ec7","24f194a9cc709776"]]},{"id":"95b12cbb41f093a1","type":"function","z":"cc4582ceffac2493","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":450,"y":940,"wires":[["9315d3541bfedd0a"]]},{"id":"9e6ab6be1de449ec","type":"ui_toast","z":"cc4582ceffac2493","position":"prompt","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"className":"","topic":"","name":"","x":370,"y":1100,"wires":[["2b7e1a8286f4635b"]]},{"id":"2b7e1a8286f4635b","type":"function","z":"cc4582ceffac2493","name":"function 107","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":550,"y":1100,"wires":[["9a6c5ec2c8de6b6c"],[]]},{"id":"42d03526e7aa4ec7","type":"ui_audio","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":305,"y":1040,"wires":[],"l":false},{"id":"24f194a9cc709776","type":"ui_toast","z":"cc4582ceffac2493","position":"prompt","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"className":"","topic":"","name":"","x":390,"y":1000,"wires":[["b1fcd0fde89fa7e5"]]},{"id":"b1fcd0fde89fa7e5","type":"function","z":"cc4582ceffac2493","name":"function 108","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":550,"y":1000,"wires":[["95b12cbb41f093a1"],[]]},{"id":"c31cded87dd34452","type":"ui_audio","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":255,"y":900,"wires":[],"l":false},{"id":"a89731ae9879a94d","type":"ui_button","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","order":2,"width":2,"height":1,"passthru":false,"label":"查詢一筆資料","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"查詢一筆資料","payloadType":"str","topic":"topic","topicType":"msg","x":180,"y":1160,"wires":[["42d03526e7aa4ec7","038826d0598cfa3c"]]},{"id":"76e039458493b9c6","type":"function","z":"cc4582ceffac2493","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":720,"y":1160,"wires":[["1b8d49b1535a772f"]]},{"id":"1b8d49b1535a772f","type":"sqlite","z":"cc4582ceffac2493","mydb":"a364eb882c401a25","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":780,"y":1080,"wires":[["b1ef1857cb7ad9fe"]]},{"id":"2c19084d1c61fa15","type":"ui_button","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","order":4,"width":2,"height":1,"passthru":false,"label":"刪除一筆資料","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"刪除一筆資料","payloadType":"str","topic":"topic","topicType":"msg","x":180,"y":1220,"wires":[["22999c97cb5c8d62","08da1b9f62b49f5d"]]},{"id":"22999c97cb5c8d62","type":"ui_audio","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":315,"y":1260,"wires":[],"l":false},{"id":"352f201ed51f5b04","type":"ui_form","z":"cc4582ceffac2493","name":"","label":"輸入id","group":"2badcf255b02a30c","order":1,"width":4,"height":1,"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":570,"y":1220,"wires":[["76e039458493b9c6","c87baa7a2d1f60b8","04e29e9c7645f7cb"]]},{"id":"c87baa7a2d1f60b8","type":"function","z":"cc4582ceffac2493","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":740,"y":1220,"wires":[["98fb411c4840d705","8b45b4022a2eceed"]]},{"id":"9db515ea863b3af3","type":"link out","z":"cc4582ceffac2493","name":"link out 65","mode":"link","links":["c83b2059543b9985"],"x":935,"y":960,"wires":[]},{"id":"c83b2059543b9985","type":"link in","z":"cc4582ceffac2493","name":"link in 63","links":["9db515ea863b3af3"],"x":315,"y":900,"wires":[["e3fae5cf397b87d8"]]},{"id":"98fb411c4840d705","type":"sqlite","z":"cc4582ceffac2493","mydb":"a364eb882c401a25","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":980,"y":1220,"wires":[["9db515ea863b3af3"]]},{"id":"4a19c64ec472da3f","type":"ui_button","z":"cc4582ceffac2493","name":"","group":"2badcf255b02a30c","order":6,"width":2,"height":1,"passthru":false,"label":"更正一筆資料","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"更正一筆資料","payloadType":"str","topic":"topic","topicType":"msg","x":180,"y":1300,"wires":[["22999c97cb5c8d62","e27f842a4156cd08"]]},{"id":"4f91a957f7087f62","type":"comment","z":"cc4582ceffac2493","name":"UPDATE查詢的WHERE","info":"UPDATE查詢的WHERE子句的基本語法如下:\n\nUPDATE table_name\nSET column1 = value1, column2 = value2...., columnN = valueN\nWHERE [condition];","x":200,"y":1340,"wires":[]},{"id":"daa8be4981a111a8","type":"function","z":"cc4582ceffac2493","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":840,"y":1340,"wires":[["98fb411c4840d705","c421a7105421bb4e"]]},{"id":"038826d0598cfa3c","type":"function","z":"cc4582ceffac2493","name":"function flow set1","func":"var s1=1;\nglobal.set(\"SEL1\",s1);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1160,"wires":[["352f201ed51f5b04"]]},{"id":"08da1b9f62b49f5d","type":"function","z":"cc4582ceffac2493","name":"function flow set2","func":"var s1=2;\nglobal.set(\"SEL2\",s1);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1220,"wires":[["352f201ed51f5b04"]]},{"id":"e27f842a4156cd08","type":"function","z":"cc4582ceffac2493","name":"function flow set3","func":"var s1=3;\nglobal.set(\"SEL3\",s1);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1300,"wires":[["352f201ed51f5b04"]]},{"id":"d7db2ddc3b9b9530","type":"ui_form","z":"cc4582ceffac2493","name":"","label":"更正欄位","group":"2badcf255b02a30c","order":3,"width":4,"height":1,"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":660,"y":1340,"wires":[["daa8be4981a111a8"]]},{"id":"8b45b4022a2eceed","type":"debug","z":"cc4582ceffac2493","name":"debug 375","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":1180,"wires":[]},{"id":"04e29e9c7645f7cb","type":"function","z":"cc4582ceffac2493","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":670,"y":1280,"wires":[["d7db2ddc3b9b9530","1446372415ae9143"]]},{"id":"1446372415ae9143","type":"function","z":"cc4582ceffac2493","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":860,"y":1280,"wires":[["1b8d49b1535a772f"]]},{"id":"c421a7105421bb4e","type":"debug","z":"cc4582ceffac2493","name":"debug 376","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":1030,"y":1340,"wires":[]},{"id":"99de55078419d4da","type":"function","z":"cc4582ceffac2493","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,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":700,"wires":[["e2a2fc3f1644dce0"]]},{"id":"e2a2fc3f1644dce0","type":"sqlite","z":"cc4582ceffac2493","mydb":"a364eb882c401a25","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":540,"y":700,"wires":[["d9fd8f0a10b2dcfb","e3fae5cf397b87d8"]]},{"id":"d9fd8f0a10b2dcfb","type":"debug","z":"cc4582ceffac2493","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":700,"wires":[]},{"id":"1641c0f6103984e5","type":"mqtt in","z":"cc4582ceffac2493","name":"","topic":"alex9ufo/esp32/led_status","qos":"1","datatype":"auto-detect","broker":"70940176.2b2d3","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":700,"wires":[["99de55078419d4da"]]},{"id":"80d1bcd6898e12af","type":"template","z":"cc4582ceffac2493","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"chatId\": 7965218469,\n\"type\":\"message\",\n\"content\":\"{{payload}}\"}\n","output":"json","x":410,"y":1440,"wires":[["efdaa503a9d37be0","343c03e47fad5304"]]},{"id":"efdaa503a9d37be0","type":"debug","z":"cc4582ceffac2493","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":1400,"wires":[]},{"id":"343c03e47fad5304","type":"telegram sender","z":"cc4582ceffac2493","name":"LED&DHT22","bot":"ae1a60539b8e5308","haserroroutput":true,"outputs":2,"x":670,"y":1440,"wires":[[],[]]},{"id":"132d719df972442d","type":"mqtt in","z":"cc4582ceffac2493","name":"","topic":"alex9ufo/esp32/led_status","qos":"1","datatype":"auto-detect","broker":"70940176.2b2d3","nl":false,"rap":true,"rh":0,"inputs":0,"x":210,"y":1440,"wires":[["80d1bcd6898e12af"]]},{"id":"cb4ec225009fc5c7","type":"ui_group","name":"LED控制","tab":"c664c97e6abfc0e6","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"70940176.2b2d3","type":"mqtt-broker","name":"","broker":"broker.mqttgo.io","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"15","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"2badcf255b02a30c","type":"ui_group","name":"LED資料庫","tab":"c664c97e6abfc0e6","order":3,"disp":true,"width":6,"collapse":false,"className":""},{"id":"a364eb882c401a25","type":"sqlitedb","db":"C:\\Users\\User\\.node-red\\EX4_LED.db","mode":"RWC"},{"id":"0f721267ca7e6a01","type":"ui_group","name":"LED顯示","tab":"c664c97e6abfc0e6","order":4,"disp":true,"width":"6","collapse":false,"className":""},{"id":"ae1a60539b8e5308","type":"telegram bot","botname":"ncutedu_ledcontrol_bot","usernames":"","chatids":"","baseapiurl":"","testenvironment":false,"updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksprotocol":"socks5","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false},{"id":"c664c97e6abfc0e6","type":"ui_tab","name":"RFID (LED)","icon":"dashboard","order":2,"disabled":false,"hidden":false}]
2) RFID (RFID)
Toker需修改
[{"id":"15a74c51685360a1","type":"function","z":"c23b19dc6443ea01","name":"CREATE DATABASE","func":"//CREATE TABLE RFIDUID (\n//id INTEGER,\n//UID TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,UID TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"CREATE TABLE RFIDUID (id INTEGER,UID TEXT,Date DATE,Time TIME,PRIMARY KEY (id))\";\nreturn msg;\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":500,"wires":[["c8ce91f0cb16049b"]]},{"id":"357eb5cc45fb63bd","type":"ui_button","z":"c23b19dc6443ea01","name":"","group":"c1460b15f679e676","order":2,"width":3,"height":1,"passthru":false,"label":"建立RFID資料庫","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"建立資料庫","payloadType":"str","topic":"topic","topicType":"msg","x":120,"y":500,"wires":[["15a74c51685360a1","6065b112f05c9e53"]]},{"id":"085970203919b14a","type":"function","z":"c23b19dc6443ea01","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 myUID = msg.payload.uid;\n\n\nmsg.topic = \"INSERT INTO RFIDUID ( UID , Date , Time ) VALUES ($myUID, $var_date , $var_time ) \" ;\nmsg.payload = [myUID, var_date , var_time ]\nreturn msg;\n\n\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//UID TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":360,"wires":[["3430b19c322d6294"]]},{"id":"3430b19c322d6294","type":"sqlite","z":"c23b19dc6443ea01","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"RFID_2025","x":450,"y":360,"wires":[["fb46fe7a3408f5a3","0ee32fc47ac27d14"]]},{"id":"56d5703f9a4a09c6","type":"debug","z":"c23b19dc6443ea01","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":500,"wires":[]},{"id":"fb46fe7a3408f5a3","type":"debug","z":"c23b19dc6443ea01","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":360,"wires":[]},{"id":"29bb6280b83e3290","type":"ui_button","z":"c23b19dc6443ea01","name":"","group":"c1460b15f679e676","order":1,"width":3,"height":1,"passthru":false,"label":"檢視資料庫資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"檢視資料","payloadType":"str","topic":"topic","topicType":"msg","x":120,"y":440,"wires":[["0ee32fc47ac27d14","6065b112f05c9e53"]]},{"id":"0ee32fc47ac27d14","type":"function","z":"c23b19dc6443ea01","name":"檢視資料","func":"//INSERT INTO RFIDUID (\n//id INTEGER,\n//UID TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//SELECT * FROM RFIDUID ORDER BY id DESC LIMIT 50;\n\nmsg.topic = \"SELECT * FROM RFIDUID ORDER BY id DESC LIMIT 50\";\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":440,"wires":[["93890f7961913e77"]]},{"id":"216bb0bfaaf493ec","type":"ui_table","z":"c23b19dc6443ea01","group":"c1460b15f679e676","name":"","order":4,"width":9,"height":5,"columns":[],"outputs":0,"cts":false,"x":750,"y":440,"wires":[]},{"id":"1e30edae0c8cb263","type":"ui_button","z":"c23b19dc6443ea01","name":"","group":"c1460b15f679e676","order":3,"width":3,"height":1,"passthru":false,"label":"刪除所有資料 ","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除所有資料 ","payloadType":"str","topic":"topic","topicType":"msg","x":120,"y":560,"wires":[["283bcd349d5dffb0","6065b112f05c9e53"]]},{"id":"b841d8e609c2cc4b","type":"function","z":"c23b19dc6443ea01","name":"DELETE ALL DATA","func":"//CREATE TABLE RFIDUID (\n//id INTEGER,\n//UID TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,UID TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"DELETE from RFIDUID\";\nreturn msg;\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":560,"wires":[["9b521d6020e9e0f4"]]},{"id":"283bcd349d5dffb0","type":"ui_toast","z":"c23b19dc6443ea01","position":"prompt","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"className":"","topic":"","name":"","x":310,"y":560,"wires":[["ace50755cc0b8922"]]},{"id":"ace50755cc0b8922","type":"function","z":"c23b19dc6443ea01","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":480,"y":560,"wires":[["b841d8e609c2cc4b"],[]]},{"id":"6065b112f05c9e53","type":"ui_audio","z":"c23b19dc6443ea01","name":"","group":"c1460b15f679e676","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":265,"y":460,"wires":[],"l":false},{"id":"fee72170f2080a85","type":"link out","z":"c23b19dc6443ea01","name":"link out 14","mode":"link","links":["b3594ffb21a76ab3"],"x":865,"y":500,"wires":[]},{"id":"b3594ffb21a76ab3","type":"link in","z":"c23b19dc6443ea01","name":"link in 17","links":["fee72170f2080a85"],"x":935,"y":500,"wires":[["0ee32fc47ac27d14"]]},{"id":"67044f11f07fbed3","type":"mqtt in","z":"c23b19dc6443ea01","name":"RFID in","topic":"alex9ufo/esp32/RFID","qos":"1","datatype":"auto-detect","broker":"584db2f88f8050c2","nl":false,"rap":true,"rh":0,"inputs":0,"x":90,"y":360,"wires":[["085970203919b14a","6423f79e018c3379","37c32400f92f4586","e048eb84a7d7dbb5","1b93cdf2963091c8"]]},{"id":"93890f7961913e77","type":"sqlite","z":"c23b19dc6443ea01","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"RFID_2025","x":570,"y":440,"wires":[["216bb0bfaaf493ec"]]},{"id":"c8ce91f0cb16049b","type":"sqlite","z":"c23b19dc6443ea01","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"RFID_2025","x":530,"y":500,"wires":[["56d5703f9a4a09c6"]]},{"id":"9b521d6020e9e0f4","type":"sqlite","z":"c23b19dc6443ea01","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"RFID_2025","x":870,"y":560,"wires":[["fee72170f2080a85"]]},{"id":"6423f79e018c3379","type":"debug","z":"c23b19dc6443ea01","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":260,"y":400,"wires":[]},{"id":"37c32400f92f4586","type":"function","z":"c23b19dc6443ea01","name":"增加 日期 時間","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 myUID = msg.payload.uid;\n\n\nmsg.payload=\"新增一筆:\"+ myUID +\", 日期: \"+ var_date +\", 時間:\"+var_time;\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":320,"wires":[[]]},{"id":"568dfb12939d9abb","type":"comment","z":"c23b19dc6443ea01","name":"LINE Messaging API","info":"","x":670,"y":280,"wires":[]},{"id":"754fc3854ea54182","type":"function","z":"c23b19dc6443ea01","name":"LINE Messaging API","func":"//CHANNEL_ACCESS_TOKEN = 'Messaging API Token';\nCHANNEL_ACCESS_TOKEN = 'P7R4jd35usv1YhlJaC9HGXwcq6G0YknpvDxOb356AnOGHt5MPpzXmJrxj5L9OY5Z70h1DSdKRGr2/6Q8cN0bVoh6PcUMISbfncKvnMmv2HG5GCR+HMgpPj2LQYqOLDKgDqUGchzrkgkrG1KhnhfnugdB04t89/1O/w1cDnyilFU=';\nUSER_ID = 'U60f091afaaf1d41e21ace45205bfd3cf'; //'使用者ID(不是Line ID)';\n\nvar msg1=msg.payload;\n\nmessage = {\n type:'text',\n text:'Line Developers傳送的訊息:'+msg1\n};\n\n\nheaders = {\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,\n};\npayload = {\n 'to': USER_ID,\n 'messages': [message]\n};\nmsg.headers = headers;\nmsg.payload = payload;\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":320,"wires":[["4ee6dab3053379d7"]]},{"id":"4ee6dab3053379d7","type":"http request","z":"c23b19dc6443ea01","name":"LINE Developers Messaging API 傳送","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://api.line.me/v2/bot/message/push","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":770,"y":320,"wires":[["aab75bf8747fe23f"]]},{"id":"aab75bf8747fe23f","type":"debug","z":"c23b19dc6443ea01","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1030,"y":320,"wires":[]},{"id":"f432139caa1b8163","type":"telegram sender","z":"c23b19dc6443ea01","name":"@ncutedu_ledcontrol_bot","bot":"a3ea8962e24bd44a","haserroroutput":true,"outputs":2,"x":650,"y":220,"wires":[["ea8e23742a423e90"],[]]},{"id":"ea8e23742a423e90","type":"debug","z":"c23b19dc6443ea01","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":860,"y":220,"wires":[]},{"id":"cdae446facd0d2ef","type":"template","z":"c23b19dc6443ea01","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n{\"chatId\": 7965218469,\n\"type\":\"message\",\n\"content\":\"新增一筆 : {{payload}}\"}\n","output":"json","x":470,"y":220,"wires":[["f432139caa1b8163"]]},{"id":"8b7bd53dd55d1a05","type":"comment","z":"c23b19dc6443ea01","name":"TeleGram Messaging API","info":"","x":610,"y":160,"wires":[]},{"id":"8c57e864ac81cdd3","type":"debug","z":"c23b19dc6443ea01","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":460,"y":280,"wires":[]},{"id":"e048eb84a7d7dbb5","type":"function","z":"c23b19dc6443ea01","name":"增加 日期 時間","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 myuid = msg.payload.uid;\n\nmsg.payload= myuid +\", 日期: \"+ var_date +\", 時間:\"+var_time;\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":280,"wires":[["cdae446facd0d2ef","8c57e864ac81cdd3"]]},{"id":"1b93cdf2963091c8","type":"function","z":"c23b19dc6443ea01","name":"get UID","func":"\nvar myuid = msg.payload.uid;\n\nmsg.payload= myuid;\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":240,"wires":[["bbcdeb072c111aa7","6065b112f05c9e53"]]},{"id":"bbcdeb072c111aa7","type":"debug","z":"c23b19dc6443ea01","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":400,"y":160,"wires":[]},{"id":"c1460b15f679e676","type":"ui_group","name":"RFID 資料","tab":"82f3819207ab5853","order":2,"disp":true,"width":9,"collapse":false,"className":""},{"id":"f5c97c74cc496505","type":"sqlitedb","db":"2025EX2_RFID.db","mode":"RWC"},{"id":"584db2f88f8050c2","type":"mqtt-broker","name":"broker.mqttgo.io","broker":"broker.mqttgo.io","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"a3ea8962e24bd44a","type":"telegram bot","botname":"@ncutedu_ledcontrol_bot","usernames":"","chatids":"","baseapiurl":"","testenvironment":false,"updatemode":"polling","addressfamily":"4","pollinterval":"300","usesocks":false,"sockshost":"","socksprotocol":"socks5","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbothost":"0.0.0.0","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false},{"id":"82f3819207ab5853","type":"ui_tab","name":"WOKWI (RFID)","icon":"dashboard","order":142,"disabled":false,"hidden":false}]










