2024年12月30日 星期一

作業3 wokwi & Node-red程式

 


WOKWI 程式


#include <ArduinoMqttClient.h>
#include <WiFi.h>

//MFRC522 程式庫  模擬mfrc522 定期送出卡號
//#include <SPI.h>
//#include <MFRC522.h>

//#define LED 13      //定義LED接腳
int LED = 13;

char ssid[]="Wokwi-GUEST";
char pass[]="";

WiFiClient wifiClient;
MqttClient mqttClient(wifiClient);

//const char broker[] = "test.mosquitto.org";
const char broker[] = "broker.mqttgo.io";

//const char broker[] = "broker.mqtt-dashboard.com";


int        port     = 1883;
String json = "";
int id[10]={0,0,0,0,0,0,0,0};

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";
//======================================================
//#define SS_PIN       5        // 晶片選擇腳位
//MFRC522 mfrc522(SS_PIN, RST_PIN);    // 建立MFRC522物件
//MFRC522::MIFARE_Key key;  // 儲存金鑰
//MFRC522::StatusCode status;
//===========================================================
//布林代數 LED狀態 是否連上網路ESP32 ready ?
bool ledState = false;
bool atwork = false;
bool Send = false;  //true
String LEDjson = "";
int Count= 0;
bool Flash = false;  //true
bool Timer = false;  //true

unsigned long previousMillis = 0;
unsigned long interval = 10000;
//===========================================================
String decimalToHex(int decimal) {
  // Create an empty string to store the hexadecimal value.
  String hex = "";
 
  // Loop through each digit of the hexadecimal value.
  while (decimal > 0) {
    // Get the remainder when dividing the decimal value by 16.
    int remainder = decimal % 16;
 
    // Convert the remainder to its hexadecimal representation.
    char hexDigit;
    if (remainder < 10) {
      hexDigit = '0' + remainder;
    } else {
      hexDigit = 'A' + remainder - 10;
    }
 
    // Add the hexadecimal digit to the front of the string.
    hex = hexDigit + hex;
 
    // Divide the decimal value by 16 to move to the next digit.
    decimal /= 16;
  }
 
  // Return the hexadecimal value.
  return hex;
}
//===========================================================
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 == "on") {
    digitalWrite(LED, LOW);  // Turn on the LED
    //ledState = true;  //ledState = ture HIGH
    //設定 各個 旗號
    LEDjson ="ON";
    Flash = false;
    Timer = false;
    Send = true ;
    Serial.print("LED =");
    Serial.println(LEDjson);
  }

  if (message == "off" ) {
    digitalWrite(LED, HIGH); // Turn off the LED
    //ledState = false; //ledState = false LOW
    LEDjson ="OFF";
    Flash = false;
    Timer = false;
    Send = true ;
    Serial.print("LED =");
    Serial.println(LEDjson);
  }
 
  if (message == "flash" ) {
    digitalWrite(LED, HIGH); // Turn off the LED
    Flash = true;
    Timer = false;
    LEDjson ="FLASH";
    Send = true ;  
    Serial.print("LED =");
    Serial.println(LEDjson);      
  }

  if (message == "timer" ) {
    digitalWrite(LED, LOW); // Turn off the LED
    Flash = false;
    Timer = true;
    LEDjson ="TIMER";
    Send = true ;
    Count= 11;
    Serial.print("LED =");
    Serial.println(LEDjson);  
  }
 
    Serial.println();
    Serial.println("-----------------------");
  }  

}

//===========================================================
String printHex(byte *buffer, byte bufferSize) {
      String id = "";
      for (byte i = 0; i < bufferSize; i++) {
        id += buffer[i] < 0x10 ? "0" : "";
        id += String(buffer[i], HEX);
        id +=" ";
      }
      return id;
}
//===========================================================
//副程式  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());
}  
//===========================================================
//判斷 旗號Flash , Timer 是否為真
void LED_Message() {
  //判斷 旗號 Flash / timer  是否為真 ? 閃爍 定時
 
  if (Flash){
    digitalWrite(LED, !digitalRead(LED));
    delay(500);
    if (digitalRead(LED))
      ledState = true;
    else
      ledState = false;

  } //(Flash)

  if (Timer) {
    digitalWrite(LED, LOW);
    delay(500);
    if (digitalRead(LED))
      ledState = true;
    else
      ledState = false;

  Count=Count-1;
  if (Count == 0 ){
    Timer=false;
    digitalWrite(LED, HIGH);
    ledState = false;
    }
  } //(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為假
  }

}
//===========================================================
void setup() {
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);  // Turn off the LED initially
  //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("You're connected to the network");
  Serial.println();
 
  String willPayload = "ESP32 Start working....!";
  bool willRetain = true;
  int willQos = 1;

  mqttClient.beginWill(willTopic, willPayload.length(), willRetain, willQos);
  mqttClient.print(willPayload);
  mqttClient.endWill();

  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();
  //SPI.begin();      // Init SPI bus
  //mfrc522.PCD_Init();   // Init MFRC522
  delay(4);       // Optional delay. Some board do need more time after init to be ready, see Readme
  //mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
  //Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
//===========================================================
void loop() {
 
  // 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();
  // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay
  // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info
  unsigned long currentMillis = millis();


 // if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
   
  //   Serial.println(F("Please scan MIFARE Classic card..."));
  // 確認是否有新卡片
   
  //  byte *id = mfrc522.uid.uidByte;   // 取得卡片的UID
  //  byte idSize = mfrc522.uid.size;   // 取得UID的長度
  //  String Type;
  //  Serial.print("PICC type: ");      // 顯示卡片類型
  // 根據卡片回應的SAK值(mfrc522.uid.sak)判斷卡片類型
  //  MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
  //  Type= mfrc522.PICC_GetTypeName(piccType);
  //  Serial.println(mfrc522.PICC_GetTypeName(piccType));
  //  Serial.print("UID Size: ");       // 顯示卡片的UID長度值
  //  Serial.println(idSize);

  //  for (byte i = 0; i < idSize; i++) {  // 逐一顯示UID碼
  //    Serial.print("id[");
  //    Serial.print(i);
  //    Serial.print("]: ");
  //    Serial.println(id[i], HEX);       // 以16進位顯示UID值
  //  }
 
  if (currentMillis - previousMillis >=interval) {

  for(int i=0; i <= 3 ; i++)
  {
    id[i] = random(255);
    Serial.print(id[i], HEX);       // 以16進位顯示UID值
    Serial.print(" ");  
  }


    Serial.println();



    json="";
    String json1="";
    //String json1=printHex(mfrc522.uid.uidByte, mfrc522.uid.size);
   
    for (byte i = 0; i <=3; i++) {
      json1 += id[i] < 0x10 ? "0" : "";
      json1 += String(id[i], HEX);
      json1 +=" ";
    }

    json1.toUpperCase();
    json = json + json1;
    json.trim();

    bool retained = false;
    int qos = 1;
    bool dup = false;

    mqttClient.beginMessage(PubTopic3,  json.length(), retained, qos, dup);
    mqttClient.print(json);
    mqttClient.endMessage();
   
    Serial.println();
    Serial.println(json);

    previousMillis = currentMillis;
    // Dump debug info about the card; PICC_HaltA() is automatically called
    // 令卡片進入停止狀態
    // Dump debug info about the card; PICC_HaltA() is automatically called
    // mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
   
    //mfrc522.PICC_HaltA();
    //mfrc522.PCD_StopCrypto1(); // stop encryption on PCD
  }
}
////===========================================================

Node-Red程式

[ { "id": "097549b2788ecdc2", "type": "tab", "label": "流程1", "disabled": false, "info": "", "env": [] }, { "id": "a987cef8cc2a4969", "type": "tab", "label": "ESP32 Node-Red MQTT", "disabled": true, "info": "", "env": [] }, { "id": "91a01f6c080e6b87", "type": "ui_group", "name": "資料庫控制區", "tab": "23ac83f3538be8bc", "order": 4, "disp": true, "width": 6, "collapse": false, "className": "" }, { "id": "c809b61ebd9643ba", "type": "ui_group", "name": "新增", "tab": "049e33377872336e", "order": 2, "disp": true, "width": 6, "collapse": false, "className": "" }, { "id": "c3321797b4291333", "type": "ui_group", "name": "LED輸入控制區", "tab": "23ac83f3538be8bc", "order": 1, "disp": true, "width": 5, "collapse": false, "className": "" }, { "id": "a443e97ada0cf14f", "type": "sqlitedb", "db": "EX2_3_LED.db", "mode": "RWC" }, { "id": "7b14a6b23895a629", "type": "ui_group", "name": "LED資料顯示區", "tab": "23ac83f3538be8bc", "order": 2, "disp": true, "width": 8, "collapse": false, "className": "" }, { "id": "cff14d809bf82c4b", "type": "ui_group", "name": "單筆控制輸入區", "tab": "23ac83f3538be8bc", "order": 5, "disp": true, "width": 5, "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, "birthTopic": "", "birthQos": "0", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willPayload": "", "willMsg": {}, "sessionExpiry": "" }, { "id": "6d6480f6bc65f976", "type": "ui_group", "name": "RFID資料顯示區", "tab": "23ac83f3538be8bc", "order": 3, "disp": true, "width": 8, "collapse": false, "className": "" }, { "id": "6174aa9d3e8c5856", "type": "mqtt-broker", "name": "", "broker": "broker.hivemq.com", "port": "1883", "clientid": "", "autoConnect": true, "usetls": false, "compatmode": false, "protocolVersion": "4", "keepalive": "15", "cleansession": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willPayload": "", "willMsg": {}, "sessionExpiry": "" }, { "id": "9e654a56c788364a", "type": "sqlitedb", "db": "EX2_3RFID.db", "mode": "RWC" }, { "id": "cdc59054c439d191", "type": "sqlitedb", "db": "C:\\Users\\User\\.node-red\\EX2_2.db", "mode": "RWC" }, { "id": "23ac83f3538be8bc", "type": "ui_tab", "name": "作業2-3", "icon": "dashboard", "order": 91, "disabled": false, "hidden": false }, { "id": "049e33377872336e", "type": "ui_tab", "name": "作業2-1", "icon": "dashboard", "disabled": false, "hidden": false }, { "id": "4d6a512a95542c6a", "type": "ui_base", "theme": { "name": "theme-light", "lightTheme": { "default": "#0094CE", "baseColor": "#0094CE", "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif", "edited": true, "reset": false }, "darkTheme": { "default": "#097479", "baseColor": "#097479", "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif", "edited": false }, "customTheme": { "name": "Untitled Theme 1", "default": "#4B7930", "baseColor": "#4B7930", "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif" }, "themeState": { "base-color": { "default": "#0094CE", "value": "#0094CE", "edited": false }, "page-titlebar-backgroundColor": { "value": "#0094CE", "edited": false }, "page-backgroundColor": { "value": "#fafafa", "edited": false }, "page-sidebar-backgroundColor": { "value": "#ffffff", "edited": false }, "group-textColor": { "value": "#1bbfff", "edited": false }, "group-borderColor": { "value": "#ffffff", "edited": false }, "group-backgroundColor": { "value": "#ffffff", "edited": false }, "widget-textColor": { "value": "#111111", "edited": false }, "widget-backgroundColor": { "value": "#0094ce", "edited": false }, "widget-borderColor": { "value": "#ffffff", "edited": false }, "base-font": { "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif" } }, "angularTheme": { "primary": "indigo", "accents": "blue", "warn": "red", "background": "grey", "palette": "light" } }, "site": { "name": "Node-RED Dashboard", "hideToolbar": "false", "allowSwipe": "false", "lockMenu": "false", "allowTempTheme": "true", "dateFormat": "DD/MM/YYYY", "sizes": { "sx": 48, "sy": 48, "gx": 6, "gy": 6, "cx": 6, "cy": 6, "px": 0, "py": 0 } } }, { "id": "5f69714a569ee0a1", "type": "ui-base", "name": "Node-Red MQTT", "path": "/dashboard" }, { "id": "2816b624b977ab0a", "type": "ui-theme", "name": "Node-Red MQTTTheme ", "colors": { "surface": "#ffffff", "primary": "#0094ce", "bgPage": "#eeeeee", "groupBg": "#ffffff", "groupOutline": "#cccccc" } }, { "id": "d8895f64e5488e59", "type": "ui-page", "name": "Home", "ui": "5f69714a569ee0a1", "path": "/home", "layout": "notebook", "theme": "2816b624b977ab0a", "order": -1, "className": "" }, { "id": "d5182ebc903db295", "type": "ui-group", "name": "LED Group", "page": "d8895f64e5488e59", "width": "6", "height": "1", "order": -1, "disp": true, "className": "" }, { "id": "e03d82c24d1a7eae", "type": "ui-group", "name": "RGB Group ", "page": "d8895f64e5488e59", "width": "6", "height": "1", "order": -1, "disp": true, "className": "" }, { "id": "8f4d7928695ce3bd", "type": "ui-group", "name": "Servo Group ", "page": "d8895f64e5488e59", "width": "6", "height": "1", "order": -1, "disp": true, "className": "" }, { "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": "918cf07e173c875f", "type": "comment", "z": "097549b2788ecdc2", "name": "TABLE LEDSTATUS", "info": "CREATE TABLE LEDSTATUS (\nid INTEGER,\nSTATUS TEXT,\nDate DATE,\nTime TIME,\nPRIMARY KEY (id)\n);", "x": 110, "y": 40, "wires": [] }, { "id": "996c8ad4ef59c633", "type": "function", "z": "097549b2788ecdc2", "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": 300, "y": 120, "wires": [ [ "b17910635e294f7c" ] ] }, { "id": "e8d2d73f9bf95030", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 6, "width": 3, "height": 1, "passthru": false, "label": "(L)建立資料庫", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "建立資料庫", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 100, "y": 120, "wires": [ [ "996c8ad4ef59c633", "2b7b379073519443" ] ] }, { "id": "2b7b379073519443", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "c809b61ebd9643ba", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 215, "y": 80, "wires": [], "l": false }, { "id": "b003126f3b443edc", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "c3321797b4291333", "order": 1, "width": 5, "height": 1, "passthru": false, "label": "ON", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "on", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 70, "y": 160, "wires": [ [ "09a1dd8f5d34faf5", "7bb86359619801b2", "1e6398fa42581387", "18be5728490793d5" ] ] }, { "id": "6c5bd8d97b809a14", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "c3321797b4291333", "order": 2, "width": 5, "height": 1, "passthru": false, "label": "OFF", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "off", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 70, "y": 200, "wires": [ [ "09a1dd8f5d34faf5", "7bb86359619801b2", "1e6398fa42581387", "18be5728490793d5" ] ] }, { "id": "0d9b0e9ae82a2a65", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "c3321797b4291333", "order": 3, "width": 5, "height": 1, "passthru": false, "label": "TOGGLE", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "toggle", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 80, "y": 240, "wires": [ [ "09a1dd8f5d34faf5", "7bb86359619801b2", "1e6398fa42581387", "18be5728490793d5" ] ] }, { "id": "d194ef87acb2d2ca", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "c3321797b4291333", "order": 4, "width": 5, "height": 1, "passthru": false, "label": "TIMER", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "timer", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 80, "y": 280, "wires": [ [ "09a1dd8f5d34faf5", "7bb86359619801b2", "1e6398fa42581387", "18be5728490793d5" ] ] }, { "id": "e97cd2def4b4d96d", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "c3321797b4291333", "order": 5, "width": 5, "height": 1, "passthru": false, "label": "FLASH", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "flash", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 80, "y": 320, "wires": [ [ "7bb86359619801b2", "09a1dd8f5d34faf5", "1e6398fa42581387", "18be5728490793d5" ] ] }, { "id": "7bb86359619801b2", "type": "function", "z": "097549b2788ecdc2", "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": 280, "y": 260, "wires": [ [ "2d36552335dbbc47" ] ] }, { "id": "09a1dd8f5d34faf5", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "c809b61ebd9643ba", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 235, "y": 220, "wires": [], "l": false }, { "id": "2d36552335dbbc47", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "a443e97ada0cf14f", "sqlquery": "msg.topic", "sql": "", "name": "LED_STATUS", "x": 460, "y": 260, "wires": [ [ "1c31c0be1d138922", "52f4ac663f53fd46" ] ] }, { "id": "090aad33988be6be", "type": "debug", "z": "097549b2788ecdc2", "name": "debug ", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 670, "y": 120, "wires": [] }, { "id": "1c31c0be1d138922", "type": "debug", "z": "097549b2788ecdc2", "name": "debug ", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 670, "y": 260, "wires": [] }, { "id": "23e05d70d78ba275", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 8, "width": 6, "height": 1, "passthru": false, "label": "(L)檢視資料庫資料", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "檢視資料", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 110, "y": 420, "wires": [ [ "52f4ac663f53fd46", "9b3908e249a866aa" ] ] }, { "id": "52f4ac663f53fd46", "type": "function", "z": "097549b2788ecdc2", "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": 320, "y": 420, "wires": [ [ "883d91c472861df7" ] ] }, { "id": "883d91c472861df7", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "a443e97ada0cf14f", "sqlquery": "msg.topic", "sql": "", "name": "LED_STATUS", "x": 500, "y": 420, "wires": [ [ "01c9a918fc6f6554" ] ] }, { "id": "7956b4f3123b6630", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 5, "width": 3, "height": 1, "passthru": false, "label": "(L)刪除資料庫 ", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "刪除資料庫 ", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 100, "y": 660, "wires": [ [ "0c6e1a3a79a9bcd5", "611f9e9c25be4490" ] ] }, { "id": "a5eb0397080ce5d7", "type": "function", "z": "097549b2788ecdc2", "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": 500, "y": 600, "wires": [ [ "86ab46b063723fee" ] ] }, { "id": "86ab46b063723fee", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "a443e97ada0cf14f", "sqlquery": "msg.topic", "sql": "", "name": "LED_STATUS", "x": 720, "y": 520, "wires": [ [ "51223e9513a5ae53" ] ] }, { "id": "7556f6279c87a729", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 4, "width": 3, "height": 1, "passthru": false, "label": "(L)刪除所有資料 ", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "刪除所有資料 ", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 100, "y": 560, "wires": [ [ "611f9e9c25be4490", "52ed25a914aad28f" ] ] }, { "id": "9283ad4a102217f4", "type": "function", "z": "097549b2788ecdc2", "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": 370, "y": 500, "wires": [ [ "86ab46b063723fee" ] ] }, { "id": "0c6e1a3a79a9bcd5", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "prompt", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 1, "ok": "OK", "cancel": "Cancel", "raw": true, "className": "", "topic": "", "name": "", "x": 290, "y": 660, "wires": [ [ "1f9d3d18b9bc77a7" ] ] }, { "id": "1f9d3d18b9bc77a7", "type": "function", "z": "097549b2788ecdc2", "name": "function 86", "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": 470, "y": 660, "wires": [ [ "a5eb0397080ce5d7" ], [] ] }, { "id": "611f9e9c25be4490", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "c809b61ebd9643ba", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 225, "y": 600, "wires": [], "l": false }, { "id": "52ed25a914aad28f", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "prompt", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 1, "ok": "OK", "cancel": "Cancel", "raw": true, "className": "", "topic": "", "name": "", "x": 310, "y": 560, "wires": [ [ "00ece397b0653752" ] ] }, { "id": "00ece397b0653752", "type": "function", "z": "097549b2788ecdc2", "name": "function 87", "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": 470, "y": 560, "wires": [ [ "9283ad4a102217f4" ], [] ] }, { "id": "9b3908e249a866aa", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "c809b61ebd9643ba", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 175, "y": 460, "wires": [], "l": false }, { "id": "422eb40cd39186e6", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 1, "width": 3, "height": 1, "passthru": false, "label": "(L)查詢一筆資料", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "查詢一筆資料", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 100, "y": 720, "wires": [ [ "611f9e9c25be4490", "08ed118b7815ee7a" ] ] }, { "id": "7124b85d13a180cd", "type": "function", "z": "097549b2788ecdc2", "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": 640, "y": 720, "wires": [ [ "17e032e915dc4950" ] ] }, { "id": "17e032e915dc4950", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "a443e97ada0cf14f", "sqlquery": "msg.topic", "sql": "", "name": "LED_STATUS", "x": 700, "y": 640, "wires": [ [ "01c9a918fc6f6554" ] ] }, { "id": "0b8cfb953c4b3ade", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 2, "width": 3, "height": 1, "passthru": false, "label": "(L)刪除一筆資料", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "刪除一筆資料", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 100, "y": 780, "wires": [ [ "4e20b975d1ec6435", "3f1426e489453cc7" ] ] }, { "id": "4e20b975d1ec6435", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "7b14a6b23895a629", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 235, "y": 820, "wires": [], "l": false }, { "id": "2b8a956c655b3940", "type": "ui_form", "z": "097549b2788ecdc2", "name": "", "label": "(L)輸入id", "group": "cff14d809bf82c4b", "order": 1, "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": 500, "y": 780, "wires": [ [ "7124b85d13a180cd", "9c27b300ac858c6f", "e6a9b7f3a55793b7" ] ] }, { "id": "9c27b300ac858c6f", "type": "function", "z": "097549b2788ecdc2", "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": 660, "y": 780, "wires": [ [ "1b1d0ceae4b6d5c3", "fb4766230be7e853" ] ] }, { "id": "51223e9513a5ae53", "type": "link out", "z": "097549b2788ecdc2", "name": "link out 46", "mode": "link", "links": [ "828c30adcefcdf3f" ], "x": 855, "y": 520, "wires": [] }, { "id": "828c30adcefcdf3f", "type": "link in", "z": "097549b2788ecdc2", "name": "link in 42", "links": [ "51223e9513a5ae53" ], "x": 235, "y": 460, "wires": [ [ "52f4ac663f53fd46" ] ] }, { "id": "1b1d0ceae4b6d5c3", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "a443e97ada0cf14f", "sqlquery": "msg.topic", "sql": "", "name": "LED_STATUS", "x": 900, "y": 780, "wires": [ [ "51223e9513a5ae53" ] ] }, { "id": "eabdf5169767c3ba", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 3, "width": 3, "height": 1, "passthru": false, "label": "(L)更正一筆資料", "tooltip": "", "color": "", "bgcolor": "green", "className": "", "icon": "", "payload": "更正一筆資料", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 100, "y": 860, "wires": [ [ "4e20b975d1ec6435", "37140a86dcc0603d" ] ] }, { "id": "437a5150b26144b7", "type": "comment", "z": "097549b2788ecdc2", "name": "UPDATE查詢的WHERE", "info": "UPDATE查詢的WHERE子句的基本語法如下:\n\nUPDATE table_name\nSET column1 = value1, column2 = value2...., columnN = valueN\nWHERE [condition];", "x": 120, "y": 900, "wires": [] }, { "id": "6c3d91be4b678015", "type": "function", "z": "097549b2788ecdc2", "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": 760, "y": 900, "wires": [ [ "1b1d0ceae4b6d5c3", "cc38d2b67a458c83" ] ] }, { "id": "08ed118b7815ee7a", "type": "function", "z": "097549b2788ecdc2", "name": "function flow set1", "func": "var s1=1;\nglobal.set(\"SEL1\",s1);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 310, "y": 720, "wires": [ [ "2b8a956c655b3940" ] ] }, { "id": "3f1426e489453cc7", "type": "function", "z": "097549b2788ecdc2", "name": "function flow set2", "func": "var s1=2;\nglobal.set(\"SEL2\",s1);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 310, "y": 780, "wires": [ [ "2b8a956c655b3940" ] ] }, { "id": "37140a86dcc0603d", "type": "function", "z": "097549b2788ecdc2", "name": "function flow set3", "func": "var s1=3;\nglobal.set(\"SEL3\",s1);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 310, "y": 860, "wires": [ [ "2b8a956c655b3940" ] ] }, { "id": "a09b68aa0b49cb0a", "type": "ui_form", "z": "097549b2788ecdc2", "name": "", "label": "(L)更正欄位", "group": "91a01f6c080e6b87", "order": 7, "width": 6, "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": 590, "y": 900, "wires": [ [ "6c3d91be4b678015" ] ] }, { "id": "fb4766230be7e853", "type": "debug", "z": "097549b2788ecdc2", "name": "debug 228", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "topic", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 870, "y": 740, "wires": [] }, { "id": "e6a9b7f3a55793b7", "type": "function", "z": "097549b2788ecdc2", "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": 590, "y": 840, "wires": [ [ "a09b68aa0b49cb0a", "57be303e7847521d" ] ] }, { "id": "57be303e7847521d", "type": "function", "z": "097549b2788ecdc2", "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": 780, "y": 840, "wires": [ [ "17e032e915dc4950" ] ] }, { "id": "cc38d2b67a458c83", "type": "debug", "z": "097549b2788ecdc2", "name": "debug 229", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "topic", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 950, "y": 900, "wires": [] }, { "id": "d242b21d2a0c5cf3", "type": "comment", "z": "097549b2788ecdc2", "name": "資料庫位置 C:\\Users\\User\\.node-red\\EX2_1.db", "info": "", "x": 420, "y": 40, "wires": [] }, { "id": "4913133f8d9ad7f1", "type": "mqtt in", "z": "097549b2788ecdc2", "name": "LED status ", "topic": "alex9ufo/esp32/led_status", "qos": "2", "datatype": "utf8", "broker": "70940176.2b2d3", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 80, "y": 1020, "wires": [ [ "c68a40405ebcb374" ] ] }, { "id": "c68a40405ebcb374", "type": "function", "z": "097549b2788ecdc2", "name": "function ", "func": "msg.payload=\" ---ESP32回來資料---\" +msg.payload;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 260, "y": 1020, "wires": [ [ "2102e7039b045250", "649acfed70035e85", "f802bd1587ed5984" ] ] }, { "id": "2102e7039b045250", "type": "function", "z": "097549b2788ecdc2", "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, "noerr": 0, "x": 450, "y": 1020, "wires": [ [ "77033780eba9e29d" ] ] }, { "id": "77033780eba9e29d", "type": "http request", "z": "097549b2788ecdc2", "name": "", "method": "POST", "ret": "txt", "paytoqs": false, "url": "https://notify-api.line.me/api/notify", "tls": "", "persist": false, "proxy": "", "authType": "", "x": 620, "y": 1020, "wires": [ [ "497d81e527b7c90e" ] ] }, { "id": "497d81e527b7c90e", "type": "debug", "z": "097549b2788ecdc2", "name": "debug 230", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 790, "y": 1020, "wires": [] }, { "id": "fa1c7c77adc7fc9a", "type": "comment", "z": "097549b2788ecdc2", "name": "Line Notify Message ", "info": "", "x": 470, "y": 980, "wires": [] }, { "id": "1e6398fa42581387", "type": "mqtt out", "z": "097549b2788ecdc2", "name": "Control LED", "topic": "alex9ufo/esp32/led", "qos": "1", "retain": "true", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "70940176.2b2d3", "x": 290, "y": 160, "wires": [] }, { "id": "adc12a2696f1243f", "type": "comment", "z": "097549b2788ecdc2", "name": "alex9ufo/esp32/led", "info": "", "x": 350, "y": 200, "wires": [] }, { "id": "18be5728490793d5", "type": "ui_text", "z": "097549b2788ecdc2", "group": "c3321797b4291333", "order": 6, "width": 5, "height": 1, "name": "", "label": "(L)發行到MQTT的資料 : ", "format": "{{msg.payload}}", "layout": "row-left", "className": "", "x": 330, "y": 300, "wires": [] }, { "id": "f802bd1587ed5984", "type": "ui_text", "z": "097549b2788ecdc2", "group": "c3321797b4291333", "order": 7, "width": 5, "height": 1, "name": "", "label": "(L)訂閱MQTT的資料 : ", "format": "{{msg.payload}}", "layout": "row-left", "className": "", "x": 480, "y": 1100, "wires": [] }, { "id": "f215286fd9b8af31", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "7b14a6b23895a629", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": "", "x": 620, "y": 1060, "wires": [] }, { "id": "649acfed70035e85", "type": "delay", "z": "097549b2788ecdc2", "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": 440, "y": 1060, "wires": [ [ "f215286fd9b8af31" ] ] }, { "id": "ab5fed5a867363af", "type": "comment", "z": "097549b2788ecdc2", "name": "TABLE RFIDtable", "info": "\n//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);\nmsg.topic = \"CREATE TABLE RFIDtable(id INTEGER PRIMARY KEY AUTOINCREMENT, uidname TEXT, currentdate DATE, currenttime TIME)\";\nreturn msg;\n", "x": 1200, "y": 40, "wires": [] }, { "id": "d7f62706d93bcb3b", "type": "comment", "z": "097549b2788ecdc2", "name": "資料庫位置 C:\\Users\\User\\.node-red\\EX2_1.db", "info": "", "x": 1300, "y": 80, "wires": [] }, { "id": "505a95f68d90462c", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 14, "width": 6, "height": 1, "passthru": false, "label": "建立資料庫", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "建立資料庫", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 1190, "y": 160, "wires": [ [ "e0a1194ce540d917", "3cb83dbd7b63b7cc" ] ] }, { "id": "09b1dfaae1abeb4b", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 15, "width": 6, "height": 1, "passthru": false, "label": "檢視資料庫資料", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "檢視資料", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 1200, "y": 600, "wires": [ [ "93b048d6f27ed952", "0ebe58b7cddd89e2", "d89e84f03410393e" ] ] }, { "id": "7bb94cdff7895501", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 12, "width": 3, "height": 1, "passthru": false, "label": "刪除所有資料", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "刪除所有資料", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 1200, "y": 860, "wires": [ [ "12017b7a6f3f09bf", "230b03329a7ee52f" ] ] }, { "id": "e0a1194ce540d917", "type": "function", "z": "097549b2788ecdc2", "name": "CREATE DATABASE", "func": "\n\n//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);\nmsg.topic = \"CREATE TABLE RFIDtable(id INTEGER PRIMARY KEY AUTOINCREMENT, uidname TEXT, currentdate DATE, currenttime TIME)\";\nreturn msg;\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1380, "y": 160, "wires": [ [ "944c5522d93029ba" ] ] }, { "id": "bf0a8d200db86645", "type": "debug", "z": "097549b2788ecdc2", "name": "debug", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1990, "y": 200, "wires": [] }, { "id": "2286d19608607f96", "type": "function", "z": "097549b2788ecdc2", "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 myRFID = flow.get('uid_temp');\n\n\nmsg.topic = \"INSERT INTO RFIDtable ( uidname , currentdate, currenttime ) VALUES ($myRFID, $var_date , $var_time ) \" ;\nmsg.payload = [myRFID, var_date , var_time ]\nreturn msg;\n\n//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1560, "y": 240, "wires": [ [ "2fb8243eea647a1b", "72f85902425dafbd" ] ] }, { "id": "2656d096116d25c6", "type": "function", "z": "097549b2788ecdc2", "name": "刪除所有資料", "func": "//DELETE from RFIDtable\nmsg.topic = \"DELETE from RFIDtable\";\nreturn msg;\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1660, "y": 880, "wires": [ [ "0d13bf0e6e2bc74b" ] ] }, { "id": "f8217cd589c6c216", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 10, "width": 3, "height": 1, "passthru": false, "label": "刪除資料庫", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "刪除資料庫", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 1190, "y": 960, "wires": [ [ "49059e7b0e7190d2", "d3afd68d2d964d74" ] ] }, { "id": "5adc4edd7745e24c", "type": "function", "z": "097549b2788ecdc2", "name": "刪除資料庫", "func": "//DROP TABLE RFIDtable\nmsg.topic = \"DROP TABLE RFIDtable\";\nreturn msg;\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1690, "y": 960, "wires": [ [ "646767e4d8f496e4" ] ] }, { "id": "166936c5d16d93b2", "type": "debug", "z": "097549b2788ecdc2", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1990, "y": 940, "wires": [] }, { "id": "d89e84f03410393e", "type": "function", "z": "097549b2788ecdc2", "name": "檢視資料", "func": "\n//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);\n\n//SELECT * FROM RFIDtable ORDER BY id DESC LIMIT 50;\n\nmsg.topic = \"SELECT * FROM RFIDtable ORDER BY id DESC LIMIT 50\";\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1840, "y": 600, "wires": [ [ "a344942e333780f1", "1370642ed41f860b" ] ] }, { "id": "b81063492dfd3f99", "type": "function", "z": "097549b2788ecdc2", "name": "SELECT ALL", "func": "var del_idtemp=msg.payload;\nflow.set(\"idtemp\", del_idtemp);\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1410, "y": 800, "wires": [ [ "e7608bf0d4fe88eb" ] ] }, { "id": "a0c72c6deca9293a", "type": "function", "z": "097549b2788ecdc2", "name": "確認 刪除", "func": "var del_id = flow.get(\"idtemp\");\n\n\nmsg.topic = \"DELETE FROM RFIDtable WHERE id= ($del_id) \" ;\nmsg.payload = [del_id]\nreturn msg;\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1640, "y": 740, "wires": [ [ "d9baa5da3147fe03" ] ] }, { "id": "a6207d2686fba611", "type": "ui_numeric", "z": "097549b2788ecdc2", "name": "", "label": "刪除的database_id", "tooltip": "", "group": "cff14d809bf82c4b", "order": 4, "width": 5, "height": 1, "wrap": true, "passthru": true, "topic": "topic", "topicType": "msg", "format": "{{value}}", "min": "1", "max": "1000", "step": 1, "className": "", "x": 1210, "y": 800, "wires": [ [ "b81063492dfd3f99" ] ] }, { "id": "ed484331a53b854b", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 11, "width": 3, "height": 1, "passthru": false, "label": "刪除一筆資料", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "刪除一筆資料", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 1200, "y": 660, "wires": [ [ "93b048d6f27ed952", "e852561d71dd3c8b" ] ] }, { "id": "e7608bf0d4fe88eb", "type": "debug", "z": "097549b2788ecdc2", "name": "debug 231", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1590, "y": 800, "wires": [] }, { "id": "8cf5670c9eca31b2", "type": "mqtt in", "z": "097549b2788ecdc2", "name": "新增 RFID", "topic": "alex9ufo/esp32/RFID", "qos": "1", "datatype": "utf8", "broker": "70940176.2b2d3", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 1140, "y": 240, "wires": [ [ "a6f94be6a5358970", "85022ed23f46402a" ] ] }, { "id": "64bd852fc03afb17", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "6d6480f6bc65f976", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 1640, "y": 400, "wires": [] }, { "id": "5133ae517d6f6036", "type": "function", "z": "097549b2788ecdc2", "name": "function ", "func": "var temp= msg.payload;\nmsg.payload= \"新增一筆資料\" + temp;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1460, "y": 320, "wires": [ [ "64bd852fc03afb17", "04c972ed40dd4aa8", "386161feb448b294" ] ] }, { "id": "93b048d6f27ed952", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "6d6480f6bc65f976", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 1400, "y": 640, "wires": [] }, { "id": "3cb83dbd7b63b7cc", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "6d6480f6bc65f976", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 1340, "y": 120, "wires": [] }, { "id": "fb6117669e42cc6b", "type": "function", "z": "097549b2788ecdc2", "name": "比對 function", "func": "//SELECT trackid,name FROM \ttracks WHERE name LIKE 'Wild%'\n//Query\n//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);\n//msg.topic = \"DELETE FROM RFIDtable WHERE id= ($del_id) \" ;\n\nvar query_uid = flow.get(\"uidtemp\");\nmsg.topic = \"SELECT id,uidname , currentdate,currenttime FROM RFIDtable WHERE uidname LIKE ($query_uid) \";\nmsg.payload = [query_uid]\nreturn msg;\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1430, "y": 1040, "wires": [ [ "341fbe2a12961e58" ] ] }, { "id": "af63b0083d8e8eee", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 13, "width": 3, "height": 1, "passthru": false, "label": "比對資料庫", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "比對資料庫", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 1190, "y": 1040, "wires": [ [ "fb6117669e42cc6b", "49059e7b0e7190d2", "62f56a4452d57264" ] ] }, { "id": "9424aaa07c070bbc", "type": "function", "z": "097549b2788ecdc2", "name": "SELECT ALL", "func": "var query_uidtemp=msg.payload;\nflow.set(\"uidtemp\", query_uidtemp);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1650, "y": 440, "wires": [ [ "b93a945416a9c451", "6e5f7740b04b13ff" ] ] }, { "id": "546a30b478747c50", "type": "ui_text_input", "z": "097549b2788ecdc2", "name": "", "label": "手動查詢資料的uidname", "tooltip": "", "group": "cff14d809bf82c4b", "order": 3, "width": 5, "height": 1, "passthru": true, "mode": "text", "delay": 300, "topic": "topic", "sendOnBlur": true, "className": "", "topicType": "msg", "x": 1430, "y": 500, "wires": [ [ "9424aaa07c070bbc" ] ] }, { "id": "00fe1108c49c7df5", "type": "function", "z": "097549b2788ecdc2", "name": "function ", "func": "var query=msg.payload;\n\nif (query== '1' )\n msg.payload='Query';\nelse\n msg.payload='NotQuery';\n\nflow.set(\"query_temp\", msg.payload);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1640, "y": 1460, "wires": [ [ "6ce6c23a73d0250a", "95eeab2bb1709078" ] ] }, { "id": "2df79724a0a1fbdd", "type": "ui_switch", "z": "097549b2788ecdc2", "name": "", "label": "新增模式 /自動比對模式 ", "tooltip": "", "group": "c3321797b4291333", "order": 9, "width": 5, "height": 1, "passthru": true, "decouple": "false", "topic": "s1", "topicType": "str", "style": "", "onvalue": "1", "onvalueType": "str", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "str", "officon": "", "offcolor": "", "animate": false, "className": "", "x": 1370, "y": 1460, "wires": [ [ "00fe1108c49c7df5", "c24f830549cea048", "b8b0fc6520b36386" ] ] }, { "id": "6ce6c23a73d0250a", "type": "debug", "z": "097549b2788ecdc2", "name": "debug 232", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1790, "y": 1440, "wires": [] }, { "id": "f42bb2388bb28f97", "type": "switch", "z": "097549b2788ecdc2", "name": "", "property": "payload", "propertyType": "msg", "rules": [ { "t": "eq", "v": "Create", "vt": "str" }, { "t": "eq", "v": "Query", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 1230, "y": 360, "wires": [ [ "2286d19608607f96", "5133ae517d6f6036" ], [ "917e2d1f6e62dc1a" ] ] }, { "id": "a6f94be6a5358970", "type": "function", "z": "097549b2788ecdc2", "name": "Query or Insert ", "func": "var query = flow.get(\"query_temp\");\n\nflow.set(\"uid_temp\", msg.payload);\n\nif (query==='NotQuery')\n msg.payload='Create'\nelse\n msg.payload='Query'\n \nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1200, "y": 300, "wires": [ [ "f42bb2388bb28f97" ] ] }, { "id": "95eeab2bb1709078", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "6d6480f6bc65f976", "voice": "Google US English", "always": true, "x": 1780, "y": 1480, "wires": [] }, { "id": "b93a945416a9c451", "type": "debug", "z": "097549b2788ecdc2", "name": "debug 233", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1850, "y": 460, "wires": [] }, { "id": "6e5f7740b04b13ff", "type": "ui_text", "z": "097549b2788ecdc2", "group": "c3321797b4291333", "order": 13, "width": 5, "height": 2, "name": "", "label": "RFID的uid", "format": "{{msg.payload}}", "layout": "row-left", "className": "", "x": 1850, "y": 360, "wires": [] }, { "id": "a2950fb159945309", "type": "function", "z": "097549b2788ecdc2", "name": "function ", "func": "//CREATE TABLE \"RFIDtable\" (\n//\t\"id\"\tINT NOT NULL,\n// \"uidname\" TEXT,\n// \"currentdate\" DATE, \n// \"currenttime\" TIME\n//\tPRIMARY KEY(\"id\")\n//);\n\n//msg.topic = \"INSERT INTO RFIDtable ( uidname , currentdate, currenttime ) VALUES ($myRFID, $var_date , $var_time ) \" ;\n//msg.payload = [myRFID, var_date , var_time ]\n//return msg;\n\n\nvar tmp=msg.payload;\nmsg.topic = \"select count( * ) as 總共有幾筆資料 from RFIDtable where uidname=($tmp)\";\nmsg.payload=[tmp];\nreturn msg;\n\n// select count( * ) as 總共有幾筆資料 from Customers where address='Japan'", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1520, "y": 1180, "wires": [ [ "ca359e9886506c1c" ] ] }, { "id": "ffb5d47b46d350be", "type": "function", "z": "097549b2788ecdc2", "name": "function ", "func": "var num=msg.payload[0].總共有幾筆資料;\nmsg.payload=num;\nreturn msg; \n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1800, "y": 1180, "wires": [ [ "874764cdeae6ba2c", "30c9edc61a728201" ] ] }, { "id": "eab803e29aa7d24d", "type": "ui_text", "z": "097549b2788ecdc2", "group": "c3321797b4291333", "order": 12, "width": 5, "height": 1, "name": "", "label": "查詢結果", "format": "<font face='arial'><font size=3><font color={{fcolor}}>{{msg.payload}}", "layout": "row-left", "className": "", "x": 2140, "y": 1240, "wires": [] }, { "id": "04294343dbfd3b01", "type": "ui_text", "z": "097549b2788ecdc2", "group": "c3321797b4291333", "order": 11, "width": 5, "height": 1, "name": "", "label": "查詢結果:筆數", "format": "<font face='arial'><font size=6><font color={{fcolor}}>{{msg.payload}}", "layout": "row-left", "className": "", "x": 2160, "y": 1180, "wires": [] }, { "id": "be160e08fd9ed8a1", "type": "mqtt in", "z": "097549b2788ecdc2", "name": "", "topic": "alex9ufo/esp32/Starting", "qos": "2", "datatype": "utf8", "broker": "6174aa9d3e8c5856", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 1220, "y": 1300, "wires": [ [ "a6130deb5716e7b4", "6005610d57299b70" ] ] }, { "id": "a6130deb5716e7b4", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "6d6480f6bc65f976", "voice": "Google US English", "always": false, "x": 1420, "y": 1340, "wires": [] }, { "id": "874764cdeae6ba2c", "type": "change", "z": "097549b2788ecdc2", "name": "", "rules": [ { "t": "set", "p": "fcolor", "pt": "msg", "to": "red", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1980, "y": 1180, "wires": [ [ "04294343dbfd3b01" ] ] }, { "id": "788d8a18a725fb90", "type": "change", "z": "097549b2788ecdc2", "name": "", "rules": [ { "t": "set", "p": "fcolor", "pt": "msg", "to": "red", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1980, "y": 1240, "wires": [ [ "eab803e29aa7d24d" ] ] }, { "id": "62f56a4452d57264", "type": "function", "z": "097549b2788ecdc2", "name": "function", "func": "\nvar a= flow.get(\"uidtemp\");\nmsg.payload=a;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1380, "y": 1180, "wires": [ [ "a2950fb159945309" ] ] }, { "id": "abf32f23cf712f1d", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "6d6480f6bc65f976", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 2140, "y": 1280, "wires": [] }, { "id": "ae298c92b01b1fc7", "type": "delay", "z": "097549b2788ecdc2", "name": "", "pauseType": "delay", "timeout": "2", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 1980, "y": 1280, "wires": [ [ "abf32f23cf712f1d" ] ] }, { "id": "30c9edc61a728201", "type": "function", "z": "097549b2788ecdc2", "name": "function ", "func": "var n=msg.payload;\n\nif (n>0)\n msg.payload='RFID符合';\nelse\n msg.payload='RFID錯誤';\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1800, "y": 1240, "wires": [ [ "ae298c92b01b1fc7", "788d8a18a725fb90", "d258d76ee69b790f" ] ] }, { "id": "04c972ed40dd4aa8", "type": "function", "z": "097549b2788ecdc2", "name": "取得UID號碼", "func": "var myRFID = flow.get('uid_temp');\nmsg.payload=myRFID;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1650, "y": 360, "wires": [ [ "6e5f7740b04b13ff" ] ] }, { "id": "49059e7b0e7190d2", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "6d6480f6bc65f976", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 1340, "y": 1000, "wires": [] }, { "id": "12017b7a6f3f09bf", "type": "ui_audio", "z": "097549b2788ecdc2", "name": "", "group": "6d6480f6bc65f976", "voice": "Microsoft Hanhan - Chinese (Traditional, Taiwan)", "always": true, "x": 1400, "y": 840, "wires": [] }, { "id": "2fb8243eea647a1b", "type": "function", "z": "097549b2788ecdc2", "name": "增加 日期 時間", "func": "var ms1=msg.payload[0];\nvar ms2=msg.payload[1];\nvar ms3=msg.payload[2];\n\nmsg.payload=\"新增一筆:\"+ms1+\", 日期: \"+ms2+\", 時間:\"+ms3;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1720, "y": 280, "wires": [ [ "970d2176dc5623ce" ] ] }, { "id": "970d2176dc5623ce", "type": "function", "z": "097549b2788ecdc2", "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, "noerr": 0, "x": 1890, "y": 280, "wires": [ [ "b28def53eb88ed09" ] ] }, { "id": "b28def53eb88ed09", "type": "http request", "z": "097549b2788ecdc2", "name": "", "method": "POST", "ret": "txt", "paytoqs": false, "url": "https://notify-api.line.me/api/notify", "tls": "", "persist": false, "proxy": "", "authType": "", "x": 2040, "y": 280, "wires": [ [ "49e8b59b82eb8ab2" ] ] }, { "id": "49e8b59b82eb8ab2", "type": "debug", "z": "097549b2788ecdc2", "name": "debug 234", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 2190, "y": 280, "wires": [] }, { "id": "95803adb96d6e149", "type": "comment", "z": "097549b2788ecdc2", "name": "Line Notify Message ", "info": "", "x": 1910, "y": 320, "wires": [] }, { "id": "ae2504c7ea0cd724", "type": "function", "z": "097549b2788ecdc2", "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, "noerr": 0, "x": 1970, "y": 1380, "wires": [ [ "77b88fbea5875ec5" ] ] }, { "id": "4bf60946872021ae", "type": "comment", "z": "097549b2788ecdc2", "name": "Line Notify Message ", "info": "", "x": 2150, "y": 1420, "wires": [] }, { "id": "77b88fbea5875ec5", "type": "http request", "z": "097549b2788ecdc2", "name": "", "method": "POST", "ret": "txt", "paytoqs": false, "url": "https://notify-api.line.me/api/notify", "tls": "", "persist": false, "proxy": "", "authType": "", "x": 2120, "y": 1380, "wires": [ [ "4ff0a110aaea79fc" ] ] }, { "id": "4ff0a110aaea79fc", "type": "debug", "z": "097549b2788ecdc2", "name": "debug", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 2250, "y": 1380, "wires": [] }, { "id": "d258d76ee69b790f", "type": "function", "z": "097549b2788ecdc2", "name": "function", "func": "\nvar a= flow.get(\"uidtemp\");\nvar b=msg.payload;\nmsg.payload=a+\"--->\"+b;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1800, "y": 1340, "wires": [ [ "ae2504c7ea0cd724", "e6883d79d1bdf08b" ] ] }, { "id": "a9e0c525a2e3dcc9", "type": "inject", "z": "097549b2788ecdc2", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": "1", "topic": "", "payload": "0", "payloadType": "str", "x": 1190, "y": 1460, "wires": [ [ "2df79724a0a1fbdd" ] ] }, { "id": "c24f830549cea048", "type": "change", "z": "097549b2788ecdc2", "name": "", "rules": [ { "t": "change", "p": "payload", "pt": "msg", "from": "1", "fromt": "num", "to": "查詢模式", "tot": "str" }, { "t": "change", "p": "payload", "pt": "msg", "from": "0", "fromt": "num", "to": "新增模式", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1460, "y": 1600, "wires": [ [ "053f185f4427c3a6", "fac4a9e1d3b1e029" ] ] }, { "id": "053f185f4427c3a6", "type": "ui_text_input", "z": "097549b2788ecdc2", "name": "", "label": "State:", "tooltip": "", "group": "c3321797b4291333", "order": 10, "width": 5, "height": 1, "passthru": true, "mode": "text", "delay": 300, "topic": "", "sendOnBlur": true, "className": "", "topicType": "str", "x": 1630, "y": 1620, "wires": [ [] ] }, { "id": "b8b0fc6520b36386", "type": "debug", "z": "097549b2788ecdc2", "name": "debug ", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1630, "y": 1520, "wires": [] }, { "id": "7a5e07caae2865e5", "type": "inject", "z": "097549b2788ecdc2", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": "1", "topic": "", "payload": "", "payloadType": "date", "x": 1580, "y": 80, "wires": [ [ "15681eab2221f3bb" ] ] }, { "id": "15681eab2221f3bb", "type": "function", "z": "097549b2788ecdc2", "name": "id SET ", "func": "var del_idtemp=1;\nflow.set(\"idtemp\", del_idtemp);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1710, "y": 80, "wires": [ [] ] }, { "id": "6005610d57299b70", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "top right", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 0, "ok": "OK", "cancel": "Cancel", "raw": false, "className": "", "topic": "", "name": "", "x": 1450, "y": 1300, "wires": [] }, { "id": "fac4a9e1d3b1e029", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "top right", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 0, "ok": "OK", "cancel": "Cancel", "raw": false, "className": "", "topic": "", "name": "", "x": 1670, "y": 1580, "wires": [] }, { "id": "230b03329a7ee52f", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "prompt", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 1, "ok": "OK", "cancel": "Cancel", "raw": true, "className": "", "topic": "", "name": "", "x": 1310, "y": 900, "wires": [ [ "38b13d567304caf4" ] ] }, { "id": "38b13d567304caf4", "type": "function", "z": "097549b2788ecdc2", "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": 1480, "y": 900, "wires": [ [ "2656d096116d25c6" ], [] ] }, { "id": "d3afd68d2d964d74", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "prompt", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 1, "ok": "OK", "cancel": "Cancel", "raw": true, "className": "", "topic": "", "name": "", "x": 1350, "y": 960, "wires": [ [ "4f920972a0699d38" ] ] }, { "id": "4f920972a0699d38", "type": "function", "z": "097549b2788ecdc2", "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": 1520, "y": 960, "wires": [ [ "5adc4edd7745e24c" ], [] ] }, { "id": "e852561d71dd3c8b", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "prompt", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 1, "ok": "OK", "cancel": "Cancel", "raw": true, "className": "", "topic": "", "name": "", "x": 1310, "y": 740, "wires": [ [ "5ab3443a7dd4860f" ] ] }, { "id": "5ab3443a7dd4860f", "type": "function", "z": "097549b2788ecdc2", "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": 1480, "y": 740, "wires": [ [ "a0c72c6deca9293a" ], [] ] }, { "id": "33d0d7ce768a28cb", "type": "link out", "z": "097549b2788ecdc2", "name": "link out 47", "mode": "link", "links": [ "6b98e5564ae03d0f" ], "x": 1945, "y": 880, "wires": [] }, { "id": "6b98e5564ae03d0f", "type": "link in", "z": "097549b2788ecdc2", "name": "link in 43", "links": [ "33d0d7ce768a28cb", "7a7a82223a0579b6" ], "x": 1735, "y": 560, "wires": [ [ "d89e84f03410393e" ] ] }, { "id": "7a7a82223a0579b6", "type": "link out", "z": "097549b2788ecdc2", "name": "link out 48", "mode": "link", "links": [ "6b98e5564ae03d0f" ], "x": 1955, "y": 240, "wires": [] }, { "id": "c9d619bc4c9e82b0", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "top right", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 0, "ok": "OK", "cancel": "Cancel", "raw": false, "className": "", "topic": "", "name": "", "x": 2170, "y": 1340, "wires": [] }, { "id": "0ebe58b7cddd89e2", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "top right", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 0, "ok": "OK", "cancel": "Cancel", "raw": false, "className": "", "topic": "", "name": "", "x": 1410, "y": 560, "wires": [] }, { "id": "386161feb448b294", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "top right", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 0, "ok": "OK", "cancel": "Cancel", "raw": false, "className": "", "topic": "", "name": "", "x": 1670, "y": 320, "wires": [] }, { "id": "e0f896772c6a29e9", "type": "debug", "z": "097549b2788ecdc2", "name": "debug", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1830, "y": 160, "wires": [] }, { "id": "917e2d1f6e62dc1a", "type": "function", "z": "097549b2788ecdc2", "name": "get UID", "func": "\nvar a= flow.get(\"uid_temp\");\nmsg.payload=a;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1420, "y": 440, "wires": [ [ "9424aaa07c070bbc", "a8381fa2caf86f58" ] ] }, { "id": "e6883d79d1bdf08b", "type": "function", "z": "097549b2788ecdc2", "name": "function", "func": "var b=msg.payload;\nmsg.payload=\"Line Notify --->\"+b;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1980, "y": 1340, "wires": [ [ "c9d619bc4c9e82b0" ] ] }, { "id": "85022ed23f46402a", "type": "ui_toast", "z": "097549b2788ecdc2", "position": "top right", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 0, "ok": "OK", "cancel": "Cancel", "raw": false, "className": "", "topic": "", "name": "", "x": 1350, "y": 200, "wires": [] }, { "id": "a8381fa2caf86f58", "type": "link out", "z": "097549b2788ecdc2", "name": "link out 49", "mode": "link", "links": [ "220e0157309579ff" ], "x": 1515, "y": 420, "wires": [] }, { "id": "220e0157309579ff", "type": "link in", "z": "097549b2788ecdc2", "name": "link in 44", "links": [ "a8381fa2caf86f58" ], "x": 1235, "y": 1220, "wires": [ [ "62f56a4452d57264" ] ] }, { "id": "226666911bc8d76f", "type": "comment", "z": "097549b2788ecdc2", "name": "Set Default Value", "info": "", "x": 1580, "y": 40, "wires": [] }, { "id": "944c5522d93029ba", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "9e654a56c788364a", "sqlquery": "msg.topic", "sql": "", "name": "RFID dB", "x": 1640, "y": 160, "wires": [ [ "e0f896772c6a29e9" ] ] }, { "id": "72f85902425dafbd", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "9e654a56c788364a", "sqlquery": "msg.topic", "sql": "", "name": "RFID dB", "x": 1820, "y": 240, "wires": [ [ "7a7a82223a0579b6", "bf0a8d200db86645" ] ] }, { "id": "a344942e333780f1", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "9e654a56c788364a", "sqlquery": "msg.topic", "sql": "", "name": "RFID dB", "x": 1980, "y": 600, "wires": [ [ "bd03d69a80903453" ] ] }, { "id": "d9baa5da3147fe03", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "9e654a56c788364a", "sqlquery": "msg.topic", "sql": "", "name": "RFID dB", "x": 1780, "y": 740, "wires": [ [ "d89e84f03410393e" ] ] }, { "id": "0d13bf0e6e2bc74b", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "cdc59054c439d191", "sqlquery": "msg.topic", "sql": "", "name": "RFID dB", "x": 1820, "y": 880, "wires": [ [ "166936c5d16d93b2", "33d0d7ce768a28cb" ] ] }, { "id": "646767e4d8f496e4", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "9e654a56c788364a", "sqlquery": "msg.topic", "sql": "", "name": "RFID dB", "x": 1840, "y": 960, "wires": [ [ "166936c5d16d93b2" ] ] }, { "id": "341fbe2a12961e58", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "9e654a56c788364a", "sqlquery": "msg.topic", "sql": "", "name": "RFID dB", "x": 1820, "y": 1040, "wires": [ [ "bd03d69a80903453" ] ] }, { "id": "1370642ed41f860b", "type": "debug", "z": "097549b2788ecdc2", "name": "debug 235", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1990, "y": 560, "wires": [] }, { "id": "ca359e9886506c1c", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "9e654a56c788364a", "sqlquery": "msg.topic", "sql": "", "name": "RFID dB", "x": 1660, "y": 1180, "wires": [ [ "ffb5d47b46d350be" ] ] }, { "id": "b17910635e294f7c", "type": "sqlite", "z": "097549b2788ecdc2", "mydb": "a443e97ada0cf14f", "sqlquery": "msg.topic", "sql": "", "name": "LED_STATUS", "x": 500, "y": 120, "wires": [ [ "090aad33988be6be" ] ] }, { "id": "49e3edfa8cca7da7", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "c3321797b4291333", "order": 8, "width": 0, "height": 0, "passthru": false, "label": "RFID區", "tooltip": "", "color": "", "bgcolor": "fuchsia", "className": "", "icon": "", "payload": "", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 860, "y": 140, "wires": [ [] ] }, { "id": "a6aa84630ea8878f", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "91a01f6c080e6b87", "order": 9, "width": 6, "height": 1, "passthru": false, "label": "RFID區", "tooltip": "", "color": "", "bgcolor": "fuchsia", "className": "", "icon": "", "payload": "", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 860, "y": 180, "wires": [ [] ] }, { "id": "0ac14c18b91cfc52", "type": "ui_button", "z": "097549b2788ecdc2", "name": "", "group": "cff14d809bf82c4b", "order": 2, "width": 5, "height": 1, "passthru": false, "label": "RFID區", "tooltip": "", "color": "", "bgcolor": "fuchsia", "className": "", "icon": "", "payload": "", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 860, "y": 220, "wires": [ [] ] }, { "id": "01c9a918fc6f6554", "type": "ui_table", "z": "097549b2788ecdc2", "group": "7b14a6b23895a629", "name": "LED 資料庫", "order": 1, "width": 8, "height": 14, "columns": [], "outputs": 0, "cts": false, "x": 790, "y": 420, "wires": [] }, { "id": "bd03d69a80903453", "type": "ui_table", "z": "097549b2788ecdc2", "group": "6d6480f6bc65f976", "name": "", "order": 1, "width": 8, "height": 14, "columns": [], "outputs": 0, "cts": false, "x": 2150, "y": 600, "wires": [] }, { "id": "b2bb172812ed38f1", "type": "change", "z": "a987cef8cc2a4969", "name": "LED Change Node", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload", "tot": "msg" }, { "t": "set", "p": "topic", "pt": "msg", "to": "alex9ufo/toggle-led", "tot": "str" }, { "t": "set", "p": "qos", "pt": "msg", "to": "1", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 470, "y": 180, "wires": [ [ "85863a8138b0e5e2", "54477ffaad79ce3b" ] ] }, { "id": "d9df1738aa969f87", "type": "ui-switch", "z": "a987cef8cc2a4969", "name": "LED Switch", "label": "Toggle LED", "group": "d5182ebc903db295", "order": 0, "width": 0, "height": 0, "passthru": false, "topic": "topic", "topicType": "msg", "style": "", "className": "", "onvalue": "true", "onvalueType": "bool", "onicon": "", "oncolor": "", "offvalue": "false", "offvalueType": "bool", "officon": "", "offcolor": "", "x": 150, "y": 180, "wires": [ [ "1329aba795b1bfe6", "b2bb172812ed38f1" ] ] }, { "id": "328761331ad9c03e", "type": "ui-radio-group", "z": "a987cef8cc2a4969", "group": "e03d82c24d1a7eae", "name": "RGB Select", "label": "Choose Color", "order": 0, "width": 0, "height": 0, "columns": 1, "passthru": false, "options": [ { "label": "RED", "value": "red", "type": "str" }, { "label": "GREEN", "value": "green", "type": "str" }, { "label": "BLUE", "value": "blue", "type": "str" } ], "payload": "", "topic": "topic", "topicType": "msg", "className": "", "x": 150, "y": 280, "wires": [ [ "1329aba795b1bfe6", "9560459d89e7533a" ] ] }, { "id": "e25eddd1db26d7cd", "type": "ui-slider", "z": "a987cef8cc2a4969", "group": "8f4d7928695ce3bd", "name": "Servo movement", "label": "Set Servo position", "tooltip": "", "order": 0, "width": 0, "height": 0, "passthru": true, "outs": "all", "topic": "topic", "topicType": "msg", "thumbLabel": true, "min": 0, "max": "180", "step": "5", "className": "", "x": 170, "y": 360, "wires": [ [ "1329aba795b1bfe6", "8e4a60f83bc455ce" ] ] }, { "id": "1329aba795b1bfe6", "type": "ui-notification", "z": "a987cef8cc2a4969", "ui": "5f69714a569ee0a1", "position": "top right", "colorDefault": true, "color": "#000000", "displayTime": "3", "showCountdown": true, "outputs": 0, "allowDismiss": true, "dismissText": "Close", "raw": false, "className": "", "name": "Notification", "x": 510, "y": 440, "wires": [] }, { "id": "85863a8138b0e5e2", "type": "mqtt out", "z": "a987cef8cc2a4969", "name": "MQTT", "topic": "", "qos": "1", "retain": "true", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "70940176.2b2d3", "x": 750, "y": 280, "wires": [] }, { "id": "9560459d89e7533a", "type": "change", "z": "a987cef8cc2a4969", "name": "RGB Change Node", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload", "tot": "msg" }, { "t": "set", "p": "topic", "pt": "msg", "to": "alex9ufo/rgb-color-set", "tot": "str" }, { "t": "set", "p": "qos", "pt": "msg", "to": "1", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 470, "y": 280, "wires": [ [ "85863a8138b0e5e2", "54477ffaad79ce3b" ] ] }, { "id": "54477ffaad79ce3b", "type": "debug", "z": "a987cef8cc2a4969", "name": "debug 236", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 730, "y": 360, "wires": [] }, { "id": "8e4a60f83bc455ce", "type": "change", "z": "a987cef8cc2a4969", "name": "Servo Change Node", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload", "tot": "msg" }, { "t": "set", "p": "topic", "pt": "msg", "to": "alex9ufo/servo-position-set", "tot": "str" }, { "t": "set", "p": "qos", "pt": "msg", "to": "1", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 480, "y": 360, "wires": [ [ "85863a8138b0e5e2", "54477ffaad79ce3b" ] ] } ]

沒有留言:

張貼留言

Node-RED 與 ESP32 - 第13集:在手機上安裝 NodeRed

  Node-RED 與 ESP32 - 第13集:在手機上安裝 NodeRed https://www.youtube.com/watch?v=IwmehQSm-I8 0:00 Start 0:18 指令:clear 0:21 指令:apt update 0:39 指令...