A low-cost IoT network to monitor microclimate variables in ecosystems

1. Microclimatic and macroclimatic data differ, and microclimatic data are most useful at short time intervals (30-min scales rather than daily/monthly scales). 2. We developed an end- to-end system to acquire such data at a high temporal resolution, transfer them to a server through an Internet of Things network using low-cost technologies, and make them available with dynamic graphical visualizations and download capabilities. 3. The system has been used for 2 years to monitor environmental variables in con - trasting agroecosystems in France, Bolivia and Kenya. It has been proven to be reliable and supports the mismatch between macro-and microclimates. 4. This low-cost Internet of Things system can capture the microclimate in contrasting environments with accuracy comparable to commercial solutions, and great flexibility in data processing. It thus constitutes a possible solution in an academic context and has the potential to be used by a broad audience of scientists interested in capturing environmental variables in real time and at a high temporal frequency.

Despite numerous studies describing the mismatch between macroclimate temperature data such as WorldClim (Hijmans et al., 2005) and temperature experienced by most species in ecosystems (Bennie et al., 2014;Buckley et al., 2013;Faye et al., 2017;Haesen et al., 2021;Hannah et al., 2014;Kearney et al., 2014;Lembrechts et al., 2019), and modelling efforts to downscale temperatures from macroclimate (Haesen et al., 2021;Kearney & Porter, 2016), the lack of microclimatic empirical data impeded the development of models that can be transposed to a finer scale (Rebaudo et al., 2016).If the spatial mismatch of temperature is a challenge, the same goes for the temporal resolution of the acquisition of temperature which is generally lower than that desired for the study of the response of species to environmental variables.A study applied to the butterfly Pieris napi L. (Lepidoptera: Pieridae) demonstrated that microclimate data led to a smaller prediction error in observed development time compared to macroclimate data only if the sampling intervals in temperatures were very small, that is, with temperatures acquired every 15 to 30 min (Schmalensee et al., 2021).This temporal resolution is important to account for small changes in temperatures that would affect species life history traits and that cannot be represented by the mean temperature because of the nonlinear form of the relationship between temperature and life history traits, also known as the Jensen's inequality (Colinet et al., 2015;Schmalensee et al., 2021).
Jensen's inequality is valid for all biological processes including nonlinear responses and applies just as much to arthropods as to plants (Ruel & Ayres, 1999) or vertebrates (Pickett et al., 2015).
Monitoring climatic environmental variables at a finer scale and higher temporal frequency to reduce the temporal and spatial mismatch between experienced and measured values has practical limitations.To capture the spatial heterogeneity of temperature within a plot, thermal imagery has been employed from the ground or from an unmanned aerial vehicle (UAV) with success to highlight the importance of crop canopy microclimate for agricultural pests (Faye et al., 2016(Faye et al., , 2017)).Despite substantial decreases in the price of UAVs and the associated thermal cameras (Bossoukpe et al., 2021;Giménez-Gallego et al., 2021), using UAVs to obtain images with sufficient resolution might be too expensive in most cases.Also, the downside of UAV imagery is the lack of desirable temporal resolution knowing that temperature can change significantly over a short period of time (15 to 30 min required for example in insects, see Schmalensee et al., 2021).Even if flights can be automatized, they cannot reach a temporal frequency required for most animal phenology or population dynamics modelling while minimizing prediction errors (Schmalensee et al., 2021).An alternative would be to reduce the spatial resolution and use classical temperature data loggers, which have been widely used in agrosystems and other ecosystems as well, but the cost remains prohibitive for wide adoption, especially if data needs to be centralized in real time on a server.To promote open science, here we suggest to use existing technologies to build low-cost Internet of Things (IoT) microclimatic stations to reduce the mismatch between macro-and microclimatic conditions experienced by most living organisms.It includes a complete system, from data acquisition to client visualization and data extraction for analysis and phenology or population dynamics model building.
Using low-cost technologies to monitor microclimate is nothing new, and several solutions in the recent years based either on microcontrollers (Mickley et al., 2019) or single card computers have been developed for that specific objective (Sethi et al., 2018) or applied to broader applications in ecology (see the review of Raspberry Pi applications for biologists by Jolles, 2021).However, to our knowledge, no development covered the whole cycle of data life, from data acquisition to data visualization, and taking into account the local constraints and diverse situations to power the devices and transfer the information to the server.While we focus on key features, extended materials and methods can be found in the Supporting Information section which contain all the information to reproduce the IoT microclimatic monitoring network, together with links pointing to upto-date software and codes.The purpose of this study is to evaluate whether an IoT low-cost system can be used to monitor environmental variables in the context of an ecological scientific study in diverse environments (France, Kenya, and Bolivia).These environments are drastically different and are characterized by seasons and temperatures with contrasting averages and amplitudes.These are therefore locations of interest for testing the applicability of this microclimate monitoring system.Our specific objective is to monitor the microclimate experienced by arthropod pests in agroecosystems.

| Overview of the IoT network
The Internet of Things (IoT) is a network allowing objects to connect to the Internet and exchange information through standard protocols (Hittinger & Jaramillo, 2019).The advantage of IoT over other information exchange technologies such as the Global System for Mobile communications network (GSM) is to be able to access information through Internet at a lower cost.The obstacles to adoption remain the technical complexity of deployment and the energy dependence.Here, we propose to meet the challenges related to technical complexity while optimizing energy dependence.Data are centralized on a server with a PostgreSQL database (any objectrelational database system can be used as an alternative).The interaction with the data is made possible thanks to a Representational State Transfer Application Programming Interface (RESTful API) allowing easy access to data.It is developed on a Linux server with NGINX Open Source web server (pronounced "engine X"; suitable for heavy traffic thanks to its asynchronous management as opposed to traditional web servers such as Apache) and the Node.jsJavaScript runtime together with the Express framework that provide features for web applications (Mardan, 2018).Thanks to the API, data are delivered in Javascript Object Notation (JSON) format from gateways through the Internet.Here, a gateway is defined as a device that connect two systems with different data formats.Sensors can be directly connected to the gateways.The alternative is to connect the sensors to microcontroller units (MCUs) equipped with a Long Range (LoRa) Radio Transceiver allowing communication with the gateways using radio frequencies (Figure 1a).LoRa is a radio telecommunications protocol allowing the communication of connected objects at low speed (as opposed to the high speed offered by GSM/cellular networks), and at long distance (as opposed to the short distances of Bluetooth, Wi-Fi, Zigbee, Z-Wave).With the IoT, the LoRa protocol makes it possible to take advantage of both technologies to locally have a free low-speed communication protocol and at the global level a high-speed communication protocol to the server via the Internet (Figure 2).This solution makes it possible not to have to depend on subscription plans of information transmission (apart from the Internet), as opposed to commercial networks such as Sigfox or LoRaWan.Here, we used RFM95W LoRa modules from HOPE Microelectronics CO.The network is designed so as to place Rapsberry Pi-based gateways near any building with access to power outlets and Internet connection, ESP32-based gateways in the surrounding fields within the Wi-Fi range and powered by batteries and solar panels, and Arduino-based MCUs (called PI2Puino in the rest of the text) in distant fields within the range of the radio frequencies and powered either by batteries or rechargeable batteries and solar panels (Figure 1b).PI2Puino MCUs are equipped with a LoRa Radio Transceiver.The resulting topology is a star network with gateways as intermediate relays.

| Data acquisition
Environmental variables are acquired using different sensors depending on the network level.For the MCU communicating with the gateway through LoRa (PI2Puino, see Figure 1b), we used a temperature sensor (DS18B20; accuracy ±0.5°C) together with a temperature and relative humidity sensors (DHT22; accuracy ±0.5°C and ±2%RH), both minimizing the energy cost.For the Raspberry Pi and ESP32 gateways that take advantage of a power outlet or a solar panel, we used a temperature, relative humidity and pressure sensor (Adafruit module BME280/680; accuracy ±3%).Gateways are also equipped with a light sensor (Adafruit module SI1145 for visible, Ultra Violet, and Infra Red light).Although these sensors were chosen for their accuracy, genericity and their community of users, any sensor can be added or used as a substitute for those presented here.

| Data transfer
Data acquired from the PI2Puino are sent using the embedded Once received by the Raspberry Pi-based gateway equipped with the RFM95W LoRa module, the gateway checks for data integrity (numerical value) and forwards data to the server using its gateway key and a JSON-encoded message.Data acquired from the sensors connected to the gateway are forwarded directly to the server.The Raspberry Pi-based gateway code was written using Python 3.9.In case of an unhandled exception, the python script is relaunched automatically thanks to a systemd unit.The ESP32based gateway is not equipped with a RF95W LoRa module but it works in a very similar way, forwarding data to the server using a gateway key.While the Raspberry Pi-based gateway is connected to an electric outlet, the EP32-based gateway is powered by a solar panel and a 3.7 V 2600 mAh Lithium-Ion battery.In order to keep power consumption to a minimum, a sleep mode is enabled between two reads.Data acquisition frequency for both gateway models are user defined.ESP32-based gateway code was written in Arduino using Arduino IDE version 1.8.Examples for both gateway models are provided in Supporting Information S1.

| Data storage and availability
Data received by the server are stored in a PostgreSQL database using the Sequelize Object Relational Mapping (ORM) tool, which allows to abstract the database software.Data can be retrieved through the RESTful API.Any sensor can be accessed directly by its identification number, and the results are returned in JSON format.

| Data visualization
Data visualization is provided with the production server so as to have a quick overview of the data.It is not the preferred way to access the data, which should be done through the API.It is however convenient to check trends in time series using a dynamic and rich visualization tool from a web browser.We used the vis.js community edition browser based visualization library (https://visjs.org/;visnetwork) and the Plotly JavaScript Open Source Graphing Library (https://plotly.com/javascript/; Figure 3a,b).Information is displayed dynamically in real time for each sensor, sorted by institution and gateway.

| Deployment and cost
The IoT microclimatic monitoring network was deployed in France, Kenya and Bolivia in contrasting environmental conditions (temperate climate near Paris in France, tropical high Andean mountain near F I G U R E 2 Overview of the IoT system.The boxes with dotted edges represent in (1) the data acquisition, in (2) the data transfer, and in (3) the data storage and availability.Data visualization is represented on the left.Here, a client is the computer that sends requests to a server.
El Alto in Bolivia, and tropical low mountain in Nairobi Kenya).We gathered data for more than 2 years (from January 2020 to November 2022) at a frequency of 1 min on a selection of data corresponding to three Raspberry Pi-based gateways.We then compared temperature data with the WorlClim database (Fick & Hijmans, 2017), therefore addressing the long term (monthly) differences between macro and microclimate.For each day, we calculated the minimum, maximum and average temperature, then we represented the data in the form of a boxplot with the monthly distributions, as well as the data extracted from the WorldClim as a reference.Regarding the cost associated with the different devices, an estimate was made of 93€ for the Raspberry Pi gateway, 75€ for the ESP32 gateway, and 44€ for the PI2Puino MCU on the basis of unit purchases (Table 1).

| Deployment and acquired data
Collected data for the three sites were aggregated to perform a comparison with the WorlClim database (Fick & Hijmans, 2017; Figure 4).Although these aspects may be the subject of future developments, it is important to note that the gateways have not been configured to send back information in the event of an Internet connectivity failure or a failure from the server side.The missing data in February 2021 on the Kenyan site confirm this problem of the Internet connectivity failure, and the August 2022 data exemplified a server side problem (Figure 4b).To cope with these problems, collected data are stored locally on the gateways so that data can be retrieved manually.In contrast, the PI2Puino device can save the data and send it back to the gateway for a period of a few days (depending on the frequency of data acquisition), but it cannot store this data for long term.In addition, the gateway based on an ESP32-type MCU and powered by a battery charged by a solar panel can continue to operate in the absence of sunlight as long as the battery holds.At an acquisition frequency of one data item every 30 min, an autonomy of approximately 4 days was experimentally measured in complete darkness.The data generally follows trends of average monthly temperature from the WorldClim database (Fick & Hijmans, 2017), but we can highlight differences in temperatures due to the location of the gateways (microclimate), for example in Nairobi where average daily temperatures were higher than expected (Figure 4b).data transferred successfully corresponding to 1,649,460 readings).While we focus here on temperature, all environmental variables can be retrieved from the server API using any programming language.
Regarding the cost associated with the different devices, it could be greatly reduced for larger orders.Due to strong fluctuations in component prices, these amounts are only estimates.The total cost remains much lower than the commercial solutions.An estimation of a comparable solution using Onset Computer Corporation configurator (https://www.onsetcomp.com/hobonet-confi gurator; accessed November 2022) with a Micro RX Station and AC power as a gateway (1264€), a temperature and relative humidity sensor without solar radiation shield attached to the gateway (208€), and a remote HOBOnet temperature and relative humidity sensor (299€) costs a total of 1771€, against less than 200€ for the low-cost system.Although in the case of our low-cost devices, it is necessary to integrate the cost of labour for construction, maintenance (e.g.changing the batteries, updating the server), deployment and the absence of warranty, after-sales service or product follow-up.The accuracy of the sensors is similar to those of commercial solutions.The temperature is measured with an accuracy of ±0.5°C against ±0.25°C for the commercial solution.The relative humidity is measured with an accuracy of ±2% against ±2.5% for the commercial solution.

| Discussion and perspectives
We provide a complete and low-cost solution for the monitoring of environmental condition specifically designed for microclimatic conditions experienced in ecosystems, which can be adapted to any ecological study requiring local monitoring of environmental variables.While we focus on key environmental variables (temperature, relative humidity, atmospheric pressure, light), any extra sensor can be added to the microcontrollers and gateways to complete data acquisition (e.g.wind TA B L E 1 Estimated cost for each device of the IoT network as of July 2022.Estimates are made based on unit purchases.The cost is greatly reduced for larger orders.The percentage of the total price is indicated in parentheses with the category.sensors, soil moisture).In an attempt to lower the cost to a minimum while using quality sensors adapted to most situations ( Scientific), our system offers users the flexibility to adapt all components of the network to their needs.In addition, our system offers total control and transparency over data transfer and storage, using open data formats that facilitate analysis and reuse of data by as many people as possible.Although this flexibility allows the integration of any type of new sensors and full control over data management, while providing a system at the lowest possible cost, the main disadvantage compared to commercial solutions remains the deployment time.To facilitate deployment, we provide a detailed appendix on the implementation of this IoT system.As a result, the proposed system is the preferred solution for measurements requiring flexibility in all stages of the data collection from its acquisition to its processing, as well as for all projects where budgetary resources may represent a constraint.As for the objective of our study to evaluate the capacity of a low-cost environmental data acquisition system for academic use, our data confirms this possibility in agreement with the existing literature (Jolles, 2021).While the comparison of macro-and microclimatic data is limited here to monthly WorldClim data, the system presented A palette from blue to green to yellow to red has been used to represent temperature in each category.The grey bars correspond to missing data or not yet acquired data to date for November 2022.Each bar corresponds to a month, with different colours depending on the number of days on the temperature category.For example, in A, January 2020, 10 days had a minimum temperature between −5 and 0°C, 11 days between 0 and 5°C, 9 days between 5 and 10°C, and 1 day with missing data.Data are displayed for France from January 2020 to November 2022 and were exported from the project server using the API from R software version 4.2.2 (R Core Team, 2021), and the httr package version 1.4.3 (Wickham, 2020).

RFM95W
LoRa module and antenna to the gateway using the lightweight Secure IoT encryption algorithm (SIT) designed for IoT networks to keep power consumption to a minimum(Usman et al., 2017).If for any reason the PI2Puino does not get a response from the gateway after sending the data, they are stored in the MCU Electrically Erasable Programmable Read-Only Memory (EEPROM) for a duration configurable by the user and sent again at the next data reading loop.Data are acquired at a fixed frequency defined by the user through the sleep_enter function in the Arduino code, with 100 cycles corresponding to approximately 15 min (see Supporting Information S1).Between two readings, the PI2Puino enters into sleep mode to limit its power consumption.The PI2Puino code was written as an Arduino sketch using Arduino IDE 1.8.(a sketch is an Arduino program).It is powered with either two AA batteries F I G U R E 1 Schematic representation of the IoT network.In A, the different components of the data workflow are represented together with the main technologies used.In B, the hardware is represented to illustrate a possible minimalist network composed of two gateways and one PI2Puino MCU.The range of the Wi-Fi network is represented by the red area.The Raspberry Pi gateway sends data over the Internet using a wired or Wi-Fi connection.The ESP32 gateway sends data directly to the server with Wi-Fi.The PI2Puino MCU sends data to the Raspberry Pi gateway using a radio signal (LoRa).Data are then forwarded by the Raspberry Pi to the server (star topology).Data are centralized on the server and accessible at any time by client computers.Background image and icons in B were retrieved from https://openc lipart.org/.directly connected to the PI2Puino for short-term usage or using a solar panel and a 3.7 V 2600 mAh Lithium-Ion rechargeable battery (together with a lithium-ion charger and a voltage regulator: see Supporting Information S1 for a detailed description).

F
I G U R E 4 Average daily minimum (blue), daily maximum (red) and daily mean (yellow) temperature boxplots of the microclimatic monitoring in three contrasting environments (°C).In (a) for France, in (b) for Kenya, and in (c) for Bolivia from July 2020 to November 2022, exported from the project server using the API from R software version 4.2.2 (R Core Team, 2021).The blue, yellow and red lines correspond to the minimum, average and maximum monthly temperature averaged over the period 1970-2000 extracted from WorldClim version 2.1(Hijmans et al., 2005).In (b) for Kenya in February 2021 and in (c) for Bolivia in August 2022, no data are displayed due to a connectivity issue.
here offers functionality equivalent to that of commercial solutions, with the advantage of flexibility.Measurements every minute were carried out under different contrasting climatic conditions in France, Kenya and Bolivia.The main problems encountered with missing data (Figure5) were not related to the hardware, but rather the adjustment of the distance between the radio transmission devices, as well as the availability of stable and reliable access to the Internet.The latter can F I G U R E 5 Minimum (a) and maximum (b) temperature diagrams displaying the number of days per month per temperature category (°C).

Table 1
(Tzounis et al., 2017)(Table1) whose model can be adapted to cover areas where sunshine is reduced, whether at higher latitudes in winter or under partial vegetation cover.As mentioned in the introduction, using IoT to monitor environmental variable is nothing new, and a vast literature covers IoT applications in agriculture and ecology(Guo et al., 2015; Zhang et al., 2018).The specificity of our contribution is to provide a free and open source solution covering all the challenges to the adoption of IoT solutions(Tzounis et al., 2017).Here, we offer a choice of sensors, energy management options, and strategies for both the transfer of information and its storage and availability.Compare to commercial systems offering similar services of data acquisition, storage and availability (e.g.Onset Computer Corporation, Campbell