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.

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
The Talk covers various experiments with JavaScript and C++, including controlling lights and creating a car control system. The speaker shares his experiences with home automation and the challenges of hiding wires. He explores using JavaScript with Esperino for face recognition and discusses the benefits and limitations of the platform. The Talk concludes with suggestions for using JavaScript in hardware projects and learning opportunities.
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
Watch video: Journey Into the Unknown: My Adventure Unravelling the Mysteries of the Netflix TVUI Universe
This Talk explores the journey of a software developer in unraveling the mysteries of Netflix TV UI. It emphasizes the importance of continuous learning in TV UI development and discusses the use of React and the TV signup process. The Talk also highlights the significance of widgets, navigation, and the TVUI Explorer app in building TV UI. It delves into the TVUI dev process, testing layers, and the value of continuous learning and fresh perspectives in the tech industry. The Talk concludes with insights on job opportunities, resources for TV development, and the Netflix hiring process.
Let’s Build a TV Spatial Navigation
React Advanced Conference 2023React Advanced Conference 2023
18 min
Let’s Build a TV Spatial Navigation
Watch video: Let’s Build a TV Spatial Navigation
This talk discusses the challenges of implementing spatial navigation for TV controls and the need for a library. The approach to spatial navigation can be improved by developing extra logic to connect TV control with the application. The demo application showcases the use of a NavigationEngine class and the useFocusRef hook function. The integration logic involves selecting the next node based on key presses and node coordinates. The talk also highlights the challenges of complex arrangements and circular navigations in smart TV application development.
Hacking an e-Reader with React
React Advanced Conference 2023React Advanced Conference 2023
7 min
Hacking an e-Reader with React
Watch video: Hacking an e-Reader with React
React for eBooks? Learn how to hack an eReader to display a tea menu. Create images and write e-books using React. Use EPUB format to create chapters and include CSS. Use Pandoc and Dino to simplify the process and make quick updates.
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
The Talk discusses the challenges of IoT development, including issues with fleet offline, data missing, alerts not working, inconsistent data, and slow loading dashboards. It explores how to build observability in IoT applications using metrics, logging, and tracing. The integration between the rules engine and Lambda is explained, highlighting the use of tools like Lambda Power Tools and X-Ray for logging, monitoring, and tracing. The Lambda invocation process and the tracing capabilities of X-Ray are also mentioned.
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
This Talk is an introduction to IoT and JavaScript, discussing the use of JavaScript and Node for IoT projects, the importance of data considerations and choosing the right databases, and the practical implementation of an Internet-connected kitty litter box. It also explores controlling LEDs with Johnny-5, solving the load cell problem, and the future of IoT. The speaker encourages experimentation and shares cool IoT projects like the magic mirror and internet-connected nano leaves. Practical IoT projects and joining the speaker's discussion rooms are also suggested for beginners.

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