With the rapid development of Things of Internet and its related technologies such as Wireless Sensor Network and remote access system development, its application on agricultural and farming domain has become a new research direction. This paper discusses a practical and efficient system by applying mobile software development technologies and ZigBee communication network. To achieve a compact and flexible iOS-based client, this study takes advantage of Model-View-ViewModel pattern as well as Client/Server style. Several encryption technologies such as Message Digest algorithm and Rivest Shamir Adleman algorithm are combined to ensure information security. Compared to the common portable marketing system, the proposed system also provides accurate growth information which is collected by wireless sensor network, and proposes a more flexible design pattern for mobile client hence obtaining a better performance on iOS devices.
With the development of Internet of Things, Wireless Sensor Network (WSN) is widely applied in many agricultural applications. What’s more, as the agricultural products safety issue becomes a focus of every country and the public, the application of WSN on agricultural growth trace is becoming a new challenging in this area. Recent years some short distance communication technologies such as ZigBee and RFID have been discussed for agricultural product inspection, and [
This paper proposes a system which combines the application of Internet of Things (IoT) and iOS platform-based mobile software development to collect and display agricultural products growth information, and also to offer products marketing function. The proposed iOS based client adopts Model-View-Viewmodel (MVVM) design pattern, which can directly update the view by binding without extra codes and therefore reduce the amount of code.
This study presents a complete system as shown in
CC2530 SoC, support a low-duty cycle, and therefore are suitable for agricultural applications such as irrigation management and growth information collection, where periodic information update is required [
The network is a multi-tier architecture [
The proposed client is based on MVVM design structure [
Client consists of following functions: agricultural products information display, agricultural products recommendation, agricultural products tracing, consumer/order management and other supplementary functions. Client/Server model [
This client is separated into following modules:
・ Product Display Module: This module is the core module. It displays the selling products from local agricultural base. Users explore and search the displaying items and select them according to their preferences. Agricultural growth information also can be obtained from corresponding view.
・ Product Recommend Module: Product recommend module collects user shopping preferences, and display daily recommend items according to the optimized recommend algorithm from the backend server. It also provides push services when users are in a given local area or at a timestamp to promote products.
・ Product Tracing Module: There are two important functions this module needs to achieve: the first is to display plant farming information through a web view, the other one is to scan the QR Code on the external pack of product as shown in
・ Order/user Management Module: This module is in charge of users’ order and personal information management. Users can browse, modify and cancel their order forms. This module will automatically send HTTPS requests to get order and personal information and refresh UI to display these data.
・ Supplementary Modules: Other supplementary modules include: shopping trolley, payment as well as preference settings.
MVVM Pattern on iOS
The typical iOS-Platform based software and software on other mobile operation system normally adopts MVC (Model-View-Controller) design pattern [
for code reuse and parallel development. According to MVC, the controller communicates with both View and Model. For example, when a model object changes, the model object usually communicates that change to a controller object, which then requests one or more view objects to update themselves accordingly. The direct contact between model and view is forbidden in this structure. Numerous characteristics such as simultaneous development, high cohesion, low coupling and multiple views for a model are benefits from this pattern [
MVC has been introduced for over 30 years, and its advantages have been appreciated by many software developers. However, in mobile platform such iOS, when the functions and modules of program have been build more and more complicated, a large amount of services, for example, responding to delegation messages or observing notifications, responding to action messages, managing the life cycle of owned objects (for example, releasing them at the proper time), and establishing connection between objects and performing initialization, are necessary to be provided by the controller. Therefore, the controller will become extremely massive and hence pose a threat to the program’s efficiency and fluency.
To deal with this problem, the proposed client uses an iOS-based Model-View-ViewModel (MVVM) design pattern. MVVM is initially developed for .NET platform to deal with architectural pattern problem on WPF application system, mainly apply on project development on WPF and Silverlight. MVVM pattern can separate business and logic, increase the reusability of code [
The hierarchical structure of MVVM pattern is shown as
Li L [
・ Define view model classes.
・ Decompose the network services module from the controller, and move it to view model class.
・ Move the data processing and presentation logics, including data formatting, data localization operation and information display management, into view model classes.
・ Supply data checking and error report in view model tier.
As shown in
Interface Building and Optimization
On iOS, the information display mostly relies on UITableView and UICollectionView SDKs from UIKit, which is provided by Apple and is the crucial infrastructures to manage interface. These components get data from the data source object, which is an object that conforms to the data source and delegate protocol. The data source provides information that UITableView and UICollectionView needs to construct and manages the data model when rows of a table are inserted, deleted, or reordered. The delegate manages table row configuration and selection, row reordering, highlighting, accessory views, and editing operations.
There are many modules integrated in the client, for example, product display, product recommend and user information management, use UICollectionView and UITableView to present data. To build heterogeneous interfaces, we create numbers of custom objects in with content or behavioral characteristics that are different from each other. However, the problem is, when we code these module, a large amount of repeated codes make the controller become inevitably heavy. According to the business logic for specified system and object oriented programming (OOP) principle, beside set up MVVM architecture stated above, some efficient optimization measures are proposed in this paper.
As an example,
and methods according to different interface scenarios.
Information Security
As a C/S application, HTTPS protocol is contained for network communication. HTTPS, the secure version of HTTP, runs HTTP on top of SSL/TLS, which is the standard protocol for providing authenticity and confidentiality on top of TCP connections [
In the products information tracing module, mobile devices users use internal cameras to scan QR Code on the product outer packages to read planting information. To handle the QR Code recognition issue, some effective QR Code scanning algorithms are presented by researchers [
Data Cache and Persistence
The presentation of product requires to download a large amount of image data from the server. To control the network flow, the client uses a two-stage data cache mechanism: using NSCache object to cache thumbnails that was downloaded, because these images will be browse frequently in short time periods; on the other hand, the client uses NSFileManager to cache those large images onto local disk.
The cache system is shown as
The proposed client keeps its user interface simple, clear and convenient for manipulation. This application is implemented in the 6th generation of iPhone with iOS 9.2. The actual runtime test is illustrated as following.
selling and planting information through product detail module as shown in
To test the integrated function of the proposed system, we deployed 16 nodes on field and divided the subject terrain into 16 areas based on different farming purpose, and the subject area is 65,000 m2. Each node consists of one image capture sensor and other pertinent sensors.
Parameter | Value |
---|---|
Temperature and humidity senor | DHT11 (http://www.aosong.com) |
Light intensity sensor | SM3590B (http://www.sonbus.com) |
ZigBee radio module | CC2430 (http://www.ti.com) |
No. of nodes | 16 for each area |
Transmission range | 80 - 100 m |
Inter-node communication | ZigBee, 2.4 GHz |
Architecture | Multi-tier heterogeneous star network |
With Internet access, the client delivers user’s shopping information to the server, which keeps the data as UML class in the database. The UML object is shown as
With Internet access, the client delivers user’s shopping information to the server, which keeps the data as UML class in the database. The UML object is shown as
The wireless sensor network and iOS based agricultural products marketing and traceable system has been proposed in this paper. The on-field sensors collect multiple agricultural growing data, and then transmit these data to base station through ZigBee. C/S structure is suitable for this application. The data on base
Field Name | Description | Type | Length | Default value | Key |
---|---|---|---|---|---|
SAF01 | Serial number | Int | 20 | Yes | |
SAF02 | Temperature | Varchar | 20 | ||
SAF03 | Humidity | Varchar | 20 | ||
SAF04 | Light Intensity | Varchar | 20 | ||
SAF05 | Fertilizer | Varchar | 20 | ||
SAF06 | Pesticide | Varchar | 20 | ||
SAF07 | Record time | Varchar | 20 |
station are transmitted to remote server through GPRS network. The iOS-based portable client sends HTTPS requests to the server for agricultural planting and transaction data. These data to be transmitted are encrypted through MD5 algorithm. QR Code that encrypted by RSA is applied for product identification and therefore user can read the traceable information. Test results on QR Code scanning function indicate that the native APIs detect as well as read the barcode images on product packages efficiently without any optimization algorithms. Optimization steps on UIKit such as UITableView for iOS markedly simplified the business logic, and these measures make a contribution to a better UI performance. Additionally, compared to traditional MVC software architecture, a mobile-based MVVM pattern not only reduces the complexity of controllers, but also separates the complicated business and network logics from presentation module, avoiding the confusion in multi-view application development and making the client more convenient to develop and maintain.
Our work is supported by The Application of Internet of Things on Agriculture and Green Source Products Information Development project, Tianjin Rural Work Committee.
Sun, H.Y., Zhang, J.P., Sun, G.L. and Li, Y.Y. (2017) Agricultural Traceable and Marketing System Based on iOS-Platform and Wireless Sensor Network. Journal of Computer and Communications, 5, 45-56. https://doi.org/10.4236/jcc.2017.56003