Real-Time IoT-Enabled Water Management for Rooftop Urban Agriculture Using Commercial Off-the-Shelf Products

: Urban agriculture is receiving increased attention not only for food security and public health but for mitigating the impacts of urbanization and climate change. In cities, rooftop urban farms provide a solution for the limited space at the ground level. However, rooftop urban farming poses several challenges, including an increased need for workforce and site visits and a demand for efﬁcient water use. Recent advancements in information and communication technology (ICT) and the Internet of Things (IoT) have enabled a tremendous suite of low-cost, wireless sensor nodes. In this work, an IoT-enabled approach is introduced to improve water management in an urban rooftop farm in downtown Toronto, Canada. Low-cost resistive water level sensors were calibrated and integrated into wireless sensor nodes to send data through LoRaWAN, an IoT protocol, to The Things Network (TTN) console, after which the processed data are visualized in the user dashboard. This paper addresses the main design stages, ﬁeld deployment, and suggestions for maintenance learned through monitoring the growing season of 2021. The combination of low-cost sensors, user-friendly microcontrollers and open-source platforms provides an opportunity to improve decision-making, lower costs and reduce reliance on labor.


Introduction
Urban agriculture (UA) has become increasingly popular across cities in various systems such as individual plots on public and private lands, community gardens and building rooftops [1]. Rooftop urban farms provide a solution for limited space at the ground level in cities. However, they pose several challenges, including an increased need for a workforce and a demand for efficient water use. Over the last decade, advancements in information and communication technology (ICT) and developments in the Internet of Things (IoT) have improved sensors' potential to monitor, transmit and manage environment-related metrics [2,3]. IoT-enabled solutions in farming and agriculture applications can reduce the workforce and the need for human interaction, reducing overall operational costs. Furthermore, using the IoT on agricultural green infrastructure provides an opportunity to improve the general understanding of how these complex systems function, which results in better design/planning strategy and operation and, therefore, improved performance.
Several studies have investigated the potential of IoT for crop production, including works that used temperature and soil moisture as indicating parameters [4,5]. When used in agricultural applications, some researchers found evidence that IoT helps in soil management and nutrient detection [6]. Others considered IoT to transform farming into a smart process by monitoring health diseases and sending alarm notifications to farmers [7,8]. Some studies have turned their attention to adaptive irrigation systems to conserve water, time and energy [9]. smart process by monitoring health diseases and sending alarm notifications to farmers [7,8]. Some studies have turned their attention to adaptive irrigation systems to conserve water, time and energy [9].
Many cities are becoming water-stressed and are also experiencing challenges with urban drainage systems. Careful water use and managed stormwater have become imperative in achieving sustainability goals through urban farming. Water management in farms requires an understanding of drainage patterns, which can be monitored through sensors. A recent line of IoT-related research has focused on developing low-cost sensors to measure water levels in rivers using various approaches such as ultrasonic sensors [10,11]. However, ultrasonic sensors are limited to higher distances and are inapplicable in small drains. Moreover, most IoT literature records have dominantly used Wi-Fi and mobile technology as protocols. Fewer studies have used LoRaWAN, a communication technology known for its highly low-power requirements and long-range coverage.
This work proposes an IoT-enabled, wireless sensor node composed of low-cost, offthe-shelf water level sensors and microcontrollers that monitor and sends real-time data through LoRaWAN to the internet. The paper is divided into several sections to address the design stages, field deployment and suggestions for maintenance.

Description of Study Site: Urban Farm Living Lab
The Urban Farm Living Lab (UFLL) is located on the rooftop of George Vari Engineering and Computing Centre at the campus of Ryerson University (renaming in process) in downtown Toronto, Canada. Initially, it was an intensive green roof built in 2004 and converted to a farm in 2014. The Urban Farm grows roughly 3500 to 4500 kg of produce annually. The farm is split into different plots, A, B, C, D, E and AA, with three drains implemented across the plots (Figure 1).

IoT System Architecture
The proposed IoT system is based on LoRaWAN technology. It consists of a microcontroller-based LoRa generic node and a water level sensor combined in a 'sensor node' placed to acquire real-time values. The monitored information is transmitted in data packets through a nearby gateway to The Things Network (TTN). TTN is an open platform that acts as a network layer by receiving and rerouting the data from sensor nodes to the cloud. The cloud server, which can be accessed through desktop and mobile applications, allows users to store the water level data and visualize it in various forms to obtain information on the volume, rate and timing of drained water. Figure 2 depicts the IoT system architecture.

IoT System Architecture
The proposed IoT system is based on LoRaWAN technology. It consists of a microcontroller-based LoRa generic node and a water level sensor combined in a 'sensor node' placed to acquire real-time values. The monitored information is transmitted in data packets through a nearby gateway to The Things Network (TTN). TTN is an open platform that acts as a network layer by receiving and rerouting the data from sensor nodes to the cloud. The cloud server, which can be accessed through desktop and mobile applications, allows users to store the water level data and visualize it in various forms to obtain information on the volume, rate and timing of drained water. Figure 2

Hardware Setup and Physical Circuit
The water level sensor is commercially known as the eTape liquid level sensor (USD 49) and works by providing a corresponding resistance value inversely proportional to the liquid level (Milone Technologies, Sewell, NJ, United States). The used LoRa sensor node is commercially known as LSN50 (USD 43), powered by a 4000-mA battery and designed to provide secure data transmission of sensors' data (LSN50, Dragino, Shenzhen, China). The sensor was connected to the node through a voltage-divider circuit, as shown in Figure 3. The circuit utilized two pins on the eTape; pins 2 and 3 connected to VDD and GND of the LSN50, respectively. To create a voltage divider between the components, a resistor with a range of 0-2000 ohms was attached between pin 3 and GND. The exact value of the resistor is not prescribed, as the calibration (discussed in the next section) is performed based on the used resistor. Additionally, pin 3 of the eTape was connected to PA0 of the LSN50 to deliver the analog input information in volts. The LSN50 was registered to TTN using the Device EUI, Application EUI and App Key provided by the manufacturer. This sensor node, similar to other LoRa devices, operates over the air authentication (OTTA) when connected to TTN, meaning that the registration keys cannot be compromised before activation. A LoRaWAN gateway installed previously on campus was used to connect the sensors. Gateways are an essential intermediary connection between sensors and TTN. This project's gateway's frequency was US-902-928, specific for North America.

Payload Encoder and Sensor Calibration
Motivated by the need for low-code IoT implementation, many LoRa device manufacturers have started to grant open access to coding documentation and online decoders requiring less user configuration. Data are exchanged over TTN through bytes which can be decoded into a usable format. In this work, the LSN50 node has an open-access code that was used in the TTN payload decoder after it was slightly modified to read the data from the used water level sensors.
Once device registration and activation on TTN were complete, the data were decoded into the specified payload format and stored temporarily on the platform before migrating to the cloud. The initial decoded data were used to calibrate the water level sensors at this stage. The sensor sends analog input voltage, which needs to be converted

Hardware Setup and Physical Circuit
The water level sensor is commercially known as the eTape liquid level sensor (USD 49) and works by providing a corresponding resistance value inversely proportional to the liquid level (Milone Technologies, Sewell, NJ, United States). The used LoRa sensor node is commercially known as LSN50 (USD 43), powered by a 4000-mA battery and designed to provide secure data transmission of sensors' data (LSN50, Dragino, Shenzhen, China). The sensor was connected to the node through a voltage-divider circuit, as shown in Figure 3. The circuit utilized two pins on the eTape; pins 2 and 3 connected to VDD and GND of the LSN50, respectively. To create a voltage divider between the components, a resistor with a range of 0-2000 ohms was attached between pin 3 and GND. The exact value of the resistor is not prescribed, as the calibration (discussed in the next section) is performed based on the used resistor. Additionally, pin 3 of the eTape was connected to PA0 of the LSN50 to deliver the analog input information in volts.

Hardware Setup and Physical Circuit
The water level sensor is commercially known as the eTape liquid level sensor (USD 49) and works by providing a corresponding resistance value inversely proportional to the liquid level (Milone Technologies, Sewell, NJ, United States). The used LoRa sensor node is commercially known as LSN50 (USD 43), powered by a 4000-mA battery and designed to provide secure data transmission of sensors' data (LSN50, Dragino, Shenzhen, China). The sensor was connected to the node through a voltage-divider circuit, as shown in Figure 3. The circuit utilized two pins on the eTape; pins 2 and 3 connected to VDD and GND of the LSN50, respectively. To create a voltage divider between the components, a resistor with a range of 0-2000 ohms was attached between pin 3 and GND. The exact value of the resistor is not prescribed, as the calibration (discussed in the next section) is performed based on the used resistor. Additionally, pin 3 of the eTape was connected to PA0 of the LSN50 to deliver the analog input information in volts. The LSN50 was registered to TTN using the Device EUI, Application EUI and App Key provided by the manufacturer. This sensor node, similar to other LoRa devices, operates over the air authentication (OTTA) when connected to TTN, meaning that the registration keys cannot be compromised before activation. A LoRaWAN gateway installed previously on campus was used to connect the sensors. Gateways are an essential intermediary connection between sensors and TTN. This project's gateway's frequency was US-902-928, specific for North America.

Payload Encoder and Sensor Calibration
Motivated by the need for low-code IoT implementation, many LoRa device manufacturers have started to grant open access to coding documentation and online decoders requiring less user configuration. Data are exchanged over TTN through bytes which can be decoded into a usable format. In this work, the LSN50 node has an open-access code that was used in the TTN payload decoder after it was slightly modified to read the data from the used water level sensors.
Once device registration and activation on TTN were complete, the data were decoded into the specified payload format and stored temporarily on the platform before migrating to the cloud. The initial decoded data were used to calibrate the water level sensors at this stage. The sensor sends analog input voltage, which needs to be converted The LSN50 was registered to TTN using the Device EUI, Application EUI and App Key provided by the manufacturer. This sensor node, similar to other LoRa devices, operates over the air authentication (OTTA) when connected to TTN, meaning that the registration keys cannot be compromised before activation. A LoRaWAN gateway installed previously on campus was used to connect the sensors. Gateways are an essential intermediary connection between sensors and TTN. This project's gateway's frequency was US-902-928, specific for North America.

Payload Encoder and Sensor Calibration
Motivated by the need for low-code IoT implementation, many LoRa device manufacturers have started to grant open access to coding documentation and online decoders requiring less user configuration. Data are exchanged over TTN through bytes which can be decoded into a usable format. In this work, the LSN50 node has an open-access code that was used in the TTN payload decoder after it was slightly modified to read the data from the used water level sensors.
Once device registration and activation on TTN were complete, the data were decoded into the specified payload format and stored temporarily on the platform before migrating to the cloud. The initial decoded data were used to calibrate the water level sensors at this stage. The sensor sends analog input voltage, which needs to be converted into a water level value. The calibration started at a reference level equal to zero (i.e., in the absence of water), then water was gradually added to 2.5, 5, 7.5, 10 and 12.5 cm. The sensor was given sufficient time to report numerous readings at each water level, and an average reading was then recorded. This protocol was followed to minimize the sensor noise and ensure accuracy. The water levels were then plotted against their corresponding voltage values, as shown in Figure 4, and the equation was used in the payload decoder to complete the calibration process.
Chem. Proc. 2022, 10, 34 4 of 7 into a water level value. The calibration started at a reference level equal to zero (i.e., in the absence of water), then water was gradually added to 2.5, 5, 7.5, 10 and 12.5 cm. The sensor was given sufficient time to report numerous readings at each water level, and an average reading was then recorded. This protocol was followed to minimize the sensor noise and ensure accuracy. The water levels were then plotted against their corresponding voltage values, as shown in Figure 4, and the equation was used in the payload decoder to complete the calibration process.

Field Deployment
As previously mentioned, the farm had three outlets to drain water. Each of these drains was equipped with a developed water level sensor node. The eTape was fitted in a polycarbonate protective tube, and a housing cap covered its pins. The wires between the eTape and LSN50 were shielded, and the node itself was mounted on a custom-made pole to ensure that the antenna was unobstructed, as shown in Figure 5.

Interactive Platform and Cloud Storage
Many open IoT development platforms have recently been used to visualize and store monitored data. Ubidots was used as a visualization platform and storage cloud in this case study. The platform also allows users to create conditional events and data-based alerts. Since the eTape does not come with LSN50 by default and it had been configured to suit the goal of this project, alerts were made to notify users through SMS messages whenever the sensor is off or its battery drops below a certain level.

Data Analysis of Rainfall Events
The sensor nodes were deployed during the growing season of 2021 between June to December on a monitoring frequency of 5 min. A sensor was fixed to a v-notch weir installed in each drain to allow flow estimation. The flow over the weir was determined using the weir rating curve developed through laboratory analysis. Precipitation data

Field Deployment
As previously mentioned, the farm had three outlets to drain water. Each of these drains was equipped with a developed water level sensor node. The eTape was fitted in a polycarbonate protective tube, and a housing cap covered its pins. The wires between the eTape and LSN50 were shielded, and the node itself was mounted on a custom-made pole to ensure that the antenna was unobstructed, as shown in Figure 5. into a water level value. The calibration started at a reference level equal to zero (i.e., in the absence of water), then water was gradually added to 2.5, 5, 7.5, 10 and 12.5 cm. The sensor was given sufficient time to report numerous readings at each water level, and an average reading was then recorded. This protocol was followed to minimize the sensor noise and ensure accuracy. The water levels were then plotted against their corresponding voltage values, as shown in Figure 4, and the equation was used in the payload decoder to complete the calibration process.

Field Deployment
As previously mentioned, the farm had three outlets to drain water. Each of these drains was equipped with a developed water level sensor node. The eTape was fitted in a polycarbonate protective tube, and a housing cap covered its pins. The wires between the eTape and LSN50 were shielded, and the node itself was mounted on a custom-made pole to ensure that the antenna was unobstructed, as shown in Figure 5.

Interactive Platform and Cloud Storage
Many open IoT development platforms have recently been used to visualize and store monitored data. Ubidots was used as a visualization platform and storage cloud in this case study. The platform also allows users to create conditional events and data-based alerts. Since the eTape does not come with LSN50 by default and it had been configured to suit the goal of this project, alerts were made to notify users through SMS messages whenever the sensor is off or its battery drops below a certain level.

Data Analysis of Rainfall Events
The sensor nodes were deployed during the growing season of 2021 between June to December on a monitoring frequency of 5 min. A sensor was fixed to a v-notch weir installed in each drain to allow flow estimation. The flow over the weir was determined using the weir rating curve developed through laboratory analysis. Precipitation data

Interactive Platform and Cloud Storage
Many open IoT development platforms have recently been used to visualize and store monitored data. Ubidots was used as a visualization platform and storage cloud in this case study. The platform also allows users to create conditional events and data-based alerts. Since the eTape does not come with LSN50 by default and it had been configured to suit the goal of this project, alerts were made to notify users through SMS messages whenever the sensor is off or its battery drops below a certain level.

Data Analysis of Rainfall Events
The sensor nodes were deployed during the growing season of 2021 between June to December on a monitoring frequency of 5 min. A sensor was fixed to a v-notch weir installed in each drain to allow flow estimation. The flow over the weir was determined using the weir rating curve developed through laboratory analysis. Precipitation data Chem. Proc. 2022, 10, 34 5 of 7 from a weather station located on the roof were used to analyze the amount of rainwater discharged by the farm.
Considering that this project's scope is limited to developing low-cost wireless water level sensor nodes using commercially available products, the gateway installed on campus had an insignificant distance to the sensor nodes, meaning that the signal strength was adequate, and data packet loss was not an issue. The developed sensor node provided consistency and high-quality data over the season. However, to address the sensor noise, water level data were smoothed to reduce dispersion and remove outliers using the exponential smoothing (ES) method. Figure 6 shows an example of raw versus smoothed sensor data.
Chem. Proc. 2022, 10, 34 5 of 7 from a weather station located on the roof were used to analyze the amount of rainwater discharged by the farm.
Considering that this project's scope is limited to developing low-cost wireless water level sensor nodes using commercially available products, the gateway installed on campus had an insignificant distance to the sensor nodes, meaning that the signal strength was adequate, and data packet loss was not an issue. The developed sensor node provided consistency and high-quality data over the season. However, to address the sensor noise, water level data were smoothed to reduce dispersion and remove outliers using the exponential smoothing (ES) method. Figure 6 shows an example of raw versus smoothed sensor data.

Energy Consumption and Maintenance Activities
One essential element that makes LoRaWAN sensors feasible is their low power need. Today, many of these sensors operate on replaceable batteries. Estimating the battery life is a critical step in designing IoT development projects. However, an accurate prediction is not always possible because battery life depends on other factors besides battery capacity and system current. In wireless sensor nodes, the drained current significantly varies during the 'sleeping' and 'sampling' modes.
Furthermore, the spreading factor (SF) is another variable that influences battery usage. It is defined as the number of bits per chirp signal and is a function of modulation bandwidth. Higher spreading factors result in longer transmission durations and consequently shorter life. In this work, the initial assessment considering the LSN50 battery capacity and eTape current revealed an approximate battery life of six months. However, batteries needed to be replaced every two months. A possible reason for this discrepancy might be that other factors such as sampling times and time on-air were not carefully analyzed. These observations suggest the need for in-depth energy usage analysis and the selection of optimal spreading factors.
The developed sensor nodes performed as expected throughout the monitoring period, and other than battery replacements, they required no human interaction. Onsite calibration checks were performed several times, and the accuracy was found to be maintained without a need for recalibration. However, after several months of installation, some nodes disconnected and became faulty. Upon investigation, the sensor pins were found to be severely corroded. The problem could be avoided by isolating the pins with liquid electrical tape. The faulty sensors were replaced, as shown in Figure 7.

Energy Consumption and Maintenance Activities
One essential element that makes LoRaWAN sensors feasible is their low power need. Today, many of these sensors operate on replaceable batteries. Estimating the battery life is a critical step in designing IoT development projects. However, an accurate prediction is not always possible because battery life depends on other factors besides battery capacity and system current. In wireless sensor nodes, the drained current significantly varies during the 'sleeping' and 'sampling' modes.
Furthermore, the spreading factor (SF) is another variable that influences battery usage. It is defined as the number of bits per chirp signal and is a function of modulation bandwidth. Higher spreading factors result in longer transmission durations and consequently shorter life. In this work, the initial assessment considering the LSN50 battery capacity and eTape current revealed an approximate battery life of six months. However, batteries needed to be replaced every two months. A possible reason for this discrepancy might be that other factors such as sampling times and time on-air were not carefully analyzed. These observations suggest the need for in-depth energy usage analysis and the selection of optimal spreading factors.
The developed sensor nodes performed as expected throughout the monitoring period, and other than battery replacements, they required no human interaction. Onsite calibration checks were performed several times, and the accuracy was found to be maintained without a need for recalibration. However, after several months of installation, some nodes disconnected and became faulty. Upon investigation, the sensor pins were found to be severely corroded. The problem could be avoided by isolating the pins with liquid electrical tape. The faulty sensors were replaced, as shown in Figure 7.