Research and Design of Wireless Sensor Middleware Based on STM32

. In order to make agricultural production become more convenient ， also meet the requirement of the modern intelligentagriculture to make control equipment integrated and miniaturization ， the paper designed a wireless sensor middleware based on STM32. This wirelessgateway receives control command from the control software of agricultural IOT application which installed in the tablet computer through the WiFi/USARTmodule ， after the data processing and protocol conversion ， then send the control signal to the wireless sensor network through the USART port. At thesame time ， if a particular model of agricultural sensor changes state ， it also can timely feedback to the tablet computer to display through thegateway. This plan solved the problem of real － time monitoring of agricultural information and realized remote control. Theexperimental results show that ， the wireless sensor middleware has the characteristics of light and handy,high control precision ， data large quantityand high speed. It’s very appropriate for intelligent agriculturalsystem application ．


Introduction
With the rapid development of Internet of things, IOT middleware becomes one of the important research topics in related fields in recent years, also acquired a lot of research results, mainly divided into application service middleware, embedded middleware.Such as White [1] put forward a kind of typical middleware based on J2EE architecture, has a good scalability.paper[2] proposed wireless sensor network middleware based on mobile Agent, the middleware has data management, integration, application target adaptive control strategy, Wang fan design and implemented an IOT middleware, that can filter the heterogeneous network data, integrate ZIGBEE and RFID (Radio Frequency Identification, RFID) data into a unified format [3].Paper [4][5][6][7] proposed database based middleware, it views the entire network as a distributed database, users use similar to SQL query command to get the data needed, query is distributed to each node through the network, the nodes determine whether the sensory data satisfy the query conditions, and decide to send data or not.Deng Yihua etc.Put forward embedded RFID middleware on smart RFID read-write device [8], it can realize the management of multiple read/write devices, strengthen the deployment flexibility.The domestic scholars make use of the gateway hardware to research IOT system [8][9][10][11], however, the research and design of STM32 based wireless sensor network middleware is still relatively rare.
The research combines the ZigBee wireless sensor network with the STM32 MCU, it has the advantages of simple structure, strong generalization ability and others.The objective of this study is to develop aneasy method to implement the remote monitoring and control system for the agricultural production environment.

2Wireless gateway hardware platform design
Wireless gateway is the data transfer station of the Agro-IOT control system and communication media, it is critical to the whole system design.The main frame of the hardware platform is shown as figure 1.

Fig. 1.Wireless gateway overall architecture diagram
The hardware involved in this paper include wireless sensor nodes and gateway hardware, hardware design is introduced as follows.CC2530F32/64/128/256 separately with 32/64/128/256KB in-system programmable flash memory.

wireless sensor nodes
The microcontroller has 8KB RAM with data remaining capacity under various power supply.CC2530 has various operating modes such as active mode RX (CPU idle), active mode TX 1dBm (CPU idle), power supply mode 1 (4us awake), power supply mode 2 (sleep timer), power supply mode 3 (external interruption), wide voltage range of power supply and so on which makes the energy consumption very low.
The wireless transceiver adopts zigbee technology.It has low power consumption, rapid response and large network capacity etc features.Figure 2 shows thewireless sensor nodes used in the system.According to the function, node types can be divided into three categories, namely the acquisition node (only responsible for data collection), routing nodes (responsible for data gathering and routing), and the coordinator node (network management).All kinds of nodes on the hardware adopts the above design, the coordinator needs a binding to the gateway via the serial port.

gateway hardware
Gateway is the key module of this system, it needs to bind with the coordinator, the gateway Circuit Diagram is shown in figure 3.

Wireless gateway software platform design
Wireless sensor network middleware software platform are actually established on the embedded development board wildfire STM32 ISO with transplantationof Linux system, and then Boa Web server, database Sqlite3 was also set up in the Linux system.
The main task of the wireless sensor network gateway is as follows: access to information of each node in the wireless sensor network, processing a request from the Internet, the wireless sensor network configuration management, and data statistics and analysis, etc.The main task of wireless sensor network is tomonitoring the state of the remote device.Literature [12] presents a so-called Cougar middleware system, Cougar views wireless sensor network as the distributed database and the network nodes are divided into clusters, cluster is a collection of multiple nodes, elects a node in the cluster as the cluster head.Paper [13] proposed a flexible wireless sensor network middleware system.The system using Web Service technology and middleware technology, the system views the wireless sensor network as middleware system, each node uses a different SOAP Engine, the coordinator node has a registration module, other sensor nodes have different event handlers, the user can use any SOAP proxy access coordinator node via TCP/IP protocol, and further access to the entire wireless sensor network.
In order to manage the wireless sensor network better and expand Internet connections to the wireless sensor network, through careful analysis of the wireless sensor network monitoring program, and combined with hardware gateway, this paper abstracts a new middleware model as shown in figure 4.  Web server provides HTTP service to external applications, and internally access to interpreter by CGI;

CGI call CGI return
The interpreter responses to explain users command, and give orders to the cluster model control layer and accept its response; Model control layer abstracts the clusters for the wireless sensor network, and provides the control interface; Sensor network coordinator interface provides an interface for gateway to read and write in wireless sensor network , the actual implementation is divided into the gateway and the coordinator two part,the coordinator and the sensor nodes' communication uses data collection protocol.

Result and Discussion
Wireless Sensor Middleware was used in livestock and poultry breeding, agricultural facilities accurate monitoring, Edible fungus production information collection and similar applications, the coordinator node on the packet is bound to the embedded gateway.Using TCP/IP protocol stack, the communication between monitoring instrument and upper computer was realized.The real time information on the upper computer is like figure 5.

Conclusions
The research analyzed the IOT middleware research status, and combining the wireless sensor network practice, proposed the Wireless Sensor Middleware Based on STM32.The software has two characteristics include embedded server and application services, it adopted the idea of components, reduced the coupling between modules, the configurable and customizable functionality improved reusability, lower development costs, solve the problems of mass data processing, and provide the visual configuration monitoring platform, the realization of Internet of things "content" of the administration and monitoring, eliminate information isolated island.This middleware application was used in Edible fungus production information collection system, and the results show that the feasibility and effectiveness of the above frameworks and methods.
CC2530 on-chip system is used for the wireless sensor nodes with very low cost and ultralow power consumption.It integrates the microprocessor module and a wireless transceiver module in one single chip.It has the excellent performance of RF transceiver adapting to IEEE 802.15.4 with extra high reception sensitivity and anti-interference.Its core is industry-standard enhanced 8051 microcontroller unit with code prefetching function.CC2530 has four different types of flash memory version i.e.

Fig. 3 .
Fig. 3.Gateway Circuit Diagram Gateway hardware uses STM32F103ZET which core is ARM Cortex-M3.F1-series is the first generation microcontrollers of STM32 that is considered as its mainstream of ARM MCU.With the development of technology, F1 series has many improvements such as CPU speed, size of internal memory and type of peripherals.The excellent peripherals and low-power, low-voltage operation make it with high performance.It is highly integrated with the simple structure and easily used tools which cost is very low.STM32 is control core of the wireless gateway, it mainly divides into five modules, include WiFi module, RF module, a central controller module, power module, JTAG emulation debugging module respectively.

Fig. 4 .
Fig. 4.Wireless sensor network middleware structure model Middleware structure model has many modules include Cluster model controller, Command interpreter, Boa server, database controller and Sensor network coordination interface and so on.

Fig. 5 .
Fig. 5.Real time data from the remote sensors