2025年4月19日 星期六

作業4 WOKWI + Node-Red + SQlite + Telegram

 作業4  WOKWI + Node-Red + SQlite + Telegram

      <<需變更 Telegram聊天機器人 名稱>>









#include <WiFi.h>
extern "C" {
  #include "freertos/FreeRTOS.h"
  #include "freertos/timers.h"
}
#include <AsyncMQTT_ESP32.h>

//#include <MFRC522.h>
#include <Arduino.h>
//=========================
//  RFID-RC522 wire pin
//  SDA = 5   SCK =18
//  MOSI=23   MISO=19
//  RST = 4  
//  GND , VCC
//=========================
//MFRC522 程式庫  模擬mfrc522 送出卡號 PB可以控制
int LED1 = 23;
int LED2 = 22;
int LED3 = 21;
int LED4 = 19;

int inPin = 12;    // pushbutton connected to digital pin 12


//#define MQTT_HOST     "broker.mqtt-dashboard.com"
//#define MQTT_HOST     "broker.hivemq.com"
//#define MQTT_HOST       "test.mosquitto.org"  
#define MQTT_HOST     "broker.mqttgo.io"
#define MQTT_PORT       1883

#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""

AsyncMqttClient mqttClient;
TimerHandle_t mqttReconnectTimer;
TimerHandle_t wifiReconnectTimer;


const char *SubTopic1 = "alex9ufo/esp32/led";
const char *PubTopic2 = "alex9ufo/esp32/led_status";
const char *PubTopic3 = "alex9ufo/esp32/RFID";
const char *PubTopic4 = "alex9ufo/esp32/Starting";

//================================================================
bool Send = false;  //true
String LEDjson = "";
int Count= 0;
int val = 0;      // variable to store the read value
bool create=false;
bool Flash1 = false;
bool Flash2 = false;
bool Flash3 = false;
bool Flash4 = false;
//================================================================
void connectToWifi() {
  Serial.println("Connecting to Wi-Fi...");
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}
//================================================================
void connectToMqtt() {
  Serial.println("Connecting to MQTT...");
  mqttClient.connect();
}
//================================================================
void WiFiEvent(WiFiEvent_t event)
{
  switch (event)
  {
#if USING_CORE_ESP32_CORE_V200_PLUS

    case ARDUINO_EVENT_WIFI_READY:
      Serial.println("WiFi ready");
      break;

    case ARDUINO_EVENT_WIFI_STA_START:
      Serial.println("WiFi STA starting");
      break;

    case ARDUINO_EVENT_WIFI_STA_CONNECTED:
      Serial.println("WiFi STA connected");
      break;

    case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
    case ARDUINO_EVENT_WIFI_STA_GOT_IP:
      Serial.println("WiFi connected");
      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());
      connectToMqtt();
      break;

    case ARDUINO_EVENT_WIFI_STA_LOST_IP:
      Serial.println("WiFi lost IP");
      break;

    case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
      Serial.println("WiFi lost connection");
      xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
      xTimerStart(wifiReconnectTimer, 0);
      break;
#else

    case SYSTEM_EVENT_STA_GOT_IP:
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
      connectToMqtt();
      break;

    case SYSTEM_EVENT_STA_DISCONNECTED:
      Serial.println("WiFi lost connection");
      xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
      xTimerStart(wifiReconnectTimer, 0);
      break;
#endif

    default:
      break;
  }
}
//================================================================
void onMqttConnect(bool sessionPresent) {
  Serial.println("Connected to MQTT.");
  Serial.print("Session present: ");
  Serial.println(sessionPresent);

  Serial.println("Connected to MQTT.");
  Serial.print("Session present: ");
  Serial.println(sessionPresent);

  uint16_t packetIdSub1 = mqttClient.subscribe(SubTopic1 , 2);
  Serial.print("Subscribing at QoS 2, packetId: ");
  Serial.println(packetIdSub1);

  //uint16_t packetIdSub2 = mqttClient.subscribe(SubTopic2, 2);
  //Serial.print("Subscribing at QoS 2, packetId: ");
  //Serial.println(packetIdSub2);

}
//================================================================

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
  Serial.println("Disconnected from MQTT.");
  if (WiFi.isConnected()) {
    xTimerStart(mqttReconnectTimer, 0);
  }
}
//================================================================
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
  Serial.println("Subscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
  Serial.print("  qos: ");
  Serial.println(qos);
}
//================================================================
void onMqttUnsubscribe(uint16_t packetId) {
  Serial.println("Unsubscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}
//================================================================
void onMqttPublish(uint16_t packetId) {
  Serial.print("Publish acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}
//================================================================
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
 
  String messageTemp;
  for (int i = 0; i < len; i++) {
    Serial.print((char)payload[i]);
    messageTemp += (char)payload[i];
  }

  if (strcmp(topic, SubTopic1) == 0) {
    // If the relay is on turn it off (and vice-versa)
    Serial.println();
    Serial.println(messageTemp);  
   
    if ((messageTemp) == "led1on") {
    digitalWrite(LED1, HIGH);  // Turn on the LED
    //ledState = true;  //ledState = ture HIGH
    //設定 各個 旗號
    LEDjson ="LED1ON";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }
  if ((messageTemp) == "led2on") {
    digitalWrite(LED2, HIGH);  // Turn on the LED
    //ledState = true;  //ledState = ture HIGH
    //設定 各個 旗號
    LEDjson ="LED2ON";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }
  if ((messageTemp) == "led3on") {
    digitalWrite(LED3, HIGH);  // Turn on the LED
    //ledState = true;  //ledState = ture HIGH
    //設定 各個 旗號
    LEDjson ="LED3ON";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }
  if ((messageTemp) == "led4on") {
    digitalWrite(LED4, HIGH);  // Turn on the LED
    //ledState = true;  //ledState = ture HIGH
    //設定 各個 旗號
    LEDjson ="LED4ON";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }

  if ((messageTemp) == "led1off" ) {
    digitalWrite(LED1, LOW); // Turn off the LED
    //ledState = false; //ledState = false LOW
    LEDjson ="LED1OFF";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }
  if ((messageTemp) == "led2off" ) {
    digitalWrite(LED2, LOW); // Turn off the LED
    //ledState = false; //ledState = false LOW
    LEDjson ="LED2OFF";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }

  if ((messageTemp) == "led3off" ) {
    digitalWrite(LED3, LOW); // Turn off the LED
    //ledState = false; //ledState = false LOW
    LEDjson ="LED3OFF";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }
  if ((messageTemp) == "led4off" ) {
    digitalWrite(LED4, LOW); // Turn off the LED
    //ledState = false; //ledState = false LOW
    LEDjson ="LED4OFF";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }
  if ((messageTemp) == "led1flash" ) {
    digitalWrite(LED1, HIGH); // Turn off the LED
    Flash1 = true;
    //Flash2 = false;
    //Flash3 = false;
    //Flash4 = false;
    LEDjson ="LED1FLASH";
    Send = true ;  
    Serial.println(LEDjson);      
  }
  if ((messageTemp) == "led2flash" ) {
    digitalWrite(LED2, HIGH); // Turn off the LED
    Flash2 = true;
    //Flash1 = false;
    //Flash3 = false;
    //Flash4 = false;
    LEDjson ="LED2FLASH";
    Send = true ;  
    Serial.println(LEDjson);      
  }
  if ((messageTemp) == "led3flash" ) {
    digitalWrite(LED3, HIGH); // Turn off the LED
    Flash3 = true;
    //Flash1 = false;
    //Flash2 = false;
    //Flash4 = false;
    LEDjson ="LED3FLASH";
    Send = true ;  
    Serial.println(LEDjson);      
  }
  if ((messageTemp) == "led4flash" ) {
    digitalWrite(LED4, HIGH); // Turn off the LED
    Flash4 = true;
    //Flash1 = false;
    //Flash2 = false;
    //Flash3 = false;
    LEDjson ="LED4FLASH";
    Send = true ;  
    Serial.println(LEDjson);      
  }

  if ((messageTemp) == "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";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }

  if ((messageTemp) == "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";
    Flash1 = false;
    Flash2 = false;
    Flash3 = false;
    Flash4 = false;
    Send = true ;
    Serial.println(LEDjson);
  }

  }
}
//================================================================
//判斷 旗號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();
    uint16_t packetIdPub1 = mqttClient.publish(PubTopic2, 1, true, LEDjson.c_str());                            
    Serial.printf("LED Published TO MQTT", PubTopic2, packetIdPub1);                            
    Send = false;    //處理過後 旗號 Send為假
  }

}
//================================================================
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

  mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));
  wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));

  WiFi.onEvent(WiFiEvent);

  mqttClient.onConnect(onMqttConnect);
  mqttClient.onDisconnect(onMqttDisconnect);
  mqttClient.onSubscribe(onMqttSubscribe);
  mqttClient.onUnsubscribe(onMqttUnsubscribe);
  mqttClient.onMessage(onMqttMessage); //callback
  mqttClient.setServer(MQTT_HOST, MQTT_PORT);
  // If your broker requires authentication (username and password), set them below
  //mqttClient.setCredentials("REPlACE_WITH_YOUR_USER", "REPLACE_WITH_YOUR_PASSWORD");
  connectToWifi();

  String temp1="Starting ESP32... ";
  uint16_t packetIdPub1 = mqttClient.publish(PubTopic4, 1, true, temp1.c_str());                            
  Serial.printf("RFID UID Number Published", PubTopic4, packetIdPub1);
}
//================================================================
void loop() {
  LED_Message();
  val = digitalRead(inPin);   // read the input pin
  if (val==LOW) create= false;
  if (val==HIGH) create= true;

if (create) {
    // 模擬 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();

    String json = "{ \"uid\": \"";
    for (int i = 0; i < uid.size; i++) {
        json += String(uid.uidByte[i], HEX);
      }
    json += "\" }";

    json.trim();
    uint16_t packetIdPub1 = mqttClient.publish(PubTopic3, 1, true, json.c_str());                            
    Serial.printf("RFID UID Number Published : ", PubTopic3, packetIdPub1);                            
    Serial.println(json);
    Serial.println();
   
    if (val==HIGH)
    {
      Serial.println("Delay...");
      delay(500);
    }
 
  }


}
//================================================================




[ { "id": "508a83bf78d1af97", "type": "ui_switch", "z": "fcce0e6bead574e7", "name": "", "label": "LED1 ON OFF", "tooltip": "", "group": "7376e0c4dc8cc058", "order": 1, "width": 4, "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": 1040, "y": 20, "wires": [ [ "6a97f1d3529e0cfd", "b799e713f3da2249" ] ] }, { "id": "20f5422869d00e3b", "type": "ui_switch", "z": "fcce0e6bead574e7", "name": "", "label": "LED2 ON OFF", "tooltip": "", "group": "7376e0c4dc8cc058", "order": 3, "width": 4, "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": 1040, "y": 60, "wires": [ [ "6a97f1d3529e0cfd" ] ] }, { "id": "f2291e7009d6d78b", "type": "ui_switch", "z": "fcce0e6bead574e7", "name": "", "label": "LED3 ON OFF", "tooltip": "", "group": "7376e0c4dc8cc058", "order": 5, "width": 4, "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": 1040, "y": 100, "wires": [ [ "6a97f1d3529e0cfd" ] ] }, { "id": "88f06c8d911ee9df", "type": "ui_switch", "z": "fcce0e6bead574e7", "name": "", "label": "LED4 ON OFF", "tooltip": "", "group": "7376e0c4dc8cc058", "order": 7, "width": 4, "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": 1040, "y": 140, "wires": [ [ "6a97f1d3529e0cfd" ] ] }, { "id": "c70dbeb8107da82e", "type": "ui_button", "z": "fcce0e6bead574e7", "name": "", "group": "7376e0c4dc8cc058", "order": 9, "width": 6, "height": 1, "passthru": false, "label": "LED all ON", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "ledallon", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 1030, "y": 180, "wires": [ [ "6a97f1d3529e0cfd" ] ] }, { "id": "27fc93ca75339a2f", "type": "ui_button", "z": "fcce0e6bead574e7", "name": "", "group": "7376e0c4dc8cc058", "order": 10, "width": 6, "height": 1, "passthru": false, "label": "LED all OFF", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "ledalloff", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 1030, "y": 220, "wires": [ [ "6a97f1d3529e0cfd" ] ] }, { "id": "6a97f1d3529e0cfd", "type": "mqtt out", "z": "fcce0e6bead574e7", "name": "LED Control", "topic": "alex9ufo/esp32/led", "qos": "1", "retain": "true", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "584db2f88f8050c2", "x": 1290, "y": 140, "wires": [] }, { "id": "b799e713f3da2249", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1240, "y": 40, "wires": [] }, { "id": "a1815bd178772a81", "type": "mqtt in", "z": "fcce0e6bead574e7", "name": "LED Status", "topic": "alex9ufo/esp32/led_status", "qos": "2", "datatype": "auto-detect", "broker": "584db2f88f8050c2", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 90, "y": 240, "wires": [ [ "653157f6067482cb", "2", "b7941493aef7ceba" ] ] }, { "id": "653157f6067482cb", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 240, "y": 400, "wires": [] }, { "id": "2", "type": "function", "z": "fcce0e6bead574e7", "name": "LED Dispatcher", "func": "// 建立一個陣列來裝每個輸出的訊息,預設都為 null\nlet outputs = Array(10).fill(null);\n\n// 根據 payload 決定要送出的輸出端口 (0~9)\nswitch (msg.payload) {\n case \"LED1ON\":\n outputs[0] = msg;\n break;\n case \"LED1OFF\":\n outputs[1] = msg;\n break;\n case \"LED2ON\":\n outputs[2] = msg;\n break;\n case \"LED2OFF\":\n outputs[3] = msg;\n break;\n case \"LED3ON\":\n outputs[4] = msg;\n break;\n case \"LED3OFF\":\n outputs[5] = msg;\n break;\n case \"LED4ON\":\n outputs[6] = msg;\n break;\n case \"LED4OFF\":\n outputs[7] = msg;\n break;\n case \"LEDALLON\":\n outputs[8] = msg;\n break;\n case \"LEDALLOFF\":\n outputs[9] = msg;\n break;\n default:\n return null;\n}\n\n// 回傳包含 10 個輸出的陣列\nreturn outputs;", "outputs": 10, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 260, "y": 240, "wires": [ [ "0a22d4a2657165ad", "f836ba8bb4d80649" ], [ "90d79b4c9d4b0773", "03ee844da78f3e80" ], [ "fbc38c9011e4c418", "053bc4bdad0549ed" ], [ "69a9a1509ba3e739", "e26cf9a59cba5bf2" ], [ "d44f7266d3524809", "e0cf3ebad64a422a" ], [ "29786589908dd6a7", "c390c4d38957ef83" ], [ "0d6635a689b7d6b0", "9b1c52b370485d97" ], [ "1b28cd3697bad642", "ec7ec922fcecb864" ], [ "f4bf4a7b5204983c", "b5d5226ae11f6768" ], [ "d617b4f4b928de16", "eecfaa191e534be4" ] ] }, { "id": "d617b4f4b928de16", "type": "function", "z": "fcce0e6bead574e7", "name": "function LEDALLOFF", "func": "if (msg.payload === \"LEDALLOFF\") {\n msg.payload = false;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 560, "wires": [ [ "f1ab102d6af41123" ] ] }, { "id": "f4bf4a7b5204983c", "type": "function", "z": "fcce0e6bead574e7", "name": "function LEDALLON", "func": "if (msg.payload === \"LEDALLON\") {\n msg.payload = true;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 500, "wires": [ [ "f1ab102d6af41123" ] ] }, { "id": "0a22d4a2657165ad", "type": "function", "z": "fcce0e6bead574e7", "name": "function LED1ON", "func": "if (msg.payload === \"LED1ON\") {\n msg.payload = true;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 570, "y": 40, "wires": [ [ "1623401c00f3052c", "553292363b556395" ] ] }, { "id": "90d79b4c9d4b0773", "type": "function", "z": "fcce0e6bead574e7", "name": "function LED1OFF", "func": "if (msg.payload === \"LED1OFF\") {\n msg.payload = false;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 570, "y": 80, "wires": [ [ "1623401c00f3052c", "553292363b556395" ] ] }, { "id": "1623401c00f3052c", "type": "ui_led", "z": "fcce0e6bead574e7", "order": 2, "group": "7376e0c4dc8cc058", "width": 2, "height": 1, "label": "1", "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": 810, "y": 80, "wires": [] }, { "id": "fbc38c9011e4c418", "type": "function", "z": "fcce0e6bead574e7", "name": "function LED2ON", "func": "if (msg.payload === \"LED2ON\") {\n msg.payload = true;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 570, "y": 160, "wires": [ [ "37fad941c49aee36", "553292363b556395" ] ] }, { "id": "69a9a1509ba3e739", "type": "function", "z": "fcce0e6bead574e7", "name": "function LED2OFF", "func": "if (msg.payload === \"LED2OFF\") {\n msg.payload = false;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 550, "y": 220, "wires": [ [ "37fad941c49aee36", "553292363b556395" ] ] }, { "id": "37fad941c49aee36", "type": "ui_led", "z": "fcce0e6bead574e7", "order": 4, "group": "7376e0c4dc8cc058", "width": 2, "height": 1, "label": "2", "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": 810, "y": 180, "wires": [] }, { "id": "d44f7266d3524809", "type": "function", "z": "fcce0e6bead574e7", "name": "function LED3ON", "func": "if (msg.payload === \"LED3ON\") {\n msg.payload = true;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 550, "y": 280, "wires": [ [ "866d4531a00e4d06", "553292363b556395" ] ] }, { "id": "29786589908dd6a7", "type": "function", "z": "fcce0e6bead574e7", "name": "function LED3OFF", "func": "if (msg.payload === \"LED3OFF\") {\n msg.payload = false;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 550, "y": 340, "wires": [ [ "866d4531a00e4d06", "553292363b556395" ] ] }, { "id": "866d4531a00e4d06", "type": "ui_led", "z": "fcce0e6bead574e7", "order": 6, "group": "7376e0c4dc8cc058", "width": 2, "height": 1, "label": "3", "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": 810, "y": 280, "wires": [] }, { "id": "0d6635a689b7d6b0", "type": "function", "z": "fcce0e6bead574e7", "name": "function LED4ON", "func": "if (msg.payload === \"LED4ON\") {\n msg.payload = true;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 550, "y": 400, "wires": [ [ "e43da95604e0e558", "553292363b556395" ] ] }, { "id": "1b28cd3697bad642", "type": "function", "z": "fcce0e6bead574e7", "name": "function LED4OFF", "func": "if (msg.payload === \"LED4OFF\") {\n msg.payload = false;\n return msg;\n} else {\n return null;\n}", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 550, "y": 440, "wires": [ [ "e43da95604e0e558", "553292363b556395" ] ] }, { "id": "e43da95604e0e558", "type": "ui_led", "z": "fcce0e6bead574e7", "order": 8, "group": "7376e0c4dc8cc058", "width": 2, "height": 1, "label": "4", "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": 810, "y": 420, "wires": [] }, { "id": "f1ab102d6af41123", "type": "link out", "z": "fcce0e6bead574e7", "name": "link out 5", "mode": "link", "links": [ "60c56a73fae93760" ], "x": 745, "y": 540, "wires": [] }, { "id": "60c56a73fae93760", "type": "link in", "z": "fcce0e6bead574e7", "name": "link in 7", "links": [ "f1ab102d6af41123" ], "x": 725, "y": 140, "wires": [ [ "1623401c00f3052c", "37fad941c49aee36", "866d4531a00e4d06", "e43da95604e0e558", "553292363b556395" ] ] }, { "id": "553292363b556395", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 820, "y": 220, "wires": [] }, { "id": "9a349abe035372bb", "type": "function", "z": "fcce0e6bead574e7", "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": 1220, "y": 560, "wires": [ [ "a2d7d7399a152e7d" ] ] }, { "id": "955a2e1ec6b03d9a", "type": "ui_button", "z": "fcce0e6bead574e7", "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": 1000, "y": 560, "wires": [ [ "9a349abe035372bb", "27477e6cbb0d1ab0" ] ] }, { "id": "1d13d8d27746f41f", "type": "function", "z": "fcce0e6bead574e7", "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": 1140, "y": 420, "wires": [ [ "ceaf38b381bc12e0" ] ] }, { "id": "ceaf38b381bc12e0", "type": "sqlite", "z": "fcce0e6bead574e7", "mydb": "f5c97c74cc496505", "sqlquery": "msg.topic", "sql": "", "name": "RFID_2025EX2", "x": 1340, "y": 420, "wires": [ [ "95a108ee567f790d", "5ba82d08c111b413" ] ] }, { "id": "ce776f39256a83d6", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug ", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1590, "y": 560, "wires": [] }, { "id": "95a108ee567f790d", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug ", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1530, "y": 420, "wires": [] }, { "id": "f19ba4f89182c827", "type": "ui_button", "z": "fcce0e6bead574e7", "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": 1000, "y": 500, "wires": [ [ "5ba82d08c111b413", "27477e6cbb0d1ab0" ] ] }, { "id": "5ba82d08c111b413", "type": "function", "z": "fcce0e6bead574e7", "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": 1300, "y": 500, "wires": [ [ "d75616872c411e2a" ] ] }, { "id": "0125ad9a2c641256", "type": "ui_table", "z": "fcce0e6bead574e7", "group": "c1460b15f679e676", "name": "", "order": 4, "width": 9, "height": 5, "columns": [], "outputs": 0, "cts": false, "x": 1630, "y": 500, "wires": [] }, { "id": "b344e00afda936d9", "type": "ui_button", "z": "fcce0e6bead574e7", "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": 1000, "y": 620, "wires": [ [ "6f036d83ed92ce38", "27477e6cbb0d1ab0" ] ] }, { "id": "b57e0d922b95bf93", "type": "function", "z": "fcce0e6bead574e7", "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": 1570, "y": 620, "wires": [ [ "6a6d7897c3cfb419" ] ] }, { "id": "6f036d83ed92ce38", "type": "ui_toast", "z": "fcce0e6bead574e7", "position": "prompt", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 1, "ok": "OK", "cancel": "Cancel", "raw": true, "className": "", "topic": "", "name": "", "x": 1190, "y": 620, "wires": [ [ "a0ef9725fe77f51f" ] ] }, { "id": "a0ef9725fe77f51f", "type": "function", "z": "fcce0e6bead574e7", "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": 1360, "y": 620, "wires": [ [ "b57e0d922b95bf93" ], [] ] }, { "id": "27477e6cbb0d1ab0", "type": "ui_audio", "z": "fcce0e6bead574e7", "name": "", "group": "c1460b15f679e676", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 1145, "y": 520, "wires": [], "l": false }, { "id": "8601544629976bf3", "type": "link out", "z": "fcce0e6bead574e7", "name": "link out 14", "mode": "link", "links": [ "5673b5e03b67335b" ], "x": 1745, "y": 560, "wires": [] }, { "id": "5673b5e03b67335b", "type": "link in", "z": "fcce0e6bead574e7", "name": "link in 17", "links": [ "8601544629976bf3" ], "x": 1815, "y": 560, "wires": [ [ "5ba82d08c111b413" ] ] }, { "id": "2e1dafb86b158821", "type": "mqtt in", "z": "fcce0e6bead574e7", "name": "RFID in", "topic": "alex9ufo/esp32/RFID", "qos": "1", "datatype": "auto-detect", "broker": "584db2f88f8050c2", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 970, "y": 420, "wires": [ [ "1d13d8d27746f41f", "8f883ca3e2e45fba", "2175a631874bfc3c", "4408606c88079552", "2735e8f8d87d3217" ] ] }, { "id": "d75616872c411e2a", "type": "sqlite", "z": "fcce0e6bead574e7", "mydb": "f5c97c74cc496505", "sqlquery": "msg.topic", "sql": "", "name": "RFID_2025EX2", "x": 1460, "y": 500, "wires": [ [ "0125ad9a2c641256" ] ] }, { "id": "a2d7d7399a152e7d", "type": "sqlite", "z": "fcce0e6bead574e7", "mydb": "f5c97c74cc496505", "sqlquery": "msg.topic", "sql": "", "name": "RFID_2025EX2", "x": 1420, "y": 560, "wires": [ [ "ce776f39256a83d6" ] ] }, { "id": "6a6d7897c3cfb419", "type": "sqlite", "z": "fcce0e6bead574e7", "mydb": "f5c97c74cc496505", "sqlquery": "msg.topic", "sql": "", "name": "RFID_2025EX2", "x": 1760, "y": 620, "wires": [ [ "8601544629976bf3" ] ] }, { "id": "8f883ca3e2e45fba", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload.uid", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1140, "y": 460, "wires": [] }, { "id": "2175a631874bfc3c", "type": "function", "z": "fcce0e6bead574e7", "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": 1160, "y": 380, "wires": [ [ "2390120793a57c4c" ] ] }, { "id": "feaf4daafd32f27d", "type": "comment", "z": "fcce0e6bead574e7", "name": "LINE Messaging API", "info": "", "x": 1550, "y": 340, "wires": [] }, { "id": "2390120793a57c4c", "type": "function", "z": "fcce0e6bead574e7", "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": 1380, "y": 380, "wires": [ [ "5d4c661a5d375779" ] ] }, { "id": "5d4c661a5d375779", "type": "http request", "z": "fcce0e6bead574e7", "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": 1650, "y": 380, "wires": [ [ "f9cb0f54c0825f98" ] ] }, { "id": "f9cb0f54c0825f98", "type": "debug", "z": "fcce0e6bead574e7", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 1910, "y": 380, "wires": [] }, { "id": "bc3b9524ad279dd6", "type": "telegram sender", "z": "fcce0e6bead574e7", "name": "@ChinYi_EE_bot", "bot": "a3ea8962e24bd44a", "haserroroutput": true, "outputs": 2, "x": 1510, "y": 280, "wires": [ [ "5f3881a4cf8b704f" ], [] ] }, { "id": "5f3881a4cf8b704f", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1740, "y": 280, "wires": [] }, { "id": "ebac5c36991c340d", "type": "template", "z": "fcce0e6bead574e7", "name": "", "field": "payload", "fieldType": "msg", "format": "handlebars", "syntax": "mustache", "template": "\n{\"chatId\": 7965218469,\n\"type\":\"message\",\n\"content\":\"新增一筆 : {{payload}}\"}\n", "output": "json", "x": 1350, "y": 280, "wires": [ [ "bc3b9524ad279dd6" ] ] }, { "id": "843a28cca1d86813", "type": "comment", "z": "fcce0e6bead574e7", "name": "TeleGram Messaging API", "info": "", "x": 1570, "y": 160, "wires": [] }, { "id": "8c3fcf85e0a58cdc", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1340, "y": 340, "wires": [] }, { "id": "4408606c88079552", "type": "function", "z": "fcce0e6bead574e7", "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": 1160, "y": 340, "wires": [ [ "ebac5c36991c340d", "8c3fcf85e0a58cdc" ] ] }, { "id": "b7941493aef7ceba", "type": "template", "z": "fcce0e6bead574e7", "name": "", "field": "payload", "fieldType": "msg", "format": "handlebars", "syntax": "mustache", "template": "\n{\"chatId\": 7965218469,\n\"type\":\"message\",\n\"content\":\"LED狀態 : {{payload}}\"}\n", "output": "json", "x": 150, "y": 540, "wires": [ [ "9d598c71ba700b7c" ] ] }, { "id": "9d598c71ba700b7c", "type": "telegram sender", "z": "fcce0e6bead574e7", "name": "@ChinYi_EE_bot", "bot": "a3ea8962e24bd44a", "haserroroutput": true, "outputs": 2, "x": 310, "y": 540, "wires": [ [], [] ] }, { "id": "f836ba8bb4d80649", "type": "function", "z": "fcce0e6bead574e7", "name": "function led1on speak", "func": "if (msg.payload === \"LED1ON\") {\n msg.payload = \"L E D 一 號 亮\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 580, "y": 20, "wires": [ [ "3839f360be83125a" ] ] }, { "id": "3839f360be83125a", "type": "ui_audio", "z": "fcce0e6bead574e7", "name": "", "group": "c1460b15f679e676", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 755, "y": 20, "wires": [], "l": false }, { "id": "03ee844da78f3e80", "type": "function", "z": "fcce0e6bead574e7", "name": "function led1off speak", "func": "if (msg.payload === \"LED1OFF\") {\n msg.payload = \"L E D 一 號 滅\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 580, "y": 100, "wires": [ [ "3839f360be83125a" ] ] }, { "id": "e26cf9a59cba5bf2", "type": "function", "z": "fcce0e6bead574e7", "name": "function led2off speak", "func": "if (msg.payload === \"LED2OFF\") {\n msg.payload = \"L E D 二 號 滅\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 200, "wires": [ [ "953a51310d12cdfa" ] ] }, { "id": "053bc4bdad0549ed", "type": "function", "z": "fcce0e6bead574e7", "name": "function led2on speak", "func": "if (msg.payload === \"LED2ON\") {\n msg.payload = \"L E D 二 號 亮\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 580, "y": 140, "wires": [ [ "953a51310d12cdfa" ] ] }, { "id": "953a51310d12cdfa", "type": "ui_audio", "z": "fcce0e6bead574e7", "name": "", "group": "c1460b15f679e676", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 805, "y": 120, "wires": [], "l": false }, { "id": "e0cf3ebad64a422a", "type": "function", "z": "fcce0e6bead574e7", "name": "function led3on speak", "func": "if (msg.payload === \"LED3ON\") {\n msg.payload = \"L E D 三 號 亮\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 260, "wires": [ [ "12d376ba4e7f14a6" ] ] }, { "id": "c390c4d38957ef83", "type": "function", "z": "fcce0e6bead574e7", "name": "function led3off speak", "func": "if (msg.payload === \"LED3OFF\") {\n msg.payload = \"L E D 三 號 滅\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 320, "wires": [ [ "12d376ba4e7f14a6" ] ] }, { "id": "12d376ba4e7f14a6", "type": "ui_audio", "z": "fcce0e6bead574e7", "name": "", "group": "c1460b15f679e676", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 775, "y": 320, "wires": [], "l": false }, { "id": "9b1c52b370485d97", "type": "function", "z": "fcce0e6bead574e7", "name": "function led4on speak", "func": "if (msg.payload === \"LED4ON\") {\n msg.payload = \"L E D 四 號 亮\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 380, "wires": [ [ "94ad2b4fe4204984" ] ] }, { "id": "ec7ec922fcecb864", "type": "function", "z": "fcce0e6bead574e7", "name": "function led4off speak", "func": "if (msg.payload === \"LED4OFF\") {\n msg.payload = \"L E D 四 號 滅\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 460, "wires": [ [ "94ad2b4fe4204984" ] ] }, { "id": "94ad2b4fe4204984", "type": "ui_audio", "z": "fcce0e6bead574e7", "name": "", "group": "c1460b15f679e676", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 765, "y": 480, "wires": [], "l": false }, { "id": "b5d5226ae11f6768", "type": "function", "z": "fcce0e6bead574e7", "name": "function ledallon speak", "func": "if (msg.payload === \"LEDALLON\") {\n msg.payload = \"L E D 全 亮\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 520, "wires": [ [ "94ad2b4fe4204984" ] ] }, { "id": "eecfaa191e534be4", "type": "function", "z": "fcce0e6bead574e7", "name": "function ledoff speak", "func": "if (msg.payload === \"LEDALLOFF\") {\n msg.payload = \"L E D 全 滅\";\n return msg;\n} else {\n return null;\n}\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 580, "wires": [ [ "94ad2b4fe4204984" ] ] }, { "id": "2735e8f8d87d3217", "type": "function", "z": "fcce0e6bead574e7", "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": 1140, "y": 300, "wires": [ [ "8e6072f5689e98ca", "27477e6cbb0d1ab0" ] ] }, { "id": "8e6072f5689e98ca", "type": "debug", "z": "fcce0e6bead574e7", "name": "debug 1", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1280, "y": 240, "wires": [] }, { "id": "7376e0c4dc8cc058", "type": "ui_group", "name": "LED控制", "tab": "82f3819207ab5853", "order": 1, "disp": true, "width": 6, "collapse": false, "className": "" }, { "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": "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": "a3ea8962e24bd44a", "type": "telegram bot", "botname": "@ChinYi_EE_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 } ]

沒有留言:

張貼留言

8-QAM Signal 4 Phases 2 Amplitudes + 8PSK

 8-QAM Signal 4 Phases 2 Amplitudes + 8PSK import tkinter as tk from tkinter import messagebox import math import cmath # --- 8-QAM 參數設定 ---...