Skip to content

ilhamx/RMT01

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RMT01 — ESP32 RFID Reader (MQTT bridge)

This project runs on an ESP32 and communicates with an external RFID reader over a UART (Serial1). When a known tag (EPC) is read the ESP32 publishes a message to an MQTT broker.

Features

  • Send inventory requests to an RFID module and parse its frame-based responses
  • Matches detected tags against configured EPCs and publishes MQTT messages
  • Uses WiFi and PubSubClient (MQTT) for reporting

Hardware

  • MCU: ESP32 (any board with Serial1 and GPIOs available)
  • RFID reader module with UART interface (frame-based protocol)
  • Connections: power, ground, UART TX/RX, optional enable pin

Wiring

The code initializes Serial1 as:

Serial1.begin(115200, SERIAL_8N1, 16, 17);

That means Serial1 RX is GPIO16 and TX is GPIO17. Wire the RFID module like this:

  • RFID TX -> ESP32 GPIO16 (Serial1 RX)
  • RFID RX -> ESP32 GPIO17 (Serial1 TX)
  • RFID VCC -> 3.3V (confirm module voltage)
  • RFID GND -> ESP32 GND
  • RFID ENABLE (if present) -> ESP32 GPIO4 (named PIN_EN in code) — the code drives this HIGH to enable the module

Adjust wiring if your module or board uses different pins.

Firmware overview

  • src/main.cpp:
    • Builds and sends an inventory request frame (singleRead) to the RFID module
    • Waits for a response and parses a custom frame format (header, type, length, RSSI, PC, EPC, CRC, end)
    • Compares the EPC payload against three example EPCs (epc_book1, epc_book2, epc_book3) and publishes a message to MQTT topic ilham/test with a human-readable message
    • Connects to WiFi using ssid and password constants and to an MQTT broker at mqtt_server

Configuration

Edit the following variables in src/main.cpp to match your environment:

  • ssid / password: WiFi credentials
  • mqtt_server: MQTT broker IP or hostname
  • epc_book1, epc_book2, epc_book3: example EPC arrays (replace with your tags)
  • PIN_EN (default 4): GPIO used to enable the RFID module
  • Timing and frame constants near the top of the file

Build & Upload (PlatformIO)

  1. Open the project folder RMT01 in VS Code with the PlatformIO extension.
  2. Build:
pio run
  1. Upload (connect your ESP32 via USB):
pio run -t upload
  1. Monitor serial output (the sketch prints on Serial at 9600 baud):
pio device monitor -b 9600

The code uses Serial1 to communicate with the RFID module and Serial for logging.

MQTT testing

By default the sketch publishes to topic ilham/test.

  • To see messages with mosquitto client (on another machine in the network):
mosquitto_sub -h 192.168.137.1 -t ilham/test -v

Replace 192.168.137.1 with the value of mqtt_server in the code.

Example serial output (trimmed)

Starting RFID reader...
Sending power setting frame...
Connecting to WiFi...
...Connected to WiFi
Received frame:
- Header: BB
- Frame type: 02
- Command: 22
- Parameter length: 00 0B
- RSSI: 5A
- Tag EPC: 21 05 00 00 00 00 00 00 00 00 00 01 00 00
Book detected: The Great Gatsby

Customization

  • Add or remove EPCs and mapped strings by editing the arrays and if checks in loop().
  • The code contains commented examples for getting/setting transmit power frames. Use them only after verifying your module's command set.

Troubleshooting

  • Timeout: If Timeout: No data received. appears, check wiring, module power and that the module uses the same baud/frame format.
  • CRC errors: The parser computes and checks CRC; mismatches may indicate the wrong framing, corrupted bytes, or different protocol variant.
  • WiFi/MQTT: Verify broker IP, network reachability, and credentials.

License

MIT — feel free to reuse and adapt. Please verify licensing if you incorporate third-party libraries.


Credits

  • Electron.id

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages