Introduction
Two years ago, I worked on a project to automate library operations. A key component was uniquely identifying books via UHF RFID tags. The enterprise chose the UHF Long Range Reader DL920, capable of reading tags up to 15 meters. Our task: deliver tag data from the reader to a Vue.js frontend. This guide shares the solution using Node.js and TCP sockets.
Understanding UHF RFID Readers
UHF RFID readers communicate over Ethernet using TCP/IP. They typically use a proprietary protocol over TCP port 9761 (common for many Chinese readers). The reader sends data packets containing tag IDs, RSSI, and other metadata. Understanding the packet structure is crucial.
Network Setup
Connect the reader to the same network as your computer. Assign a static IP (e.g., 192.168.1.100) via the reader’s web interface or manual. Ensure port 9761 is open.
Node.js TCP Client
We’ll use Node.js’s built-in net module to create a TCP client. Install dependencies: npm install net (built-in).
const net = require('net');
const client = new net.Socket();
client.connect(9761, '192.168.1.100', () => {
console.log('Connected to RFID reader');
// Send command to start reading (example: 0xBB 0x00 0x03 0x00 0x01 0x00 0x04)
const startCmd = Buffer.from([0xBB, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04]);
client.write(startCmd);
});
client.on('data', (data) => {
console.log('Received:', data.toString('hex'));
// Parse data packet
parseTagData(data);
});
client.on('close', () => {
console.log('Connection closed');
});
Parsing Tag Data
The reader sends packets with a header, length, data, and checksum. For the DL920, typical packet format: 0xBB 0x00 length data checksum. Tag IDs are 12-byte hex strings. Example parser:
function parseTagData(buffer) {
if (buffer[0] !== 0xBB) return;
const length = buffer[2];
const data = buffer.slice(3, 3 + length - 2); // exclude checksum
const checksum = buffer[3 + length - 2];
// Verify checksum (XOR of all bytes except header)
let calc = 0;
for (let i = 1; i < buffer.length - 1; i++) {
calc ^= buffer[i];
}
if (calc !== checksum) return;
// Extract EPC (tag ID) from data
const epc = data.slice(2).toString('hex').toUpperCase();
console.log('Tag ID:', epc);
return epc;
}
Real-Time Streaming to Frontend
Use WebSocket to push tag data to the browser. Install ws: npm install ws. Create a WebSocket server and broadcast tag IDs.
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
client.on('data', (data) => {
const tagId = parseTagData(data);
if (tagId) {
wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify({ tagId }));
}
});
}
});
Complete Integration
Combine the TCP client and WebSocket server into a single Node.js app. Handle reconnection, errors, and multiple readers. Example full script available on GitHub.
Conclusion
Integrating a UHF RFID reader with Node.js is straightforward using TCP sockets. This approach works for many Chinese readers with similar protocols. Adapt the packet parsing to your reader's manual. Now you can build real-time inventory systems, library automation, and more.