Once, they called me and asked if I could do a little automation for a sewage pumping station (SPS)? Without really asking anything, and putting the phone down, I began to think what to do and how.
Being a SCADA specialist for more than 10 years, mainly in the products of the Tomsk company Elesi, it immediately occurred to me to use some well-known package like TraceMode and others like it. However, having met with the customer and having learned in more detail what he needed, I decided not to use ready-made packages.
The task was simple: to eliminate the grandmother sitting in the building of the KNS and observing the periodic process of buildup of the tank with sewage. The pumps were controlled by a Modicon PLC as part of some Russian control panel. A grandmother was required in the event of a pump crash, to inform the repair team and to prevent the container from overflowing. Control was to be carried out remotely, control functions were not required.
Having delivered the documentation on the automation panel, I was glad to find a description of the controller registers with bitwise signal layout. Well, there is information, business for small - to implement.
')
Organization of communication
It was decided to monitor the work of the CND in the browser via the Internet. Immediately there was a task - how to transfer data from the CND, located on the outskirts of one of the districts of the city? The Internet will not go there, and it is stupid, I would have to put a computer there. The PLC in the panel had an RS-485 interface and supported the Modbus protocol (which is natural, since this protocol was created by Modicon).
After a long googling, such a device came across:

CCU-Wireless COM
The device is a GSM extension COM port, supports RS-232, RS-485 and RS-422 interfaces. It is proposed by the NGO Sibsvyaz, and I still do not understand who is developing. It cost 15 thousand rubles. Additionally, a GSM antenna was purchased. A SIM card Beeline with the Telemetry tariff was installed in the device.
The company already had a web server (IIS), so no additional costs were required. The com-port driver for communication with the CCU was installed on the web server, the device was configured and a test of communication took place. The driver is supplied with the port monitoring program, so it was immediately obvious that the device communicates with the server and we get a com-port in our system, as if physically connected to the controller. Now you can work directly with the PLC.
Server part
Somehow it was necessary to transfer data from the com-port to the MySQL database. Having small programming skills on VB6 and knowledge of the Modbus protocol, a program was written that reads the registers from the PLC and writes them into a text file. I did not directly record into the database solely because of laziness and a couple of unsuccessful attempts to make VB6 friends with MySQL, and because of something else, I don’t remember. Because of this, I had to make a crutch, which has been working for the 4th year and does not break.
Read the data from a text file was entrusted to a script in PHP, which was run using nnCron to change the file recording time.
The database has been created tables of alarms, event names, their importance, etc. - all, as in adult systems. The reading script lays everything out to the database bit by bit and sends an SMS if the necessary event has worked.
Client part
The client part is an ordinary browser. Connect to the right address and see this picture:

The picture is drawn in TraceMode and is used as a background. Active elements are divs on top of the image. Information is updated every 15 seconds, which is even very often, because Start-stop of pumps occurs approximately once every 40 minutes.
Here we see that the two pumps are in automatic mode, the zeros next to the pumps is the current consumption. In the tank, the first level sensor worked.
Information comes to the browser via AJAX in the form of xml:
<shittank> <signals> <name>pump1_on</name> <datatimer>2012-10-04 16:09:05</datatimer> <name_signal></name_signal> <type>B</type> <alarm_text> 1 </alarm_text> <priority>1</priority> <data>0</data> </signals> <signals> <name>pump1_man</name> <datatimer>2012-10-04 16:09:05</datatimer> <name_signal></name_signal> <type>B</type> <alarm_text> 1 </alarm_text> <priority>0</priority> <data>0</data> </signals> … … </shittank>
In accordance with the data parameter of each signal, the style of the block changes, so it is colored in real time depending on the event. At the bottom there is a window in which events are displayed as text. In this screenshot, when you first start, all events are uploaded to correctly display the states of the aggregates, then only those signals that have been changed, which saves traffic, come.
When debugging the system, I ran into the problem of caching data by the browser, which I did not need at all. I solved the problem by adding a random value to the url:
var url = "update.php? =" + Math.random ();
The “no connection” signal is generated when there is no response from the PLC for 20 minutes. At the same time, SMS is sent to the servicing engineer. Communication may be absent due to "forgot to put money on the SIM card" and the lack of tension in the building of the CNS.
The “History” button opens the event history window.

The “Summary” button opens the pump start summary window.

During the operation, it turned out that no one was looking at the screen, so there was no need to draw all these beauties and implement the display a la real SCADA. All that the operator does is from time to time it opens the history of events and looks at the accidents, and at the end of the month enters the report on pump operating time.
Total:
The solution has been working without fail for the fourth year. The grandmother was fired, modern technology defeated old age.
In a similar way, you can organize control and management of home automation without the use of third-party software products.