2020年7月19日 星期日

第十三篇 ESP32 LINE通知:倉庫溫度異常機器人

第十三篇 ESP32 LINE通知:倉庫溫度異常機器人



程式撰寫
就如第二節所展示,這次我們的程式將使用wificlientsecure進行實做,wificlientsecure跟上一章的httpclient不同的地方在於wificlientsecure可以支援https加密協定,而httpclient只能用HTTP GET協定做參數傳遞,wificlientsecure及wificlient可以用來做POST協定。
程式主要分成幾4個流程
1.    初始化設定:設定無線網路SSID, Password, LINE API網址, 權杖密碼等資訊
2.    連線Wifi網路
3.    在Loop中重複監看DHT11溫濕度資料
4.    發現DHT11溫度或濕度過高,則利用wificlientsecure將資料POST到LINE網址
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <SimpleDHT.h>

//請修改以下參數--------------------------------------------
char SSID[] = "YourSSID";
char PASSWORD[] = "YourPassword";
String Linetoken = "Your Line Token";
int pinDHT11 = 14;//假設DHT11接在腳位GPIO14,麵包板左側序號8
//---------------------------------------------------------
SimpleDHT11 dht11(pinDHT11);//DHT11物件
WiFiClientSecure client;//網路連線物件
char host[] = "notify-api.line.me";//LINE Notify API網址
void setup() {
  Serial.begin(115200);
  //連線到指定的WiFi SSID
  Serial.print("Connecting Wifi: ");
  Serial.println(SSID);
  WiFi.begin(SSID, PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  //連線成功,顯示取得的IP
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);
}
void loop() {
  //嘗試讀取溫濕度內容
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT11 failed, err="); Serial.println(err); delay(1000);
    return;
  }
  //讀取成功,將溫濕度顯示在序列視窗
  Serial.print("Sample OK: ");
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" H");

 //設定觸發LINE訊息條件為溫度超過30或濕度超過80
  if ((int)temperature >= 30 || (int)humidity >= 80) {
    //組成Line訊息內容
    String message = "檢測環境發生異常,請協助儘速派人查看處理,目前環境狀態:";
    message += "\n溫度=" + String(((int)temperature)) + " *C";
    message += "\n濕度=" + String(((int)humidity)) + " H";
    Serial.println(message);
    if (client.connect(host, 443)) {
      int LEN = message.length();
      //傳遞POST表頭
      String url = "/api/notify";
      client.println("POST " + url + " HTTP/1.1");
      client.print("Host: "); client.println(host);
      //權杖
      client.print("Authorization: Bearer "); client.println(Linetoken);
      client.println("Content-Type: application/x-www-form-urlencoded");
      client.print("Content-Length: "); client.println( String((LEN + 8)) );
      client.println();      
      client.print("message="); client.println(message);
      client.println();
      //等候回應
      delay(500);
      String response = client.readString();
      //顯示傳遞結果
      Serial.println(response);
    }
    else {
      //傳送失敗
      Serial.println("connected fail");
    }
  }
  //每5秒讀取一次溫濕度
  delay(5000);
}

2020年7月18日 星期六

ESP32 mfrc522 RFID + MQTT + Telegram bot

ESP32 mfrc522 RFID + MQTT + Telegram 









/*********
  Rui Santos
  Complete project details at https://randomnerdtutorials.com  
*********/

#include <WiFi.h>
#include <PubSubClient.h>
#include <SPI.h>
#include "MFRC522.h"
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>   // Universal Telegram Bot Library written by Brian Lough: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>


const int RST_PIN = 22; // Reset pin
const int SS_PIN = 21; // Slave select pin
//==========================
//esp32     mfrc522
//21        SDA
//18        SCK
//23        MOSI
//21        MISO
//22        RST
//GND       GND
//3.3v      3.3V
//==========================

// Update these with values suitable for your network.
//const char *ssid = "PTS-2F";
//const char *pass = "";
//const char *ssid = "WBR-2200";
//const char *pass = "0226452362";

const char *ssid = "74170287";
const char *pass = "24063173";
//const char *ssid =  "yourSSID";     // change according to your Network - cannot be longer than 32 characters!
//const char *pass =  "yourPASSWORD"; // change according to your Network

// Initialize Telegram BOT
//#define BOTtoken "XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"  // your Bot Token (Get from Botfather)
#define BOTtoken "925728551:AAGrTFW2NXqMs3uMJDW3891GUVJF-l1YtVc"  // your Bot Token (Get from Botfather)
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
//#define CHAT_ID "XXXXXXXXXX"
#define CHAT_ID "1143751158"


#define MQTTid              ""                           //id of this mqtt client
#define MQTTip              "broker.mqtt-dashboard.com"  //ip address or hostname of the mqtt broker
#define MQTTport            1883                         //port of the mqtt broker
#define MQTTuser            "alex9ufo"                   //username of this mqtt client
#define MQTTpsw             "alex1234"                   //password of this mqtt client
//#define MQTTuser          "your_username"              //username of this mqtt client
//#define MQTTpsw           "your_password"              //password of this mqtt client
#define MQTTpubQos          2                            //qos of publish (see README)
#define MQTTsubQos          1                            //qos of subscribe

WiFiClientSecure client1;
UniversalTelegramBot bot(BOTtoken, client1);

// Checks for new messages every 1 second.
int botRequestDelay = 1000;
unsigned long lastTimeBotRan;

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

//Variables
long lastMsg = 0;
char jsonChar[100];
String IDNo_buf="";
const int BUILTIN_LED = 2; //D2
const int ledPin = 2; //D2
bool Flash = false;  //true
bool ledState = LOW;
String IPaddress;


//=============================================================================
boolean pendingDisconnect = false;
void mqttConnectedCb(); // on connect callback
void mqttDisconnectedCb(); // on disconnect callback
void mqttDataCb(char* topic, byte* payload, unsigned int length); // on new message callback

WiFiClient wclient;
PubSubClient client(MQTTip, MQTTport, mqttDataCb, wclient);

//=============================================================================
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);
      }
      return id;
    }
//=============================================================================
void mqttConnectedCb() {
  Serial.println("connected");
  
  // Once connected, publish an announcement...
  client.publish("alex9ufo/outTopic/RFID/json", jsonChar, MQTTpubQos, true); // true means retain
  // ... and resubscribe
  client.subscribe("alex9ufo/inTopic", MQTTsubQos);

}
//=============================================================================
void mqttDisconnectedCb() {
  Serial.println("disconnected");
}
//=============================================================================
void mqttDataCb(char* topic, byte* payload, unsigned int length) {

  /*
  you can convert payload to a C string appending a null terminator to it;
  this is possible when the message (including protocol overhead) doesn't
  exceeds the MQTT_MAX_PACKET_SIZE defined in the library header.
  you can consider safe to do so when the length of topic plus the length of
  message doesn't exceeds 115 characters
  */
  char* message = (char *) payload;
  message[length] = 0;

  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  Serial.println(message);
  // Switch on the LED if an 1 was received as first character
  if (message[0] == '0') {
     digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
     // but actually the LED is on; this is because 
     Serial.println("Received 0 , Send LOW TO BuildIn_LED off LED");
     Flash = false;
    } 
   if (message[0] == '1') {
     digitalWrite(BUILTIN_LED, HIGH);   // Turn the LED off (Note that HIGH is the voltage level
     // but actually the LED is on; this is because
     Serial.println("Received 1 , Send HIGH TO BuildIn_LED on LED");
     Flash = false;
   }
    if (message[0] == '2') {
     digitalWrite(BUILTIN_LED, HIGH);   // Turn the LED off (Note that HIGH is the voltage level
     // but actually the LED is on; this is because
     Serial.println("Received 2 , Flashing BuildIn_LED ");
     Flash = true;
   } //if (message[0] == '2')
}

//======================================================
// Handle what happens when you receive new messages
void handleNewMessages(int numNewMessages) {
  Serial.println("handleNewMessages");
  Serial.println(String(numNewMessages));

  for (int i=0; i<numNewMessages; i++) {
    // Chat id of the requester
    String chat_id = String(bot.messages[i].chat_id);
    if (chat_id != CHAT_ID){
      bot.sendMessage(chat_id, "Unauthorized user", "");
      continue;
    }
    
    // Print the received message
    String text = bot.messages[i].text;
    Serial.println(text);

    String from_name = bot.messages[i].from_name;

    if (text == "/start") {
      String welcome = "Welcome, " + from_name + ".\n";
      welcome += "Use the following commands to control your outputs.\n\n";
      welcome += "/led_on to turn GPIO ON \n";
      welcome += "/led_off to turn GPIO OFF \n";
      welcome += "/state to request current GPIO state \n";
      bot.sendMessage(chat_id, welcome, "");
    }

    if (text == "/led_on") {
      bot.sendMessage(chat_id, "LED state set to ON", "");
      ledState = HIGH;
      digitalWrite(ledPin, ledState);
      Flash = false;
    }
    
    if (text == "/led_off") {
      bot.sendMessage(chat_id, "LED state set to OFF", "");
      ledState = LOW;
      digitalWrite(ledPin, ledState);
      Flash = false;
    }

    if (text == "/led_flash") {
      bot.sendMessage(chat_id, "LED state set to Flash", "");
      ledState = LOW;
      digitalWrite(ledPin, ledState);
      Flash = true;
    }
    
    if (text == "/state") {
      if (Flash==true){
        bot.sendMessage(chat_id, "LED is Flash", "");
      }
      else 
      if (digitalRead(ledPin)){
        bot.sendMessage(chat_id, "LED is ON", "");
      }
      else{
        bot.sendMessage(chat_id, "LED is OFF", "");
      }
    }
  }
}

//======================================================
void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  
  bot.sendMessage(CHAT_ID, "Bot started up", "");
  bot.sendMessage(CHAT_ID, "/start" , "");
}
//======================================================
void setup() {
  Serial.begin(115200);
  setup_wifi();
  pinMode(BUILTIN_LED, OUTPUT);
  Serial.println(F("Booting...."));
  SPI.begin();           // Init SPI bus
  mfrc522.PCD_Init();    // Init MFRC522
  Serial.println(F("Ready!"));
  Serial.println(F("======================================================")); 
  Serial.println(F("Scan for Card and print UID:"));
}
//======================================================
void process_mqtt() {
  if (WiFi.status() == WL_CONNECTED) {
    if (client.connected()) {
      client.loop();
    } else {
    // client id, client username, client password, last will topic, last will qos, last will retain, last will message
      if (client.connect(MQTTid, MQTTuser, MQTTpsw, MQTTid "/status", 2, true, "0")) {
          pendingDisconnect = false;
          mqttConnectedCb();
      }
    }
  } else {
    if (client.connected())
      client.disconnect();
  }
  if (!client.connected() && !pendingDisconnect) {
    pendingDisconnect = true;
    mqttDisconnectedCb();
  }
}
//======================================================
void loop() {
  process_mqtt();
  long now = millis();
  if (Flash)
  {
    digitalWrite(BUILTIN_LED, !digitalRead(BUILTIN_LED));
    delay(500);
  }

  //======================================================
  if (millis() > lastTimeBotRan + botRequestDelay)  {
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

    while(numNewMessages) {
      Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }
    lastTimeBotRan = millis();
  }
  //======================================================
  
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) { // 如果出現新卡片就讀取卡片資料
     delay(100);
     String IDNo = printHex(mfrc522.uid.uidByte, mfrc522.uid.size);
     // Show some details of the PICC (that is: the tag/card)
     if ((IDNo != IDNo_buf) || (now - lastMsg > 5000)) {  //不同卡片 或是 等5秒
         lastMsg = now; 
         Serial.print(F("Card UID:"));
         Serial.println(IDNo);
         //Serial.println(IDNo_buf);
    
         IDNo_buf="";
         IDNo_buf=IDNo;
         // Convert data to JSON string 
         String json =
         "{\"data\":{"
         "\"RFID_No\": \"" + IDNo + "\"}"
         "}";
         // Convert JSON string to character array
         json.toCharArray(jsonChar, json.length()+1);
    
         if  (client.connected()) {
              Serial.print("Publish message: ");
              Serial.println(json);
              // Publish JSON character array to MQTT topic
             client.publish("alex9ufo/outTopic/RFID/json",jsonChar);
             //========================================
             bot.sendMessage(CHAT_ID, jsonChar , "");
             //========================================
         } 
      } // if ((IDNo != IDNo_buf) || (now - lastMsg > 5000))
  }  // if (mfrc522.PICC_IsNewCardPresent()

}   //Loop
//======================================================

ESP32 MQTT Publish and Subscribe

ESP32 MQTT Publish and Subscribe RFID ID No, LED on/off/flash






/*********
  Rui Santos
  Complete project details at https://randomnerdtutorials.com 
*********/

#include <WiFi.h>
#include <PubSubClient.h>
#include <SPI.h>
#include "MFRC522.h"

const int RST_PIN = 22; // Reset pin
const int SS_PIN = 21; // Slave select pin
//==========================
//esp32     mfrc522
//21        SDA
//18        SCK
//23        MOSI
//21        MISO
//22        RST
//GND       GND
//3.3v      3.3V
//==========================

// Update these with values suitable for your network.
//const char *ssid = "PTS-2F";
//const char *pass = "";
//const char *ssid = "WBR-2200";
//const char *pass = "0226452362";

const char *ssid = "74170287";
const char *pass = "24063173";
//const char *ssid =  "yourSSID";     // change according to your Network - cannot be longer than 32 characters!
//const char *pass =  "yourPASSWORD"; // change according to your Network


#define MQTTid              ""                           //id of this mqtt client
#define MQTTip              "broker.mqtt-dashboard.com"  //ip address or hostname of the mqtt broker
#define MQTTport            1883                         //port of the mqtt broker
#define MQTTuser            "alex9ufo"                   //username of this mqtt client
#define MQTTpsw             "alex1234"                   //password of this mqtt client
//#define MQTTuser          "your_username"              //username of this mqtt client
//#define MQTTpsw           "your_password"              //password of this mqtt client
#define MQTTpubQos          2                            //qos of publish (see README)
#define MQTTsubQos          1                            //qos of subscribe

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

//Variables
long lastMsg = 0;
char jsonChar[100];
String IDNo_buf="";
const int BUILTIN_LED = 2; //D2
bool Flash = false;  //true
//=============================================================================
boolean pendingDisconnect = false;
void mqttConnectedCb(); // on connect callback
void mqttDisconnectedCb(); // on disconnect callback
void mqttDataCb(char* topic, byte* payload, unsigned int length); // on new message callback

WiFiClient wclient;
PubSubClient client(MQTTip, MQTTport, mqttDataCb, wclient);

//=============================================================================
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);
      }
      return id;
    }
//=============================================================================
void mqttConnectedCb() {
  Serial.println("connected");
 
  // Once connected, publish an announcement...
  client.publish("alex9ufo/outTopic/RFID/json", jsonChar, MQTTpubQos, true); // true means retain
  // ... and resubscribe
  client.subscribe("alex9ufo/inTopic", MQTTsubQos);

}
//=============================================================================
void mqttDisconnectedCb() {
  Serial.println("disconnected");
}
//=============================================================================
void mqttDataCb(char* topic, byte* payload, unsigned int length) {

  /*
  you can convert payload to a C string appending a null terminator to it;
  this is possible when the message (including protocol overhead) doesn't
  exceeds the MQTT_MAX_PACKET_SIZE defined in the library header.
  you can consider safe to do so when the length of topic plus the length of
  message doesn't exceeds 115 characters
  */
  char* message = (char *) payload;
  message[length] = 0;

  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  Serial.println(message);
  // Switch on the LED if an 1 was received as first character
  if (message[0] == '0') {
     digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
     // but actually the LED is on; this is because
     Serial.println("Received 0 , Send LOW TO BuildIn_LED");
    }
   if (message[0] == '1') {
     digitalWrite(BUILTIN_LED, HIGH);   // Turn the LED off (Note that HIGH is the voltage level
     // but actually the LED is on; this is because
     Serial.println("Received 1 , Send HIGH TO BuildIn_LED");
   }
    if (message[0] == '2') {
     digitalWrite(BUILTIN_LED, HIGH);   // Turn the LED off (Note that HIGH is the voltage level
     // but actually the LED is on; this is because
     Serial.println("Received 2 , Flashing BuildIn_LED ");
     Flash = true;
   } //if (message[0] == '2')
}
//======================================================
void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
 
}
//======================================================
void setup() {
  Serial.begin(115200);
  setup_wifi();
  pinMode(BUILTIN_LED, OUTPUT);
  Serial.println(F("Booting...."));
  SPI.begin();           // Init SPI bus
  mfrc522.PCD_Init();    // Init MFRC522
  Serial.println(F("Ready!"));
  Serial.println(F("======================================================"));
  Serial.println(F("Scan for Card and print UID:"));
}
//======================================================
void process_mqtt() {
  if (WiFi.status() == WL_CONNECTED) {
    if (client.connected()) {
      client.loop();
    } else {
    // client id, client username, client password, last will topic, last will qos, last will retain, last will message
      if (client.connect(MQTTid, MQTTuser, MQTTpsw, MQTTid "/status", 2, true, "0")) {
          pendingDisconnect = false;
          mqttConnectedCb();
      }
    }
  } else {
    if (client.connected())
      client.disconnect();
  }
  if (!client.connected() && !pendingDisconnect) {
    pendingDisconnect = true;
    mqttDisconnectedCb();
  }
}
//======================================================
void loop() {
  process_mqtt();
  long now = millis();
  if (Flash)
  {
    digitalWrite(BUILTIN_LED, !digitalRead(BUILTIN_LED));
    delay(500);
  }

 
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) { // 如果出現新卡片就讀取卡片資料
     delay(100);
     String IDNo = printHex(mfrc522.uid.uidByte, mfrc522.uid.size);
     // Show some details of the PICC (that is: the tag/card)
     if ((IDNo != IDNo_buf) || (now - lastMsg > 5000)) {  //不同卡片 或是 等5秒
         lastMsg = now;
         Serial.print(F("Card UID:"));
         Serial.println(IDNo);
         //Serial.println(IDNo_buf);
   
         IDNo_buf="";
         IDNo_buf=IDNo;
         // Convert data to JSON string
         String json =
         "{\"data\":{"
         "\"RFID_No\": \"" + IDNo + "\"}"
         "}";
         // Convert JSON string to character array
         json.toCharArray(jsonChar, json.length()+1);
   
         if  (client.connected()) {
              Serial.print("Publish message: ");
              Serial.println(json);
              // Publish JSON character array to MQTT topic
             client.publish("alex9ufo/outTopic/RFID/json",jsonChar);
         }
      } // if ((IDNo != IDNo_buf) || (now - lastMsg > 5000))
  }  // if (mfrc522.PICC_IsNewCardPresent()

}   //Loop
//======================================================

2020年7月11日 星期六

Node-RED 由Dashboard UI Buttom 控制 MQTT Out , 經由MQTT in 控制 Dashboard UI Text 與 Line Notify

Node-RED 由Dashboard UI Buttom 控制 MQTT Out , 經由MQTT in 控制 Dashboard UI Text 與 Line Notify



執行畫面 127.0.0.1:1880/UI  




1) 設定 On LED , Off LED




設定 payload :  Light-emitting diode on  與  Light-emitting diode off

2) 設定 audio out 讓 LED 設定的 payload  Light-emitting diode on  與  Light-emitting diode off 能說出來




 3) 設定 MQTT Server 與 Topic

MQTT Server :  broker.mqtt-dashboard.com:1883

Topic  :  alex9ufo/led/led_event




 4) 設定 dashboard Text



 5)  取得 Line Notify 的 發行權杖 使得LEN ON , LED OFF 狀態可以隨時由手機APP LINE取得資訊

LINE結果 畫面




進入 發行權杖

指定 名稱 與 要Line通知的人 或 群組


將發行權杖 複製

檢視一下 發行的權杖是否active 


6) LINE 通知 的方法1

將剛才設定的 放入Name 與 Access Token 中


手機Line Notify 會送出 HEllo! LED Change 與一個貼圖 



7) LINE 通知 的方法2


設定2個function



function1

var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
if(h<10){
    h = '0'+h;
}
if(m<10){
    m = '0' + m;
}
if(s<10){
    s = '0' + s;
}
msg.payload = msg.payload + ' --> Time:(' + h + ':' + m + ':' + s + ')' ;

return msg;


function 2
發行權杖 放入 Authorization':'Bearer 後面
A4wwPNh2WqB723dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};


msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB723dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};
msg.payload = {"message":msg.payload};
return msg;

//oR7KdXvK1eob33Rr2sRRgsl4PMq23DjDlhfUs96SyUBZu

設定Htpp Request

Request 方法 :POST
URL :  https://notify-api.line.me/api/notify


8) 整個 程式碼


[{"id":"7377d363.84128c","type":"tab","label":"MQTT_LED","disabled":false,"info":""},{"id":"9a9808d2.b904e8","type":"mqtt in","z":"7377d363.84128c","name":"","topic":"alex9ufo/led/led_event","qos":"1","datatype":"auto","broker":"841df58d.ee5e98","x":140,"y":100,"wires":[["ff64ce35.d54d6","cc43c13c.49236","bd66ced7.e745b","7b270a19.2bfba4"]]},{"id":"ff64ce35.d54d6","type":"ui_text","z":"7377d363.84128c","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"name":"","label":"MQTT Suscribe Data","format":"{{msg.payload}}","layout":"col-center","x":400,"y":100,"wires":[]},{"id":"e10b330a.0e832","type":"ui_button","z":"7377d363.84128c","name":"","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"passthru":false,"label":"On led","tooltip":"","color":"white","bgcolor":"","icon":"fa-circle","payload":"Light-emitting diode on","payloadType":"str","topic":"","x":110,"y":300,"wires":[["a4db0e32.936f8","6d69def.f1acb2"]]},{"id":"5ccc4685.ea9d18","type":"ui_button","z":"7377d363.84128c","name":"","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"passthru":false,"label":"Off led","tooltip":"","color":"black","bgcolor":"","icon":"fa-circle-o","payload":"Light-emitting diode off","payloadType":"str","topic":"","x":110,"y":360,"wires":[["a4db0e32.936f8","6d69def.f1acb2"]]},{"id":"a4db0e32.936f8","type":"mqtt out","z":"7377d363.84128c","name":"","topic":"alex9ufo/led/led_event","qos":"1","retain":"false","broker":"841df58d.ee5e98","x":360,"y":300,"wires":[]},{"id":"6d69def.f1acb2","type":"ui_audio","z":"7377d363.84128c","name":"","group":"6c9116b.b62d4e8","voice":"zh-TW","always":"","x":320,"y":360,"wires":[]},{"id":"cc43c13c.49236","type":"function","z":"7377d363.84128c","name":"Format timestamp","func":"var date = new Date();\nvar h = date.getHours();\nvar m = date.getMinutes();\nvar s = date.getSeconds();\nif(h<10){\n    h = '0'+h;\n}\nif(m<10){\n    m = '0' + m;\n}\nif(s<10){\n    s = '0' + s;\n}\nmsg.payload = msg.payload + ' --> Time:(' + h + ':' + m + ':' + s + ')' ;\n\nreturn msg;","outputs":1,"noerr":0,"x":190,"y":240,"wires":[["d3901e4c.e507d"]]},{"id":"d3901e4c.e507d","type":"function","z":"7377d363.84128c","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":370,"y":240,"wires":[["2d2f8066.cb721"]]},{"id":"2d2f8066.cb721","type":"http request","z":"7377d363.84128c","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":540,"y":240,"wires":[["6085953d.1462ec"]]},{"id":"6085953d.1462ec","type":"debug","z":"7377d363.84128c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":240,"wires":[]},{"id":"bd66ced7.e745b","type":"debug","z":"7377d363.84128c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":60,"wires":[]},{"id":"7b270a19.2bfba4","type":"line-notify","z":"7377d363.84128c","name":"NODE-RED MQTT LED","message":"Hello! \nLED Changed","contentType":"sticker","imageUrl":"","stickerPackageId":"1","stickerId":"2","x":410,"y":160,"wires":[]},{"id":"841df58d.ee5e98","type":"mqtt-broker","z":"","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"6c9116b.b62d4e8","type":"ui_group","z":"","name":"LED","tab":"28920cc.c23e2f4","order":1,"disp":true,"width":"6","collapse":false},{"id":"28920cc.c23e2f4","type":"ui_tab","z":"","name":"MQTT_LED","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

2020年7月8日 星期三

DB Browser for SQLite 視覺化的 SQLite 管理工具

DB Browser for SQLite 視覺化的 SQLite 管理工具、新增、瀏覽資料超方便

要建立資料表時,就得下指令的方式,將資料表與所需的資料欄位建立起來,甚至當要預覽資料時,就得下SQL語法,才能看到裡面的資料一個超好用的工具,不但全圖形化界面,還可輕鬆的建立資料庫與欄位,與設定每個欄位屬性,且在這工具中,還能直接瀏覽資料庫中的資料,更棒的是這工具不但免費,且還支援Windows與MAC等平台,因此有使用SQLite的朋友,這個管理工具千萬別錯過了。
DB Browser for SQLite
軟體名稱:DB Browser for SQLite
支援平台:Windows XP+、macOS X 
當安裝完畢後,開啟DB Browser for SQLite後,點左上「新增資料庫」,並輸入資料庫名稱與儲存位置。

接著再設定資料表名稱。

以及建立所需的資料表欄位,甚至還可以針對每個欄位設定所需的屬性。



當要新增資料庫中的資料時



 當要預覽資料庫中的資料時,再將上方的頁籤切到「Browse Data」以及選擇要瀏覽的表單,這樣就可看到裡面的資料啦!

Node-Red --> MQTT --> Fuxa

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...