VOOZH about

URL: https://thenewstack.io/building-a-plant-monitoring-tool-with-iot/

⇱ Building a Plant Monitoring Tool with IoT - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-05-08 09:27:01
Building a Plant Monitoring Tool with IoT
sponsor-influxdata,sponsored-post-contributed,
Data / Edge Computing / Operations / Software Development

Building a Plant Monitoring Tool with IoT

A beginner-friendly tutorial for anyone who loves the idea of indoor gardening but forgets to check their plants regularly.
May 8th, 2023 9:27am by Zoe Steinkamp
👁 Featued image for: Building a Plant Monitoring Tool with IoT
InfluxData sponsored this post.
Creating an Internet of Things (IoT) app to monitor a house plant is a pragmatic starting place to learn about data that changes over time. It’s useful for anyone who loves the idea of indoor gardening but forgets to check their plants regularly. This project is accessible to everyone from students working on a science fair project to botanists monitoring exotic plant nurseries. There are many ways to monitor a houseplant, but this is the high-tech way — with sensors and advanced software systems. For this project, we’ll use InfluxDB, a time series platform that specializes in storing sequential data as it appears over time. This is useful when comparing data, creating alerts for specific thresholds and monitoring events in the physical and virtual worlds alike. 👁 Image
The full list of supplies, a schematic drawing for your breadboard (with microcontroller of choice) and the source code are all available from my git repository if you want to follow along for your own edification or desperately need to keep a houseplant alive.

The Architecture

👁 Image
An IoT sensor tracks my plant’s health metrics at timed intervals. We classify the data it collects as time series data because it includes a timestamp, which appears as the first column in storage. The IoT sensors generate data about the plant’s health. Then I use Telegraf, an open source collection agent, and the Python client library to collect that data and send it to the storage layer, InfluxDB. The Plotly graphing library provides the data visualization. I coded the project in Python and it uses the Flask library for routing.
InfluxData is the creator of InfluxDB, the leading time series platform. More than 1,900 customers use InfluxDB to collect, store, and analyze all time series data at any scale. Developers can query and analyze their time-stamped data to predict, respond, and adapt in real-time.
Learn More
The latest from InfluxData

Getting Started

Instruments:
  • A plant to monitor
  • A Particle Boron or similar microcontroller
  • At least one IoT sensor for your plant
  • A breadboard
  • Jump wires
I use four sensors to generate the following five data points:
  • Air temperature
  • Humidity
  • Light
  • Soil temperature
  • Soil moisture

👁 Image

Microcontroller

I use the Boron microcontroller and set the device up through the company website. To receive data from the microcontroller itself, I connect it to my laptop via a USB cable. Microcontroller setup depends on which microcontroller you selected for use. Your microcontroller might provide other connection options, including Bluetooth or small server access over TCP/IP. Follow the instructions provided by your microcontroller’s manufacturer until you receive input from your sensors. You don’t need to make sense of the data yet; just make sure your microcontroller is sending raw data.

InfluxDB

Sign into InfluxDB. Create a bucket, which is where InfluxDB stores data. We will connect to InfluxDB via an API. The next step is to create the required credentials and tokens.

Code

Writing data into InfluxDB is straightforward and starts with the client library. I use InfluxDB’s Python client library for this project. The code below is an example of how you can write code to send raw data from your microcontroller’s sensors to InfluxDB.
def write_to_influx(self,data):
	p = (influxdb_client.Point("sensor_data")
 	.tag("user",data["user"])
 	.tag("device_id",data["device"]) 
 	.field(data["sensor_name"], int(data["value"])
 	))
	self.write_api.write(bucket=self.cloud_bucket, org=self.cloud_org, record=p)
	print(p, flush=True)

Tags

Measurements are the InfluxDB equivalent to tables in a relational database. My code makes good use of tags. Tags aren’t required but come in handy because they’re metadata that makes the data easier to understand and work with. In this case, they can specify different plants, devices or something else depending on how complicated you want to get.

Querying Data

👁 Image
Queries return tables similar to the one below. Before I can query my data, I need to initialize the Flight SQL client. from flightsql import FlightSQLClient Followed by:
# This is our flight client setup, it’s how we will query from IOX
 	# we need to remove the Https:// from our host
 	host = host.split("://")[1]
 	self.flight_client = FlightSQLClient(host=host,
 	token=token,
 	metadata= {'bucket-name': bucket}
 	 )
 
 	self.cloud_bucket = bucket
 	self.cloud_org = org
Below is a basic SQL query to retrieve data from InfluxDB. SELECT {sensor_name}, time FROM sensor_data WHERE time > (NOW() - INTERVAL '2 HOURS') AND device_id='{deviceID}' Before we can retrieve and read the data, we have to convert it to Pyarrow format. The code below is a function that includes the query and connection to Flight SQL to retrieve the data.
def querydata(self, sensor_name, deviceID) -> DataFrame: 	
 
 query = self.flight_client.execute(f"SELECT {sensor_name}, time FROM sensor_data WHERE time > (NOW() - INTERVAL '2 HOURS') AND device_id='{deviceID}'")
 	
 # Create reader to consume result
 	reader = self.flight_client.do_get(query.endpoints[0].ticket)
 
 	# Read all data into a pyarrow.Table
 	Table = reader.read_all()
 	print(Table)
 
 	# Convert to Pandas DataFrame
 	df = Table.to_pandas()
 	df = df.sort_values(by="time")
 	print(df)
 	return df
You can call the previous query and substitute the variables for your selections, including bucket, sensor and device. The returned result allows you to graph your incoming data. The return df method pulls our data out in a data frame format.

Data Frames

Pandas DataFrames are two-dimensional data structures that enable fast data analysis and processing. We convert our data to a DataFrame to make it easier to work with in Python. There are a few other data output options to choose from if you prefer a different style.
@app.callback(Output("store", "data"), [Input("button", "n_clicks")])
def generate_graphs(n):
# Generate graphs based upon pandas data frame. 
 df = influx.querydata( "soil_temperature", graph_default["deviceID"] )
 soil_temp_graph = px.line(df, x="time", y="soil_temperature", title="Soil Temperature")
 
 df = influx.querydata( "air_temperature", graph_default["deviceID"] )
 air_temp_graph= px.line(df, x="time", y="air_temperature", title="Air Temperature")
 
 df = influx.querydata( "humidity", graph_default["deviceID"] )
 humidity_graph= px.line(df, x="time", y="humidity", title="humidity")
 
 df = influx.querydata( "soil_moisture", graph_default["deviceID"] )
 soil_moisture= px.line(df, x="time", y="soil_moisture", title="Soil Moisture")
 
 df = influx.querydata( "light", graph_default["deviceID"] )
 light_graph= px.line(df, x="time", y="light", title="light")

The graphing library expects you to return a data frame for visualization. This is the end result of querying for the data points. The images below are hard-coded graphs that illustrate the data points. Different tabs display different graphs and track separate metrics. This is just a small portion of the project’s capabilities.

Conclusion

Check out my presentation centered around Plant Buddy for a more in-depth discussion on this project and the InfluxDB ecosystem at large. Our community page has other great examples of exciting projects. Now get started with InfluxDB and build something cool!
InfluxData is the creator of InfluxDB, the leading time series platform. More than 1,900 customers use InfluxDB to collect, store, and analyze all time series data at any scale. Developers can query and analyze their time-stamped data to predict, respond, and adapt in real-time.
Learn More
The latest from InfluxData
TRENDING STORIES
Zoe Steinkamp is a developer advocate for InfluxData, after working as a frontend software engineer for over eight years. As developer advocate, she helps developers to engage with the InfluxData database platform, open source tools and time series data solutions....
Read more from Zoe Steinkamp
InfluxData sponsored this post.
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Pragma.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
👁 Image
Join the millions of developers using InfluxDB to predict, respond, and adapt in real-time.