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.

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.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

How I've been Using JavaScript to Automate my House
JSNation 2022JSNation 2022
22 min
How I've been Using JavaScript to Automate my House
Software Programming is naturally fun but making something physical, to interact with the world that you live in, is like magic. Is even funnier when you can reuse your knowledge and JavaScript to do it. This talk will present real use cases of automating a house using JavaScript, Instead of using C++ as usual, and Espruino as dev tools and Microcontrollers such as Arduino, ESP8266, RaspberryPI, and NodeRed to control lights, doors, lockers, and much more.
Journey Into the Unknown: My Adventure Unravelling the Mysteries of the Netflix TVUI Universe
React Summit US 2023React Summit US 2023
30 min
Journey Into the Unknown: My Adventure Unravelling the Mysteries of the Netflix TVUI Universe
At Netflix, millions of our users watch Netflix on TV Devices. How do we develop the UI for all of the different types of devices? That's exactly what I wanted to know! I'll be sharing why it's important to take on new growth opportunities, how to navigate the difficulties of learning a whole new platform at a new company, and some of the things I've learned about how we use React to bring Netflix to your TV!
Let’s Build a TV Spatial Navigation
React Advanced Conference 2023React Advanced Conference 2023
18 min
Let’s Build a TV Spatial Navigation
In this talk, I'll take you through my journey as I joined the team supporting our Smart TVs application and share my experience learning one of the most overlooked but essential pieces of functionality we have.
Tools for better Observability in NodeJS Serverless IoT Applications
Node Congress 2023Node Congress 2023
8 min
Tools for better Observability in NodeJS Serverless IoT Applications
Observability is crucial for successfully operating large IoT fleets. IoT incorporates different components, including hardware, network, on-device software, and cloud. Devices operate under unreliable conditions and constraints, and need to be monitored remotely. Cloud applications become complex and costly, as they are built to handle device activity at scale. Answering questions such as:
-    Do I have a problem in my IoT application?
-    Where is the problem?
-    What is causing the problem?
-    How much of my fleet is affected?
-    Is my code expensive to run and if yes, how can I fix that? ,
can be challenging. Logging, monitoring and tracing are fundamental observability pillars. However, they are often viewed as non-functionals in IoT applications, and can fall off the radar, or are not standardized during development.

This session will show how to leverage Open Source tools, such as AWS Lambda PowerTools, in a fully functional Serverless IoT application, to ease adoption of best practices for modern application development, and integrate services such as Amazon X-Ray, Amazon CloudWatch and AWS IoT Core features, to achieve end-to-end observability.
An Introduction To IoT; Or How I Built an IoT Kitty Litter Box Using JavaScript
JSNation Live 2021JSNation Live 2021
23 min
An Introduction To IoT; Or How I Built an IoT Kitty Litter Box Using JavaScript
My favorite things in life are cats, computers and crappy ideas, so I decided to combine all three and make an IoT (Internet of Things) litter box using a Raspberry Pi and JavaScript! If you have ever wanted to get build your own IoT project, but didn’t know how to start, then this is the talk for you.Together, we will go through how I setup my IoT Litter Box from start to finish. Including how to setup Node.js on a Raspberry Pi and how to connect sensors to a Raspberry Pi and how to read the sensor inputs with Node.js.
Hacking an e-Reader with React
React Advanced Conference 2023React Advanced Conference 2023
7 min
Hacking an e-Reader with React
I wanted to have a tea menu to show guests and for my own reference. Turns out e-Readers use so little power and can render HTML! I'll share how to generate an e-book with all your drinks with React using Deno, as well as rendering a custom cover page with SVG. Wow your friends by turning an old device into a smart home tea menu, and learn how to write your next book with React.

Workshops on related topic

Build an IoT App With InfluxDB
JSNation Live 2021JSNation Live 2021
105 min
Build an IoT App With InfluxDB
Workshop
Miroslav Malecha
Miroslav Malecha
InfluxDB is an open source time series database that empowers developers to build IoT, analytics and monitoring software. It is purpose-built to handle the massive volumes and countless sources of time-stamped data produced sensors, applications and infrastructure.
This workshop showcases a fully functional sample application called IoT Center that is built on InfluxDB. This application demonstrates the capabilities of the InfluxDB platform to develop a JavaScript-enabled time-series-based application. It collects, stores and displays a set of values that include temperature, humidity, pressure, CO2 concentration, air quality, as well as provide GPS coordinates from a set of IoT devices. With this data stored in InfluxDB, the application can query this data for display as well as write data back into the database.
This hands-on workshop will show students how to install this open source code to learn how to query and write to InfluxDB using the InfluxDB JavaScript client, and gain familiarity with the Flux lang query language which is designed for querying, analyzing, and acting on time series data. And finally, collect and visualize performance data of the Node JS application.
IoT Center Workshop by InfluxData
Node Congress 2021Node Congress 2021
131 min
IoT Center Workshop by InfluxData
Workshop
Miroslav Malecha
Miroslav Malecha
InfluxDB is an open source time series database that empowers developers to build IoT, analytics and monitoring software. It is purpose-built to handle the massive volumes and countless sources of time-stamped data produced sensors, applications and infrastructure. This workshop showcases a fully functional sample application called IoT Center that is built on InfluxDB. This application demonstrates the capabilities of the InfluxDB platform to develop a JavaScript-enabled time-series-based application. It collects, stores and displays a set of values that include temperature, humidity, pressure, CO2 concentration, air quality, as well as provide GPS coordinates from a set of IoT devices. With this data stored in InfluxDB, the application can query this data for display as well as write data back into the database.
This hands-on workshop will show students how to install this open source code to learn how to query and write to InfluxDB using the InfluxDB JavaScript client, and gain familiarity with the Flux lang query language which is designed for querying, analyzing, and acting on time series data. And finally, collect and visualize performance data of the Node JS application.
Prerequisites
Registered free InfluxDB Cloud account at https://cloud2.influxdata.comThree options available (via Google account, via Microsoft account or via email)Test login after the registration and save credentials for the workshopInstallation of the git tool (e.g. from https://git-scm.com/downloads)IoT Center cloneRun: git clone https://github.com/bonitoo-io/iot-center-v2Installed nodejs (from https://nodejs.org/en/download)Installed yarn package manager (from https://classic.yarnpkg.com/en/docs/install)Installed required packagesIn the cloned directoryRun: cd appRun: yarn install