Build a cloud integrated RFID card reader based on HaaS100

1 Introduction

Radio Frequency Identification (RFID) is a type of automatic identification technology. It uses wireless radio frequency to carry out non-contact two-way data communication, and uses radio frequency to read and write electronic tags or radio frequency cards to achieve identification. Goals and purpose of data exchange.

 

RFID technology has the characteristics of strong anti-interference and no need for manual identification, so it is often used in some fields that need to collect information, such as logistics, warehousing, anti-counterfeiting, and identification.

 

Next, we will learn how to build an RFID card reader based on HaaS100, read the card information, and transmit it to our mobile phone through the Alibaba Cloud platform.

image.png

2. The working principle of RFID radio frequency identification system

After the electronic tag enters the antenna magnetic field, if it receives a special radio frequency signal from the reader, it can use the energy obtained by the induced current to send the product information stored in the chip (passive tag), or actively send a certain frequency After the signal (active tag), the reader reads and decodes the information, it is sent to the central information system for relevant data processing.

 

A typical RFID system is mainly composed of three parts: application system software, RFID reader and electronic tag.

 

image.png

 

3. Introduction to RFID Reader

image.png

 

TX522 is a Mifare card reader/writer module based on 13.56MHz frequency. It can support multiple types of cards. TX522 Mifare card reader/writer module has antenna integration and the recognition distance reaches 80mm. It can communicate with HaaS100 through the UART interface.

 

Swipe:

When the RFID card is detected approaching; the red indicator light flashes, and the card serial number related instructions are sent out through the serial port.

 

Instruction protocol description

Data communication is carried out in units of one frame, and the format is as follows:

Data communication frame structure:

第1字节:起始符;

第2字节:包号,默认:0x00;

第3字节:命令—上位机发送给IC卡读写器;

第4字节:此帧有效数据的长度。从紧接着的第1个字节开始,到倒数第3个字节结束,为有效字节。

第5字节 到  倒数第3字节: 有效数据。

倒数第2字节:校验和;

倒数第1字节:结束符;

 

Swipe. The indicator light on the module will be on, and the serial number of the card will be sent to the host computer through the serial port. At this time, the host computer will receive the relevant instructions of the card serial number.

For example, the command: 20 00 01 08 04 00 00 00 A6 40 FE E4 0E 03.

20:起始符

00:包号

01:命令字节,模块主动输出卡片序列号时,该字节为0x00;其他指令为命令字

08:表示后面8个字节为有效数据位

04 00:表示卡片属性为S50卡

00 00:此2个字节无实际意义。

A6 40 FE E4 :表示卡片序列号。刷不同卡片,此4个字节会变。

0E:校验和。从包号(SEQNR)开始到数据(DATA)的最后一字节异或,然后再取反 得到。

03:帧结束符。

 

The card serial number is an important information we pay attention to. We read the card serial number information through the serial port and send it to Alibaba Cloud, and the cloud sends this information to our mobile APP.

 

4. Hardware connection

The RFID module communicates with HaaS100 through the UART interface.

This is the HaaS100 hardware interface definition:

 

Connect the power cord, ground wire, serial port RX, and serial port TX to the HaaS board.

image

 

5. Access to Alibaba Cloud IoT platform

 

Please refer to Building Smart Home Application Based on HaaS 100 to create your own application.

Quickly build smart home applications based on HaaS100

 

It should be noted that the custom function is added on the function definition page: card serial number CardID

image

Select the device ID on the product panel page to display the read RFID card serial number on the mobile phone.

image

 

6. HaaS software code

Next we start to write the software code on HaaS, read the serial port data, extract the card serial number from it, and send the serial number to the Alibaba Cloud IoT platform through the linkkit SDK interface.

 

6.1 Software flow chart

image.png

6.2, HaaS100 serial communication part

UART serial port operation instructions:

https://help.aliyun.com/document_detail/161062.html?spm=a2c4g.11186623.6.574.73d4c806uT1bKl

The specific code can refer to this file: application/example/example_legacy/uart/uart.c

int application_start(int argc, char *argv[])
{

  printf("uart sample application started...\n");
  uart_dev_t uart_demo;
  uart_demo.port                = 2;
  uart_demo.config.baud_rate    = 9600;
  uart_demo.config.mode         = MODE_TX_RX;
  uart_demo.config.flow_control = FLOW_CONTROL_DISABLED;
  uart_demo.config.stop_bits    = STOP_BITS_1;
  uart_demo.config.parity       = NO_PARITY;
  uart_demo.config.data_width   = DATA_WIDTH_8BIT;

  ret = hal_uart_init(&uart_demo);

  int  i;
  int  ret;
  char rev_buf[1];
  int  rev_length;

  while (1) {
    ret = hal_uart_recv_II(&uart_demo, rev_buf, sizeof(rev_buf), &rev_length, AOS_WAIT_FOREVER);
    if (ret != 0) {
      printf("recv data from uart error\r\n");
      break;
    }

    for(i = 0; i < rev_length; i++) {
      printf("%02x ", rev_buf[i]&0xff);
    }
    printf("\r\n");
  }
  return 0;
}

6.3. Send data to Alibaba Cloud IoT platform

We use the IOT_Linkkit_Report interface in the linkkit component to send the read card serial number DeviceID to the Alibaba Cloud IoT platform.

linkkit_event.c

void user_post_data(uint8_t value)
{
	int res = 0;

	char property_payload[30] = {0};

	HAL_Snprintf(property_payload, sizeof(property_payload), "{\"DeviceID\": %s}", "123987");
	res = IOT_Linkkit_Report(EXAMPLE_MASTER_DEVID, ITM_MSG_POST_PROPERTY,
                                (unsigned char *)property_payload, strlen(property_payload));
}

linkkit_main:
while (1) {
	user_post_data();
}

7. End-cloud joint debugging

7.1, download the software version

For compilation and programming steps, please refer to  HaaS100 for quick start

7.2. Equipment distribution network

Configure the network through the command line and enter the following commands through the serial port to complete the network configuration:

netmgr -t wifi -c {ssid} {password}

7.3. Device and cloud smart APP binding

The installed cloud smart APP ensures that the mobile phone and the device are connected to the same APP. Click the red "+" button in the upper right corner to start the device search.

image.png

Find the device after a few seconds, as shown in the figure below, click Finish.

 

image.png

The binding is now complete.

7.4, demo effect picture

When an RFID card is close to the reader, we will see the serial number of the card on the phone.

image.png

 

8. Summary

This document describes how to build an RFID card reader based on HaaS100, read card information, and transmit data to our mobile phone through the Alibaba Cloud IoT platform, which involves HaaS serial port operations and sending data to Alibaba Cloud IOT.

In addition to reading the data on the card, the RFID module can also write data to the card. There are more functions that you can explore and explore together.

In addition to the serial port, HaaS100 can also link external sensors or other devices through i2c, spi and other interfaces.

Through the process described in this document, you can create more application scenarios, and you can take action together and make a set of your own smart devices by yourself!

9. Developer technical support

If you need more technical support, you can join the Dingding Developer Group.

   

For more technology and solution introduction, please visit the Aliyun AIoT homepage https://iot.aliyun.com/

Guess you like

Origin blog.csdn.net/HaaSTech/article/details/111307770