This app provides a simple to construct greenhouse monitoring device that can be deployed inside a greenhouse. The app monitors soil moisture and soil temperature as well as ambient light and ambient temperature. Using off-the-shelf hardware and modular components, you can use this solution to add monitoring to an existing greenhouse.
Connect the I2C Qwiic cable between the Notecarrier and the BME280 breakout board:
Insert the Qwiic JST cable connector into one of the F_I2C connectors on the edge of the Notecarrier-F next to the USB port. You may also connect it to the I2C connector on the Swan.
Insert the other end of the Qwiic JST cable into one of the JST connectors on the BM280 breakout board.
Connect the photo transistor:
Connect the 3 jumper wires between the Notecarrier and breadboard as follows
GND on Notecarrier to the negative rail at the edge of the breadboard
VMAIN on Notecarrier to the positive power rail at the edge the breadboard
A1 on Notecarrier to a row of points on the breadboard
Insert one leg of the 1kΩ resistor into the ground rail, and the other leg to the same row of points connected to A1 in last step above.
Insert the longer leg of the photo transistor into the positive power rail, and the shorter leg into the same row of points as the A1 wire.
Connect the STEMMA connector to the soil sensor. Connect the colored male jumper wires at the other end of the cable as follows:
BLACK to the negative power rail on the breadboard.
RED to the positive power rail on the breadboard.
WHITE to SDA on the Notecarrier.
GREEN to SCL on the Notecarrier.
The assembled hardware should look similar to this:
Connect the Swan to your computer using a micro-USB cable. This is so that the firmware can be uploaded and allows the app to be monitored over USB serial.
Optionally, connect an SWD programmer, such as ST-Link Mini, to the Swan using the ribbon cable, and to your computer using a micro-USB cable. This makes it possible to upload firmware without needing to press buttons on the Swan and enables step debugging with the VSCode IDE.
This solution can be used to monitor a single greenhouse, or monitor multiple greenhouses at a facility by deploying multiple instances of this app. When monitoring multiple greenhouses at a facility, it can be useful to group the monitors at a facility into a Fleet. For more details, see The Fleet Administrator's Guide.
The application firmware is found under the firmware folder and can be built and uploaded to Swan using these development environments:
PlatformIO extension for Visual Studio Code
Arduino extension for Visual Studio Code
We recommend using the PlatformIO extension for Visual Studio Code, as this is the easiest to set up and use, and provides a comprehensive development experience. However, if you're familiar with the Arduino IDE, that can be used as well but requires a little more setup.
There is no special setup required for the project beyond what is normally required to configure a PlatformIO project in VSCode. This tutorial explains how to install and use PlatformIO.
The PlatformIO project is located in the firmware folder, where you'll find platformio.ini that configures the project, including the libraries required, location of the sources and compile-time definitions required.
The source code for the Arduino project is under firmware/greenhouse/ in this repository folder. We have included the correct configuration in .vscode/arduino.json which selects the Swan board as the build target and configures the required compiler options.
Before building the project, you will need to install the required libraries listed below.
Before compiling and uploading the sketch, be sure to install the STM32Duino board support package. The tutorial Using the Arduino IDE in the Swan documentation shows how to install support for Swan in Arduino IDE and how to compile and upload firmware.
You will also need to install the required libraries.
Before uploading the app firmware, you should set the ProductUID to correspond to the project you created in Notehub setup earlier.
There are two ways to configure the ProductUID, either using the in-browser terminal to send a request to the Notecard, or by editing the firmware source code. For more details on what the ProductUID is and how it set it please see this guide.
When alert thresholds are configured, and one or more sensor readings are outside of the normal range, the event also includes alert and alert_seq properties to indicate the severity of the alert and the progress of the alert. See the section on Alerts for details about these properties.
In addition to reporting the sensor values, the app can send an alert when a particular sensor value is too high or too low. The app uses environment variables to configure alert ranges for each sensor. The alert ranges are:
normal: Describes the normal range of values for the sensor. The app sends a warning alert when the sensor value is higher than the high threshold or lower than the low threshold.
warning: Describes the range of values for which the app sends a warning alert. When defined, values falling outside the warning range produce a critical alert. Values inside the warning range but outside the normal range produce a warning alert.
You configure the ranges using environment variables that include the sensor name and range to set, following this format:
<sensor-name>_<range>_low: Configures the lower bound of a range for the named sensor.
<sensor-name>_<range>_high: Configures the upper bound of the range for the named sensor.
Note: You don't have to configure both high an low values for a range - the application checks just the thresholds provided.
light_level_normal_low=100: sets the lower bound of normal readings from the light_level sensor to 100. A warning alert is produced when the light_level value is below 100.
soil_temp_normal_high=40, soil_temp_warning_high=50: sets the upper bound for normal and warning ranges for the soil_temp sensor. With this configuration, alerts are produced as follows:
No alert is produced when the soil temperature is below 40.
A warning alert is produced when the soil temperature is between 40 and 50.
A critical alert is produced when the soil temperature is above 50.
When the app detects an alert condition, it captures details of the alert and sends an event to alert.qo. The event includes the overall alert level (warning/critical) and details of the sensor readings, similar to this:
alert: Describes the overall alert level. This is the highest alert level of all of the sensors. Values are warning, critical, or not present, meaning no alert, which happens when sensor readings return to normal.
alert_seq: Distinguishes between the start of an alert, an ongoing alert, and when an alert has been cleared. The property has these values:
first: This is set when the first alert event is sent. The event is sent immediately.
ongoing: This is set when the alert condition is still present and the alert is ongoing. An event is sent every report_mins minutes for as long as the alert condition is still present.
cleared: This is set when the alert condition is no longer present and the alert is cleared. The event is sent immediately at the end of the alert.
status: Describes the status of a sensor value:
ok: The sensor value is in normal range, that is, above any configured low threshold and lower than any configured high threshold.
low: The sensor value is too low.
high: The sensor value is too high.
Note: The alert_seq field makes it easy to detect when an alert starts and stops. You can use this to send external notifications immediately when an alert is detected and when it is cleared. Events with alert_seq set to ongoing provide periodic reminders that the alert is still ongoing.
The soil_moisture and light_level are scalar readings that correlate to the amount of moisture in the soil and the amount of light, with more moisture and more light resulting is higher values, and less moisture and less light resulting in lower values. We suggest you use the app in the greenhouse for a few days, and t to greenhouse.qo to determine the normal ranges for these values. You can then set the environment variables soil_moisture_normal_low etc.. to reflect the expected normal range of values.
When you deploy the solution in your greenhouse, you will power the Notecarrier from a USB power brick. Additionally you may want to waterproof all of the electronics. Here are some suggestions:
Waterproof the soil moisture sensor using heat shrink tubing over the top part of the sensor where the electronics are located, and make watertight using smaller gauge heat shrink tubing and/or waterproof tape to seal any small openings.
Place the breadboard and Notecarrier in a waterproof project box or tupperware container, using rubber cable glands to waterproof the USB cable and soil sensor cable bundle where they exit the enclosure.
Use heat shrink tubing over the BME280 sensor and/or waterproof tape. You may also place the BME280 sensor in the waterproof box housing the other electronics, although the heat produced by the electronics may slightly raise the temperature inside the box.
To consume less power and potentially less bandwidth, you may want to consider changing the hub.set request from continuous mode to periodic mode with appropriate values for inbound and outbound. See Configuring Synchronization Modes for more details. When using periodic mode, set the environment variable polling interval to half of the inbound value.
Initial alerts and cleared alerts are always sent immediately to Notehub, and are not affected by the outbound latency.