{"id":110608,"date":"2024-05-14T18:28:10","date_gmt":"2024-05-14T18:28:10","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=110608"},"modified":"2024-05-21T08:55:03","modified_gmt":"2024-05-21T08:55:03","slug":"esp32-influxdb","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-influxdb\/","title":{"rendered":"ESP32: Getting Started with InfluxDB"},"content":{"rendered":"\n<p>This guide will get you started quickly with InfluxDB using the ESP32 board. InfluxDB is an open-source time series database (TSDB). It&#8217;s ideal to store sensor data with timestamps over a determined period. In this tutorial, you&#8217;ll set up an InfluxDB bucket to save data from the ESP32.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-Getting-Started-with-InfluxDB.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Board Getting Started with InfluxDB Arduino IDE\" class=\"wp-image-110667\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-Getting-Started-with-InfluxDB.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-Getting-Started-with-InfluxDB.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-Getting-Started-with-InfluxDB.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-Getting-Started-with-InfluxDB.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p><em>Updated 14 May 2024<\/em><\/p>\n\n\n\n<p>We have a similar tutorial for the <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-influxdb\/\">ESP8266 NodeMCU board: Getting Started with InfluxDB<\/a><\/p>\n\n\n\n<p><strong>Table of Contents<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#influxdb-intro\">Introducing InfluxDB<\/a><\/li>\n\n\n\n<li><a href=\"#create-influxdb-account\">Creating an InfluxDB Account<\/a><\/li>\n\n\n\n<li><a href=\"#load-data-influxdb\">Loading Data in InfluxDB<\/a><\/li>\n\n\n\n<li><a href=\"#ESP32-influxdb\">Interfacing the ESP32 with InfluxDB<\/a><\/li>\n\n\n\n<li><a href=\"#visualize-data\">Visualizing Data on InfluxDB<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"influxdb-intro\">What is InfluxDB?<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"400\" height=\"104\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/influxdb-logo.png?resize=400%2C104&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"What is InfluxDB\" class=\"wp-image-110655\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/influxdb-logo.png?w=400&amp;quality=100&amp;strip=all&amp;ssl=1 400w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/influxdb-logo.png?resize=300%2C78&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/figure><\/div>\n\n\n<p>InfluxDB is an open-source high-performance time series database (TSDB) that can store large amounts of data per second. Each data point you submit to the database is associated with a particular timestamp. So, it is ideal for IoT datalogging projects like storing data from your weather station sensors.<\/p>\n\n\n\n<p>You can run <a href=\"https:\/\/www.influxdata.com\/products\/influxdb\/\" target=\"_blank\" rel=\"noreferrer noopener\">InfluxDB in InfluxDB Cloud<\/a>, or locally on your laptop or <a href=\"https:\/\/randomnerdtutorials.com\/install-influxdb-2-raspberry-pi\/\">Raspberry Pi<\/a>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&#8220;<strong>Why use InfluxDB Cloud?<\/strong> It&#8217;s a fast, elastic, serverless real-time monitoring platform, dashboarding engine, analytics service and event and metrics processor.&#8221;<\/p>\n<cite>https:\/\/www.influxdata.com\/products\/influxdb-cloud\/<\/cite><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">InfluxDB Key Terms<\/h3>\n\n\n\n<p>Before getting started, there are some important terms you need to understand. We&#8217;ll just take a look at the most relevant terms, you can read the complete <a href=\"https:\/\/docs.influxdata.com\/influxdb\/v2.2\/reference\/glossary\/\" target=\"_blank\" rel=\"noreferrer noopener\">glossary<\/a>. Don&#8217;t worry if some of the terms are confusing. You&#8217;ll better understand those terms when you start writing to the database.<\/p>\n\n\n\n<p>In InfluDB, a <strong>bucket<\/strong> is named location where the time series data is stored. All buckets have a <strong>retention period<\/strong>\u2014it defines the duration of time that a bucket retains data. Points with timestamps older than the retention period are dropped.<\/p>\n\n\n\n<p>Data in InfluxDB is stored in tables within rows and columns. A set of data in a row is known as <strong>point<\/strong> (similar to a row in a SQL database table). Each point has a <strong>measurement<\/strong>, a <strong>tag set<\/strong>, a <strong>field key<\/strong>, a <strong>field value<\/strong>, and a <strong>timestamp<\/strong>;<\/p>\n\n\n\n<p>Columns store <strong>tag sets<\/strong> (indexed) and <strong>fields sets<\/strong>. The only required column is <strong>time<\/strong>, which stores <strong>timestamps <\/strong>and is included in all InfluxDB tables.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>tag<\/strong>: the key-value pair in InfluxDB\u2019s data structure that records metadata. Tags are an optional part of InfluxDB\u2019s data structure but they are useful for storing commonly-queried metadata; tags are indexed so queries on tags are performant.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>tag key<\/strong>: tag keys are strings and store metadata. Tag keys are indexed so queries on tag keys are processed quickly.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>tag value<\/strong>: tag values are strings and they store metadata. Tag values are indexed so queries on tag values are processed quickly.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>field<\/strong>: the key-value pair in InfluxDB\u2019s data structure that records metadata and the actual data value. Fields are required in InfluxDB\u2019s data structure and they are not indexed &#8211; queries on field values scan all points that match the specified time range and, as a result, are not performant relative to tags.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>field key<\/strong>: the key of the key-value pair. Field keys are strings and they store metadata.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>field value<\/strong>: the value of a key-value pair. Field values are the actual data; they can be strings, floats, integers, or booleans. A field value is always associated with a timestamp. Field values are not indexed &#8211; queries on field values scan all points that match the specified time range and, as a result, are not performant.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>measurement<\/strong>: the part of InfluxDB\u2019s structure that describes the data stored in the associated fields.<\/li>\n<\/ul>\n\n\n\n<p>We also recommend taking a quick look at the <a href=\"https:\/\/docs.influxdata.com\/influxdb\/v2.2\/reference\/key-concepts\/\" target=\"_blank\" rel=\"noreferrer noopener\">InfluxDB key concepts<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"create-influxdb-account\">Creating an InfluxDB Account<\/h2>\n\n\n\n<p class=\"rntbox rntclblue\">If you want to run InfluxDB locally on a Raspberry Pi, follow the next tutorial first: <a href=\"https:\/\/randomnerdtutorials.com\/install-influxdb-2-raspberry-pi\/\">Install InfluxDB 2 on Raspberry Pi<\/a>. Then, proceed to the <a href=\"#load-data-influxdb\">Loading Data in InfluxDB<\/a> section.<\/p>\n\n\n\n<p><strong>1) <\/strong>Go to <a href=\"https:\/\/cloud2.influxdata.com\/signup\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/cloud2.influxdata.com\/signup<\/a> and create an InfluxDB account.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"431\" height=\"826\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-create-account.png?resize=431%2C826&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Creating an InfluxDB Account\" class=\"wp-image-110616\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-create-account.png?w=431&amp;quality=100&amp;strip=all&amp;ssl=1 431w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-create-account.png?resize=157%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 157w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/figure><\/div>\n\n\n<p><strong>2)<\/strong> Select where you want to save your data. Choose the place closer to your location. Insert a name for the Company and Organization.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"804\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/set-up-influxdb-2.png?resize=750%2C804&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB-set-up-account-organization\" class=\"wp-image-155351\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/set-up-influxdb-2.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/set-up-influxdb-2.png?resize=280%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 280w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>3)<\/strong> Select the InfluxDB plan. For this example, we&#8217;ll be using the Free plan. For most of our IoT projects, the Free plan works just fine. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"746\" height=\"664\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Influx-DB-Select-Plan.png?resize=746%2C664&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB select plan\" class=\"wp-image-110619\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Influx-DB-Select-Plan.png?w=746&amp;quality=100&amp;strip=all&amp;ssl=1 746w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Influx-DB-Select-Plan.png?resize=300%2C267&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/figure><\/div>\n\n\n<p><strong>4)<\/strong> Then, fill out the form to continue.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/how-do-you-plan-use-influxdb.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"743\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/how-do-you-plan-use-influxdb.png?resize=750%2C743&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB Getting Started Form\" class=\"wp-image-155353\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/how-do-you-plan-use-influxdb.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/how-do-you-plan-use-influxdb.png?resize=300%2C297&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/how-do-you-plan-use-influxdb.png?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n<p><strong>5)<\/strong> Finally, you&#8217;ll be redirected to the resource center.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-resource-center.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"461\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-resource-center.png?resize=750%2C461&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB resource center\" class=\"wp-image-155354\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-resource-center.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-resource-center.png?resize=300%2C184&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"load-data-influxdb\">Loading Data in InfluxDB<\/h2>\n\n\n\n<p><strong>6)<\/strong> Click on the<strong> Load Data<\/strong> icon and select <strong>Sources<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"319\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-sources-1.png?resize=655%2C319&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB Cloud Sources\" class=\"wp-image-155355\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-sources-1.png?w=655&amp;quality=100&amp;strip=all&amp;ssl=1 655w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-sources-1.png?resize=300%2C146&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 655px) 100vw, 655px\" \/><\/figure><\/div>\n\n\n<p><strong>7)<\/strong> Scroll down until you find the <strong>Arduino <\/strong>option under the <strong>Client Libraries<\/strong> section.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-client-libraries-arduino.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"481\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-client-libraries-arduino.png?resize=750%2C481&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB-Client-Libraries\" class=\"wp-image-155356\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-client-libraries-arduino.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-client-libraries-arduino.png?resize=300%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n<p><strong>8)<\/strong> Click on Initialize Client.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influx-db-initialize-arduino-client.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"565\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influx-db-initialize-arduino-client.png?resize=750%2C565&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB Initialize Arduino Client\" class=\"wp-image-155357\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influx-db-initialize-arduino-client.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influx-db-initialize-arduino-client.png?resize=300%2C226&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n<p>The page that opens allows you to create buckets, and it also shows some sample code to interface the ESP8266 or ESP32 boards with InfluxDB.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating an InfluxDB Bucket<\/h3>\n\n\n\n<p><strong>9)<\/strong> Create a new bucket to store your data. Click on <strong>+ Create Bucket<\/strong> to create a new bucket for this example. You can use the settings by default, or you can customize them.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"643\" height=\"386\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-creating-bucket.png?resize=643%2C386&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB Cloud Creating a Bucket\" class=\"wp-image-128153\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-creating-bucket.png?w=643&amp;quality=100&amp;strip=all&amp;ssl=1 643w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-creating-bucket.png?resize=300%2C180&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"influxdb-URL\">Getting InfluxDB URL and API Token<\/h3>\n\n\n\n<p><strong>10)<\/strong> Get your InfluxDB URL* and other details you&#8217;ll need later. Scroll down to the<em> Configure InfluxDB profile<\/em> snippet. Then, copy the <span class=\"rnthl rntliteral\">INFLUXDB_URL<\/span>, <span class=\"rnthl rntliteral\">INFLUXDB_TOKEN<\/span>, <span class=\"rnthl rntliteral\">INFLUXDB_ORG<\/span>, and <span class=\"rnthl rntliteral\">INFLUXDB_BUCKET<\/span>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-details-arduino-client.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"412\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-details-arduino-client.png?resize=750%2C412&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-128154\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-details-arduino-client.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-details-arduino-client.png?resize=300%2C165&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\"><strong>*<\/strong> if you&#8217;re running InfluxDB locally on a Raspberry Pi, the URL will be the Raspberry Pi IP address on port 8086. For example <span class=\"rnthl rntliteral\">192.168.1.106:8086<\/span>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"influxdb-token\">API Tokens<\/h3>\n\n\n\n<p>If you&#8217;ve followed the previous steps, InfluxDB Cloud has already created an API token that you can find in the snippet presented in the previous step. If you go to the Load Data icon and select API Tokens, you&#8217;ll find the previously generated API token.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"261\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-api-token.png?resize=750%2C261&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-128155\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-api-token.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-api-token.png?resize=300%2C104&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>On this page, you can generate a new API token if needed.<\/p>\n\n\n\n<p>At this moment, you should have saved the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>InfluxDB Server URL<\/li>\n\n\n\n<li>InfluxDB Organization<\/li>\n\n\n\n<li>InfluxDB Bucket Name<\/li>\n\n\n\n<li>API Token<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ESP32-influxdb\">Interfacing the ESP32 with InfluxDB<\/h2>\n\n\n\n<p>We&#8217;ll program the ESP32 using Arduino IDe, so make sure you have the ESP32 boards add-on installed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/installing-esp32-arduino-ide-2-0\/\" title=\"\">Installing ESP32 Board in Arduino IDE 2<\/a><\/li>\n<\/ul>\n\n\n\n<p>Alternatively, you can use VS Code with the PlatformIO extension. Check the following tutorial to get started with VS Code + PlatformIO:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/vs-code-platformio-ide-esp32-esp8266-arduino\/\">Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Install the InfluxDB Arduino Client Library<\/h3>\n\n\n\n<p>There is a library that makes it easy to interface the ESP32 with InfluxDB: the <a href=\"https:\/\/github.com\/tobiasschuerg\/InfluxDB-Client-for-Arduino\" target=\"_blank\" rel=\"noreferrer noopener\">InfluxDB Arduino Client Library<\/a>. This library is also compatible with ESP8266 boards.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Installation \u2013 Arduino IDE<\/h4>\n\n\n\n<p>If you\u2019re using Arduino IDE, follow the next steps to install the library.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong><\/li>\n\n\n\n<li>Search for InfluxDB and install the ESP8266 Influxdb library by Tobias Sh\u00fcrg (even though it has ESP8266 in the name, it is also compatible with the ESP32).<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"520\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/install-influxdb-library.png?resize=750%2C520&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install influxdb library arduino ide 2\" class=\"wp-image-155360\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/install-influxdb-library.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/install-influxdb-library.png?resize=300%2C208&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h4 class=\"wp-block-heading\">Installation \u2013 VS Code<\/h4>\n\n\n\n<p>If you&#8217;re using VS Code with the PlatformIO extension, start by creating an Arduino project for your ESP32 board.<\/p>\n\n\n\n<p>Then, click on the&nbsp;<strong>PIO Home<\/strong>&nbsp;icon and then select the&nbsp;<strong>Libraries tab<\/strong>. Search for \u201c<strong>influxdb<\/strong>\u201c. Select the&nbsp;<strong>ESP8266 Influxdb<\/strong> byt Tobias Sch\u00fcrg.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"648\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Install-InfluxDB-library-VS-Code.png?resize=734%2C648&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install InfluxDB library VS Code\" class=\"wp-image-110613\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Install-InfluxDB-library-VS-Code.png?w=734&amp;quality=100&amp;strip=all&amp;ssl=1 734w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Install-InfluxDB-library-VS-Code.png?resize=300%2C265&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 734px) 100vw, 734px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">ESP32 Save Data in InfluxDB<\/h3>\n\n\n\n<p>To show you how to save data to InfluxDB using the ESP32, we&#8217;ll take a look at one of the examples provided by the library. In your Arduino IDE, go to File &gt; Examples &gt; ESP8266 Infuxdb &gt; Secure Write. Or simply copy the code below to your Arduino IDE.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/**\r\n * Secure Write Example code for InfluxDBClient library for Arduino\r\n * Enter WiFi and InfluxDB parameters below\r\n *\r\n * Demonstrates connection to any InfluxDB instance accesible via:\r\n *  - unsecured http:\/\/...\r\n *  - secure https:\/\/... (appropriate certificate is required)\r\n *  - InfluxDB 2 Cloud at https:\/\/cloud2.influxdata.com\/ (certificate is preconfigured)\r\n * Measures signal level of the actually connected WiFi network\r\n * This example demonstrates time handling, secure connection and measurement writing into InfluxDB\r\n * Data can be immediately seen in a InfluxDB 2 Cloud UI - measurement wifi_status\r\n * \r\n * Complete project details at our blog: https:\/\/RandomNerdTutorials.com\/\r\n * \r\n **\/\r\n\r\n#if defined(ESP32)\r\n  #include &lt;WiFiMulti.h&gt;\r\n  WiFiMulti wifiMulti;\r\n#define DEVICE &quot;ESP32&quot;\r\n  #elif defined(ESP8266)\r\n#include &lt;ESP8266WiFiMulti.h&gt;\r\n  ESP8266WiFiMulti wifiMulti;\r\n  #define DEVICE &quot;ESP8266&quot;\r\n#endif\r\n\r\n#include &lt;InfluxDbClient.h&gt;\r\n#include &lt;InfluxDbCloud.h&gt;\r\n\r\n\/\/ WiFi AP SSID\r\n#define WIFI_SSID &quot;REPLACE_WITH_YOUR_SSID&quot;\r\n\/\/ WiFi password\r\n#define WIFI_PASSWORD &quot;REPLACE_WITH_YOUR_PASSWORD&quot;\r\n\/\/ InfluxDB v2 server url, e.g. https:\/\/eu-central-1-1.aws.cloud2.influxdata.com (Use: InfluxDB UI -&gt; Load Data -&gt; Client Libraries)\r\n#define INFLUXDB_URL &quot;REPLACE_WITH_YOUR_DATABASE_URL&quot;\r\n\/\/ InfluxDB v2 server or cloud API token (Use: InfluxDB UI -&gt; Data -&gt; API Tokens -&gt; Generate API Token)\r\n#define INFLUXDB_TOKEN &quot;REPLACE_WITH_YOUR_TOKEN&quot;\r\n\/\/ InfluxDB v2 organization id (Use: InfluxDB UI -&gt; User -&gt; About -&gt; Common Ids )\r\n#define INFLUXDB_ORG &quot;REPLACE_WITH_YOUR_ORG&quot;\r\n\/\/ InfluxDB v2 bucket name (Use: InfluxDB UI -&gt;  Data -&gt; Buckets)\r\n#define INFLUXDB_BUCKET &quot;ESP32&quot;\r\n\r\n\/\/ Set timezone string according to https:\/\/www.gnu.org\/software\/libc\/manual\/html_node\/TZ-Variable.html\r\n\/\/ Examples:\r\n\/\/  Pacific Time: &quot;PST8PDT&quot;\r\n\/\/  Eastern: &quot;EST5EDT&quot;\r\n\/\/  Japanesse: &quot;JST-9&quot;\r\n\/\/  Central Europe: &quot;CET-1CEST,M3.5.0,M10.5.0\/3&quot;\r\n#define TZ_INFO &quot;WET0WEST,M3.5.0\/1,M10.5.0&quot;\r\n\r\n\/\/ InfluxDB client instance with preconfigured InfluxCloud certificate\r\nInfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);\r\n\/\/ InfluxDB client instance without preconfigured InfluxCloud certificate for insecure connection \r\n\/\/InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN);\r\n\r\n\/\/ Data point\r\nPoint sensor(&quot;wifi_status&quot;);\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n\r\n  \/\/ Setup wifi\r\n  WiFi.mode(WIFI_STA);\r\n  wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);\r\n\r\n  Serial.print(&quot;Connecting to wifi&quot;);\r\n  while (wifiMulti.run() != WL_CONNECTED) {\r\n    Serial.print(&quot;.&quot;);\r\n    delay(500);\r\n  }\r\n  Serial.println();\r\n\r\n  \/\/ Add tags\r\n  sensor.addTag(&quot;device&quot;, DEVICE);\r\n  sensor.addTag(&quot;SSID&quot;, WiFi.SSID());\r\n\r\n  \/\/ Alternatively, set insecure connection to skip server certificate validation \r\n  \/\/client.setInsecure();\r\n\r\n  \/\/ Accurate time is necessary for certificate validation and writing in batches\r\n  \/\/ For the fastest time sync find NTP servers in your area: https:\/\/www.pool.ntp.org\/zone\/\r\n  \/\/ Syncing progress and the time will be printed to Serial.\r\n  timeSync(TZ_INFO, &quot;pool.ntp.org&quot;, &quot;time.nis.gov&quot;);\r\n\r\n  \/\/ Check server connection\r\n  if (client.validateConnection()) {\r\n    Serial.print(&quot;Connected to InfluxDB: &quot;);\r\n    Serial.println(client.getServerUrl());\r\n  } else {\r\n    Serial.print(&quot;InfluxDB connection failed: &quot;);\r\n    Serial.println(client.getLastErrorMessage());\r\n  }\r\n}\r\n\r\nvoid loop() {\r\n  \/\/ Store measured value into point\r\n  sensor.clearFields();\r\n  \/\/ Report RSSI of currently connected network\r\n  sensor.addField(&quot;rssi&quot;, WiFi.RSSI());\r\n  \/\/ Print what are we exactly writing\r\n  Serial.print(&quot;Writing: &quot;);\r\n  Serial.println(client.pointToLineProtocol(sensor));\r\n  \/\/ If no Wifi signal, try to reconnect it\r\n  if (wifiMulti.run() != WL_CONNECTED) {\r\n    Serial.println(&quot;Wifi connection lost&quot;);\r\n  }\r\n  \/\/ Write point\r\n  if (!client.writePoint(sensor)) {\r\n    Serial.print(&quot;InfluxDB write failed: &quot;);\r\n    Serial.println(client.getLastErrorMessage());\r\n  }\r\n\r\n  \/\/Wait 10s\r\n  Serial.println(&quot;Wait 10s&quot;);\r\n  delay(10000);\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP\/ESP_InfluxDB_SecureWrite.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Before uploading the code to your board, you need to insert your network credentials, InfludDB URL, organization ID, and bucket name.<\/p>\n\n\n\n<p>This example illustrates how to create a data point on the database with tags and fields. It saves the RSSI of the connected network (Wi-Fi strength between the ESP32 and your router) every 10 seconds.<\/p>\n\n\n\n<p>Let&#8217;s take a quick look at how the code works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>First, it starts by including the required libraries. In this example, it uses the <span class=\"rnthl rntliteral\">WiFiMulti<\/span> instead of the <span class=\"rnthl rntliteral\">WiFi<\/span> library to connect the ESP32 to a network. It also defines the <span class=\"rnthl rntliteral\">DEVICE<\/span> name depending on the selected board.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#if defined(ESP32)\n  #include &lt;WiFiMulti.h&gt;\n  WiFiMulti wifiMulti;\n  #define DEVICE \"ESP32\"\n#elif defined(ESP8266)\n  #include &lt;ESP8266WiFiMulti.h&gt;\n  ESP8266WiFiMulti wifiMulti;\n  #define DEVICE \"ESP8266\"\n#endif<\/code><\/pre>\n\n\n\n<p><strong>Note<\/strong>: the <span class=\"rnthl rntliteral\">WiFiMulti<\/span> library allows the ESP32 to connect to the network with the best RSSI (received signal strength indicator) among a list of added networks. In this example, it only connects to one network.<\/p>\n\n\n\n<p>Include the required InfluxDB libraries to e able to communicate with InfluxDB:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;InfluxDbClient.h&gt;\n#include &lt;InfluxDbCloud.h&gt;<\/code><\/pre>\n\n\n\n<p>Insert your network credentials in the following variables so that the ESP32 can connect to the internet:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ WiFi AP SSID\n#define WIFI_SSID \"REPLACE_WITH_YOUR_SSID\"\n\/\/ WiFi password\n#define WIFI_PASSWORD \"REPLACE_WITH_YOUR_PASSWORD\"<\/code><\/pre>\n\n\n\n<p>Insert the InfluxDB server URL on the following lines\u2014<a href=\"#influxdb-URL\">the one you&#8217;ve gotten in this step<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ InfluxDB v2 server url, e.g. https:\/\/eu-central-1-1.aws.cloud2.influxdata.com (Use: InfluxDB UI -&gt; Load Data -&gt; Client Libraries)\n#define INFLUXDB_URL \"REPLACE_WITH_YOUR_INFLUXDB_URL\"<\/code><\/pre>\n\n\n\n<p><strong>Note: <\/strong> if you&#8217;re running InfluxDB locally on a Raspberry Pi, the URL will be the Raspberry Pi IP address on port 8086. For example <span class=\"rnthl rntliteral\">192.168.1.106:8086<\/span>.<\/p>\n\n\n\n<p>Insert your InfluxDB token\u2014<a href=\"#influxdb-token\">saved in this step<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define INFLUXDB_TOKEN \"REPLACE_WITH_YOUR_INFLUXDB_TOKEN\"<\/code><\/pre>\n\n\n\n<p>Add your InfluxDB organization name\u2014<a href=\"http:\/\/influxdb-URL\">check this step<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define INFLUXDB_ORG \"REPLACE_WITH_YOUR_INFLUXXDB_ORGANIZATION_ID\"<\/code><\/pre>\n\n\n\n<p>Finally, add your InfluxDB bucket name:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define INFLUXDB_BUCKET \"ESP32\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Setting your Timezone<\/h3>\n\n\n\n<p>You must set your timezone accordingly to <a href=\"https:\/\/www.gnu.org\/software\/libc\/manual\/html_node\/TZ-Variable.html\" target=\"_blank\" rel=\"noreferrer noopener\">these instructions<\/a>. The easiest way is to <strong><a href=\"https:\/\/github.com\/nayarsystems\/posix_tz_db\/blob\/master\/zones.csv\" target=\"_blank\" rel=\"noreferrer noopener\">check this table and copy your timezone from there<\/a>.<\/strong> In my case, it&#8217;s Lisbon timezone:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define TZ_INFO \"WET0WEST,M3.5.0\/1,M10.5.0\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">InfluxDB Client<\/h3>\n\n\n\n<p>Now that you have all the required settings, you can create an <span class=\"rnthl rntliteral\">InfluxDBClient<\/span> instance. We&#8217;re creating a secure client that uses a preconfigured certificate\u2014<a href=\"https:\/\/github.com\/tobiasschuerg\/InfluxDB-Client-for-Arduino#secure-connection\" target=\"_blank\" rel=\"noreferrer noopener\">learn more about secure connection here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Point<\/h3>\n\n\n\n<p>Then, we create a <span class=\"rnthl rntliteral\">Point<\/span> instance called <span class=\"rnthl rntliteral\">sensor<\/span>. The point will be called <span class=\"rnthl rntliteral\">wifi_status<\/span> on the database. Later in the code, we can refer to that point (<span class=\"rnthl rntliteral\">sensor<\/span>) to add tags and fields.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Point sensor(\"wifi_status\");<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntclgreen\"><strong>Note: <\/strong> A set of data in a database row is known as <strong>point<\/strong>. Each point has a <strong>measurement<\/strong>, a <strong>tag set<\/strong>, a <strong>field key<\/strong>, a <strong>field value<\/strong>, and a <strong>timestamp<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">setup()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p> Setup and connect to Wi-Fi:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Setup wifi\nWiFi.mode(WIFI_STA);\nwifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);\n\nSerial.print(\"Connecting to wifi\");\nwhile (wifiMulti.run() != WL_CONNECTED) {\n  Serial.print(\".\");\n  delay(500);\n}\nSerial.println();<\/code><\/pre>\n\n\n\n<p>Then, we add tags to our data. Tags are metadata that allows us to better organize our data. It&#8217;s also an easier way to query data in a more efficient way later on. In this example, we have the <span class=\"rnthl rntliteral\">device<\/span> tag that saves the device name (either <span class=\"rnthl rntliteral\">ESP32<\/span> or <span class=\"rnthl rntliteral\">ESP8266<\/span>), and the <span class=\"rnthl rntliteral\">SSID<\/span> tag that saves the SSID of the connected network. To add a tag we call the <span class=\"rnthl rntliteral\">addTag()<\/span> method to the <span class=\"rnthl rntliteral\">sensor<\/span> point. We pass as arguments the tag key and value.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Add tags\nsensor.addTag(\"device\", DEVICE);\nsensor.addTag(\"SSID\", WiFi.SSID());<\/code><\/pre>\n\n\n\n<p>Imagine that you have this example running on multiple boards and each board has a unique device tag. Then, it would be easier to query the data relative to a specific device using the device tag. The same for the SSID of the connected network.<\/p>\n\n\n\n<p>The following lines sync the time with the NTP servers.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>timeSync(TZ_INFO, \"pool.ntp.org\", \"time.nis.gov\");<\/code><\/pre>\n\n\n\n<p>The following snippet checks the connection to the InfluxDB server:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (client.validateConnection()) {\n  Serial.print(\"Connected to InfluxDB: \");\n  Serial.println(client.getServerUrl());\n} else {\n  Serial.print(\"InfluxDB connection failed: \");\n  Serial.println(client.getLastErrorMessage());\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">loop()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, we add fields (the actual data) to the point. We start by clearing the point fields:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>sensor.clearFields();<\/code><\/pre>\n\n\n\n<p>We add a field to that point, using the <span class=\"rnthl rntliteral\">addField()<\/span> method and passing as arguments, the key (<span class=\"rnthl rntliteral\">rssi<\/span>) and the actual RSSI value (<span class=\"rnthl rntliteral\">WiFi.RSSI()<\/span>).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>sensor.addField(\"rssi\", WiFi.RSSI());<\/code><\/pre>\n\n\n\n<p>Print in the Serial Monitor what we&#8217;re writing to the point:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.println(client.pointToLineProtocol(sensor));<\/code><\/pre>\n\n\n\n<p>Finally, to actually add the point to the database, we use the <span class=\"rnthl rntliteral\">writePoint()<\/span> method on the <span class=\"rnthl rntliteral\">InfluxDBClient<\/span> object and pass as argument the point we want to add: <span class=\"rnthl rntliteral\">client.writePoint(sensor)<\/span>. We run the command inside an if statement for debugging purposes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (!client.writePoint(sensor)) {\n  Serial.print(\"InfluxDB write failed: \");\n  Serial.println(client.getLastErrorMessage());\n}<\/code><\/pre>\n\n\n\n<p>We write new data to the database every 10 seconds.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/Wait 10s\nSerial.println(\"Wait 10s\");\ndelay(10000);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"visualize-data\">Demonstration &#8211; Visualizing Data on InfluxDB<\/h2>\n\n\n\n<p>After inserting all the required settings on the code, you can upload it to your ESP32 board. If you get any error during compilation, check the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check that you have an ESP32 board selected in <strong>Tools <\/strong>&gt; <strong>Board<\/strong>.<\/li>\n\n\n\n<li>Check your ESP32 boards installation version in <strong>Tools <\/strong>&gt; <strong>Board <\/strong>&gt; <strong>Boards Manager<\/strong> &gt; <strong>ESP32<\/strong>. Select version <strong>2.0.1<\/strong> if you&#8217;re getting issues with other versions.<\/li>\n<\/ul>\n\n\n\n<p>After uploading the code to your board, open the Serial Monitor at a baud rate of 115200. Press the ESP32 on-board RST button to restart the board. It should print something similar on the Serial Monitor:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"676\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/ESP32-write-secure-example-influxdb.png?resize=750%2C676&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-155361\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/ESP32-write-secure-example-influxdb.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/ESP32-write-secure-example-influxdb.png?resize=300%2C270&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Now, go to your InfludDB account and go to the <strong>Data Explorer<\/strong> by clicking on the corresponding icon.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"298\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-data-explorer.png?resize=726%2C298&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-155362\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-data-explorer.png?w=726&amp;quality=100&amp;strip=all&amp;ssl=1 726w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/influxdb-data-explorer.png?resize=300%2C123&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><\/figure><\/div>\n\n\n<p>Now, you can visualize your data. Start by selecting the bucket you want\u2014in our case, it&#8217;s the ESP32. Then, we need to add filters to select our data. Select the <strong>wifi_status<\/strong> under the <strong>_measurement <\/strong>field, your <strong>SSID <\/strong>under the <strong>SSID<\/strong> tag (in this case we just have one SSID, but if we add multiple SSIDs, we could filter the data easily because we added the SSID as a tag). Finally, select the field tag (<strong>rrsi<\/strong>) and device (<strong>ESP32<\/strong>).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/data-explorer-select-data-influxdb.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"552\" height=\"705\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/data-explorer-select-data-influxdb.png?resize=552%2C705&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Data Explorer InfluxDB\" class=\"wp-image-155380\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/data-explorer-select-data-influxdb.png?w=552&amp;quality=100&amp;strip=all&amp;ssl=1 552w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/05\/data-explorer-select-data-influxdb.png?resize=235%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 235w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/a><\/figure><\/div>\n\n\n<p>Finally, click on the <strong>RUN<\/strong> button.<\/p>\n\n\n\n<p>This will display your data in your chosen format, select the <strong>GRAPH <\/strong>option.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"343\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-display-data.png?resize=1200%2C343&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-155379\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-display-data.png?w=1384&amp;quality=100&amp;strip=all&amp;ssl=1 1384w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-display-data.png?resize=300%2C86&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-display-data.png?resize=1024%2C293&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-display-data.png?resize=768%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>This was just a quick introduction to InfluxDB with the ESP32. You learned how to create a database bucket and how to create and send points using the ESP32. In this example, we&#8217;re sending the RSSI. In an IoT application, you can add sensor readings, current consumption, or any other data that makes sense for your IoT and Home Automation projects.<\/p>\n\n\n\n<p>Follow the next tutorial to learn how to <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-sensor-bme280-influxdb\/\">Send BME280 Sensor Readings to InfluxDB with ESP32\/ESP8266 boards<\/a>.<\/p>\n\n\n\n<p>We hope you liked this tutorial and that it helped you get started with InfluxDB. We&#8217;ll create more tutorials about this subject soon. So, stay tuned!<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/install-influxdb-2-raspberry-pi\/\">Install InfluxDB 2 on Raspberry Pi<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/monitor-raspberry-pi-influxdb-telegraf\/\">Monitoring Your Raspberry Pi System using InfluxDB Telegraf<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-sensor-bme280-influxdb\/\">ESP32\/ESP8266: Send BME280 Sensor Readings to InfluxDB<\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the ESP32 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/firebase-esp32-esp8266-ebook\/\">Firebase Web App with ESP32 and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">Free ESP32 Projects and Tutorials\u2026<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will get you started quickly with InfluxDB using the ESP32 board. InfluxDB is an open-source time series database (TSDB). It&#8217;s ideal to store sensor data with timestamps over &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32: Getting Started with InfluxDB\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-influxdb\/#more-110608\" aria-label=\"Read more about ESP32: Getting Started with InfluxDB\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":110667,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[281,276,277,299,264],"tags":[],"class_list":["post-110608","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-Getting-Started-with-InfluxDB.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/110608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=110608"}],"version-history":[{"count":49,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/110608\/revisions"}],"predecessor-version":[{"id":155666,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/110608\/revisions\/155666"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/110667"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=110608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=110608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=110608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}