Distributed weather monitoring in gardens

Data Analysis and Visualization

Building full-featured dashboards is not really possible with the limited graphing capabilities of Prometheus. For that task, I turned to another free and open source Linux tool, Grafana [21]. Again, you can find many excellent tutorials for installing Grafana on your system online [22].

Once installed, navigate to the home page and click on the settings icon (the gear icon, to the left). Select Prometheus from the list, and unless the Prometheus data port has been changed or Prometheus is running on another machine, you can accept the defaults.

Now you can create your first dashboard by clicking New | New dashboard. The new dashboard has one panel, initially called New Panel. To see the simplest Grafana visualization, click Visualization and choose Gauge. Next, switch to query, and type avg(temperature), which displays the current temperature averaged over all the sensors. The avg function is an example of the powerful Prometheus query language that allows data to be manipulated before it is displayed.

If you repeat the above process but choose the Graph visualization and simply type temperature for the query, Grafana produces a time-based graph (Figure 10). At the top right you can select the time period. Note that each sensor will have its own plot.

Figure 10: Time-based graph in Grafana.

Starting with the basic graph, you can make many enhancements by adding units, limits, plot styles, axis labels, and so on. Moreover, you can combine many panels on a single dashboard and have many dashboards (Figure 11). One advantage of this web-based approach to data presentation is that the graphs are available on mobile devices, too (Figure 12).

Figure 11: The garden dashboard with a time-based graph and a gauge that reports current conditions for each sensor.
Figure 12: Grafana detects the device type and produces data in a suitable format.

Next Steps

In terms of software, it would be better if the sensor's given name, rather than hardware ID was used to identify the sensors in Prometheus and Grafana. I will have to look at the MQTT API to see if that is possible. Otherwise, a static mapping table in the golang code would work but would be less elegant.

Many other sensors could provide useful data: soil moisture meters, pH meters, rainfall indicators, and wind speed indicators, to name but a few. Additions to the code can do so much more with the data, such as generating alarms for frost and excessive temperatures or analyzing areas to find the highest light level. Another option is to generate multiple Grafana dashboards that show the data in different forms, as well as after postprocessing.

Conclusion

The system presented here is still in development, but the results are already bearing fruit. Knowing the true outdoor temperature has allowed me to plan spring planting with more certainty, and with one sensor placed in the greenhouse, I know when it's necessary to turn on heaters or open the ventilation. This system could easily be expanded to support the needs of a small market garden, a nursery, or other forms of agriculture, where access to such detailed data could save money and increase profit.

For myself, I've learned a great deal about the local weather in my garden and about IoT, and I've increased my knowledge about so much of the excellent free and open source software available. Happy gardening (and engineering)!

Infos

  1. LoRa wiki: https://en.wikipedia.org/wiki/LoRa
  2. LoRaWAN sensor devices: https://www.thethingsnetwork.org/marketplace/products/devices
  3. MOSFET switch: https://www.electronics-tutorials.ws/transistor/tran_7.html
  4. STM32L432KCU6 microcontroller: https://www.arrow.com/en/products/stm32l432kcu6/stmicroelectronics
  5. KiCad: https://kicad-pcb.org
  6. Code and files from this article: ftp://ftp.linux-magazine.com/pub/listings/linux-magazine.com/239
  7. STEP file definition: https://en.wikipedia.org/wiki/ISO_10303-21
  8. Hammond enclosure: https://www.hammfg.com/electronics/small-case/plastic/1551
  9. STM32CubeMX tool: https://www.st.com/en/development-tools/stm32cubemx.html
  10. STLink programming utility: https://github.com/stlink-org/stlink
  11. GitHub project page: https://github.com/andrewrussellmalcolm/instrumeted_garden
  12. LoRaWAN introduction: https://www.thethingsnetwork.org/docs/lorawan/
  13. LoRaWAN gateway: https://shop.imst.de/media/pdf/a7/a1/53/iC880A_Datasheet_V1_1.pdf
  14. LoRaWAN gateway quick start guide: https://github.com/ttn-zh/ic880a-gateway/wiki
  15. The Things Network: https://www.thethingsnetwork.org
  16. The Things Network console: https://console.thethingsnetwork.org/gateways/register
  17. The Things Network APIs: https://www.thethingsnetwork.org/docs/applications/
  18. The Things Network MQTT protocol: https://www.thethingsnetwork.org/docs/applications/mqtt/
  19. The Things Network golang example and GoDoc: https://godoc.org/github.com/TheThingsNetwork/go-app-sdk#example-package
  20. Installing Prometheus on Ubuntu: https://linoxide.com/linux-how-to/install-prometheus-ubuntu/
  21. Grafana: https://en.wikipedia.org/wiki/Grafana
  22. Installing Grafana: https://grafana.com/docs/grafana/latest/installation/

The Author

Andrew Malcolm (CEng, MIET) works as a staff engineer for Guru Systems (https://www.gurusystems.com/), a fast-growing IoT hardware and SaaS company working on low-carbon energy projects. In his spare time he likes to combine software engineering with his first love, hardware engineering. With all the open source tools available, he is never short of design projects. You can contact Andrew at mailto:andrewrussellmalcolm@gmail.com.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • LoRa Long Range Radio

    WiFi is convenient for devices that are in the same house. If you want to extend the distance, give LoRa a call.

  • Prometheus

    Legacy monitoring solutions are fine for small-to-medium-sized networks, but complex environments benefit from a different approach. Prometheus is an interesting alternative to classic tools like Nagios.

  • Automated Irrigation

    An automated watering system comprising a Raspberry Pi Zero W, an analog-to-digital converter, and an inexpensive irrigation kit can help keep your potted plants from dying of thirst.

  • Electronic Weighing

    Create your own weighing device with easily available components and open source software.

  • Ren'Py

    Ren'Py helps you create Android, Linux, macOS, Windows, and HTML5 games and apps.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News