{'fraction_non_alphanumeric': 0.024342710056995773, 'fraction_numerical': 0.007041735613164185, 'mean_word_length': 5.093546941519158, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Complex Event Processing Methods for Greenhouse Control

In the greenhouse environment, the application of complex event processing (CEP) technology can effectively tackle the problem of recognition of the complex patterns that appeared in greenhouse conditions. In the existing research, few scholars have proposed a scheme to integrate complicated scenes within the greenhouse environment with high efficiency, convenience, and low coupling. Therefore, in order to solve the problem of hard recognition and fusion of complex patterns in the greenhouse environment, based on the characteristics of the greenhouse, this paper proposes a complex event processing method for greenhouse control. Our method has high applicability and high expansibility, including 13 types of event processing agents and 21 types of typical events involved in greenhouse automatic control. This method has the advantages of low information coupling and multi-domain integration, which can be directly used by agricultural experts and related workers and is of great significance to promote the extensive application of CEP technology in the greenhouse field. Our experiment successfully realized a greenhouse intelligent control system based on CEP technology is successfully realized in our experiment. The experimental statistics shows that the structure of the control system was accessible and effective.


Introduction
With the development of smart agriculture, a new generation of sensor technology has been further integrated with agricultural production [1]. Consumers in urban cities have an increasing demand for fresh vegetables [2]. As a result, the greenhouse, serving as production equipment, is playing an increasingly momentous role in modern agriculture. There are many influencing factors in the greenhouse environment, which makes the greenhouse have the characteristics of nonlinearity, strong coupling, large inertia, and multi-disturbance [3]. In addition, the greenhouse environment and crops will change with the seasons and the market, with uncertainty, so many control parameters in the greenhouse still need to be dynamically identified [3]. Therefore, it is necessary to collect and summarize knowledge from the agricultural field and combine the agricultural expert system with the greenhouse automatic control technology to realize automatic reasoning and determine the control parameters and control strategies suitable for crop growth [3] in order to further realize the intelligent automatic control of greenhouses.
To facilitate the process from decision-making to control, it is necessary to use computers to describe greenhouse scenes [4]. A greenhouse is a typical complex system [3] with a variety of data types. It is difficult to describe complex scenes in a greenhouse using the traditional threshold control method with a single parameter expression. Only multiparameter fusion expressions of multi-parameter fusion can meet the needs of planting personnel [5]. For example, the opening and closing of the skylight, air conditioner, and wet curtain need to be considered in the regulation of temperature. These controllers will also affect other factors such as carbon dioxide, humidity, and light in the greenhouse, and then the temperature, humidity, and light outside the greenhouse also need to be considered. To realize the adjustment of complex greenhouse scenes, a reasonable approach is to separate the execution of scene detection from the response decision algorithm [6]. Therefore, we know whether the expected complex scene in the greenhouse has occurred before the response decision, and then drive the response decision and execution. When describing the above scenario, it is very necessary to find composite data with numerical, temporal, and logical significance in the data stream obtained by the sensor.
In traditional multi-variable control systems, since the weak connection between variables is often ignored, the use of multiple subsystems for separate control [7] will lead to obvious control oscillation and other problems. Multivariable control systems based on fuzzy control [8] and neural networks [9] often attempt to calculate multiple types of variables to calculate at the same time, resulting in difficulties in maintenance and modification and poor interpretability. Traditional multivariable control system based on production rules [10,11] realizes greenhouse control by explicitly defining control rules, which has the advantage of strong interpretability [11], but it is difficult to design and modify rules due to the common coupling between rules [12]. Rules will also become very complex due to the necessity of expressing complex scenarios through simple logic such as production and or not. For example, when the external sensor detects an increase and subsequent decrease in air temperature, a steep decrease and subsequent increase in air pressure, and a sharp increase in humidity, a hailstorm is expected [13], and the greenhouse skylight needs to be closed. If the production rule is used to judge whether this scene occurs, it is necessary to determine whether the values of multiple sensors show these directional change characteristics at the same time, calculate the times when the values of each sensor begin to change, and judge the sequence of these times to know whether the complex scene occurs. An event-based rule system uses formal language to standardize the relationship between events, has a strong ideographic ability [14], and can greatly simplify the expression of rule logic [15]. It is also effective at analyzing the complex scene of photosensitive sensors mentioned above. An event-based rule system can judge whether the value of each sensor has the characteristics of directional change asynchronously and in real-time, resulting in events such as "rapid rise in external humidity". The tracking of the above scenarios can then be completed through an event filtering rule similar to "((outside temperature rises) before (outside temperature drops)) and ((outside air pressure rises rapidly) after (outside air pressure drops rapidly)) and (outside humidity rises rapidly)". An event processing system using the event itself as the carrier for information transmission also has the characteristics of high cohesion and low coupling, which makes most modules reach the low coupling degree of stamp coupling [12], and produces defined rules that are easier to modify and improve.
The occurrence of an event corresponds to the change of some states of the physical world [6]. Whether an event occurs can be judged through data flow filtering, timing analysis, and logic analysis. To monitor complex scenes, a feasible method is to regard the emergence of complex scenes in a greenhouse as the occurrence of an event, record the data flow characteristics of the scene according to expert experience, detect the event in the existing data flow, and then guide greenhouse control. However, the conditions for the occurrence of the above events are very complicated. It is difficult to detect their occurrence directly through the original data stream. It can be assessed only by further testing the timing and logic relationships between a series of simple events. This method of detecting complex events through simple event groups is called event aggregation. As an efficient event stream processing technology, complex event processing technology can effectively realize the monitoring and aggregation of complex events.
Complex event processing (CEP) is an active data processing technology born in the field of databases [16]. It regards a change in a single data state as an atomic events and the emergence of complex scenarios as the occurrence of complex events. It detects the occurrence of complex events by matching the occurrence of a large number of atomic events with predetermined complex event patterns and logical calculations, which trigger further actions [17]. CEP technology can make full use of information from different approaches to make decisions on a particular situation. It offers strong asynchronous decoupling and situation analysis ability and is an important means to realize real-time processing and automation. Therefore, it is an important method that can solve the problem of multi-temporal event flow processing [18]. It has been widely used in internet of things scenarios such as industrial production lines [19], smart homes [20], intelligent logistics [21]. However, so far, the research on agricultural-oriented CEP has remained at the basic application of the Internet of Things and the expansion of theoretical operators. It has not yet formed a complete and versatile method for constructing a CEP system. This paper applies CEP to intelligent control in the greenhouse environment and builds an intelligent system for greenhouse control. This paper takes the intelligent control of the greenhouse as the core of the research, analyzes the information generation role and transmission characteristics, and encapsulates the main information in the greenhouse environment. A theoretical scheme of greenhouse CEP system with high applicability and high expansibility has been obtained to solve the key difficulties in the application of CEP theory in the greenhouse.
The main contributions of this work are as follows: 1. This article innovatively applies CEP technology to the intelligent control of agricultural greenhouses. By analyzing the commonalities and differences of many agricultural issues, we propose an effective, greenhouse-oriented complex event processing system structure. It is of great significance to promote the extensive application of CEP technology in the greenhouse field; 2.
We have improved the automata algorithm for event aggregation, which allows CEP technology to be used more flexibly in complex greenhouse scenarios. Our algorithm includes 13 types of event processing agent types, 21 types of typical events involved in greenhouse automatic control, which can correspond to the seven most common specific agricultural problems; 3.
This work incorporates knowledge in related greenhouse research fields such as greenhouse planting schemes. It gives full play to the advantages of various control methods to deal with the different control characteristics that need to be solved in the greenhouse environment.

Related Work
Since the 1940s, FW Went presided over the construction of the world's first plant artificial climate chamber, which brought a revolutionary change to the field of facility agriculture. In the early period, greenhouse control algorithms often simply used threshold control based on farming experience [22]. In the traditional threshold control system, due to the large coupling of various factors in the greenhouse environment, the regulation of a single environmental factor often affects other factors in the same closed space. For example, to reduce the temperature, the optional control strategy is to open the sunshade, but this measure will correspondingly reduce the number of lights [23]. Limited by the weak representation ability of the threshold control method, it is difficult to manage complex scenes and the interaction between multiple environmental factors. Therefore, an algorithm with stronger regulation ability is essential.
Over the years, the regulation methods to multiple environmental factors in complex scenes are basically divided into two kinds: the control strategy based on the physical model and the intelligent control algorithm based on experience and data [24]. The essence of using the physical method is to establish a physical model of a greenhouse through mechanism analysis and use a multivariate decoupling method to achieve control [25]. More specifically, control strategies include robust controls proposed by Linker [26] and Bennis [27], nonlinear controls used by Pasgianos [28] and Wu Xiuhua [29], adaptive controls used by Cunha [30], Guzman [31], Ahmed [32], etc., and model prediction control, etc. used by Camacho [33], Ramirez [34], Berenguer [35], etc. However, the greenhouse is a complicated system that has nonlinear multi-inputs and multi-outputs [36]. Factors near the greenhouse will affect the physical and chemical properties of its internal environment. Additionally, some of these factors are difficult to accurately measure or model. Besides, different physical parameters in the greenhouse will also fluctuate due to the aging of the equipment, resulting in deviations between the parameters calculated by the decoupling control and the actual ones [37]. Therefore, it is hard to establish a long-term effective physical model suitable for a greenhouse environment. All in all, for the traditional linear parameter model, even if it performs well in a specific greenhouse, it is difficult to apply effectively in a wide range of greenhouses [38].
The greenhouse intelligent control algorithm based on experience and data combines the analysis of historical data and the experience of expert planting. It mainly includes control algorithms based on fuzzy logic and control algorithms based on machine learning. This algorithm is not limited to the complete physical model of a specific greenhouse when it is defined.
The fuzzy logic control algorithm was first proposed by Zadehd et al. [39]. This algorithm solves the problem of uncertain reasoning in the control system by transforming the expert construction language information into control strategies [40]. However, when applied to the time-varying nonlinear system of the greenhouse, the fuzzy control algorithm must define very clear control rules in advance in order to achieve a good control effect [41]. As the controlled process of a nonlinear system has the disadvantages of nonlinearity, high order, and time variability, it is therefore intractable to use the existing control theory and analysis methods to design a fuzzy control system [42].
Machine learning [43] is a type of algorithm based on statistical theory that can directly learn relevant laws from data and is usually used in regression and pattern recognition [44]. In recent years, machine learning algorithms have also achieved good results in greenhouse control. Whether directly using artificial neural networks [9] or combining it with PID control technology [45], WDNN technology [46], machine learning methods have achieved amazing achievements in the field of temperature, disease, and pest control in greenhouses [47]. However, it needs to collect a large amount of data in the same scene for training, and the output results are not scientifically interpretable. Therefore, it is difficult to maintain satisfactory results when directly migrating to a similar greenhouse scene.
CEP techniques were first emerged from the active database domain [48]. It can properly describe the connection between the monitored event and the execution command, so as to more accurately locate the conditions under which a specific response action occurs [49]. With the development of active databases, researchers have gradually realized that the logical relationships between events are not only limited to simple "and", "or", and "not", but also intricate as temporal relationships. In 1992, Gatziu S. etc. proposed the SAMOS Active Database System [50], and operators related to timing logic [51]. In 2008, D. Gyllstrom et al. proposed the SASE+ improvement system and applied the green closure operator for repeated events [52]. In the same year, Magid Y. et al. also strictly defined a series of operators, applying scenario description methods to complex event models [53]. With the vigorous development of computer technology and the exponential growth of data, event detection methods emerged one after another [18]. Among them, CEP technology based on rule description stands out because of its excellent multi-data processing function [54]. It has achieved remarkable success in many fields such as industry [55] and commerce [56]. In current practice, CEP technologies often use graph structure model [57], automata model [58], matching tree [59], Petri net [60], event pattern language [61], and other methods for event pattern matching. An automatic machine to realize event pattern recognition is the most representative and excellent way to realize a high-performance CEP system [3].
In the agricultural field, Bertha et al. [62] proposed the application of complex event processing engines to build peripheral systems. Li et al. [63] conducted a detailed analysis of the spatiotemporal event model in farmland. Deng et al. [64] also made relevant attempts for the use of non-CEP structured time automata in the greenhouse environment. Li et al. [14] propose a space-time event model for the processing of complex events of the farmland Internet of Things and extends the logical relationship of complex events to the definition of spatial topology relationship. Nie Juan et al. [5] proposed a new type of CEP engine called PUCEP, which can calculate the probability of complex events. It improves the real-time performance of the system by improving the matching efficiency of uncertain complex events, reducing computing time and resource consumption. Mazon et al. [62] proposed the RE-CEP structure for precision agriculture and applied it to the intelligent irrigation system of the banana test area in Macara, Ecuador, which confirmed the feasibility of CEP technology in agricultural production. However, the above-mentioned research mainly revolves around the model design and feasibility analysis of complex event processing technology. Research on the overall control of greenhouses is scarce.

Overall Introduction
To realize intelligent greenhouse control, the CEP system needs to regard the fluctuation of different types of data in the greenhouse as the most basic atomic events at first. Additionally, it should continuously match and calculate to generate more complex events by analyzing the logical relationship between basic events. Some of the complex events contain the control commands and complex scene information needed in the greenhouse environment. The goal of our design is to provide a CEP system with simple data analysis capabilities and a complex event processing system framework that can yield control instructions based on expert commands or automatic control schemes. The core work is to design and implement a complex event processing engine. Figure 1 shows the connection between the system and other objects in the greenhouse. These objects are sensors, feedback units, experts and other analysis systems, control strategies, and actuators in addition to the CEP system and greenhouse. Among them, different functional sensors include air humidity sensors, soil sensors, etc. The feedback unit and actuator can work on Internet of Things software platforms such as Fiware and ZigBee network facilities to transmit the data of sensors and controllers. Other analysis systems could be PhenoArch or other phenotype analysis platforms, which can generate meticulous and ample data information. The control strategy could be a simple switching operation or a more complex timing control mechanism. When a control strategy needs to be executed, the state of the controllers could be modified according to the preset instructions. In detail, the sensors are responsible for collecting the physical and chemical information in the greenhouse and transmitting the original data to the feedback unit, agricultural experts, and other analysis systems to achieve preliminary processing. The feedback unit packs environmental data into events (atomic events) and transmits them to the CEP system. Agricultural experts and other analysis systems conduct preliminary analysis based on actual conditions. The feedback unit, agricultural experts, and other analysis systems package the analysis results into events and send them to the CEP system. When the CEP system receives this data and the event containing equipment status information fed back by the actuator, it will be transmitted to different processing modules (event processing agent, EPA) in the CEP engine through the event distribution middleware. EPA will analyze the input events in time sequence and logic according to the predetermined CEP rule set, so as to get high-density complex scene information. The identified complex scenes can eventually be fed back to agricultural experts and other analysis systems and mapped to the corresponding control strategies. In this way, the closed-loop control of the greenhouse is realized by the whole system.
For the convenience of description, according to the functions of the above objects, they are divided into four major information objects: CEP system (left, dark gray), controller (above, red), worker (middle, blue), and environment (below, green). In the CEP system, all input and output information will be packaged into events and delivered through event distribution middleware. The CEP engine runs according to the designed CEP rule set, including filtering, aggregating, and generating events. Nowadays, middleware technology represented by Kafka [65] has matured, so this article focuses on the layout of CEP rules to provide reliable assistance for agricultural workers to use CEP technology in greenhouses.
As mentioned above, to build a CEP rule set, we need to stipulate the category of events, define atomic events, complex events, and the specific input and output of each type of EPA that can realize the event aggregation function, and finally constitute a complete event aggregation structure. This can reduce the repetition and incidental loss of intermediate information, thereby achieving information decoupling and determining whether complex scenes occur, and scheduling control strategies.
The following will present the general structure of the greenhouse-oriented CEP engine, the structural definition of various events, and the functional definition of EPA. It provides a general implementation of the greenhouse-oriented CEP system for agricultural experts and related workers. Subsequent experiments will be based on this structure for concrete function realization and feasibility verification.

Complex Event Processing Logical Relationships
In the process of judging complex scenes, it is necessary to analyze the logical relationship in time and space between low-level simple events to determine whether high-level complex events have occurred. Then, the complex event flow is synthesized by calculating the relevant information of the high-level events. The process of simple event flow evolving into complex event flow is called event aggregation. The logic between events that has been set is called event mode. The unit that performs matching and event generation based on event patterns is called an event processing agent (EPA). Through layer-by-layer aggregation, complex events are finally generated. These events can trigger control commands, get more valuable judgment information, and complete the reasoning process.
This article proposes 13 types of EPA and 21 types of typical events involved in greenhouse automatic control. The aggregation relationship between EPA and events is shown in Figure 2. The circular nodes in the figure represent events. The color of the nodes represents the information source and destination of the event (as shown in Figure 1 in the above section). Gray nodes represent the output of the event by the system. The square nodes correspond to the classes of EPA of the CEP engine, which can aggregate the input events to obtain the output events. In particular, the dashed arrows in the figure represent that one EPA module directly modifies the parameters of another EPA module. Each EPA module can be built using the existing CEP technology or can be replaced with any event processing module with the same type of event input and output (e.g., using machine learning for event classification filtering [66]). This makes the CEP system have the characteristics of multi-field and multi-technology integration. Each event flow from the beginning to the end corresponds to a specific farming problem. The system needs to use the existing coping strategies to build an event processing unit, analyze the current situation according to the event sequence, and transmit the analysis results to other units. The specific agricultural problems contained in the system are as follows: In terms of environment, it is necessary to observe the changing trend of the greenhouse during the regulation (EPA2), find the most favorable greenhouse environment state for crop growth according to the crop planting plan (EPA5, EPA6, EPA3), and consider the mutual influence relationship existing in the greenhouse refinement regulation target (EPA7). The search for the most favorable greenhouse environment can be further refined into looking for the impact of the environment on crop growth (EPA5), the determination of crop growth status and the adjustment of control targets (EPA6), and the combination of control targets to judge the current state of the greenhouse (EPA3).
In terms of control, the system needs to monitor whether the connection and operation of the controller are normal (EPA8), consider the impact of the environment on the controller effect (EPA1, EPA4), how to dispatch the controller and generate early warning information (EPA9, EPA10, EPA11, EPA12), and whether the instruction execution is smooth (EPA13).
For the convenience of description, we have given the name of the EPA that solves the corresponding agricultural issues in parentheses. In the following, we will introduce the corresponding types and definitions of each event and the implementation methods and specific functions of each EPA one by one. In the experiment, we will build an example of the CEP system based on common solutions to agricultural problems.

The Event Definition
In this paper, the state change of the complex system is called "event". To make the structure shown in Figure 2 work smoothly, it is necessary to strictly define the type and basic structure of events transmitted between each EPA module and system input and output.
Backus Naur Form (BNF) paradigm is a formal syntax representation method, which is often used to describe program syntax [67] and data structure [68]. This paper will use the following extended BNF paradigm to define the structure of events: • <> Angle brackets are used to separate strings that are the names of grammatical elements. If a triple with "e.g.," as the second element appears in the angle brackets, the triple is a type of terminal symbol with a specific meaning. The first element is the category name of this type of terminal symbol, and the third element is some examples of this type of terminal symbol; • ::= The operator used for definition. Represents that the syntax element on the left can be replaced by the string appearing on the right; The elements in square brackets can appear 0 or 1 times; • / The vertical line indicates that the element on the left can be replaced by the element on the right.
JSON is a lightweight data exchange format. It can describe the basic structure of data through key-value pairs [69]. This article will wrap a specific data structure with a pair of braces. Each data structure is composed of multiple key-value pairs similar to "key: value", separated by commas.
The following will use the BNF paradigm to specify the specific structure of the above events in the form of JSON string and list some specific examples of all terminations.
Most events have a unique number, type, name, timestamp, and other basic event information. Some special events may also have location and source information. Therefore, to simplify the subsequent expression, first define the basic event structure (BES) syntax as follows. (1) For most of the information content types of the control system, there are three main categories, namely numeric class, state class, and information class. They appear in a single numeric, enumeration, and string type. The event wrapping of these three types of information is relatively simple, just add the necessary information content to the underlying event structure. The structure is as follows: (2) For some special information, we need to tailor it to: • Environmental trends, which mainly reflect environmental changes, are usually obtained by differential or forecasting of environmental information and need to indicate the start and end times, the specific structure of which is as follows: (3) • Control method, which simply distinguishes the type of method called by name, as follows: (4) • System configuration information, which includes executable commands and some descriptions, as follows: For greenhouse scenes, the event is divided into three levels.

1.
Input information (the simplest atomic event). This information originates from other information objects and acts on the control system and is the basis for the calculation of control system reasoning, as shown in Table 1.

2.
Intermediate information (intermediate-level complex events). This message is not directly related to the input and output of the control system, but is used as a carrier of reasoning results in the control system, as shown in Table 2.

3.
Output information (highest level complex events). This information originates from the control system, acts on other information objects, determines the control action of the controller, and makes it easy for workers to know about the green-house, which is an important part of the realization of automatic control, as shown in Table 3.

EPA Definition
This article uses automata technology to build EPA and uses transitions between states to identify the content of events and their relationships. When entering a new state, complete the corresponding instructions, modify local variables, and achieve event aggregation. There are three types of transition (or jump) between states, which are triggered by specific events, timers, and boundary conditions.
Transitions triggered by specific events can check the causal dependence between events, and whether data parameters and contextual relationships are in line with expectations. Its transitional rules include three parts: pre-transition state, post-transition state, and Boolean expression. Its Boolean expression can contain two types of parameters: the type of the received event and its parameters, and the local variables in the EPA. Event parameters include information such as the source of the event, the event ID, and timestamp. When a new event is received, the EPA will determine whether the pre-transition state in the jump rule triggered by the specific event is consistent with the current state. If it matches and the Boolean expression in the rule is true, it will transition to the post-transition state. Otherwise, no operation is performed. For all transitional rules with the same pre-transition state, their Boolean expressions are mutually exclusive and should not be established at the same time.
Transitions triggered by the timer can check whether the time relationship between events is in line with expectations. The transitional rules include three parts: pre-transition state, post-transition state, and elapsed time. Among them, the elapsed time is the length of time elapsed after entering the pre-transition state. When the EPA is in a certain state, it will determine whether the pre-transition state in the transitional rule triggered by all the timers is consistent with the current state and if they match, the timer will be established according to the elapsed time. When the timer expires, the EPA will transition to the specified post-jump state. If the EPA has made a state transition before the timing is over, all current timers will be closed and no longer executed. For any state, if there are transitional rules triggered by multiple timers, the transitional rules will never be executed. Therefore, in a specific implementation, the pre-transition state of the transitional rule triggered by all timers in any EPA is different.
Transitions triggered by boundary conditions are mainly used in the EPA at the bottom of the system, and specific atomic events can be identified from the input of the system. The transitions triggered by the boundary condition will continuously check whether the input value meets the expected condition. The transitional rule includes three parts: pre-transition state, post-transition state, and the boundary condition. Among them, the boundary condition is a Boolean expression containing two types of variables, local variables, and input values in EPA. When the input values are updated, it will check whether the boundary condition is established. If it is established, the corresponding transition will be performed.
When the EPA transitions to the next state, a collection of actions required to be performed within the state is executed once. Among them, the action contains three kinds of modification of local variables, generating new events, and executing specific instructions using the event information just received.
As shown in Figure 3, an intermediate layer EPA triggers a jump without a boundary condition. The EPA has three states (State), T, L, and N, and when it enters the T state, a Cdt event is generated, with parameters Fan and RISE, the L state is the same, and the N state has no action to perform. The EPA has no arguments and there are two jump Boolean expressions. Wherein, the t-jump Boolean expression is used to determine whether the received event is an Eft type, the first argument is tem and the second argument is Inward condition, l jump takes 5 s, and if the EPA is in the N or T state for 5 s, it jumps to the L state. For example, when the EPA is in state N and receives an Eft(tem, Inward) event, the EPA will check whether t is established. As the result is that t is established, the EPA jumps to the T state and generates a Cdt(Fan, RISE) event. Since there is a time jump l in the T state, a timer with a duration of 5 sec is established. When the timer expires after 5 s, the EPA will automatically jump from the T state to the L state and generate a Cdt(Fan, DECLINE) event. The subsequent process is the same.
As shown in Figure 4, it is an example of a bottom EPA with boundary conditions triggering a jump. It has four states, two parameters, two jump Boolean expressions, and two boundary conditions. The ra jump, ua jump, and all state actions are similar to the middle layer EPA and will not be explained here. The EPA has two parameters from outside input. It will continuously observe the changes of these two parameters at a certain frequency. When the relationship between the two parameters matches the up or dn jump Boolean expression, the jump will be executed. For example, when EPA is in state U, tem is 10.0, and tem_0 is 15.0, the external temperature sensor inputs a value, and tem_0 is updated to 5.0, and EPA will check whether the dn boundary condition is established. Obviously, tem_0 < tem is established at this time, so the EPA state will jump to D, and then an Eft (tem, Inward) event will be generated.
The transceiver unit for event transmission between EPAs can form a network of multiple EPAs to communicate with each other. Each EPA will respond to input events and pass the output events to other EPAs. This type of structure constitutes an EPA communication network called the event processing network (EPN). It is the key to the aggregation of complex events.
This chapter uses Kafka middleware with a publishing subscription pattern to deliver and receive events between EPA. For each type of event in the system, a message queue with the event name as the theme is established to hold all generated events of that type in the build order. When an EPA needs to send a specific type of event, it needs to find the message queue for the topic based on the event type and publish the event to this message queue. When the EPA needs to get a specific type of event, it subscribes to the message queue for the topic based on the event type and reads from the specified location in order, and then waits for the next event to enter the queue. When the system first starts, the message queue is emptied and all subscriptions are read from the header of the message queue.
The typical EPA for greenhouses is shown in Tables 4 and 5. Record the current environmental event and the last environmental event processed, calculate the change value of the environmental factor and the time difference between the two events, and obtain the historical or future environmental factor change speed (change trend)

EPA3
Gets the difference between the state of the environment and setting goals Obtain the current physical and chemical characteristics of the environment through environmental information events (Ari/Lgi/Soi), then compare it to the established adjustment target, and package the comparison result into an Est event and send it out Table 4. Cont.

EPA4
Predict the effect of a certain control operation According to EPA1's calculation results of environmental factors that affect the effect of the controller, the environmental impact and work efficiency of the controller during operation are estimated, and the control direction event (Cdt) transmission analysis result is generated EPA5 Get the current crop growth stage according to the initial planting plan and current environmental conditions According to the established planting plan, the time that has passed since entering the current stage and the changes in the environment, judge whether the crop enters the next growth cycle and whether there is disease

EPA6
Set the corresponding environmental goals through the crop growth phase Obtain the information of the current growth stage of the plant according to the content of the plant state event, and then adjust the parameters in EPA3 according to the stage to achieve the purpose of setting the environmental regulation target suitable for the current growth stage of the crop EPA7 Estimate the amount of adjustment that each factor in the greenhouse needs to be adjusted for Through the status (Est), changing trend (Etd) of each factor that needs to be adjusted in the greenhouse, and the mutual influence relationship between environmental factors, the adjustment target is revised, and the environmental demand event (End) is sent to transmit the analysis result Table 5. EPA function Table 2.

EPA8
Provide the worker with a controller connection status According to the controller connection event (Cni) received by the system, an instrument error information event (Cdt) is generated to transmit the analysis result

EPA9
Provide the controller information needed to select the method, and judge whether a method can run normally Filter the controller connection status and control direction information required by a method, and determine whether there are mutually exclusive methods running to determine whether a method is running well and can be performed smoothly

EPA10
Collect the environmental information required for the method and estimate whether the method is suitable for the current environmental conditions Using the adjustment target event of the current environment, combined with the regulatory characteristics of the complete execution of the method, a series of parameters are obtained to judge the suitability of the method execution EPA11 Score the best for each control method By Clt and Elt events, determine which methods are suitable for running in the current environment, and consider the situation where the method cannot be executed at the same time and the worker participates in the regulation, give the serial number of the governance method that needs to be executed at present, and pass the method number to be called through the Cmt event.
Method numbers are used to distinguish between different governance methods, and their values are defined in EPA12

EPA12
Perform specific control methods Each contains a governance method that, by receiving control method events, determines whether it needs to start and stop the execution, generates a series of control instructions(Cnd) and environmental alert information (Ewi) when executing, and fine-tunes the control policy by controlling the information returned (Cet)

EPA13
Receive the control request of the method, send the execution command to the control element, and ensure the correct execution of the command Used to check the execution of a controller's control instruction, by generating an Aci event governance controller, listening to the Csi event to determine whether the instruction was executed successfully, and then feeding back the information of the success of the execution to EPA12 in the form of a Cet event, informing the worker that there is a problem with the control in the form of a Cei event when execution fails

Case Study
Nowadays, lettuce is the main representative of Commercial Vegetables in cities [2], also as a typical crop in North China Plain, central and Western China [70]. Therefore, lettuce was chosen as the planting crop in the experiment. The experiment includes the comparison of planting schemes, the construction of the structure, and the realization of an entire greenhouse control process through CEP. We collected and studied crop planting articles and web pages written by Shi, Sun, etc. [71][72][73][74][75]. We have formulated a comprehensive planting plan for Italian lettuce. The planting plan covers various greenhouse tuning indicators, which can achieve the goal of large crop yield and high quality. Some scenarios are shown in Table 6. Below, through the definition of 13 types of EPA, the temperature-related control of the greenhouse is realized. EPA1 ( Figure 4)-Take the fan control effect to calculate the internal and external temperature difference as an example: there are two types of internal and external temperature differences, which are internal low and external high, and internal high and external low. The exhaust fan is also divided into two modes: access system and disconnection. It needs to jump to generate exhaust fan control events through connection change events and temperature difference information.
EPA2 ( Figure 5)-Taking temperature as an example, there are three types of fluctuation trends in the actual scene: rising, falling, and steady. Three types of boundary conditions are defined here: the difference between the predicted value and the true value is greater than the threshold, the difference between the true value and the predicted value is equal to the threshold, and the absolute value of the difference between the predicted value and the true value is less than the threshold. EPA3 ( Figure 6)-For most crops, for example, there are two states of optimal growth and normal growth, corresponding to the most suitable growth temperature range and normal growth temperature range, corresponding to four thresholds: the normal growth temperature nether, the most suitable growth temperature nether, the most suitable growth temperature upper bound, and the normal growth temperature upper bound. EPA4 (Figure 7)-Take the temperature control effect of the exhaust fan affected by the temperature difference between inside and outside as an example: there are two situations. One is to increase the indoor temperature, and the other is to lower the indoor temperature. At the beginning of the system operation, the direction of temperature control by the exhaust fan can be judged by calculating the difference between the inside and outside of the temperature. EPA5 ( Figure 8)-Lettuce growth is divided into 5 growth stages. As the growth phases in the planting plan are all of fixed duration, the jump between the states of each growth phase is only determined by the staying time, and the jump is triggered by the timer. A new state needs to be defined here to indicate that the lettuce has not yet been planted, which is set by the worker. EPA6 (Figure 9)-When the adjustment scene is the heading stage of Italian lettuce, the temperature during the day must be maintained at 20~22 • C, and the temperature at night must be maintained at 10~15 • C to achieve the best growth state of lettuce. EPA7 ( Figure 10)-Take the goal of correcting temperature regulation only through temperature changes, when the greenhouse temperature is rising sharply or the temperature is too high, the temperature will be lowered, and when entering the state will be issued the need to lower the temperature of the event, and vice versa, increase the temperature to maintain the greenhouse temperature stability. EPA8 ( Figure 11)-Taking the connection status of the exhaust fan provided to the worker as an example: the exhaust fan has two connection states: connected and disconnected, and the worker is notified of the current connection state of the exhaust fan when the status changes. EPA9 ( Figure 12)-Take the control method with shading, down ventilation and water valve control, and the need to cool down through the down ventilation as an example: there are three states: non-operational, equipment connection, and executable. The condition for normal operation is that the exhaust fan, down ventilation and water valve are controlled at the same time. It is in the connected state, and the lower ventilation is in the state of opening and cooling. EPA10 ( Figure 13)-Taking the humidification method as an example: there are two states: humidification (N) and dehumidification (F). When the environment needs to be humidified, the method does not need to be executed. When the environment needs to be humidified, it determines whether to enter the predetermined threshold and generates the environment list event in each clock cycle.  Figure 14) In the process of greenhouse regulation, there are two types of situations. One is the general situation where the greenhouse can be adjusted back to the target state through a series of controls without causing other factors to deviate from the established range. The other is the special situation where a certain environmental factor deviates too far from the target, cannot find a suitable method to adjust it back to the target state, and needs to restore the factor to the target state first. The evaluation functions of the above two cases are, respectively, denoted as f-search and f-extreme. When the two functions are searched in the method set, they can return the number of the optimal control method and whether it is found.  EPA12 ( Figure 15) In the case of the boundary method, the length of the queue for receiving events is 1. For general methods, you do not have to generate an environment alert event at the end. EPA13 ( Figure 16) In the case of fan exhausts, the length of the receive event queue is 1. The control information generated by receiving controller state information and method generates formal control information, whether the control in the feedback method is effective, and whether the feedback to the worker controller is wrong so that the greenhouse can cope with complex situations.

Experiments
Based on the modeling method designed by Peng et al. [76] and collected 10 kinds of real control data, a model of temperature and humidity changes in Zhuozhou was established to simulate the changes after greenhouse regulation. Inputting the collected real data and the control instructions output by the CEP system into the above model, the entire process of temperature and humidity changes and operations under the control of the CEP system can be simulated.
After considering the above situation, the CEP system built in this experiment has realized six functions. The first is to study the changing trend of environmental factors from environmental information. Second, mark the difference between the state of the environment and setting goals. The third is to determine the actual adjustment range of each factor in the greenhouse. Fourth, collect the required environmental information and estimate whether the method is suitable for the current environmental conditions. Fifthly, score each control method and select the one with the highest current score. The sixth is to execute concrete control methods and issue instructions. Based on the above procedures, we built a CEP engine for simulation experiments of short-term greenhouse control.
In order to verify the performance of our CEP system in the real greenhouse scenario, we collected the temperature and humidity as supporting data of the solar greenhouse of Zhuozhou Farm of China Agricultural University from January 15 to 17, 2021, with the collection frequency of approximately 200 s/time. We use it as the bias value in response to changes in temperature and in the experiment to simulate fluctuation of temperature in real scenarios and compare the early warning capabilities of the three types of methods. A total of 1069 pieces of valid data were collected in this experiment, with a duration of about two and a half days. The curve of temperature and humidity are represented in Figure 17. They are used as the temperature and humidity fluctuations in the real greenhouse environment to be superimposed on the experimental model for subsequent control experiments. Substituting the above data, Figure 18 can be obtained. Figure 18 is divided into three parts from top to bottom: temperature, humidity curve, and corresponding controller status. The dark color part in the background of the curve denotes the optimal growth interval of the crop, while the light color denotes the normal growth interval of the crop.
The abscissa is the number of cycles, 200 s per cycle, which is the same as the frequency of the sensor during acquisition, while the ordinate is the temperature and humidity value. In the lower controller state diagram, the states of the upper vent, lower vent, water pump, and sun visor are drawn from top to bottom. The color corresponding to each period on the right signifies the current state of the controller, including the opening and closing of the upper and lower vents, the opening and closing of the water pump, and the shading area of the sun visor. The first three controllers can be switched on and off. The sun visor can be switched in three states: 0%, 50%, and 100%. For example, the humidity was low at first, the temperature was normal, and the greenhouse was being ventilated and watered. After a period, the CEP system found that the humidity had returned to normal through the collected information, and immediately issued an instruction to stop watering. However, at that time, affected by the external humidity, the humidity in the greenhouse was still rising, the CEP system immediately shut down the lower ventilation, and the humidity and temperature dropped so that the temperature and humidity could be controlled within a reasonable range.
Similarly, around the 400th time, the temperature was high, and the humidity was normal. In such conditions, the CEP system issued a command to adjust the shading area from 0% to 50% and then opened the lower ventilation, which greatly reduced the temperature. However, the opening of the lower ventilation also caused a significant drop in humidity, which was lower than the predetermined target value. At this time, the system immediately adjusted the shading area from 50% to 0%, which increased the temperature, accelerated the transpiration of plants, and brought the humidity to normal. Table 7 is the proportion of data points where the temperature and humidity are in the most normal and optimal growth range of the crop during regulation. It can be clearly found that the proportion of temperature and humidity data points in the most suitable and normal range after being regulated by the CEP system has increased significantly compared with that before being regulated. This illustrates regulation effect of our system is remarkable. According to the values in the experiment, when our greenhouse CEP system is applied to the absolute real environment, the temperature and humidity can be controlled within the predetermined range by controlling ventilation, watering, and shading. The experimental results demonstrate that the architecture of the greenhouse complex event processing system designed in this paper is accessible and effective.

Conclusions
This paper designs a greenhouse automatic control method and system based on complex event processing and provides a general greenhouse-oriented CEP system implementation plan for agricultural experts and related workers. This structure of our system has the advantages of high efficiency, convenience, and low coupling, which can solve the problem of identification and integration of complex patterns in the greenhouse. This paper categorizes the information appearing in the greenhouse, defines 21 types of event types and structures, 13 types of EPA, and specific construction methods of EPA, and obtains a CEP method for greenhouse control. Specifically, the information obtained is used to determine whether an atomic event has occurred. Then, the atomic events are input into the CEP engine to form complex events and control information. Finally, the greenhouse controller in the greenhouse is regulated by this information. The CEP engine designed according to the theory of this article effectively solves the problems of a large amount of greenhouse data, strong coupling, and low cohesion. It is suitable for most greenhouse control scenarios, and also brings convenience to agricultural experts and related workers when using and expressing complex scenarios.

Patents
The results of this article have been sorted and published as a patent and authorized by the State Intellectual Property Office in China. The patent number is ZL202010506335.6.

Funding:
The study was partially supported by Natural Science Foundation of China through Grants (61601471).

Institutional Review Board Statement: Not applicable.
Informed Consent Statement: Not applicable.

Data Availability Statement:
The simulated experimental data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest:
The authors declare no conflict of interest.