How I carried out complex automation of the greenhouse economy: a subject area for IT managers

Experience in the implementation of IoT in the domestic agricultural sector. Routers, controllers, seedlings and greenhouses with Wi-Fi in an open field in southern Russia.

1.jpg

We had 2 MikroTik routers, 40 DS1820B temperature sensors, 5 ESP32-based controllers, half a column of rosin and a mountain of wires, heat shrinkage and all that, all colors, and also a Soviet soldering iron, a three-phase electric motor, a package of resistors of different denominations, packaging of Chinese smart sockets and two dozen 5 Amp solid state relays. Not that all this was needed on a trip, but since I started to deal with the Internet of Things, then go in your hobby to the end. The only thing that bothered me was the Arduino. There is no one in the world more helpless, irresponsible and immoral than a programmer who starts production on a similar solution. And I knew that pretty soon we were going to plunge into it.

2.jpg

Introduction to the course

Evergreen has launched a new florist delivery service to reach the growing segment of bouquets, flower shops and floristry centers. For 2 years the company occupied 60% of the regional market for wholesale supplies of flowers.

This is a bold attempt to reach out to small and medium-sized business players, launch sales at competitive prices, providing an assortment of international flower auctions and a European level of service.

The problem was that key business processes required a lot of manual labor. Disassembling and sorting one shipment of flowers took 12 hours of work for five people each week. In parallel, the construction of cultivation facilities - greenhouses and hydroponic "nurseries" for seedlings was underway.

3.jpg

My name is Christopher Robin and I am a broad spectrum IT professional with fifteen years of experience. It may sound a little odd or even loud, but this is the most honest description I could come up with. For 15 years in the IT field, I had to solve problems from reinstalling Windows to leading the development of a geographic information system for a federal project.

I had to set up a network in offices distributed in different cities, butt with foreign counterparties about the clauses of the agreement, make up the IT part of the budget for a year, prepare a corporate event and even organize a public event for 500 people in the VDNKh park.

I realized that the value of a team member lies in his or her usefulness to the team, and the benefit is a set of competencies that allows solving the problems of the team. My competencies allow me to solve a fairly wide range of tasks and they are far from always “IT”. Rather, they are always managerial, but with an IT background. The story with Evergreen is a prime example of the application of these competencies.

I was impressed by both the Evergreen project team and the industry itself. With what I just did not deal, but agriculture has not yet come across. I had to work with a dozen young guys who sell imported flowers in bulk, and even grow their own in greenhouses.

After several skype sessions, I already had an image of the problem and I had a rough idea of ??what I would have to deal with and what tools could be used to solve this or that issue. And, most importantly, professional excitement arose. That feeling when you understand that you can solve a task perfectly, do everything right as much as technology and industry standards allow. Moreover, I saw an opportunity to use cutting edge technology and create a brand new product in the segment. Both the task itself and the mood of the owner disposed to this.

With such optimistic thoughts, I checked into a flight at Vnukovo airport. In flight, I thought about all sorts of "killer features" using computer vision and convolutional neural networks to detect parasites on plants, predict the beginning of flowering, and, in general, automatic control of greenhouse nodes through machine learning based on data from sensors. As often happens, reality turned out to be harsher and more prosaic than my technical fantasies.

Prioritization

While I breathed, unusual after Moscow, the foothill wind and smiled at the bright southern Sun, the owner introduced me to the current state of affairs:

    Two months later, 20,000 units of seedlings arrive, they need to be grown to the size of the planting and transported to greenhouses. Grow in hydroponic racks. There are racks, but there are no hydroponics and no lamps either. In greenhouses, you need to organize control of environmental parameters, help the guys in the field with water supply and, in general, talk to a biotechnologist and do everything well.

    By March 8, the largest supply of imported flowers in 3 years arrives, without electronic registration we will not physically be able to process it, we need to come up with something.

Three completely different directions with a bunch of subtasks, different deadlines, subordination and intersection. And everything is relatively urgent. It took a couple of days to collect information and communicate with the team, the structure of the plan was outlined. It was important to understand what to do first, at what time you can switch to other tasks and what can be parallelized.


There was at least some clarity with the automation of accounting. The company had a working business process in Excel, employees formed orders, price lists and calculated cost and delivery. This process can be shifted to 1C.

Nothing is clear at all about the greenhouse and seedlings, and seedlings are expected in 2 months, so I decided first of all to start an active study of this direction. Together with the architect, they sketched a diagram of the hydroponic system on paper, decided on the key nodes and the architect built a 3D model and a drawing in Autocad. We calculated the cross-section of the pipes, the pump power and the drainage system.

4.jpg

Hydroponic racks. All components were found in hardware stores and the aquarium center.

The situation with lighting turned out to be much more complicated. Together with a biotechnologist for two weeks, we studied the formulas for calculating the spectrum, the crystal market and selected suitable suppliers. We brought in an expert lighting technician with experience in agriculture. We called all the major manufacturing companies and found LED modules based on Samsung crystals that are suitable in terms of spectral parameters. We calculated the current consumption and selected the right drivers.

5.jpg

Hydroponics is mounted and cassettes with seedlings are displayed in the racks.

A separate story is the delivery of cargo to the region (long and expensive). After a week of ordeals, we received our load, assembled a test bench and ... experienced a deep sense of disappointment and confusion. The LED color flickered like a strobe at a disco. For plants, this is not important, but for engineers it is a blow to pride, and it is simply impossible for a living person to be in a room with such a flicker.

After long conversations with the supplier, we found out that the problem is in cheap Bulgarian drivers, they do not pull out the maximum power. Issued a refund and took the proven Honeywell drivers at twice the price elsewhere. We lost two more weeks on this.

6.jpg

Driver and LED modules mounted in parallel-serial method.

With the new drivers, the booth shone with an even bright light, exactly what the biotechnologist expected.

The next big step was the assembly of the fixtures. The luminaire consists of an aluminum L-shaped profile, LED modules, driver and wiring. One profile contains nine LED modules, six lamps per shelf, two shelves in a rack, seven shelves in a room.
A total of 84 fixtures had to be assembled in 3 weeks. A branch of the Chinese province of Guangzhou was temporarily opened in the company's office emoticon_smile

We drew a diagram, cut out patterns. He taught the team to properly solder and isolate contacts. He organized the conveyor: one person cut the profiles and drilled holes, the second mounted the modules, soldered the contacts and made the wiring, and the third mounted the lamps on the shelves.
7.jpg

Installation of LED modules on aluminum profiles.

When the seedlings arrived, we were still collecting the lamps. The work was distributed so that the maximum number of seedlings could be put on supplementary lighting. So, for a while, the entire floor of the room was covered with greenery so that it received at least reflected light.

There is one problem with plants, they cannot be asked to wait. These are living organisms that are 100% dependent on environmental factors. And the longer they are in low light, the lower their potency and the higher the risk that they will get stressed and not grow by standards, which means a decrease in the final cost of the product.

Our delay was not critical, there were large windows in the room and the seedlings tolerated a week well in combined light, which cannot be said about us. It is extremely difficult to lug around four-meter profiles while stepping through the jungle on the floor. But no one said it would be easy. The main thing is seedlings under the light, you can go further. The first deadline has been overcome.

8.jpg

Seedlings under a ready-made lamp.

9.jpg

Another seedling under the same light.

Sales accounting automation

Now there is time to figure it out, taking into account the sales and preparations for March 8th. Of all the possible automation at the facility, there was only wi-fi and office computers. The first thing I did was to deal with the infrastructure. It was necessary to raise the connection between the office, the retail store and the field vehicle. To do this, I replaced the Tp-link home routers with more functional MikroTik. I changed the tariffs of the provider and connected white ip-addresses. This solution allowed me to set up an encrypted GRE + IPSEC channel between the store and the office. After combining the store and office, I created a guest wif-fi for clients and separated it from the corporate network. For the subsequent configuration of the workplace of the exit machine, I configured the L2TP + IPSEC VPN server.

The picture became more colorful, a network and a common reference point - the server - appeared.

The server was assembled from available hardware - I rebuilt some machines. Core i7 and 20GB of RAM are enough for 1C 8.3 with the "Trade Management" configuration. Within a couple of days, I set up and launched 1C on MSSQL, implemented the correct backup using SQL in three different ways at different intervals.

Together with the general manager and accountant, we described the business process, wrote the technical assignment for the 1C programmer and ordered the necessary processing for arranging orders by boxes, calculating the cost and printing price tags.

They collect a pre-order from customers, then the managers carry out the purchase at a Dutch auction, the flower arrives in large wholesale boxes. Each box contains packed lots - bunches. Each client orders only a few. The task of the receivers is to sort the bulk lot into order boxes for the end customer. They open a box of one sort and put bunches out of it into order boxes, then the next one, and so on until the entire delivery is unpacked.

The whole problem is in making a list of “to whom and how much”, each time manually drawing up the signs, printing them out - it's an awfully long time.

I screwed a barcode scanner to this beauty and launched it into production. From that moment on, a period of clarity began in the company. All purchases in the store were reflected in the general database and the office could see the current balances, the movement of boxes was reflected in the order, the price tag and the layout of the boxes for orders could be printed with one click. Before that, only one printing and posting of price tags took several hours, but now the girls just spanked barcode stickers on the boxes. The flower arrangement map by boxes was also simplified, there was no need to manually create a table for each order. I printed out all the orders at once and distributed them to the collectors.
For off-site sales from a car, I prepared a laptop with VPN access to the office and a 1C thin client.

The second deadline was closed ahead of schedule and even managed to test the solution before March 8.

10.jpg

Another room with a different type of seedlings and temperature conditions. Mixed light.

Field automation

The most interesting thing started in the greenhouse complex. This field is 50 km away from civilization, any light rain erodes the road for a couple of days. Each trip is an expedition in full gear with a backpack. The complex consists of two hundred-meter greenhouses and one fifty-meter greenhouse.

11.jpg

Let's go to the fields.

Arranged coverage of 300 m2 with Wi-Fi coverage with seamless roaming. The Internet in the field received through a flashing of the LTE modem and fixing TTL. The result is unlimited Internet twice as cheap as the previous provider's limit plan. Channel width 20 Mbps through a directional MIMO antenna. I scanned the nearest base stations, determined the best RSSI value and pointed the antenna to the best one.

This is a very fun task: a ten-meter mast, wind 15 m / s, a colleague turns the antenna, and I analyze the data with a laptop, both swing on the stairs like on a boat, my eyes are afraid - my hands do it. We calculated the correct position of the antenna, welded a metal post to the mast and mounted the antenna. Welding at height is a spectacular event, sparks of molten metal fly in all directions and turn into long glowing lines. As if at a concert at Rammstein.

12.jpg

Antenna and weather station installation.

Mobile providers have difficulties in allocating white IP addresses, so I set up the channel to the office using the on-site trade method, through the L2TP + IPSEC VPN client, only there was a router instead of a laptop. Now communication was at all points of the company, this greatly simplified all further maneuvers.

In my spare time, I did commercial intelligence. It turned out that in the region, and in the segment as a whole, the situation looks literally collective farm. Manual labor is everywhere, the maximum of automation is timer irrigation, and even then not everywhere. People just grow flowers the old fashioned way. This was the case in my case as well.

After several planning meetings with the field team, I identified two main areas of work: collecting data on environmental parameters for the biotechnologist and automating irrigation.

  • A biotechnologist needs to constantly monitor air temperature and humidity at three points in each greenhouse and outside. Based on this data, he calculates the number of drugs required for application, and also adjusts the schedule.
  • Workers in the greenhouse do the watering the most and the longest. They constantly run to switch hoses and turn on the pump. Obviously, the biotechnologist does not intend to stop at temperature sensors, and the number of greenhouses will continue to grow. The water supply system has not been fully approved, and the workers need to be helped now.

After analyzing the situation, I came to the conclusion that it is necessary to make a scalable system in which, upon request, you can add or remove any sensor and connect or disconnect any active unit.

I chose the classic botnet as a model for my architecture. The command server (C&C) with the admin panel generates tasks for bots, only I have microcontrollers instead of bots, and a sensor node as a command server. Controllers send data to the sensor node and receive daily tasks from it.

Configuration selection for an IoT solution

The time has come for the selection of electronic components. Conducted a comprehensive market research, ordered and touched a dozen available devices. The Raspberry Pi microcomputer and ESP8266 / ESP32 microcontrollers reached the final.

Arduino boards proved to be a purely niche solution, due to the limited capabilities of hardware, the lack of built-in wi-fi and memory for recording data. It is difficult to build something relatively flexible on them, but it is quite possible to use it to solve local problems.

13.jpg

ESP8266 board.

  • I liked ESP at first sight. A beautiful and compact piece of iron. The number of output pins is the same as in the Raspberry Pi, there is a built-in wi-fi. Found a Lua firmware for her. I soldered the first device and wrote the lua code. It turned out that the Lua implementation was damp and too cumbersome, it did not have enough memory and the system constantly crashed and behaved unpredictably. The path turned out to be a dead end - Lua was fired.
  • Next, I tried to write code in the Arduino IDE in his native language wiring. A lot of scribbling, hard syntax, impossible to implement multithreading, unpleasant language. Wiring was fired too.
  • Finally, I found a python implementation for ESP controllers, and two types at once. Proprietary Zerynth and open source micropython. As a sample of the Zerynth platform, I wrote code to collect data on wind parameters: strength and speed. The big plus of this platform is the excellent IDE, however, Zerynth did not find a normal way to implement the task scheduler, and this functionality is critical for my architecture. In addition, the platform was paid and each controller was flashed and cost money. As a result, Zerynth was fired as well.
  • Now it's micropython's turn. Everything turned out to be fine in it, except for the normal IDE, but this is not critical for the architecture and system performance, so I wrote all the main code for the esp8266 and esp32 microcontrollers on it.

14.jpg

The process of installing a garland of temperature sensors DS1820B.

The Raspberry Pi was perfect as a touch node. For it, you can write code in python, under the hood, a cron scheduler and, in general, the entire arsenal of a full-fledged Linux system. This is all redundant for retrieving data from sensors, and the size is too large, but it fits perfectly as a local server.

Plunging deeper and deeper into the jungle of the iot industry, I decomposed all the technologies on the shelves and deployed the following stack on the Raspberry Pi: grafana, telegraf, mqtt, influxdb.

Communication between the controllers and the node is carried out using the MQTT protocol and is processed by the MQTT server. Data collection goes through the telegraf module and is stored in the InfluxDB DBMS. Grafana is in charge of all the beauty: it provides real-time visualization of charts. I also wrote several command scripts to manually manage the controllers, since the admin panel did not exist yet.

15.jpg

Dashboard on Grafana

Never forget about backing up your data. Especially when the system is far away in the field. For this, I developed a sd card hot backup system on the Raspberry Pi.

The fact is that an external hard drive is connected to the RPI, on which the database files are physically stored. Such a solution is necessary for optimal use of the SD card resource, otherwise the data flow from the controllers will simply kill it with constant write operations. This hard disk is full of free space and it is convenient to add images of the sd card to it weekly.

If an accident suddenly occurs and the card dies, then the worker on the spot will take out a spare blank card, write down the last working image there, insert it into the RPI and it will work.

While I was constructing the correct system on my microcontrollers, I deployed a solution from the Chinese company Sonoff in greenhouses. These are four-port controllers with a mobile app. They are rather dumb in capabilities, but thanks to the mobile application and the cloud platform, they have established themselves as a convenient prototyping tool. All workers installed the application and I gave access to pumps and switches. When ready, I just replaced sonoff with esp.

16.jpg

Connecting a motorized crane to the Sonoff unit.

As a transitional solution, I wrote scripts for integrating the sensor node and sonoff through the API. Thus, it became possible to create a system for autofilling a container with water. Sonoff turned on the pump, and the sensor node gave the command to turn it on, relying on the water level sensor, the data from which was sent to the node by my ESP controller.17.jpg

Sonoff hack with solid state relay.

In general, a close integration came out with Sonoff, their relays are electromagnetic and weak, you will not let a large load through them - they will fuse. I had to hack it a little and solder it in parallel with the standard relay - solid-state 20 Ampere.

The task with the level of liquid in the container gave me a lot of vivid emotions. I had to assemble an intermediate portable prototype in order to climb with it onto a three-meter five-cubic capacity and make control measurements of the water level with a full tank, with an empty tank and fix the level at which auto-priming was to be turned on. Felt like a ghost hunter with such a gravity in his hands.

18.jpg

Ultrasonic Rangefinder HC-SR04, LED Display, Arduino, Power Bank. Shows the current distance in centimeters on the display every half a second.

In the meantime, the seedlings have grown and preparations have begun for planting in the greenhouse. I connected all pumps and solenoid valves to the system and gave access to workers on smartphones. They were happy because they stopped running all the way to the switch and could control all the pumps and switch the direction of the water from anywhere in the greenhouse complex.

The biotechnologist received monitoring of environmental parameters in real time from a smartphone in a user-friendly interface.

I managed to implement a system architecture in which you can quickly add new devices, reconfigure units on the fly and combine devices from different manufacturers.

Thanks to automated order processing, the managers in the office freed up time to teach students how to sort the flower. Hiring hired employees to analyze supplies is an important stage in the development of the company, it was constantly postponed because there was not physically enough time for training.

My opinion on the industry

The flower business, as a private phenomenon in the agricultural sector, remains one of the most technically backward in Russia. I believe that this state of affairs is due to both the managerial will of the owners and the lack of personnel and insufficient popularization of the industry among young professionals.

I would like to believe that my work laid the foundation for the automation of the flower industry in the southern regions.

19.jpg

These are Evergreen greenhouses

Conclusions
  • If you have an intelligent engineer, it doesn't matter what problem to solve.
  • No matter how intelligent the engineer and the manager are, the two of them won't do much - you need a team.
  • If you look at the problem for a long time, it will reveal itself.
  • There are no good or bad solutions - there are solutions that work and that don't.
  • If there is a sensible manager, he will always find an intelligent engineer.