Wireless Sensor Network for Environmental Monitoring: Application in a Coffee Factory

Wireless sensor networks have been a big promise during the last few years, but a lack of real applications makes difficult the establishment of this technology. In this paper a real monitoring application in an instant coffee factory is presented. This application belongs to the group of environmental solutions based on wireless sensor networks, and it is focused on the impact of the instant coffee production processes in one of the largest instant coffee factories in Europe. The paper includes the entire application scenario, from the hardware of the WSN nodes to the software that will evaluate the impact and will close the loop.


Introduction
The environmental care has become one of the biggest concerns for almost every country in the last few years. Even though the industrialization level has been increasing without any control in the last decades, the current situation is clearly changing towards more environmentally friendly solutions.
Water and air quality are essential to maintain the equilibrium between human development and a healthy environment. It is also important to notice that by means of looking for a more efficient production in factories both pollution and consumption of natural resources can be decreased. Processes, such as boiling, drying, binding, and so forth, are being carried out by almost every kind of the current factories. Those processes are responsible of a great amount of gas emissions and polluted water discharges. Although the majority of the factories have their own sewage plants, it is crucial to measure the quality of the waste water that is being poured into the public sewer.
Due to the reasons above, the necessity of monitoring production processes and environmental parameters has become an essential task for the industrial community. The solution proposed in this text is an environmental monitoring system based on a wireless sensor network (WSN hereafter) platform called Cookies [1], to measure both gas emissions and waste water quality in an instant coffee factory in Spain. Even though there are myriad other approaches that are now being used, WSNs can offer a cheaper solution while having data acquisition in real time, working in an unattended way.
Typically, the environmental data acquisition in factories is carried out manually and occasionally or using wired systems that are normally expensive and not flexible. This solution is not the best in terms of security, as it is necessary to hire workers to take measurements in dangerous places such as chimneys or waste water pipes. In this way, if a catastrophic discharge occurs, the factory will not notice it until next measurement, which can be several weeks later. That is one of the reasons why WSNs can offer a more reliable and safe measuring process.
In the state of the art, it is possible to find quite a few environmental solutions based on WSNs such as watershed monitoring systems [2], health monitoring in rivers [3], or energy management solutions to reduce both the amount of resources needed and the atmospheric emissions [4].
The work presented in this paper shows a closed-loop system which involves all the different steps to make the environmental impact assessment (EIA from now on) in a coffee factory. Each of these steps will be carried out by different companies and research centers. First of all, the environmental analysis will take place in an instant coffee 2 International Journal of Distributed Sensor Networks factory in Spain. As it was mentioned before, the WSN platform used to take the measurements is the one developed by the Universidad Politécnica de Madrid (UPM) called Cookies. The WSN will send all the data to a web tool designed by Inkoa, the company in charge of the project management. Finally, once the information is stored, a research center called Gaiker will make the EIA in order to report the results to the factory closing the loop.
This work is developed under the umbrella of the SustenTIC Project, which is a technology demonstration project, funded by the Spanish Government. It began in 2008 with the study of the processes and parameters to be measured in the factory and will finish with the deployment of the network and the evaluation of the environmental data in the summer of 2011. The project covers many different aspects related to WSN management for continuous monitoring, such as network communications quality, power consumption, state of the sensors, and so forth. But what makes it different from other applications in this field are the tools to evaluate the incoming data. Those tools will store and compare the data taken from the factory with different environmental data bases in order to make the EIA and being able to report the results directly to the factory.
This project will cover all the different steps to reach this very ambitious target, starting from the study of the processes in the coffee manufacturing and finishing with the results of the platform deployment.
The rest of the paper is organized as follows. Section 2 details the state of the art related to WSN applications for environmental monitoring. Section 3 describes the application scenario in order to obtain a better understanding of the main goals of the project. Section 4 gives a general outlook about food industry and its sustainability explaining the processes followed to carry out the EIA. Section 5 details the Cookies architecture and the new hardware and software needed to cover the requirements of this specific application. Section 6 shows how the measurements were done and the obtained results. Section 7 gives a summary of the different steps to close the loop. Section 8 shows the lessons learned during the project and concludes the paper.

State of the Art
In this section, the different solutions that already exist in the state of the art related to environmental monitoring will be detailed.
WSNs and environmental care have been always very close to each other, either because they have been evolving alongside one another during the last decade or because WSN features seem to suit very well into the environmental evaluation requirements.
One of the first references available of a WSN deployment for environmental issues is the habitat monitoring analysis made by UC at Berkeley University [5]. This is one of the first long-term and large-scale deployments in the state of the art with four-month duration and more than one hundred Mica2 motes using TinyOS. The main goal of this deployment was the observation of seabird nests and the effect of the microclimatic changes in its placements along the Great Duck Island in Maine. By using passive infrared (PIR) sensors to measure heat and by testing both temperature and humidity variations in the environment, they were able to evaluate the effects of a prolonged occupancy in the habitat during a long period of time, even though the burrow-deployed nodes failed in a couple of weeks. The difficulties of this kind of deployments are clear due to the large areas that need to be covered. By contrast, in the case of the coffee factory, the problems will appear due to the signal attenuation between nodes caused by the big amount of metallic tanks and machines that are all around the factory and not because of large distances.
When talking about environmental applications for WSNs, there is a relevant work made by the CSIRO Center in Australia [6] which covers both a complete set of environmental and agricultural applications and a complete review of past and future opportunities in WSN applications.
Some of these applications are cattle and ground water quality monitoring, virtual fencing, rainforest and lake water quality monitoring, and so forth. As well as the previous example, the first deployments were done using the Berkeley Mica2 motes. Although after using the Berkeley motes for these first cases, they built their own motes, Flecks, and its different upgrades. It is important to emphasize the big reliability of these nodes in long-term applications since they were working for almost one year and a half with only two maintenance visits. Apart from that, they used a very wellknown operating system, TinyOS, which can be very useful in these large-scale deployments when at the same time allows the programmer to build the application without taking care of the hardware behind. They even made a modification of the operating system called FOS. In the case of the SustenTIC project, the deployment consists of less than ten nodes, and the Cookies platform already has an application code based on custom libraries instead of a use of an operating system.
Since this paper is focused on a specific application deployment, there are other interesting references like the one called "The Game of Deployment" [7] and some others facing the differences between deploying a WSN in different scenarios. This first work shows interesting aspects in how the deployment should be faced by means of showing the problem as a game. In this game, the board is the map where the nodes have to be deployed and the counters are the nodes themselves. In this way, the map can be seen as a group of tiles with different placement restrictions where the way of placing them is a calculus optimization problem.
Even though through this kind of games the different scenarios can be generalized, it is possible to find other works showing that not all of them can be seen in the same way. The University of Trento has evaluated the huge differences between three different scenarios that at first glance seemed to be similar [8]. Those scenarios are a traffic tunnel, a mine tunnel, and a vineyard where they analyzed the communication problems caused by traffic, humidity, temperature, light, and how they affect the quality of the measurements in each of these different places. This is a very interesting study, since it shows both the problems and challenges of deploying a WSN and how these issues can change from one place to another. In the SustenTIC Project, International Journal of Distributed Sensor Networks 3 a very specific scenario is shown where these deployment troubles are faced and evaluated.
Apart from general environmental applications, it is important to analyze more in detail those applications focused in both water and air quality monitoring.
There are quite a few applications related to water monitoring. Most of them are being carried out in China, where pollution has become one of the biggest problems for the current government. For example, in [8], the authors propose a monitoring system to measure parameters such as pH, dissolved oxygen, conductivity, and temperature for aquiculture, river, and lakes monitoring, where the convenience of using this kind of systems in terms of price, flexibility, and real time processing is explained. Even though they talk about low price and low power, there is no reference neither of the power consumption of the node nor from the sensor prices which, in this case, can be very high. In [3], water parameters such as turbidity, pH, and so forth are measured in an artificial lake in the Hang-Zhou Dian-Zi University. Samples were taken every one hour during approximately one month, and the values were compared during night and day through five different points in order to compensate the measurement drifts. This is an other important difference. While taking measurements every one hour can be enough for a lake or a pond, in the case of water monitoring for waste water in a factory what is interesting is to have data every five minutes or so, to be able to generate alarms in case of a problem in the sewage plant occurs.
Another effort related to water monitoring applications is exposed in [2], with a study of a river watershed in North Carolina. They present an end-to-end hardwaresoftware structure to monitor water parameters through a large number of highly distributed sensor networks. The sensor nodes used are also stackable, like the Cookies platform, which allows some kind of modularity. In this case they installed in the same PCB both the conditioning circuits for six different analog sensors and a communication module based on an XBee platform. In the Cookies platform, the functionalities of the node are separated in layers so that it is possible to combine different sensors with different communication modules with different frequency of operation. The second layer of their platform consists of a general purpose microcontroller (uC) (AVR) and a basic power regulator with a noise filter. In the platform used in this paper, by contrast, both power supply and processing functions are placed in different layers to allow different combinations of powering and processing as it will be explained in Section 5. They also have an in situ collection and uplink infrastructure and a representation tool for the data management. It is also important to notice that they combine different kind of motes making a heterogeneous network formed by commercial data loggers and custom boards as the ones explained before.
To finish with the water monitoring applications, in [9], some recommendations of water quality measurements are detailed. This application shows a water monitoring system at river basin level based on WSNs. They also compare the advantages of these wireless systems with the lab methods, highlighting factors like price or real-time measurements. This study is part of a project called DEPLOY to demonstrate the use of a WSN in the river lee in Cork (Ireland). The main goal of this application is to comply with the regulation imposed by the European Water Framework Directive (WFD) by measuring the water quality in five different areas of the river.
Apart from testing the advantages of having continuous data from the river, they also want to demonstrate the reliability of the measurements by comparing the results of the multistation system when at the same time they also face problems such as fouling sensors, power management, or the study of available sensors for the application. These aspects will be also studied in this paper for this specific application.
While the majority of these applications are focused in natural environments, the deployment shown in the SustenTIC project is based on the requirements imposed by the government for industrial emissions and water discharges. This implies a very important difficulty due to the low amount of places with the same or similar features than the place of the final deployment, to make previous tests.

Application Scenario
In this section, all the details about the application presented in this paper are to be explained. This research work is part of a demonstration project funded by the Spanish Ministry of Industry, called SustenTIC, whose main goal is to evaluate the environmental impact in an instant coffee factory.
First of all, the features of the deployment scenario are shown. As it was mentioned before, the deployment will take place in an instant coffee factory in Spain. This factory can be considered as a medium size factory even though it is one of the most important instant coffee manufacturers in Europe. This kind of scenarios has a very important handicap when talking about wireless communications because of the problems caused by factory machines and the presence of metallic objects such as tanks, pipes, and intense trucks traffic.
The environmental measurements will take place in two different areas in order to cover two different kinds of quality parameters. The first place is the sewage treatment plant where both pH and water temperature need to be monitored. The main challenges in this measuring point are the corrosive environment and the sensor soiling, apart from the attenuations caused by metallic objects and the traffic around the sewage plant house which is placed in a separated building than the rest of the factory facilities.
In addition to the water quality measurements, it is also very interesting, from the environmental point of view, to monitor the gas emissions caused by the factory processes. The parameters chosen for this demonstration project are carbon monoxide, nitric oxide, and sulfur dioxide, since some of them can be very dangerous for human health and it is necessary for the factory to comply with the government regulations. There are three different chimneys where the measurements need to be done, these are (i) the boiler: carbon monoxide (limit value 500 ppm), sulfur dioxide (limit value 4300 mg/m 3 N), and nitric oxide; 4 International Journal of Distributed Sensor Networks (ii) the drying tower: carbon monoxide (limit value 500 ppm), nitric oxide; (iii) the toaster: carbon monoxide (limit value 500 ppm), sulfur dioxide (limit value 4300 mg/m 3 N), and nitric oxide.
It is important to notice that, even though the factory has two different production lines, the demonstration will be done only in one of them. In contrast with the previous water measurements, the main challenges in this case are due to the gas conditions inside the chimneys. The first problem is caused by the output temperature of the emitted gas which can be more than 100 • C when the temperature range of the sensors is only −30 • C to 50 • C. Therefore, to face this problem it is necessary to cool down the output gases. Another problem is the volume variation, since these gas sensors need approximately a constant flow to give a stable response. In order to solve this situation, the air needs to be sucked out from the chimney into a spiral tube and then into an isolated box where the sensor is located. Besides, the assembly must be protected from the atmospheric phenomenon.
Apart from the emissions and water quality measurements, it is crucial to know the temperature and humidity in different parts of the factory, either to compensate the gas measurements or to analyze the effect on the wireless communication quality. In this way, the router nodes will also act as sensor nodes in some cases.
In normal operation, the nodes are powered by lithium or AA batteries. However, due to the places where the nodes are located and the fact that the factory needs the information every four seconds, the power consumption becomes very high so that the batteries should be changed very often, and this is not affordable by the factory staff. Due to all of these reasons, some of the nodes are powered directly from the mains.
Taking into account the features of this scenario, it seems to be logical to think about powering some of the nodes by solar cells. Nevertheless, due to the big amount of coffee dust on the roofs, the cells would be covered needing a periodical maintenance to clean them up.
Once the peculiarities of the scenario are explained, it is important to know some information about the processes that are being carried out in the factory. The main processes involved in the coffee manufacturing are raw coffee recollection, toasting, blending, grinding, aroma extraction, drying, and binding [10]. All these processes are responsible of both gas emissions and polluted water discharges. In order to clarify the explanation, the coffee manufacturing processes are shown in Figure 1.
Even though raw coffee recollection is not one of the processes carried out on the factory, it is crucial to highlight that this first step is one of the most important when talking about the final coffee quality. Once the green grains have arrived to the factory, they have to be stored in different brown bags depending on the place of origin. This storage must be done keeping the temperature and humidity values in a very accurate range. The first transformation process is toasting. The raw coffee is introduced in the toasters where the temperature varies from 200 • C to 250 • C during 200 to 600 s. After this process, the toasted coffee is weighted and the value is compared with the previous one in order to know the amount of water that has been lost.
The next step in the coffee manufacturing is blending. By mixing different types of coffee grains, the manufacturers can define what makes them different from the others. This part is only known by the company as part of their know-how so it is extremely important because it defines the final taste of the instant coffee.
Once the mixture is done, all the coffee grains are grinded together and stored in another warehouse. After being stored for a while, the next step is the aroma extraction, which can be done in a few different ways. The last three processes are aroma recovery, drying, and the binding of the coffee dust into bigger particles.
Due to all of these transformation processes, both gas emissions and water pollution must be measured to comply with regulation and to know as much as possible about the efficiency of the factory.

Sustainability Parameters.
Today, the food and drink industry is the single largest manufacturing sector in the EU in turnover, value added, and employment terms, ahead of automobile, chemicals, and machinery industry. It is also the second leading manufacturing sector in the EU in terms of number of companies [11]. Despite the fact that food industry nowadays represents a crucial motor for the development of the economy and society, as an industrial process, the sector reports serious environmental, economic, and social impacts. Environmental degradation (water, soil, climate), competition for resources, agricultural subsidies, and trade barriers, unfair distribution of revenues to the different actors in the food production system and the integration of the primary sector into the international economy, threaten the sustainability of many food production systems.
With regards to the environmental sustainability, the food industry is a major energy user (food sector consumes about 10-15% of total energy in industrialized countries) and a major user of water (around 8% of all water used by the entire industrial sector). Moreover, the food and International Journal of Distributed Sensor Networks 5 drink manufacturing industry accounts for about 1.5% of total greenhouse gases emissions in the EU-15, where direct emissions account for 0.9%. This sector is also a significant source of waste generation (the food and drink manufacturing sector accounts for about 3.25% of overall waste generation in the EU) [12].
The whole production process of instant coffee is energy intensive (in the coffee factory 11.99 kW natural gas/kg product and 1. 57 kW electricity/Kg product). Concerning the air emission, the outlet of both the roasting and drying processes are CO 2 , SO 2 , NO x , and volatile organic compounds (VOCs). Solid wastes are mainly produced during the extraction stage, with around 40 tons of coffee wastes produced per day. Water usage is an issue in the production of instant coffee as water is used as a solvent in extraction processes and during the cleaning processes. This cleaning generates waste water containing soluble and insoluble organic material and SS [13].
For these reasons, nowadays, the idea that methods and techniques must be designed on the concept of sustainability has gained acceptance and considerations of sustainability will guide future developments in European industry and therefore in the food sector [14]. In that sense, the EU has placed increasing emphasis in the need of integrating sustainability in the sectoral policies, becoming the sustainable development, which "meets the needs of the present without compromising those of future generation," a central objective of the European Commission. In this framework, the European Council in Lisbon (March 2000) launched the Lisbon Strategy the main pillars of which are economy, society, and environment.
For the assessment of progress towards sustainable development, several sustainability indicators have been employed since the 1992 Earth Summit recognized the important role that indicators can play in helping countries to make informed decisions concerning sustainable development. This recognition is articulated in Chapter 40 of Agenda 21 which calls on countries at the national level, as well as international, governmental, and nongovernmental organizations to develop and identify indicators of sustainable development that can provide a solid basis for decision-making at all levels [15].

Impact Analysis Methodology Tools.
Regarding the environmental protection, the EU has a set of common rules for permitting and controlling industrial installations in the Directive 96/61/EC on Integrated Pollution Prevention and Control (IPPC) whose main objective is to secure a high level of protection of the environment taken as a whole [17]. One of the sectors where the implementation of this directive is nowadays more crucial is the agrofood sector, since environmental impacts occur in all the processes within the food supply chain.
Nowadays, a large number of tools for the assessment of environmental impacts are available, such as life cycle assessment (LCA), material flow analysis (MFA), environmental impact assessment (EIA), and system of economic, environmental auditing and environmental accounting [18]. LCA is the most widely tool employed for the quantification of the environmental impacts nowadays.
LCA is a "compilation and evaluation of the inputs and outputs and the potential environmental impacts of a product throughout its life cycle" [19]. Therefore, LCA as analytical tool allows the assessment of the environmental impacts and resources employed throughout the whole life cycle of a product. The International Organization for Standardization (ISO) in the ISO 14040 series has standardized a framework for LCA.
LCA, while increasingly accepted and more facile to perform due the databases and software systems, faces some important challenges over the coming decades including evaluations and comparisons of the results obtained through different methodology's variants, uncertainty and data quality, LCA sophistication. Methods, operational procedures, and concepts for the implementation into business processes need more attention and research, in order to enable the wide-scale exploitation of LCA's potential [20].
For about 20 years now, the Life Cycle Assessment (LCA) method has successfully been used to analyze agricultural production systems and food chains. Although progress in terms of methodological robustness and data availability and reliability has been widely demonstrated [21], the application of LCA methodology to the food and drink sector has several weaknesses. An effort must be done to explore the suitable functional units, system boundaries and allocation procedures for LCA in food production to facilitate a valid comparison between different products [22].

Dynamic System for Sustainable Transformation Processes.
According to the Reference Document on Best Available Techniques in the Food, Drink and Milk Industries of the European Commission, (August 2006), environmental management tools, identified as a general best available technique for the food and drink sector, require checking systems in place to evaluate the effectiveness of measures implemented to minimize consumption and emission levels and to monitor and review their effects periodically. By ongoing monitoring, the effectiveness of the chosen measure can be periodically checked to see whether it is meeting the set targets, for example, consumption and emission performance levels. Underperformances can thereby be detected and rectified. Also, monitoring shows trends and can identify priority areas for improvement.
The main environmental impact categories that are nowadays monitored in the food sector are natural resources depletion, global warming, ecological toxicity, solid waste, embodied energy, acidification, human toxicity, smog formation, indoor air quality eutrophication and ozone depletion. the following indicators are normally measured to monitor the impact categories previously mentioned.
(i) Resources Consumption, The main resources consumed are water, electricity, and fossil fuels. Their measurement and control by the company tends to be simple because industries typically acquire the consumable resources from other companies and transaction data are documented and recorded. (ii) Wastewater An adequate monitoring of the wastewater can control both the maximum concentration values of chemical parameters such as the quantification of the quantities discharged. The measurement and control of physical and chemical parameters of the wastewater is often achieved by direct methods.  [25]. There is also a standard that establishes standard procedures for the measurement of the characteristics of the flow of gases: UNE 77225 : 2000 [26]. (iv) Subproducts/wastes. The main wastes generated by the food industry are organic waste, waste oils, batteries, laboratory waste, solvents, glass, plastics, paper, carton, and so on.
Several approaches have been made for the development of technologies and methodologies for the monitoring of emissions and consumption levels of energy, water, and wastes throughout the whole supply chain as follows.
(i) In case of energy consumption, data are normally obtained from the monthly utility bills which are irregular and cannot quantify any on-site energy consumption, so researchers in this field are focused nowadays in the development of real-time web-based monitoring systems including a data logger that monitors sensors and sorts their values. (ii) Regarding environmental impacts generated by wastes, researchers are mainly focused in monitoring wastewater quality. Sampling and laboratory analysis are not well adapted to wastewater quality monitoring in a process control or hazards prevention context, for which on-line/on-site measurements are preferable [27]. Some of the rapid toxicity tests available today require certain conditions to function properly or their results do not always correlate with other methods.
(iii) Systems and methods for monitoring and controlling fluid consumption in a fluid-supply system are disclosed using one or more sensors for generating signals indicative of the operation thereof. Systems and methods herein involve one or more sensors in a fluid-based system for generating signals indicative of the operation thereof.
As a summary, existing systems for the monitoring and reporting of environmental parameters are based in the collection of data obtained from irregular sources such as monthly utility bills or in robust and dependable sensors. Therefore, those systems are irregular, cannot quantify any on-site parameter, and do not assure continuous functionality and data transmission.

Cookies Platform Description
The Cookies WSN platform [1] consists in four different layers that can be changed depending on the application making the modularity its best feature. Each of these layers matches with a different functionality: power supply, communication, sensing/actuating, and processing.

General.
As it has been said before, a Cookie is a HW platform for WSNs. Every Cookie is a node of the network and is composed of four main layers. This node has been used already in a security application, which can be seen in [28].
Depending on the requirements of the application, the platform can be adapted by changing these layers. In this way, it is very easy to obtain an optimum design in a very short time. It is not the purpose of the authors to deeply describe the Cookies platform, as they were analyzed in other works like [1] and [29].
In the application studied in the present work, different modifications have been carried out, demonstrating the advantages of such a solution, specifically in sensing and power supply layers. These developments are detailed in the following subsections.
In Table 1, a comparison between different WSN platforms can be seen.
The platform Cookies is based on an 8051 uC from Analog Devices and a Spartan 3 FPGA from Xilinx, which make it one of the most powerful platforms in the state of the art. Moreover, its modularity allows to use it in prototyping stage and to proof different concepts before deployment in a short time. Due to its modularity, only part of the platform was redesigned to make it suitable for the application presented in this work.

Hardware Developed for This Application.
In order to comply with the requirements imposed by this specific application, it is necessary to design two new layers of the platform. First of all, a sensor layer needs to be adapted to face the water quality measurements, and, on the other hand, another sensor layer has to be developed to measure the gas emissions. As it was mentioned before, these new measurements are In this application, even though the nodes are normally powered by batteries, it will be necessary to mix the batteries with nodes powered directly from the mains, since it is required that the measurements are taken every four seconds and the power consumption is quite high (about 70 mA).

Water Quality Measurements (pH and Temperature).
The pH value expresses the proton concentration in a water solution given by the drop voltage between two electrodes. This drop voltage appears when two different liquids with two different pH values are separated by a crystal membrane. Due to this reason, the pH sensor is made of two different electrodes: a reference electrode immersed in a known solution and the measurement electrode in contact with the liquid sample.
In order to obtain the pH value it is necessary to measure the drop voltage between both electrodes but it is crucial to take into account that this drop voltage depends on the temperature of the liquid following the expression shown below: where pH(x) is the target value, pH(S) is the pH value, of the reference solution (pH = 7), (Es − Ex) is the drop voltage, F is the Faraday constant (F = 9.6485309 · 10 4 C · mol −1 ), R is the ideal gas constant (R = 8.314510 J K −1 mol −1 ), and T is the temperature of the liquid sample. In this way, the sensor must be capable of measuring both the drop voltage between the electrodes, and the temperature of the liquid. The sensor chosen is the InPro 4260/120 manufactured by Mettler. It is a passive sensor since it does not need to be powered externally. The voltage response can be either positive or negative, so that it is considered as a bipolar sensor. Another important feature of this kind of sensors is the huge impedance that can reach values of 10 MΩ or even 1000 MΩ. Due to this fact, it will be necessary to measure the voltage response through a very high impedance operational amplifier. The sensor includes a resistance temperature detector (RTD hereafter) Pt100 to measure the temperature and to compensate the value of the drop voltage.
Since this is an analog sensor, the response signal needs to be adapted to the voltage range understood by the ADC (integrated in the microcontroller of processing layer) which is 0 V-2.5 V. As it was said before, the response signal can be either positive or negative which obliges to have negative power supply in the conditioning circuit. The power supply of the platform is given by the power supply layer, but it is only positive (1.2 V, 2.5 V, 3.3 V), so, in order to be able to power the circuit with a symmetric voltage of −3.3 V to 3.3 V, it was necessary to set up a charge pump.
The sensor output consists of seven different wires: crystal electrode, reference electrode, ground, cable shield and three cables for the pt100 sensor.
Both electrodes have to be connected to a voltage follower made by a very precise operational amplifier due to the very high impedance of the sensor. After that, the drop voltage between them is adapted to the desired range by an amplifier stage with variable gain and offset.
At the same time, the RTD response has to be measured. Since it is a three-wire RTD connection, the measurement circuit is very simple (Wheatstone bridge). Besides, there is a cable shield to protect the signal against noise and, of course, the circuit ground.
The voltage response of the bridge will be also amplified and corrected with an offset in order to adapt it to the ADC range. In Figure 2 the PCB for pH and water temperature measurements is shown.
Once the circuit is designed and validated, the next step is calibration. First of all, it is necessary to calibrate the temperature measurement. To do so, a buffer solution with a known pH value was introduced in a special chamber (in the Laboratorio Central Oficial de Electrotecnia, LCOE), increasing the temperature and measuring the sensor response.   After that, the theoretical values were compared with the experimental results and the measurement was corrected as shown in Figure 3.
After temperature calibration, the sensor was immersed in different buffer solutions with known temperature in order to obtain similar curves and to be able to make the correction of the values (Figure 4).
The admissible pH values in the sewage plant can vary from 5 to 8, 6 being the optimum value. The temperature will oscillate between 30 • C and 40 • C.

Air Quality Measurements
Gas Emissions. The gases that are to be measured in the factory are Carbon monoxide is a poisonous, colorless, odorless, insipid, and very toxic gas. It is usually emitted because of incomplete combustion processes, and it is very dangerous since it replaces the oxygen in the hemoglobin causing what is commonly called the "sweet death." The limit value to comply with regulation in the factory is 500 ppm.
Sulfur dioxide is a colorless, irritant, toxic gas with a very particular suffocating smell. It is the main producer of the acid rain because it is transformed into sulfuric acid in the atmosphere. The maximum value to comply with regulation is 4300 mg/m 3 N.
Nitric oxide is also an irritant and toxic gas produced during combustion processes. Normally it can be very dangerous when oxidized into nitric dioxide.
The sensors that have been chosen for these measurements are manufactured by a British company called Alphasense: (i) carbon monoxide (CO-BF), (ii) sulfur dioxide (SO 2 ), (iii) nitric oxide (NO).
All of them are electrochemical sensors. Those sensors consist in three different electrodes with a thin screen of electrolyte between them.
The first one, the working electrode or sensing electrode, is the one in contact with the outside gas, so that it is the real surface where the reduction or the oxidation occurs. In this way, a current which is linearly proportional to the volume of the toxic gas is generated. The second electrode is called the counter electrode, and it is in charge of balancing the reactions on the working electrode generating the same current but in the opposite sense.
The last one is the reference electrode. This one is to ensure that the working electrode is always working in the correct region of the current-voltage curve. By keeping the potential of the working electrode as stable as possible, the spoilage of the sensor can be dramatically reduced when at the same time both linearity and sensitivity are increased.
Those are also analog sensors, so that it is also necessary to adapt the signal to make it fit into the ADC voltage range. The typical conditioning circuit used for this kind of sensors is known as potentiostatic circuit, shown in Figure 5.
This potentiostatic circuit can be divided in three different parts.
(i) Control. This is the upper part of the circuit. Since it is the part connected both to the reference electrode and to the counter electrode, it will be in charge of giving the necessary current to maintain the equilibrium between the working electrode and the reference one. In this way, when the circuit is turned on, the FET is set in high impedance, and both electrodes are fixed at the same voltage. In order to be able to maintain good linearity and sensitivity, the amplifier must be a very precise operational amplifier with a very low value of bias current.
(ii) Current Measurement. This corresponds with the lower part of the circuit. When the working electrode is exposed to the toxic gas, an oxidation reaction occurs creating a current response. This current will be converted into a voltage response which is proportional to the toxic gas concentration in the transimpedance amplifier.
(iii) FET. The transistor works just to avoid the polarization of the sensor when the circuit is not powered. When the circuit is turned off, the JFET creates a shortcut between the working and the reference electrodes to guarantee that they have the same voltage. In Figure 6, a node with the potentiostatic circuit can be seen.
Once the circuit board is finished, the sensors must be calibrated. The calibration process consists in doing two different tests to find two different working points. Two points will be enough since the sensor response is linear.
The goal of the first test is to find the zero value that corresponds with the sensor response when there is no target gas. This test was done in the lab, considering that the gas concentration is negligible compared with the target values. On the other hand, the second test was done to find the sensor response using a gas bottle with a known concentration value. With the information given by these two points, the response line can be drawn and compared with expected one in order to be corrected by software. Another important issue is how the temperature affects the measurements. Due to this fact, it is crucial to measure the temperature and to correct the value according to the curves given by the manufacturer.
In order to clarify the process, a test example is shown in Figure 7.
According to the response curve shown in Figure 8, the voltage value takes about 2 minutes to be stable after the circuit is turned on. It is important to notice that the older the sensor is the slower the response becomes. With a new sensor, the response time should be much lower, but it also depends on the volume and test conditions. As it can be seen, the voltage value for 300 ppm is 2 V, which corresponds with the expected value.
Air Temperature and Humidity. The effect of the air temperature and humidity on wireless communications can be very notable. As it was explained above, the Cookies communication modules are based on the ZigBee protocol which is highly affected by these parameters. By monitoring both temperature and humidity in some points of the deployment, it is possible to compare how the communication quality indicators such as the link quality indicator (LQI) and the receive signal strength indicator (RSSI), varies over the changes in the environment. Besides, the gas temperature on the chimneys is necessary to compensate the measurements taken by the gas sensors. The sensor used to measure both air temperature and humidity is the SHT11 manufactured by Sensirion (included in the Cookie platform; see Figure 9). This is a digital, low-power, fully calibrated sensor so it is very convenient for this WSN application. The output signal is processed by the FPGA in the processing layer. Since it is a prototype version of the platform, the processing layer includes an FPGA which is not the best solution in terms of power consumption, at least in the current platform.

Software Description.
The application software is composed of two different groups. A WSN distributed application, running on the nodes of the network, and a management application, running on a PC. Working as an interface between the network and the PC, a special kind of node called sink acts as a gateway. This node processes and translates all the information sent by the sensor nodes to make it compatible with the application running on the computer. Figure 10 shows the basic structure of the application. The WSN distributed application includes three different elements: sensor nodes, router nodes, and the sink node. As it was reported before, the sink node processes and translates the information received from the network. This means not only to transform the binary information received to their corresponding physical magnitude but also to process the messages related to network management and sending the relevant information to the management application. Every time the sink sends a message to the management application, it also attaches a timestamp. This timestamp refers to the start time of the network which is different from the GMT time.
Apart from the processing tasks, the sink node acts like the coordinator of the network. This implies that the application of the sink node needs to handle the startup of the network and in case of a network collapse it has to create a new one.
On the other hand, the router nodes send the received messages to the sink node. This is done on the network level so that the application does not have to handle the routing of the messages. Sensor nodes application main tasks are to control the activation of the processing unit, reading from the analog and/or digital sensors and, once all the measurements have been made, sending the data to the coordinator. Another task will be processing all the messages received from the communication layer while the node is active.
Router and sensor nodes application share some common tasks on the commissioning side. These are controlling the status of the node, monitoring batteries, warranting the presence of the node in the network and notifying the node type to the sink node.
In order to accomplish with all the tasks, a structured application message mechanism has been designed. This mechanism is based on 4 basic messages.
(i) Commissioning messages in order to keep trace of the quality of the network, battery life, and so forth.
(ii) Error message used to communicate to the coordinator any unexpected situation, that is, malfunctions in sensors.
(iii) Node identification. These types of messages are used by the monitoring application to assign the appropriate indicator in the visualization interface. This message is sent when the node joins the network. It only contains the sensor node descriptor.
(iv) Sensor measurement. These messages contain the measure values of all the sensor of a unique node, and no separate values for different sensor of the same node can be sent; that is if a node has sensors of pH and temperature a message has to contain values for both magnitudes, ph and temperature cannot be separate in two different sensor measurement messages.
In order to allow a simple decoding mechanism, a 1 byte application message header is used in all the messages. The structure of the header is shown in Table 2.
These different fields are explained below.
(i) Type. This section indicates the message type; it corresponds to one of the four messages described previously.
(ii) Descriptor. This field informs about the data type contained in the message. In the case of messages containing measurements, it contains the type of the node. This attribute can change its meaning depending on the type of nodes used in each application. For commissioning messages, it indicates what information is inside, communications quality, battery life, and so forth.
(iii) Data length. This is the number of data packets included in the message. Every data packet is 2 bytes length. The data is sent in binary format, without conversion to native units (Celsius degrees, pH, etc.). This conversion will be done in the sink node before sending the messages to the management application.
(iv) Data. This is the information given by the sensors, such as communications quality, battery life, and so forth.
In the application presented on this document, five different types of nodes are used, including router nodes and four different types of sensor nodes (pH and water temperature, NO SO 2 , and CO, and ambient humidity and temperature). This implies the use of five different descriptors.
The WSN distributed application works as follows.
(i) The Sink node creates the network.
(ii) Sensor nodes and routers join the network, and then they send an identification message to the sink.
(iii) Periodically (depending on the sensor type), sensor nodes activate their processing unit, read the sensor data, and send the acquired values to the sink. Once this process has finished, the processing unit goes back to standby mode.
(iv) Periodically, router and sensor nodes send commissioning messages to the sink node.
(v) When a message is received in the sink node, it processes the information, attaches a timestamp, and sends the result to the management application.
The management application is used as a visual interface between the user and the sensor network. It is also used as a data logger to create log files with the data sent by the sink. Figure 11 shows the interface of the management tool. The main characteristics of the interface will be presented below.
On the top left part, the configuration interface for the serial port is placed, which communicates the management application with the sink node.
The left-side bottom includes the network status table. This status table shows the information about the nodes that have joined the network, the node identifier (node ID), type (translation of the binary descriptors to its matching names), timestamp of the last message received from the node, location of the node (it has to be filled by the user; cookie nodes do not have geolocation capabilities yet), and the status. The status is used to shown if the node still connected to the network (status OK) or if the node is disconnected, that is, by a temporary fail of communications, or completely out of batteries, which will be shown as status ERROR.
On the right side, the indicators of each different node used in the application are placed; when an identification message arrives to the sink, it extracts the node identification from the message and the descriptor enclosed and sends both to the management application in order to allow it to assign an appropriate indicator depending on the sensor type. Each indicator has only a node attached; in this way all the data received from a unique node will be shown in the same display.
As it was explained before, the management application has another important task, storing all the information sent by the sink to the computer. There are mainly two different groups of messages, the ones related to sensor measurements and those related to the network commissioning, so the application stores the information in two separate folders depending on which group the message belongs to. The application handles the creation of new files for both types of messages with a time interval set by the user.
To conclude, the main features of the software application are summarized as follows.
(1) There are two groups in the software side, the application running in the nodes of the network and the management application running on the computer.
(2) The distributed application main task is to measure environment parameters, and not only sending the information to the sink but also keeping the communication structure alive.
(3) The sink centralizes the information processing and sends the data to the management application.
(4) The management application shows the information about the status of the network and the instant measurements of the sensor nodes in a visual interface, but it also stores all the messages received separating the data related to sensor measurements and the data related to the commissioning of the network in different files.

Deployment, Measurements, and Results
In this section, the results of the measurements taken in the factory are detailed. In order to test different parameters of the WSN platform, the deployment was carried out in two different tests. The first experiment was done to cover the perimeter of the factory using the fewer amount of nodes possible. On the contrary, the second test was a complete deployment where both air quality and waste water quality were measured while all the data was sent to a sink node placed on the factory offices.

Test 1.
In this first test, 4 nodes were deployed as seen in Figure 12. The features of each one of these nodes are (1) sensor node, measuring pH, temperature of the waste water, and power consumption, (2) sensor/router node, measuring air temperature, humidity, power consumption, RSSI, and LQI to study the quality of the communications, (4) sink node to harvest all the information from the rest of the nodes.
During this test, node no. 1 was left on the sewage plant as the sink node was getting further following the path shown in Figure 12. Once the sink node reached the north-east corner of the factory, communication was lost due to signal attenuation caused by the buildings and trucks in this side of the factory. Then, node no. 2 was left on this corner acting as a router node between the one on the treatment plant and the sink node (the distance between node no.1 and node no. 2 is 128 m). The sink node was then carried until next corner where the communication was lost again due to interferences (distance between node no. 2 and node no. 3 is 160 m). Finally, node n no. 3 was left on the next corner while the sink node was carried to the last one as seen in Figure 12.
In Figure 13, some measurement results are shown. The pH value oscillates from 5.5 to 6 pH units while the temperature of the water varies from 30 • C to 32 • C. The power consumption changes depending on whether the node is transmitting or receiving data. It is important to take into account that 4 nodes are enough for covering the perimeter of the factory because there are only a few sources of signal attenuation between them. When the path has to cross the factory, there are a lot of buildings and metallic tanks where the signal can be lost so that a bigger amount of nodes is necessary.
In Figure 14 and Figure 15, the results for the RSSI value can be seen. In Figure 14, the received signal strength indication tends to decrease due to the interferences caused by the trucks that were working while the test was done. In the case of Figure 15, the interferences were only caused by one or two trucks passing by, because there was not a lot of activity in this place in this specific moment. Another important question is that, even though the node no. 3 was placed in the south-east corner, at the end of the experiment the node no. 2 was directly connected to the sink node. In this way it is possible to notice that the range of the nodes can be quite high even facing the attenuation caused by buildings and the factory machines. Nevertheless, this connection was not very reliable so it was considered as a better option to include an alternative path for the cases where the interferences were bigger.

Test 2.
The second experiment consisted of 5 nodes (Figure 17), with the main goal of monitoring water quality, emissions on the drier chimney (Figure 16), air temperature, humidity, and the communication quality in different places of the factory. As it was explained before, some of the nodes were to be connected directly to the mains. In this case, only nodes no. 1 and no. 2 were connected in this way.
The sink node was placed in the office buildings in order to collect all the data harvested by the rest of the nodes. It is important to highlight that, once the node no. 1 and node no. 2 were deployed, when node no. 3 was going to be placed on the roof, the communication between the sink node and node no. 2 was lost. This happened because of the attenuation inside the building. Once the node was on the roof, it rejoined the network automatically.
In Figure 18, the measurement results on the drier chimney are shown. Even though the experiment time was quite short, due to the temperature of the gas, it is possible to see the time necessary for the sensor to give a stable measurement after being powered. The experiment time could not be longer because the system needed to cool down the gas is not installed yet. This time is, in this case, 3 min. although it can be reduced using a new sensor with a nonworn membrane. It is also possible to notice that after 5 minutes the gas concentration started to decrease as the smoke of the chimney did the same.
Another important aspect that it is necessary to take into account is the sensor fouling ( Figure 19). After being immersed inside the waste water in the output of the sewage plant, the membrane of the pH sensor was covered by coffee grounds. This caused a drift on the sensor measurement so the membrane needed to be cleaned up. After having the sensor immersed in the waste water for an hour, the membrane was partially covered so the measurements were not trustworthy. The way to solve that is setting up a shield around the sensor to filter the floating matter, but this is still future work. In this first deployment, the sensor was cleaned manually after one hour, since the drifts at this time were more than 40%. The correction of this kind of drifts caused by the dirtiness is quite difficult since the sensor fouling is hard to foresee. The only solution seems to be preventing the sensor from the dirtiness by using the shield mentioned above.

Challenges of the Deployment.
When facing this kind of real applications, a lot of challenges appear along the way. First of all, it is fair to say that it is the first time the Cookies have to deal with this kind of environmental measurements. At the beginning, the adaptation of these chemical measurements was really tough, since the nature of the sensors was completely unknown for the team. Due to this reason, a big effort in order to understand how the sensors worked was necessary. Another challenge related to these sensors, is that the majority of the pH ones always include their own signal conditioning systems which, of course, are not compliant with the Cookies platform. The documents and guides are not prepared for using only the sensor so it was difficult to adapt the signal given by the sensor to the platform needs. A factory is not an ideal scenario. What can be really easy in a laboratory can become a real problem when deploying the network in such an unfriendly environment. In a factory like this one, the production line cannot be stopped. This fact can be really uncomfortable when trying to set the nodes in the test points.
An example of how difficult the scenario can become is the signal attenuation caused by the metallic objects all around the place including the trucks in charge of delivering and rubbish recollection in the factory. In the initial planning, most of the router nodes were placed inside the buildings. Nevertheless, the team realized that placing the nodes outside the coverage was improved, so fewer devices were needed. Even with these trucks moving around the nodes, the attenuation was important but not enough for interrupting the communication. In the rare cases where the communication was lost, the nodes rejoined the network in a few seconds so no important information was missed.
The best way to solve this situation is to characterize the deployment environment before the network is set up. This is one of the biggest challenges today in WSNs, and several works are being carried out by the scientific community to find a suitable solution, in terms of planning, simulation, and maintenance tools for WSNs.
Temperature conditions on the test points were also a big deal when trying to organize the deployment. In the case of the gas emissions, the temperature inside the chimneys was really high (around 100 • C), so the sensors could not work without cooling the air first. That is why the results were taken only during a short period of time. This problem needs still to be solved because the platform to cool the air down is being studied by the factory.
Other important problem was related to power consumption, since the measurements had to be taken every three minutes. Taking into account that the normal way to power the nodes is using either AA or Lithium batteries, with such a big amount of data transfer, the batteries would need to be changed every two days. Due to this reason, the nodes with the biggest power consumption were directly connected to the mains.
Regarding the web tool developed for the data storage and evaluation, it was necessary to install some programs in the PC in charge of receiving the data in the factory. The main purpose of this software is sending the information automatically from this PC to the Inkoa server where the data is uploaded to be used by the web tool. In order to do so, some ports of the private network of the factory had to be opened. This was a problem, since it opened a path for possible illegal users.

Closing the Loop
The data obtained from the WSN will serve as input to a software application ( Figure 20) whose main functionality is the development of environmental impact studies at unitary process and company level in vegetable processing facilities. The software application will enable the customer the assessment of the environmental sustainability of their production processes under a life cycle approach and the identification of processes' impacts on the environment. The software application is structured into 2 different modules.
(i) Monitoring module to compile and record data about the end users' consumption and emission levels and that will be supported by the WSN enabling the measurement of specific parameters.
(ii) Assessment module to perform the life cycle assessment of a product based on ISO 14040 and 14044 methodology and enabling the identification of environmentally unfriendly production processes as well as prevention and minimization options. For the life cycle impact assessment, the software includes the method "Eco-Indicator 99" that enables the assessment of the damage caused by a product system to human's health and the ecosystem quality and resources.
To allow communication between the sensor network and the software platform, it is necessary to dispose of a dedicated application invisible to the user, which runs through a scheduled daily task. At the time the application is running, it accesses to the monitoring files, reads them one by one, and connects to the database software application to store them in a table. In this table, for each record, the application saves the date and time of measurement, the sensor, the node, and the measurement made.
For the development of the software application, a web server has been employed, performing bidirectional and/or unidirectional and synchronous or asynchronous connections with the client side. The services offered by this web server are FTP, SMTP, NNTP, and HTTP/HTTPS. The web pages that collect the software application have been published in the same computer where the web server has been set up. The web pages are accessible both local and remotely. The server services have provided the tools and features necessary to easily manage the web server.
For the database management, a system based on entityrelationship model has been used. Its languages for query are T-SQL and ANSI SQL. The version of the database used includes increased security, integration with power-shell, transparent data encryption, data auditing, data compression, and reviewer of Transact-SQL and IntelliSense languages. It also includes new data and functions types (spatial data, new data on time (date time 2 and date time offset), types of hierarchical data, etc.).

Conclusion and Lessons Learned
This paper has shown a real application of a WSN. Many contributions are presented about the use of a custom platform, such as the adaptation to a heterogeneous network, the study of an interesting industrial field which is applicable worldwide in many installations, the integration of management and control tools with WSNs, and so forth. This paper may serve as a starting point for many replicas of environmental control applications. A closed loop has been presented where three different partners have joined efforts to achieve a complete monitoring system based on a nonintrusive and unattended technology. Thanks both to the chemical nature of the measurements and to this very specific industrial application, this project has been very didactic for the team since it was necessary to learn about very different topics to face all the requirements. Apart from that, the application has served as well in the development of the Cookies platform which is now capable of facing very demanding applications in terms of reliability and adaptation to the measurement of new parameters. Besides, deploying the network in a very hard place in terms of communication reliability has been very important in order to know more about the limitations of the platform and, in this way, being able to improve or change some aspects.
This application opens a wide opportunity in the environmental control of food industry which is one of the strongest industries around Europe while it continues with a very interesting research line in the WSN field.