NSensor – Wireless Sensor Network for Environmental Monitoring

This paper reports the development and integration of a wireless sensor network for environmental monitoring. The main goals of this system include modularity, low power consumption and ease of expansion. The system includes three main elements: sensor nodes, gateways and a server. Each sensor node can only connect to a gateway, resulting in a star network layout. Data collected from the different sensor nodes is stored in a database within the server. A web-based user interface for this system was developed and made available online. Keywords— environmental monitoring, instrumentation, internet of things, wireless sensor network.


Introduction
In recent years, there has been an increase in the variety of usages for sensor systems, from industrial control and environmental monitoring to agriculture and medicine.
These sensors have increased precision and resolution as well as featuring smaller sizes and lower power consumption. This makes their use in intelligent systems more interesting.
Sensors with processing and communication capabilities are one of the key elements of the Internet of Things and are commonly known as smart sensors.
Smart sensors are usually integrated in wireless sensor networks (WSN), based on the combination of multiple sensors in different locations with wireless communication infrastructure and software data processing. In this way, the system can monitor and record the evolution of several parameters. Commonly monitored parameters include temperature, relative humidity, atmospheric pressure, illuminance, sound level, power consumption, chemical concentration and body health signals.
Wireless sensor networks are used in various fields, such as environmental monitoring [1,2], health [3,4], sports [5,6], surveillance [7], acoustics [8], industrial equipment monitoring [9,10] and in engineering education [11]. A WSN usually involves three main components: sensor nodes, gateways and a main server. The latter is responsible for the storage of the acquired data, as well as for making the data available to the users. Gateways receive the data measured by the sensor nodes through wireless communication and route it to the main server. Alternatively, the nodes may also connect to each other, creating a multi-hop network. In this type of solution, the data will go through several nodes before reaching a gateway, increasing the network's range but also the power consumption in the middle nodes.
This work comes as the result of teaching and research activities in the instrumentation for measurement field and its integration in mechatronic systems. This created the need to have a monitoring system that allows the integration of different sensor types, both sensors with digital interfaces and purely analog sensors, and that can be easily expanded, integrating new sensors and new features.
Academic monitoring solutions often involve the use of Arduino, Raspberry Pi and other development boards [12][13][14][15][16]. However, the adopted solution is based on embedded custom electronics in order to maximize its integration potential in industrialoriented solutions with mass market aims, while allowing the ease of expansion not found in commercial solutions. The developed system can be easily customized to integrate custom-built sensors for different purposes, being also a building platform for the development of other remote monitoring solutions [17].
These systems may be used for various teaching activities in distinct areas, such as instrumentation for measurement, control, mechatronics, civil engineering and thermodynamics fields. The system may also be used as a tool for data mining, the interdisciplinary field of computer science. They enable the study of the variations that environmental parameters experience depending on external conditions, allowing, for example, the evaluation of buildings' conditions, highlighting the influence of the building materials, design approaches and predicting seasonal or periodic disturbances.

Development of a Wireless Sensor Network
The NSensor wireless sensor network adopts a star network layout and includes the typical three main elements of a WSN ( Figure 1): • Sensor Node: acquires sensor data and routes it to the server through the gateway; • Gateway: routes the data from the wireless sensor nodes to the server using a physical Ethernet connection. It is also capable of routing packets in the opposite direction; • Server: gathers the data from each sensor node, storing it in a database. It is also capable of sending commands to the sensor nodes through the gateway.
The developed system uses embedded electronics based on microcontrollers from Microchip Technologies and implements standard communication protocols, namely MiWi as the wireless protocol between the sensor nodes and the gateway and Ethernet/HTTP as the wired protocol used between the gateways and the server. The main reason for choosing this technology is its low power consumption, as well as the authors' familiarity with the solutions provided by Microchip Technologies. http://www.i-jim.org

Sensor node
The sensor nodes are, as previously stated, the system components responsible for data acquisition. Different sensors can be integrated within the same sensor node in order to measure different environment parameters, leading to customized sensor nodes. They acquire the data from the multiple sensors and transmit it to the server through the gateways. The nodes will attempt a limited number of retries to send information in case there are communication problems. If unsuccessful, the node will try to communicate once again one second later.
The sampling period of each sensor node can be defined by the user through the server's interface. The period is maintained using the microcontroller's Real-Time Clock and Calendar (RTCC) module and allows periods ranging from one second to one day.
The developed firmware is capable of automatically detecting the presence of the different sensors on boot and adjusting its behaviour accordingly. For example, if the node concludes that a particular sensor is not present, it will not attempt to communicate with it anymore and will not power up any related circuitry.
Currently, five different sensors have already been implemented in the NSensor system, allowing the measurement of seven parameters. These implemented sensors and measured parameters are listed in Table 1.
Each sensor readings are treated as individual parameters. So, since both the AM2320 and the BMP180 are capable of supplying temperature information, the system reports two different temperature values, one for each sensor, instead of averaging the readings. The communication between the sensor node and the gateway can use up to 60 bytes of data, including tags for each measured parameter. The system also records other parameters, namely the battery level and the last communication's link quality (LQI, Link Quality Indicator) and signal strength (RSSI, Received Signal Strength Indicator). These last two parameters and the source node MAC address are added to every frame sent by the gateways to the server.
The enclosure of the sensor node was designed to resemble clouds. Two major versions of this enclosure were developed. The first one, Figure 2 (a), is only operable using batteries and does not feature support for the iAQ-core sensor. The other enclosure, Figure 2 (b), can be operated using either batteries or a mini-USB connection and features support for this sensor.
The user interacts with these nodes through a tactile switch placed on its back, and receives feedback through a blue LED that will turn on when the device is active (during the startup procedure and sensor sampling) and off when the device is inactive (powered off or sleeping).

Gateway
The gateways are responsible for routing the data acquired by the sensor nodes to the main server. Their main task involves receiving packets though the MiWi wireless protocol and sending them to the main server through its Ethernet interface using HTTP. Furthermore, they are also capable of routing information from the server to a specific node, which can be used, for example, to define the sensor node sampling period.
A gateway will use DHCP (Dynamic Host Configuration Protocol) by default to configure the network, but can fallback to static IP configurations, as well as being reconfigurable by the user. If the need arises, there is a reset button that can be pressed for four seconds on boot to reset the network configuration of the module.
Even though the use of WiFi could remove the need for gateways, the MiWi wireless protocol was the chosen option, mainly due to its lower power consumption. This wireless protocol is based on the IEEE 802.15.4 standard that was developed for lowdata-rate, low-power and low-complexity radio frequency transmissions [18]. As such, protocols based on this standard are the most interesting for this particular application.
MiWi can operate in multiple radio frequencies, the most common being 2.4 GHz. This protocol "offers a significantly smaller foot-print relative to the open standard based ZigBee® compliant protocol stack" [19].
This, allied with its integration into Microchip's products, such as the selected antenna IC (MRF24J40) made MiWi the chosen wireless protocol for this system.
The enclosure of the gateways feature a similar design to the sensor nodes, Figure  3. The main distinguishable design feature of this enclosure are the openings on the front that resemble the typical wireless symbol, included to improve air circulation in this module. The gateways need an external power adapter.

Server
The last major component of the NSensor system is the Server. The current implementation makes use of an open-source solution using a Linux-based Apache HTTP Server with a MySQL database management system.
The server-side scripting language is PHP. The system was tested with several versions, namely 5.4, 5.6 and 7.0.

User Interface
The user interface is made available through a collection of web pages developed for this specific purpose. The main page, Figure 4, includes a graph of the data acquired in the last 24 hours by a particular node, as well as the values and timestamp from the latest sample. The device's name and location are also featured and support HTML code, enabling the use of hyperlinks.
The user can change devices using the combo-box in the upper right corner of the content panel. This page will continuously check for updated data, in order to display the latest values available.
The graphs are powered by Highcharts [20] and allow enabling and disabling particular series of data with automatic rescaling of the remaining data. This allows the usage of a single Y axis without losing usability due to differences in scale between parameters.
In the main page's case, some parameters are hidden by default, such as the battery level, UV radiation intensity and atmospheric pressure. This framework also enables the user to export the graph as an image.
Additional functionality is limited to registered users, through the login page, even though registration is open to anyone. Every user is capable of accessing and exporting the nodes' data. However, only administrators can edit devices.
Upon login, the users are returned to the main page, enabling access to the list of sensor nodes that are present in the system, as well as their most important details, such as sampling interval, alarm status, MAC address and the respective gateway's IP address.
For each sensor node, there is a details page, Figure 5, where users are presented additional information about the sensors.
On the top right, there is a graphical representation of the node battery level and signal strength. This information is updated after each successful communication from the node. For administrators, there is an additional button, enabling access to the device edit popup, Figure 6, where it is possible to edit the name, location, sampling interval and alarms.
Any changes made to the sampling interval are only made effective after the node's next communication. That is, if the sampling interval is currently set to 10 minutes and the user changes it to 30 seconds, the new sampling interval will only be applied when the current 10 minute period ends.
The alarms allow the user to set a maximum value, a minimum value or both, with hysteresis for each measured parameter. If the measured parameters exceed the alarm ranges defined by the user, an alarm entry will be added into the Alarm Status on the device details page. These alarms are currently website-only, but can be easily expanded, enabling email and other types of warning system activation.
The details page also includes a list of the parameters monitored by this particular node. Each parameter has a related popup page, Figure 7, listing the main characteristics of the sensor, as well as any datasheet available for it.
Another important feature of this page is the log view setup, where the user can select which sensor data to analyze and the time interval to consider. This loads a new webpage, Figure 8, which presents the selected information as a graph and enables the download of a file in csv format containing this data.   6. Example of the device edit popup [21] 32 http://www.i-jim.org

Conclusion
A Wireless Sensor Network for environmental monitoring was developed, prototyped and integrated in an information system. It has been fully operational since May 2016.
Multiple nodes with different sensors were developed, being capable of currently monitoring up to eight parameters each.
The sensor node operated with four AAA batteries has an estimated autonomy of up to twenty months if the sensors are sampled every ten minutes and the iAQ-core is not included. So far, one of the modules has been in continuous operation for five months. The power consumption of each sensor node in sleep mode is typically 50 µA.
Regarding communication distance, two tests were performed in order to verify the working range of the system. In open field, the working range was tested up to 35 meters without packet loss. Theoretically, the communication in this conditions should be stable up to 100 meters. Another test, currently under way, involves one sensor node located around twenty five meters away from the gateway with two concrete walls in between. It is fully functional, even though it has occasional dropped packets. Tests are still under way to identify the performance of the communication. Preliminary results show that in a period of 48 hours the server received all planned samples (one sample each 10 minutes), although it was verified that the sensor node had to resend the information in four occasions. The system has now been working for 7 months straight.
The developed system is based on custom embedded electronics with low power consumption and ease of expansion in order to facilitate its potential usage in industrial applications.
The first custom-built sensor for this platform, a thermistor-based thermoanemometer for low air velocities in indoor environment, was developed and is currently under evaluation.
The user interface for this system was also developed and uses open-source server solutions to allow remote access to the information and an alarm management system through a web server.
This system allows the remote measurement of environmental parameters, enabling the remote study of related phenomena, such as the influence of either seasonal or periodic disturbances on the measured environmental parameters. One prototype is currently under use for the environment study of rooms in Mediterranean buildings within ADAI, University of Coimbra, and a few others will integrate small scale building prototypes in a European project in the civil engineering area.

Acknowledgment
Authors gratefully acknowledge the funding of Project NORTE-01-0145-FEDER-000022 -SciTech -Science and Technology for Competitive and Sustainable Industries, cofinanced by Programa Operacional Regional do Norte (NORTE2020), through Fundo Europeu de Desenvolvimento Regional (FEDER). This work was also funded by Project LAETA -UID/EMS/50022/2013 and project U-Academy from Calouste Gulbenkian Foundation.