TNS
VOXPOP
Will JavaScript type annotations kill TypeScript?
The creators of Svelte and Turbo 8 both dropped TS recently saying that "it's not worth it".
Yes: If JavaScript gets type annotations then there's no reason for TypeScript to exist.
0%
No: TypeScript remains the best language for structuring large enterprise applications.
0%
TBD: The existing user base and its corpensource owner means that TypeScript isn’t likely to reach EOL without a putting up a fight.
0%
I hope they both die. I mean, if you really need strong types in the browser then you could leverage WASM and use a real programming language.
0%
I don’t know and I don’t care.
0%
Edge Computing / Software Development

Building an IoT Weather Station with MicroPython or Arduino

How we built an IoT weather station that backs up sensor data to InfluxDB. It is open source and has implementations using both Arduino and MicroPython.
May 27th, 2022 10:19am by
Featued image for: Building an IoT Weather Station with MicroPython or Arduino
Feature image via Pixabay

Getting started with IoT development can be intimidating, even for simple hobby projects. There are many options when it comes to both hardware and software and ways to integrate them to achieve the goals of your project.

Charles Mahler
Charles is a technical marketing writer at InfluxData. Charles’ background includes working in digital marketing and full-stack software development.

To help you get started, this article will walk through some of the decisions we made at InfluxData when creating an IoT weather station as a prototype for potential customers and prizes for developers, as well as a reference architecture for those building their own IoT setups.

The weather station backs up sensor data to an instance of InfluxDB and can pull historical data from it to show on its OLED display. Data pulled from external APIs can be displayed by clicking on the external button to flip between different dashboards. It is open source and has implementations using both Arduino and MicroPython.

Purpose of the InfluxData Weather Station

Some of the problems solved by a time-series database and why they are useful can be abstract, even when explaining them to people with technical backgrounds. So we wanted to come up with something that would make things a bit more concrete conceptually, as well as make it easier to get up and running.

Here are some of the requirements we considered when designing the weather station:

  • Cheap enough to build that we could send them to potential customers for testing or as gifts at events.
  • Easy to set up and start generating time-series data.
  • Source code is useful as reference material for developers looking to integrate InfluxDB with their IoT application.
  • Stand out at events compared to usual demos that involved dashboards on a laptop.

Working with those requirements, this was the result:

Based on the positive response from developers, we have continued development and added more functionality that we thought would be helpful to users for learning purposes. Newer versions of the weather station also feature improved cases and dashboards to show more information.

Hardware Breakdown

There are three main components in the weather station: the microcontroller, display and sensor. For the microcontroller, we went with the ESP8266 due to the built-in Wi-Fi support, which would simplify the setup process by allowing users to connect to the device through that Wi-Fi access point and configure it through a web interface. The ESP8266 also has a number of SDKs available, which made the development process easier.

The second component is the OLED display, which is used for the dynamic dashboards that show different data from the sensors and external data sources. For this, we went with the SSD1306. For the sensor, we used a DHT11 sensor, which is able to collect temperature and humidity data.

The case that holds the components is 3D printed. The design is also available in the GitHub repo. For the newest version of the weather station, the sides have vents, which reduces the amount of material used while printing and also makes the temperature sensor more accurate. We now use a biodegradable material for printing rather than a standard plastic that was used on the first iteration. We’ve also improved the fasteners inside the case that hold the components in place so the device is more stable when moved around.

Modified case design to improve airflow and reduce material used.

Weather station internal components after removing side panel.

Software Breakdown

For software, the full-featured implementation is written in Arduino, which is essentially an extension of C/C++ with some features to make working with hardware easier. There is also a less complex MicroPython implementation. The source code for both is available on GitHub, along with installation instructions if you have compatible hardware.

The weather station takes advantage of a number of other open source libraries to add features. To make it easier to get started, we used the ESP Async Web Server to provide a web interface so users don’t have to use the command line to interact with the device.

Web UI for configuring weather station

You can find a list of the other libraries used in the GitHub repo, if you are interested.

Weather Station Dashboards

The weather station provides the following dashboards via its OLED display:

  • Line chart showing the last 90 minutes of data collected by sensors
  • Three-day weather forecast
  • Local weather data based on geolocation
  • Sunset and sunrise dashboard
  • COVID spread risk dashboard generated based on humidity and temperature based on this research study

Dashboards that aren’t using direct sensor data pull information from the open weather map API. Here are some images of those dashboards in action:

Sunrise and sunset dashboard

Three-day forecast dashboard

InfluxDB Integration

The weather station will hold and display data for the last 90 minutes on its charts by default. If you want a more permanent way to store historical data, you will need to integrate with some sort of storage.

Because it was designed as a demo application for InfluxDB, that is currently the only built-in integration via the InfluxDB Arduino client library. Using the web interface, you can provide the URL and an API key for any InfluxDB instance that is accessible via network. Any other data store with Arduino support could also be added by forking and extending the project.

Here are a few examples of historical data being displayed using InfluxDB’s built-in visualization tools:

Last 30 days of humidity and temperature data from the weather station running in my house — humidity is purple and temperature is blue

 

Humidity and temperature data after the weather station was put into a freezer and then removed over the course of an hour — humidity is blue, temperature is purple.

What Can You Do with the Weather Station?

The weather station isn’t intended to be a workhorse in terms of processing power by any means, but it does its job of being able to get data into InfluxDB. Once that happens, there is quite a bit you can do. Let’s look at a few potential ideas.

Create Automations and Alerts

Once your data is inside InfluxDB, you can easily create alerts and automations to act on your data. For example, you can schedule a query to run at a defined interval to check the humidity and temperature values. If they are above or below a certain threshold, you can create a task to take action on that accordingly.

InfluxDB provides a number of integrations with things like Slack or Twilio (over 20 total) to generate alerts. You could also use an IoT platform like Node-RED that provides integrations with many different devices and services, and that allows you to create custom functionality using JavaScript. One example could be using InfluxDB to send data to a Node-RED endpoint and then connect Node-RED to your smart thermostat to automatically adjust the temperature in your house.

Time-Series Forecasting and Analysis

Creating basic alerts and tasks is definitely useful, but the real value of time series is unlocked when you are able to start doing more detailed analysis and forecasting on your data. This could be done using a number of built-in methods provided by Flux or in your programming language of choice using InfluxDB’s client libraries. Python is a very common choice for this type of work using libraries like Pandas to manipulate and visualize data.

Conclusion

Hopefully this article has given you some potential ideas for your IoT project and how you can benefit from using a time-series database like InfluxDB. If you want some info on an IoT setup with more processing power and versatility than the weather station, you should also check out our breakdown of the Raspberry Pi cluster we use for generating demo data and running basic benchmarks.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Pragma.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.