# Pervasive Agricultural Environment Monitoring System Based on Embedded Database

Hu Zhao, Sangen Wang, Dake Wu

<figure><img src="image_1.png" /></figure>

► To cite this version:

Hu Zhao, Sangen Wang, Dake Wu. Pervasive Agricultural Environment Monitoring System Based on Embedded Database. 4th Conference on Computer and Computing Technologies in Agriculture (CCTA), Oct 2010, Nanchang, China. pp.166-176, 10.1007/978-3-642-18336-2_20. hal-01562763

HAL Id: hal-01562763

https://inria.hal.science/hal-01562763

Submitted on 17 Jul 2017

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_2.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
Pervasive Agricultural Environment Monitoring
System Based on Embedded Database

Hu Zhao, Sangen Wang, Dake Wu

Southwest University, tiansheng road 216,chongqing, China
tiger100118@163.com

**Abstract.** According to space constraints of the traditional agricultural environment monitoring system, a small database called SQLite was transplanted into the ARM and Linux operation which could store and manage the field information. Users can get information anytime and anywhere through the GSM (Global System for Mobile Communications)network and the WSN(Wireless Sensor Network) by this design, instead of inquiring data from the PC(Personal Computer) which was widely used now. Sensors embedded in the environment, information spread in the air and captured by the handheld instruments, which is a typical application of pervasive computing.

**Keywords:** The pervasive computing, SQLite, WSN, ARM, GSM

# 1 Introduction

Wireless sensor network of the field monitoring was constructed by Han Huafeng(2009) to transmitting the field acquired data to the designated database server on PC based on the ZigBee protocol, and data warehousing and decision support was used at the national agriculture statistics service by Yost M(2000). The most recently study was the WSN(Wireless Sensor Network) system based on the in-field soil water content monitoring designed by Jackson T, Mansfield K, Saafi M and so on(2007). Data of field were transmitted to the monitoring center through the GPRS network or Internet, and processed by the database system on PC in these systems. The field or greenhouse could be monitored remotely by the operator only in the monitoring center. These systems were expensive and complicate. So they were used only by universities and research institutes, but not in the vast rural areas.

The era of pervasive computing is coming with the development of technology. People can get information anytime and anywhere by using a handheld device. It has already been used widely in the Mobile TV, 3G phones and so on. In this article, a pervasive agricultural environment monitoring system based on embedded database was proposed to achieve the following objectives:

(1) The greenhouse environmental data are transmitted to control module through WSN;

(2) The embedded system can collect, store and process the data independently;

(3) The system can send SMS to remind the users automatically at appointed time or the moment of abnormal;
(4) Users can query real-time and history data anytime and anywhere through mobile phones.

## 2 Hardware Design

The system is composed of control module and monitor units. The control module include MCU (Microprogrammed Control Unit), store module, GSM module and RF module; The real-time environmental information is detected and transmitted to the control module by monitor units scattered around the greenhouse. Structural diagram of the system is shown in Figure 1.

<figure><img src="image_3.png" /><figcaption>Fig.1 Structural diagram of the system</figcaption></figure>

The S3C2410 is used to manage data and control other modules in the control module. The NOR FLASH of 16MB is the program memory of the system with the read-write file system. Environmental data will be protected in the FLASH when the power is off suddenly. There are 6 Banks in the S3C2410, and 2 of them were assigned to the ROM, SRAM and SDRAM respectively. The SDRAM of the system is 2 HY57V561620CT of 32M bytes. The TC35 of Siemens works as SMS Module, and the RFM12 transmits and receives data as the wireless modules.

The monitors units include the MCU, sensors and the RF module. They spread around the greenhouse detecting the environmental information. The core of monitor units is a PIC16F877A with the strong anti-interference ability and rich resources.

### 2.1 Control Module

The ARM processor has becoming the preferred choice for the embedded system design now. The S3C2410 is selected as the MUC considering the factors of the processing speed, storage space, interface and the power consumption. The core of the S3C2410 is an ARM920T and it can save cost and improve the performance with advantages of low prices, high performances and high level of integration. The DS1302 provide accurate date and time.
## 2.2 WSN Module

The star-type network topology was adopted for the WSN module. The Unique ID was corresponded to the different monitoring units. A number of monitoring units spread around the greenhouse which sent one packet per second. The control module received data by identifying the ID code circularly. For example, the control module received and processed the data of the second units only after receiving the first by identifying the ID code, and so on. The architecture of the WSN system is shown in Figure 2.

<figure><img src="image_4.png" /><figcaption>Fig.2 the architecture of the WSN system board</figcaption></figure>

The RFM12 is a low costing ISM band transceiver RF module implemented with unique PLL. Its work signal bands ranges from 315/433/868/915MHZ, complying with FCC, ETSI regulations. The SPI interface is used to communicate with the MCU for the parameters setting. The data are sent into internal registers of RFM12 at the rising edge of the clock when the chip selecting signal nSEL is low. The synchronization header is sent at first, and then the data needed are sent. The next data can be sent when the SDO pin is high. The nIRQ pin is pulled low to notice the MCU when the RFM12 receives data. The MCU then reads the data stored in the buffer temporarily. The receiving register is closed when the receiving procedure finish.

The greenhouse's information includes the air temperature and humidity, soil temperature and humidity, light intensity and CO₂ concentration. Digital sensors have the priority because of the calibration-free and high precision. It also makes it easy for multisensor fusion. The main performances of sensors are described as following:

(1) Air temperature and humidity sensors—Used to detect the air temperature and humidity, and the model is the SHT10 (Basic type), the main performances: the humidity measuring range 0~100%rh, temperature measuring range -40~+123.8℃, Temperature accuracy ±0.3℃ (25℃), humidity accuracy ±1.8%RH, Response time 8s, power supply 2.4~5.5V, and the Digital output(I2C bus).

(2) Soil temperature and humidity sensors—Used to detect the soil temperature and humidity, and the model is the SHT10P (Protection type), the main performances: the humidity measuring range 0~100%rh; temperature measuring range -40~+123.8℃; Temperature accuracy ±0.3℃ (25℃); humidity accuracy ±1.8%RH; Response time 8s; power supply 2.4~5.5V; and the Digital output (I2C bus).

(3) Light intensity sensor—Used to detect the light intensity, and the model is the BH1710FVC. The main performances: the measuring range 0 ~ 65,535Lx; Sensitivity±15%; power supply 2.4~3.6V; and the Digital output(I2C bus).
(4) CO₂ concentration sensor

Used to detect the CO₂ concentration, and the model is H-550. The main performance: the measuring range 0~5,000ppm; sensitivity ±30ppm±5%(0~50℃); response time≤30s; power supply DC9V~18V; current consumption 50mA(mean value); and the Digital output(I2C bus)

## 2.3 GSM Module

The TC35 is an industrial grade GSM module integrated RF modules and the baseband processor. It Supports the data, voice, SMS and fax[8]. The IGT pin maintains low(at least 100ms) at first when the TC35 starts. Then it keeps high to ensure TC35 working. The input/output interfaces of TC35 use a serial asynchronous receiver, meeting with the ITU-TRS232 interface standard. The data of the interface disposition are 8 bit data position, one stop position, and do not have the verification position. The hardware handshake signal uses the RTSO/CTSO. The software flow is controled by using the Xon/Xoff. The TC35 supports the AT command set.

# 3 Software Design

The software architecture of the data analysis unit is shown in Figure 3. The embedded operating system µCLinux is located at the lowest layer. It manages the software and hardware resources of the system. The user programs are located at the most top layer. It receives and analyzes the environment parameters, and makes assess of the greenhouse' state. The database management system based on SQLite is located at core intermediate level. It is composed of the numerous program modules and the function is to organize, manage and deposit the shared data effectively.

<figure><img src="image_5.png" /><figcaption>Fig.3 Structural diagram of the data analysis unit</figcaption></figure>

## 3.1 Design of embedded database system

The µCLinux is an open project funded and maintained by Lineo. It was made popular by its ability to run on processors without memory management hardware and with a typical kernel footprint of only 512 Kbytes or less.

* It inherits stability and robustness from Linux;

* It supports a large number of devices, file systems, and networking protocols;
* No license fee leads to very low cost;

* It gives developers complete visibility of the source code based on GPL license;

* Kernel can be customized on demand.

The software platform was built on µClinux.

The system establishes cross compiling environment by using arm-elf-tools-20030314.sh. This program is copy to the root directory first and run, then µCLinux can be compiled and transplanted. A directory called “images” will be generated in the µCLinux-dist/ directory after cross-compilation successfully. It includes 3 binary file: image. ram, image. rom and romfs.img.

The Bootloader is designed to make it sure that the execution jumps to the location of the kernel when resets. The MCU core must be initialized and extended in order to achieve the main functions. The whole procedure consists of the following steps:

(1) Establishing interrupt vector table;

(2) Initialization of various processor models;

(3) Introduction of special variables;

(4) Initialization of memory;

(5) Copy codes.

The right to use the CPU is returned to the operating system after hardware initialization process. Then the ultimate goal of the Bootloader is completed.

Structfile_operations structure is used to define the various operation set of equipment in the µCLinux kernel. The main purpose of writing character device drivers is to achieve the various functions of structfile_operations structure. Structfile operations structure is defined in /include/linux/fs.h file. The drivers include the RF module, store module and GSM module. They were turned on and off by following functions:

(1) RF12_open()/RF12_close();

(2) FLASH_open()/FLASH_close();

(3) TC35_open()/TC35_close().

## 3.2 Design of embedded database system

Large amounts of environmental information are collected and processed in the system. The Database is needed to store and manage a large amount of data. Traditional enterprise databases such as Oracle, Sybase and so on have the difficult to work in the embedded system because of the limited resources. The SQLite is small, fast, and reliable, so it is a good choice for embedded systems. It has the following advantages compared with the traditional databases:

(1) It can run in the embedded devices which have less memory and computing power;

(2) It can reset easily when the power or memory capacity runs out;

(3) The cost of establishment and maintenance is very low;

(4) It has strong portability to suit the complexity of embedded systems.

The SQLite is a universal embedded database. It must be transplanted and compiled before apply to the "S3C2410+uCLinux" environment. The main steps of transplanting are described below:

(1) Download sqlite-2.8.15.tar.gz;
(2) Unzip to directory uClinux-dist/user;

(3) User application settings.

The SQLite is added as a user application and converted into a shell. The following
files need to be compiled:

(1) uClinux-dist/user/Makefile

(2) uClinux-dist/config/Configure.help

(3) uClinux-dist/config/config.in

Run the program"make menuconfig" of uCLinux after above amendments.
Selecte"CustomizeVendor/

User Settings" and "Miscellaneous Applications",

There will be a new"sqlite (NEW)" which added by us before. The SQLite will be
compiled to parts of romfs at the stage of"make romfs" later. The following
documents needed to be added and modified finally, and thus to complete the
compilation of the SQLite under uCLinux.

• Modify sqlite/main.mk

• Add sqlite/Makefile

• Modify sqlite/src/os.c

• Modify sqlite/src/shell.c

The SQLite uses a standardized design structure based on relational database mode.
It can be divided into 9 major auto units, as shown in Figure 4. These sub-functional
units form the top-down tool chain: compile in the upper layer, query in the middle
layer, storage data and operate system interface in the underlying.

<figure><img src="image_6.png" /><figcaption>Fig.4 Structural diagram of SQLite</figcaption></figure>

The SQLite supports most of the standard SQL92 statement, especially to support
the view, trigger and services. The API interface of the C language was provided by
the SQLite insteading of the database engine. The access operations of data can be
achieved by the way of calling the appropriate API functions directly. The Header
file "sqlite3.h" must be referenced by the application program. There are 3 core API
functions that should be emphasized:
(1) Open database
```c
int sqlite_open
(const char *filename, /* name of database */
int mode,                 /* Read-write mode */
sqlite3**ppDb);          /* Output database handle */
```

(2) Execute database
```c
int sqlite_exec
 Mis database handle already be opend */
const char *sql,
/* database statement should be executed */
sqlite_callback, /* Callback function */
void,
/* The parameters passed to the callback function */
char **errmsg;      /* Save error message */
/* Parameters is the database handle */
```

(3) Close database
```c
Int sqlite_close/sqlite3*);
```

## 3.3 Design of the main procedure

The GSM module runs first when the main program begins. Receiver functions (`read_SMS()`) are called to decoding the short message content when the SMS reaches (`InterruptInt_Uart(void)` interrupt 4 using `3()`). The needed value is read from database and sent to the users(`send_SMS()`). Then environmental information is received from the monitoring units (`Receive_data()`). The values are saved into database at the setting time. The alarm messages are sent to the users when the environmental values are exceeding the normal value. The flow chart of main procedure is shown in Figure 5.
<figure><img src="image_7.png" /><figcaption>Fig.5 Flow chart of main procedure</figcaption></figure>

## 3.4 Design of the RF module

The RFM12 is initialized (Open TX) at first in the sending mode, then calls subfunction "Send_data()" to send environmental parameters. The first two hexadecimal numbers of data are ID(Identify) codes which are unique for each unit. The next part of the data is the representatives of the air temperature and humidity, soil temperature and humidity, light intensity and CO2 concentration. The nIRQ pin is pull down at the end of sending to notice MCU sending the next data. The program diagram is shown in Figure 6(a).

The RFM12 is initialized(Open RX) at first in the receiving mode, The nIRQ pin is pull down when the MCU reads the data. The FIFO must be reset after receiving the packet. The received data can be processed only through the validation procedures. The program diagram is shown in Figure 6(b)
<figure><img src="image_8.png" /><figcaption>Fig. 6 Flow chart of RFM12</figcaption></figure>

## 4 Test results

The system was tested in the 3rd greenhouse of Southwest University agricultural demonstration center from October 2009 to May 2010. There are 16 monitoring units spreading evenly in the greenhouse. The monitored environmental parameters include the air temperature and humidity, soil temperature and humidity, light intensity and CO₂ concentration. Data are automatically stored every 2 hours.

The SMS will be divided into two parts if the length is longer than 67 characters (including letters, numbers, or punctuation). The SMS query mode is designed as follows:

(1) Send"201005040901",system will return" E24.53°C 60.23%S21.54℃ 72.36% Li31111lx C04237ppm" automatically, mean the parameters of 1st monitoring point are:air temperature 24.53℃, air humidity60.23%,soil temperature21.54, soil humidity 72.36%,light intensity31111lx,CO₂ concentration 4237ppm;

(2) Send"date+te"(air temperature)," date+he"(air humidity)," date+ts"(soil temperature)," date+hs"(soil humidity)," date+li"(light intensity)," date+c02"(CO₂ concentration),system will return the data of the date.
Among the total of 521 text messages, there were 2 errors, 5 missing, and 514 corrects. The data could be stored six months until the new covered them automatically. Experiments show that the greenhouse remote monitoring system based on"ARM+uCLinux+SQLite" performs reliably and efficiently.

# 5 Conclusion

The system that combined the pervasive computing with the agricultural information was suitable for the vast rural areas. The most significant features of the pervasive agricultural system are low cost, simple to use, and people-oriented design. It can be expected that control center room, wired communication network, and complex database system based on PC would disappear in the future. The farmers can monitor and control the environmental factors of the field or greenhouse anytime and anywhere by handheld devices.

# References

1. Han Huafeng,Du Keming,Sun Zhongfu,Zhao Wei,Chen Ran,Liang Jubao: Design and application of ZigBee based telemonitoring system for greenhouse environment data acquisition Transactions of the CASE,pp.158-163(2009)

2. Yost M: Data warehousing and decision support at the national agriculture statistics service.Social Science Computer Renew,pp. 434-441(2000)

3. Gao Feng,Yu Li,Zhang Wen'an,Xu Qingxiang,Yu Lijie: Research and design of crop water status monitoring system based on wireless sensor networks. Transactions of the CASE,pp.107-112(2009)

4. Li Zhen,Wang Ning,Hong Tiansheng,Wen Tao,Liu Zhizhuang: Design of wireless sensor network system based on in-field soil water content monitoring. Transactions of the CASE,pp.212-217(2010)

5. Jackson T, Mansfield K, Saafi M, et al. Measuring soil temperature and moisture using wireless MEMS sensors. Journal of Measurement, pp. 381-390(2007)

6. Huisman J A, Sperl C, Bouten W, et al. Soil water content measurements at different scales: accuracy of time domain reflectometry and ground-penetrating radar.Journal of Hydrology,pp. 48-58(2001)

7. Shen Li: Pervasive Computing. Computer Engineering & Science,pp.77-82(2005)

8. Liao Dianxin: A Survey of the Pervasive Service. ZTE Communications,pp.32-35(2008)

9. Zeng Xiangzhong,Liu Gang,Zheng Dianping,Zhang Ran: Study development of a field information acquisition system based on wireless technique. Chinese Society of Agricultural Engineering collected papers,pp.151-154(2005)

10. Li xiaoyu,Wang Wei,Lei Tingwu,Shen Yi: Prospects of the application of multisensor information fusion techniques in agricultural engineering. Transactions of the CASE,pp.10-13(2003)

11. Zhou Guoxiang,Zhou Jun,Miao Yubin,Liu Chengliang: Development and application on GSM-based monitoring system for digital agriculture. Transactions of the CASE,pp.158-163(2009)

12. Hu Wei: Study on SQLite Implementation on the Embedded System. Computer & Digital Engineering,pp.158-165(2009)
**Project supported by**

“the Key Program of Chongqing Natural Science”(CSTC2009BA1006)

“the Fundamental Research Funds for the Central Universities”(Grant No. XDJK2009C141)

**Author introduction**

Hu Zhao(1974-),male, Chongqing people, lecturer, Doctoral student, (E-mail)tiger100118@163.com

Corresponding author: Sangen Wang(1954-), male, Chongqing people, professor, Doctoral supervisor, (E-mail)wangsg@swu.edu.cn

The third author: Dake Wu(1975-), male, Chongqing people, Associate Professor, Doctor, (E-mail)keda5@swu.edu.cn