Using the Flux VS Code Extension for IoT Application Development
Anais Dotis-Georgiou /
Use Cases, Developer, Product
Sep 20, 2021
InfluxData prides itself on its effort to prioritize developer happiness. This included providing developers with a variety of tools to interact with InfluxDB v2 OSS or InfluxDB Cloud, so they can pick the development style that works best for them. This article assumes you’re using the InfluxDB Cloud Free tier, which is the easiest way to get started and maintain InfluxDB. You can use any of the following tools for your IoT application development:
The Visual Studio Code Flux extension in combination with the CLI is the preferred tool for most developers. The CLI offers an easy approach to InfluxDB database management, and the Visual Studio Code Flux extension provides an easy way to query and write Flux scripts (including Flux tasks). If you haven’t given it a try already, I encourage you to install the Flux extension for Visual Studio Code. To query your InfluxDB Cloud account with the Flux extension, you must first configure it and connect to your cloud account.
How developers are using the Flux VS Code Extension
I recommend checking out this three-part blog series on building a house plant monitoring application on top of InfluxDB with the CLI and VS Code Flux extension for an example of how to leverage those tools for IoT application development.
- Part One: Prototyping IoT with InfluxDB Cloud
- Part Two: Queries, Tasks and Dashboards
- Part Three: Building an IoT App with InfluxDB Cloud, Python and Flask
I also enjoy using the Flux VS Code extension for debugging complicated Flux scripts and optimizing the performance of my Flux scripts because I can save my Flux scripts and easily compare Flux performance with the Flux Profiler.
Exciting new features in the Flux VS Code Extension
Today I want to take a moment to highlight the new features that were included in the latest release. They include the ability to:
- Create and delete buckets
- Create and delete tasks
To create a bucket, right-click on the Buckets dropdown and select Create bucket.
This will bring you to a configuration tab where you can name your bucket and specify the retention period of your bucket. Click Create to create your bucket.
To delete a bucket, right-click on any bucket in the Buckets dropdown and select Delete bucket. Delete tasks in the same way you delete buckets.
To create a task, right click on the Tasks dropdown and select Create task, which will bring you to the following tab where you configure your task options.
Click Save and continue to create a new task. A new tab is populated with the task options and Flux boilerplate. Write your Flux query after the task options. Right-click on the task tab to Run Query and verify that your Flux is transforming your data correctly. The output of your task will be populated in a tab to the right.
It’s best practice to use task options in your task script. To ensure that your script queries data from the last time the task was run, use the task.every option in your range() function,
|> range(start:-task.every). Additionally, make sure to append the to() function to your query to write your new data to a new destination bucket or measurement. Finally, save the task script to create an active task in InfluxDB Cloud.
Final thoughts on the Flux VS Code Extension
I hope this post inspires you to take advantage of the Visual Studio Code Flux extension. If you are using the extension or Flux and need help, please ask for some in our community site or Slack channel. If you’re developing a cool IoT application on top of InfluxDB, we’d love to hear about it, so make sure to share your story! Additionally, please share your thoughts, concerns or questions in the comments section. We’d love to get your feedback and help you with any problems you run into!
While this post aims to provide a comprehensive overview of how to optimize the performance of your Flux queries, the following resources might also interest you:
- TL;DR InfluxDB Tech Tips – Optimizing Flux Performance in InfluxDB Cloud: This post describes how to optimize your Flux performance with the Flux Profiler and the Flux VS Code extension.
- Use the Flux VS Code extension: The documentation page on how to install and set up the Flux VS Code extension.