Building an IoT App With InfluxDB, JavaScript, and Plotly.js

Rate this content
Bookmark

The Internet of Things (IoT) is increasingly driven by sensor data, with devices taking measured actions based on everything from wind speed and direction, vital body functions, illumination intensity, and temperature.


In this session we will showcase how to build a fully functional sample IoT monitoring application built with javascript and utilizing InfluxDB as its backend. With integrations to visualization libraries such as Plotly, creating automated alerts with InfluxDB as well as data downsampling.

This talk has been presented at JSNation 2023, check out the latest edition of this JavaScript Conference.

FAQ

InfluxDB is a time series database designed to handle high write and query loads, making it ideal for IoT projects which often involve high data ingestion rates and the need for real-time analytics.

Time series data is data collected at regular intervals over time, focusing on tracking changes. This contrasts with other data types that might not be time-dependent or regularly updated.

Common sensors in IoT plant applications include light sensors, humidity sensors, soil temperature sensors, and moisture sensors to monitor various environmental conditions affecting plant growth.

The Telegraph plugin library is an open-source library used for collecting time series data in IoT projects. It supports over 300 plugins, offering flexibility depending on the IoT device used.

To set up an IoT device for monitoring plant conditions, you need a microcontroller like Particle Boron, various sensors (e.g., for humidity, light), a breadboard, and jump wires for connections. Data is collected from sensors and processed via a server or directly to a cloud platform like InfluxDB.

First, collect data using sensors and a microcontroller. Use a JavaScript client library to send data to InfluxDB. Finally, query the data from InfluxDB and visualize it using PlotlyJS to create interactive graphs based on the collected sensor data.

In InfluxDB, you can set data retention policies for each bucket (database) to specify how long data should be retained. API tokens are used for authentication, allowing read and write access to the database, with the option to set specific permissions for security.

Yes, you can use Python for IoT projects. There is a Python version of the Plant Buddy project available, which similarly utilizes InfluxDB and sensor data collection for plant monitoring.

Zoe Steinkamp
Zoe Steinkamp
20 min
05 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk introduces building an IoT app with InfluxDB, JavaScript, and PlotlyJS, highlighting the benefits of time series databases for handling high ingestion rates and data manipulation. It provides instructions for setting up IoT devices and connecting sensors, along with data cleaning and transformation techniques. The Talk covers creating a bucket in InfluxDB, using JavaScript client libraries for data read and write, querying and graphing data with InfluxDB and Plotly.js, creating dashboards, and available learning resources. Overall, it offers a comprehensive overview of building IoT applications with InfluxDB.

1. Introduction to InfluxDB and IoT Data

Short description:

Hello, and welcome to my presentation. Today, I'll be going over building an IoT app with InfluxDB, JavaScript, and PlotlyJS. Time series data is different from other types of data, and for our project, IoT data is considered metrics data. Time series databases are ideal for storing IoT data as they can handle high ingestion rates and allow for data manipulation over time. We provide the Telegraph plugin library for data acquisition, but you can also use our JavaScript client library. Feel free to check out the project link to follow along and deploy the project on your own.

Hello, and welcome to my presentation. So today I'm going to be going over building an IoT app with InfluxDB, JavaScript, and PlotlyJS. My name is Zoe Steinkamp. I am a developer advocate at InfluxData, which means I am a person who not only likes to educate developers on some of our features, but also just in general listen to our open source community and talk with them about different things that they'd like to see and, you know, get feedback and help people.

If you have any questions, feel free to reach out to me on LinkedIn after this talk and just in general. So the agenda today, I'll go over the InfluxDB overview just to give you an idea of some of the tools that we're using the IoT hardware setup, the data ingestion setup, the data request, and then the GitHub code base. And again, you can feel free to reach out to me with questions on LinkedIn.

So introduction to InfluxDB. So first things first, something that you should probably understand is that time series data is a little bit different than some of the data that you're probably more used to working with. And for our project, IoT data is considered metrics data. It's values that are collected regularly over time. So for example, as you're going to find out in this project, for the plant, we monitor things like the humidity of the air, the water amount in the soil, the overall moisture content. So those are going to be things where the sensors will send us a data point roughly every second or so depending on the sensor that you use and how you structure your data. But that is roughly what we would expect. There's other types of time series data, things that are events that are more regularly generated and also things like traces. So as I mentioned before, time series databases are a pretty good spot for putting your IoT data. You're going to find that through most of the internet if you start to build up your own IoT projects. Most people will mention the fact that you really want to pick a database that can handle the higher ingestion rate, but also make sure that you can do things like downsampling or manipulating your data, especially over time. Things like I want to know at this time period what was happening to the plant. It's a little harder to do that in other types of DBS, especially a SQL DB, which is not built for that type of querying normally.

And when it comes to data acquisition methods, so one thing to note is that we do take care of the Telegraph plugin library, which is an open-source plugin library for specifically time series data. It has a lot of different plugin options. It has about 300 plus. And some of these might actually work for your use case, depending on the IoT device that you're working with. For the project, I'm using a Boron particle microcontroller which is very specific in how it works and how I get data off of it. So I'm using the client library, specifically our JavaScript client library, to get that data off. But you also might be able to use Telegraph depending on the device that you have. So, I'm going to go ahead and link the project here. So go ahead and grab this link. This will allow you to follow along as well as to actually deploy this project on your own.

2. Setting up IoT devices and required components

Short description:

It just gives you in general the code, the instructions, explanations for things that possibly I'm not going to get into quite as much during my 20 minutes here. So setting up your IoT devices. Basically, how this works is the microcontroller reads the data off of your IoT sensors. From there, it goes through the JS client library and is put up into InfluxDB Cloud. You're going to need a plant, preferably alive. A particle bore on microcontroller or another compatible microcontroller. If you choose to use something like a Raspberry Pi for this project, you're going to have to do a lot to get it to work. Different microcontroller brands do things slightly differently in how much capability they give you to get the data off.

It just gives you in general the code, the instructions, explanations for things that possibly I'm not going to get into quite as much during my 20 minutes here. And you know, it's just a good link to grab. I won't be repeating this link, so I'm going to leave this up for just one more second here. All right. And I can probably post this. If we have like a chat or anything, when this goes live, I'll go ahead and post it there.

So setting up your IoT devices. So a really quick background. Basically, how this works is the microcontroller reads the data off of your IoT sensors. So like I said, that's going to be things like a light sensor, humidity, soil temperature. This is all in the context of a plant. So these are all things that plants tend to care about. If you were to do an IoT project that was not plant-based, maybe you're monitoring something like beer brewing or an aquarium, your sensors are going to be slightly different which is why I just categorized them as IoT devices.

From there, you send it through, at least for my personal use, we send it through a server, basically normally my home Wi-Fi. And from there, the application server, which is normally my computer. Basically, my computer has a USB that is plugged into it that reads the data off of my microcontroller. It's not an ideal setup. In the future, I think I'd like to maybe route it through something like Raspberry Pi or some other type of application server that I could use. Something that is not my laptop, but for now, that's how this setup works. From there, it goes through the JS client library and is put up into InfluxDB Cloud. You could also put it into the InfluxDB open source. We'll have examples for both of those within the GitHub project, so you can kind of pick your own adventure somewhat and decide where you want to put your data.

You're going to need in no particular order as you can see from my beautiful photo setup here, a plant, preferably alive. I've done it with a fake plant. It doesn't really work that well. A particle bore on microcontroller or another compatible microcontroller. We have the code for an Arduino as well, so you can reference that one. If you choose to use something that's a little, like if you choose to use like a Raspberry Pi for this project, you're going to have to do a lot of, what's the word here? Difficulty code. You're just going to have to do a lot to get it to work, but I will say that there is tons and tons of resources online about getting a Raspberry Pi to do something similar to this, but just keep in mind that different microcontroller brands, different brands in general when it comes to these type of IoT devices, they do things slightly differently in how much capability they give you to get the data off. Some of them give you a lot of capabilities.