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();
}
//===================================================================================  

RFID Reader MFRC522 interface with NodeMCU using Arduino IDE

RFID Reader MFRC522 interface with NodeMCU using Arduino IDE


In this tutorial we will learn How to interface NodeMCU with RC522 RF ID Reader using Arduino library for MFRC522 and other RFID RC522 based modules.
This library read and write different types of Radio-Frequency IDentification (RFID) cards on your Arduino or NodeMCU using a RC522 based reader connected via the Serial Peripheral Interface (SPI) interface. Before we move to actual code lets know more about RF ID.
RF ID Reader MFRC-522
RF ID Reader

What is RFID?

Radio-Frequency Identification (RFID) is the use of radio waves to read and capture information stored on a tag attached to an object. A tag can be read from up to several feet away and does not need to be within direct line-of-sight of the reader to be tracked. This is the advantage over Bar-code.
RFID reader is a device used to gather information from an RFID tag, which is used to track individual objects. Radio waves are used to transfer data from the tag to a reader.
passive tag is an RFID tag that does not contain a battery, the power is supplied by the reader. When radio waves from the reader are encountered by a passive rfid tag, the coiled antenna within the tag forms a magnetic field. The tag draws power from it, energizing the circuits in the tag.

What are the RC522 RF ID Reader Specifications?

RC522 – RFID Reader / Writer 13.56MHz with Cards Kit includes a 13.56MHz RF reader cum writer module that uses an RC522 IC and two S50 RFID cards. The MF RC522 is a highly integrated transmission module for contact-less communication at 13.56 MHz. RC522 supports ISO 14443A/MIFARE mode.
RC522 – RFID Reader features an outstanding modulation and demodulation algorithm to serve effortless RF communication at 13.56 MHz. The S50 RFID Cards will ease up the process helping you to learn and add the 13.56 MHz RF transition to your project.
The module uses SPI to communicate with microcontrollers. The open-hardware community already has a lot of projects exploiting the RC522 – RFID Communication, using Arduino.

RC522 – RFID Reader / Writer Features:

  • Integrated MF RC522
  • 13.56MHz contactless communication card chip.
  • Low-voltage, low-cost, small size of the non-contact card chip to read and write.
  • Suitable for Smart meters and portable handheld devices.
  • Advanced modulation and demodulation concept completely integrated in all types of 13.56MHz passive contactless communication methods and protocols.
  • 14443A compatible transponder signals.
  • ISO14443A frames and error detection.
  • Supports rapid CRYPTO1 encryption algorithm, terminology validation MIFARE products.
  • MFRC522 support MIFARE series of high-speed non-contact communication, two-way data transmission rate up to 424kbit/s.
  • Low cost, and ideal for user equipment development.
  • The reader and RF card terminal design meets advanced applications development and production needs.
  • Can be directly loaded into the various reader molds, very convenient.

RC522 – RFID Reader / Writer Specifications:

  • Operating Current :13-26mA / DC 3.3V
  • Idle Current :10-13mA / DC 3.3V
  • Sleep Current: < 80uA
  • Peak Current: < 30mA
  • Operating Frequency: 13.56MHz
  • Supported card types: mifare1 S50, mifare1 S70 MIFARE Ultralight, mifare Pro, MIFARE DESFire
  • Environmental Operating Temperature: -20 – 80 degrees Celsius
  • Environmental Storage Temperature: -40 – 85 degrees Celsius
  • Relative humidity: relative humidity 5% – 95%
  • Reader Distance: ≥ 50mm / 1.95″ (mifare 1)
  • Module Size: 40mm × 60mm
  • Module interface: SPI
  • Data transfer rate: Maximum 10Mbit/s

Hardware Components

  • NodeMCU
  • MFRC522 RFID Reader
  • RFID Tags ( 13.56 MHz )
  • Bread Board
  • Jumper Wires
  • Micro USB Cable

Software Components

  • Arduino IDE

Connections of MFRC522 RF ID Reader With Node MCU

NodeMCU RC522 Interface Circuit
NodeMCU RC522 Interface
or Refer Connection Chart Given in Code

Arduino Code for MFRC522 RF ID Reader

For this program we need RF ID Library Download it from here.rfid-master
Upload Sketch to NodeMCU and test it.

Results and Testing

Open serial monitor with baud rate settings of 115200. and move card near to the card Reader module. Observe serial monitor. It will show UID for that card.
RC522 NodeMCU Reader

Additional resources

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...