Today we will talk about the access control system (ACS), which, being connected to the Rightech IoT Cloud Internet of Things platform (hereinafter referred to as the platform), is the basic element in the system for counting the number of people in the office.

How it all started
The task of providing control over entry and exit in the office arose back in those days when we had access to the roof with an excellent view of Moscow, and therefore people who were not our employees often came. Then we decided to take some security measures and install an access control system.

Map door opening system
GATE-8000 was chosen as the module responsible for processing information on reading contactless cards.

The main advantages of the controller:

• formation and storage of the necessary information about the fact of opening the door according to the card and the time of the person’s passage to the office;
• the possibility of autonomous operation and protection against freezing;
• storage of 16 thousand keys and 8 thousand events;
• simple connection and management;
• Russian manufacturer, good documentation describing the operation of the controller.

The basic principle of operation: the controller processes the information coming from the reader and, using the built-in relay, switches the actuator – an electromagnetic door lock.

Platform interaction system
After the controller was installed into the system according to the general connection scheme, and the cards were written into memory, we already secured ourselves from strangers entering the office. And then the question arose of how to connect this controller to the Rightech ioT Cloud platform. After all, it’s great to have a) a graphical interface in which you can scroll through the history of all passages, b) the ability to send commands to open the door remotely without leaving the workplace, for example, for guests or a food delivery man.

The controller has no Internet access and no visible ability to connect to the platform, in addition, all events must be forced to read from its circular buffer. However, it has its own data exchange protocol with the control computer, thanks to which it is possible to send commands to the controller, such as reading from the controller, writing to the controller, opening / closing the lock, and others. So, you need to make some software and hardware layer between the controller and the platform – an agent that will send commands to read events and control the controller.

Please note that in this architecture, the function of opening the door when a card is applied will not cease to be performed in the absence of the Internet. The ACS controller is responsible for opening the door and collecting information, so if the Internet is lost, the only thing that threatens us is that the agent that delivers data to the platform will not function, since it will not be able to receive commands to read the buffer. However, when the connection is restored, all events are considered in full and will not be lost, since they will be stored in the buffer of the ACS controller.

To begin with, it was necessary to select a device that will always be in the active state with the agent program turned on in the immediate vicinity of the ACS board. Of the variety of microcomputers, the first thing that came to hand was the Raspberry Pi.

Then the question arose of how to connect the GATE-8000 to the Raspberry – that is, how to connect the RS485 serial interface from GATE to USB from the microcomputer. The search for a USB-RS485 adapter began. The first option we tried is the Espada for 200 rubles. There was little hope that the little flimsy Chinese adapter would work. He did not earn. Instead of the necessary data, something similar in appearance and size came, but … still not the same. What was the matter: in the absence of galvanic isolation, the inability to maintain a speed of 19200 bps, or simply in a poor-quality element base, is a mystery. But after contacting the manufacturer of GATE-8000, we received a recommendation for a more expensive (10 times) and bulky (but neat and packaged) Z-397 adapter, which immediately worked as it should.

Software part
We begin the development of the program by determining what functions it should perform.

What is needed is interaction with the GATE-8000 to send commands and receive data.
As we decide, we will study the GATE protocol, write a data serializer and deserializer, and connect the library to work with the serial port.
What you need is interaction with the platform to receive commands and send data.
As we decide, we will choose the MQTT protocol for communication, in the code we will use the ready-made Paho MQTT library.
So, we started studying the GATE-8000 protocol, which is closed, so only some of its features are described below. It is quite low-level, and it is necessary to access the device memory registers directly. The document on this protocol describes the frames of requests from the computer to the controller and the frames of responses of the controller to the computer. By changing the fields in the request frame, you can send various commands to the device and receive information from the registers.

One of the features of the protocol is that the exchange is always initiated by the computer. Therefore, there are two approaches to working with the device:

1) set the entire logic of work in the agent;

2) use external requests (from the platform).

We chose the second option and moved the logic from the end device to the platform. So it is easy to adapt and adjust, while the program code remains compact and allows you to simply generate commands for the device, and the platform, in turn, coordinates the sending of commands and their frequency.

Is it always necessary to take the logic of work from the device?

Such a solution, of course, will not work if the device is required to take actions instantly (for example, if we are talking about a person’s life), but even in this case, part of the logic can be moved to the platform. As an option, to select pre-programmed behavior patterns.

After we carefully studied this protocol, the frame format and the list of commands, the first difficulty arose. There were no commands for reading the buffer, which contains events about who came and what time. But getting this information is a top priority. It was necessary to examine the controller’s memory card to determine the addresses from which to read the data.

Leave a Reply

Your email address will not be published. Required fields are marked *