2019年10月7日 星期一

Node-Red 基本元件操作實驗

Node-Red基本元件操作實驗

在Node-Red使用Json資料庫儲存資料

應用程式存取網址  選取 JSON檔案格式
https://opendata.epa.gov.tw/webapi/api/rest/datastore/355000000I-000259?sort=SiteName&offset=0&limit=1000















[{"id":"c55a4b45.0cdf98","type":"inject","z":"d2ac9b5e.1faa08","name":"","topic":"","payload":"","payloadType":"date","repeat":"20","crontab":"","once":true,"onceDelay":"5","x":110,"y":80,"wires":[["3fd95521.40e43a","f44d2ebd.aa6f8"]]},{"id":"3fd95521.40e43a","type":"http request","z":"d2ac9b5e.1faa08","name":"PM2.5網頁","method":"GET","ret":"obj","url":"http://opendata.epa.gov.tw/ws/Data/REWIQA/?$orderby=SiteName&$skip=0&$top=1000&format=json","tls":"","x":410,"y":80,"wires":[["a99ed099.b2b7b","b08ed856.94e488"]]},{"id":"2b7d15ba.f685ca","type":"function","z":"d2ac9b5e.1faa08","name":"設定地區","func":"var a = msg.payload;\n\na.forEach (function(e,i){ \n   if(e.SiteName == global.get('Location')) {\n        \n        msg.PM25 = ' PM2.5=' + e['PM2.5'] ;\n        msg.AQI = ' AQI=' + e['AQI'] ;\n        msg.Status = ' Status=' + e['Status'] ;\n        msg.PublishTime =' PublishTime='+ e['PublishTime'] ;\n        msg.payload=global.get('Location')+msg.PM25+msg.AQI+msg.Status+msg.PublishTime;\n\n        msg.PM251 =  e['PM2.5'] ;\n        msg.AQI1 =  e['AQI'] ;\n        msg.Status1 = e['Status'] ;\n        msg.PublishTime1 = e['PublishTime'] ;\n   }\n} );\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":240,"wires":[["b8db8759.46bfa8","ed4a20fd.ecada","1b20ea9e.47aea5","879be4e4.5b0f78","40d3c2e4.a20e0c","acebd89d.8ef228","69819cf6.2232c4","874c0434.f9f868","d585534c.b2b0a"]]},{"id":"b8db8759.46bfa8","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"PM25","x":870,"y":240,"wires":[]},{"id":"ed4a20fd.ecada","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"Status","x":670,"y":240,"wires":[]},{"id":"1b20ea9e.47aea5","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"PublishTime","x":870,"y":300,"wires":[]},{"id":"879be4e4.5b0f78","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"AQI","x":660,"y":300,"wires":[]},{"id":"b6b94e54.4d635","type":"comment","z":"d2ac9b5e.1faa08","name":"台灣空氣品質狀況","info":"","x":110,"y":40,"wires":[]},{"id":"40d3c2e4.a20e0c","type":"mqtt out","z":"d2ac9b5e.1faa08","name":"空氣品質 AQI","topic":"alex9ufo/Dali/AQI","qos":"1","retain":"true","broker":"40bf4d5e.0395f4","x":680,"y":180,"wires":[]},{"id":"1b2055db.7a243a","type":"ui_gauge","z":"d2ac9b5e.1faa08","name":"","group":"ac7bd49c.51cf38","order":0,"width":"6","height":"3","gtype":"gage","title":"PM2.5 [0..35] 良好","label":"units","format":"{{value}}","min":0,"max":"80","colors":["#00b500","#e6e600","#ca3838"],"seg1":"35","seg2":"53","x":950,"y":360,"wires":[],"inputLabels":["msg.PM25"]},{"id":"f9561345.51fcf","type":"ui_text","z":"d2ac9b5e.1faa08","group":"ac7bd49c.51cf38","order":0,"width":"6","height":"2","name":"","label":"空氣品質","format":"{{msg.payload}}","layout":"row-spread","x":920,"y":480,"wires":[],"inputLabels":["msg.payload"]},{"id":"acebd89d.8ef228","type":"function","z":"d2ac9b5e.1faa08","name":"PM2.5 [0..80]","func":"msg.payload=msg.PM251;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":360,"wires":[["1b2055db.7a243a"]]},{"id":"69819cf6.2232c4","type":"function","z":"d2ac9b5e.1faa08","name":"AQI [0..400]","func":"msg.payload= msg.AQI1;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":420,"wires":[["f48d7445.519b58"]]},{"id":"f48d7445.519b58","type":"ui_gauge","z":"d2ac9b5e.1faa08","name":"","group":"ac7bd49c.51cf38","order":0,"width":"6","height":"3","gtype":"gage","title":"AQI [0..50] 良好","label":"units","format":"{{value}}","min":0,"max":"400","colors":["#00b500","#e6e600","#ca3838"],"seg1":"50","seg2":"100","x":940,"y":420,"wires":[],"inputLabels":["msg.PM25"]},{"id":"874c0434.f9f868","type":"function","z":"d2ac9b5e.1faa08","name":"Status","func":"msg.payload=msg.Status1;\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":480,"wires":[["f9561345.51fcf"]]},{"id":"d585534c.b2b0a","type":"function","z":"d2ac9b5e.1faa08","name":"PublishTime","func":"msg.payload=msg.PublishTime1;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":540,"wires":[["298e66f7.64a34a"]]},{"id":"298e66f7.64a34a","type":"ui_text","z":"d2ac9b5e.1faa08","group":"ac7bd49c.51cf38","order":0,"width":"6","height":"3","name":"","label":"發表時間","format":"{{msg.payload}}","layout":"row-spread","x":920,"y":540,"wires":[],"inputLabels":["msg.payload"]},{"id":"a99ed099.b2b7b","type":"DataIn","z":"d2ac9b5e.1faa08","collection":"7a14aca8.b15994","name":"PM2.5","update":false,"path":"/myRootTest","x":650,"y":80,"wires":[]},{"id":"f44d2ebd.aa6f8","type":"trigger","z":"d2ac9b5e.1faa08","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":260,"y":140,"wires":[["4e72cc00.8e9084"]]},{"id":"4e72cc00.8e9084","type":"DataOut","z":"d2ac9b5e.1faa08","collection":"7a14aca8.b15994","name":"PM2.5","path":"/myRootTest","error":false,"x":300,"y":240,"wires":[["2b7d15ba.f685ca","5d25865e.a5b848"]]},{"id":"b3b8c570.82b628","type":"function","z":"d2ac9b5e.1faa08","name":"","func":"if (msg.payload===null)\n{\n    global.set('Location','大里');\n}\nelse\n{\n    global.set('Location',msg.payload);\n}\nnode.status({filee:\"green\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":150,"y":240,"wires":[["4e72cc00.8e9084"]]},{"id":"26364fb8.d2499","type":"ui_dropdown","z":"d2ac9b5e.1faa08","name":"","label":"","place":"Select option","group":"ac7bd49c.51cf38","order":0,"width":0,"height":0,"passthru":true,"options":[{"label":"大里","value":"大里","type":"str"},{"label":"二林","value":"二林","type":"str"},{"label":"板橋","value":"板橋","type":"str"},{"label":"士林","value":"士林","type":"str"},{"label":"南投","value":"南投","type":"str"}],"payload":"","topic":"","x":80,"y":160,"wires":[["b3b8c570.82b628"]]},{"id":"b08ed856.94e488","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":120,"wires":[]},{"id":"5d25865e.a5b848","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":320,"wires":[]},{"id":"40bf4d5e.0395f4","type":"mqtt-broker","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":15,"cleansession":true,"birthQos":"0","willQos":"0"},{"id":"ac7bd49c.51cf38","type":"ui_group","z":"","name":"空氣品質狀況","tab":"ba052423.3729f8","order":1,"disp":true,"width":"6","collapse":false},{"id":"7a14aca8.b15994","type":"json-db-collection","z":"","name":"DATA","collection":"DATA","save":false},{"id":"ba052423.3729f8","type":"ui_tab","z":"","name":"Weather","icon":"dashboard","order":1}]

2019年9月24日 星期二

MQTT_RFID 中的 PubSubClient 程式庫安裝問題


MQTT_RFID 中的 PubSubClient 程式庫安裝問題

MQTT_RFID_2 中的 PubSubClient 程式庫安裝問題


我的Arduino 版本是1.6.5

有關 pubsubclient.h 問題        (PubSubClient Version 2.6.0版本)
1)    若是已經安裝者pubsubclient 程式庫者 請將 C:\Users\使用者\Documents\Arduino\libraries 中的目錄 pubsubclient刪除





2)    將pubsunclient-master解壓縮後 整個目錄 copy 到 C:\Users\使用者\Documents\Arduino\libraries 中的目錄。


3)    打開Arduino 組譯 是否有錯誤  ???
  // Once connected, publish an announcement...
  client.publish("alex9ufo/outTopic/RFID/json", jsonChar, MQTTpubQos, true); // true means retain
  // ... and resubscribe
  client.subscribe("alex9ufo/inTopic", MQTTsubQos);

4)    沒有錯誤代表PubSubClient.h 程式庫正確

5) 下載點







https://www.mediafire.com/file/ndfqkgl45m0m31b/pubsubclient-master.rar/file

2019年9月23日 星期一

RFID Reader MFRC522 interface with NodeMCU using Arduino IDE

RFID Reader MFRC522 interface with NodeMCU using Arduino IDE

修改 MFRC522 <-> NodeMCU 介面

/*
 * ----------------------------------------------------------------------
 * Example program showing how to read new NUID from a PICC to serial.
 * ----------------------------------------------------------------------
 * https://circuits4you.com
 * 
 * RC522 Interfacing with NodeMCU
 * 
 * Typical pin layout used:
 * ----------------------------------
 *             MFRC522      Node     
 *             Reader/PCD   MCU      
 * Signal      Pin          Pin      
 * ----------------------------------
 * RST/Reset   RST          D1 (GPIO5)        
 * SPI SS      SDA(SS)      D2 (GPIO4)       
 * SPI MOSI    MOSI         D7 (GPIO13)
 * SPI MISO    MISO         D6 (GPIO12)
 * SPI SCK     SCK          D5 (GPIO14)
 * 3.3V        3.3V         3.3V
 * GND         GND          GND
 */
 
#include <SPI.h>
#include "MFRC522.h"

/* Wiring RFID RC522 module
=============================================================================
GND     = GND   3.3V    = 3.3V
The following table shows the typical pin layout used:
Signal        MFRC522     WeMos D1 mini     NodeMcu     Generic
RST/Reset     RST         D3 [1]            D3 [1]      GPIO-0 [1]
SPI SS        SDA [3]     D8 [2]            D8 [2]      GPIO-15 [2]
SPI MOSI      MOSI        D7                D7          GPIO-13
SPI MISO      MISO        D6                D6          GPIO-12
SPI SCK       SCK         D5                D5          GPIO-14
[1] (1, 2) Configurable, typically defined as RST_PIN in sketch/program.
[2] (1, 2) Configurable, typically defined as SS_PIN in sketch/program.
[3] The SDA pin might be labeled SS on some/older MFRC522 boards
=============================================================================
*/

#define RST_PIN  D3     // RST-PIN für RC522 - RFID - SPI - D3 
#define SS_PIN   D8     // SDA-PIN für RC522 - RFID - SPI - D8

 
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
 
MFRC522::MIFARE_Key key; 
 
// Init array that will store new NUID 
byte nuidPICC[4];
 
//===================================================================================  
/**
 * Helper routine to dump a byte array as hex values to Serial. 
 */
void printHex(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }
}
//===================================================================================  
/**
 * Helper routine to dump a byte array as dec values to Serial.
 */
void printDec(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], DEC);
  }
}
//=================================================================================== 
//=================================================================================== 
void setup() { 
  Serial.begin(115200);
  SPI.begin(); // Init SPI bus
  rfid.PCD_Init(); // Init MFRC522 
 
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
 
  Serial.println(F("This code scan the MIFARE Classsic NUID."));
  Serial.print(F("Using the following key:"));
  printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
  Serial.println();
}
//===================================================================================  
void loop() {
 
  // Look for new cards
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
 
  // Verify if the NUID has been readed
  if ( ! rfid.PICC_ReadCardSerial())
    return;
 
  Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  Serial.println(rfid.PICC_GetTypeName(piccType));
 
  // Check is the PICC of Classic MIFARE type
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&  
    piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
    piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }
 
  if (rfid.uid.uidByte[0] != nuidPICC[0] || 
    rfid.uid.uidByte[1] != nuidPICC[1] || 
    rfid.uid.uidByte[2] != nuidPICC[2] || 
    rfid.uid.uidByte[3] != nuidPICC[3] ) {
    Serial.println(F("A new card has been detected."));
 
    // Store NUID into nuidPICC array
    for (byte i = 0; i < 4; i++) {
      nuidPICC[i] = rfid.uid.uidByte[i];
    }
   
    Serial.println(F("The NUID tag is:"));
    Serial.print(F("In hex: "));
    printHex(rfid.uid.uidByte, rfid.uid.size);
    Serial.println();
    Serial.print(F("In dec: "));
    printDec(rfid.uid.uidByte, rfid.uid.size);
    Serial.println();
  }
  else Serial.println(F("Card read previously."));
 
  // Halt PICC
  rfid.PICC_HaltA();
 
  // Stop encryption on PCD
  rfid.PCD_StopCrypto1();
}
//===================================================================================  

  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...