{"id":110725,"date":"2024-05-14T18:11:00","date_gmt":"2024-05-14T18:11:00","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=110725"},"modified":"2024-05-16T18:27:22","modified_gmt":"2024-05-16T18:27:22","slug":"esp32-esp8266-sensor-bme280-influxdb","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-esp8266-sensor-bme280-influxdb\/","title":{"rendered":"ESP32\/ESP8266: Send BME280 Sensor Readings to InfluxDB"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll learn how to send BME280 sensor readings to InfluxDB using the ESP32 or ESP8266 boards. InfluxDB is a time series database. Each record on the database is associated with a timestamp, which makes it ideal for datalogging IoT and Home Automation projects.<\/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\/2022\/04\/ESP32-ESP8266-BME280-InfluxDB.jpg?quality=100&#038;strip=all&#038;ssl=1\"><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-ESP8266-BME280-InfluxDB.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 NodeMCU Send BME280 Sensor Readings to InfluxDB\" class=\"wp-image-110729\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-ESP8266-BME280-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-ESP8266-BME280-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-ESP8266-BME280-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-ESP8266-BME280-InfluxDB.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure><\/div>\n\n\n<p><em>Updated 14 May 2024<\/em><\/p>\n\n\n\n<p>By the end of this tutorial, you&#8217;ll be able to build a dashboard as shown below to display all your sensor readings over time.<\/p>\n\n\n\n<p class=\"rntbox rntcred\">At the moment, dashboards are not compatible with <a href=\"https:\/\/docs.influxdata.com\/influxdb\/cloud-serverless\/reference\/cli\/influx\/dashboards\/\" target=\"_blank\" rel=\"noopener\" title=\"\">InfluxdDB serverless<\/a>. You must use InfluxDB 2 (running on a Raspberry Pi, for example\u2014<a href=\"https:\/\/randomnerdtutorials.com\/install-influxdb-2-raspberry-pi\/\" title=\"\">see this post to set InfluxDB on Raspberry Pi<\/a>.)<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"551\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-ESP8266-Sensor-Readings-Dashboard.png?resize=750%2C551&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Sensor Readings Dashboard InfluxDB\" class=\"wp-image-110767\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-ESP8266-Sensor-Readings-Dashboard.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-ESP8266-Sensor-Readings-Dashboard.png?resize=300%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>To get started with InfluxDB, read one of the following guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-influxdb\/\">ESP32: Getting Started with InfluxDB<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-influxdb\/\">ESP8266 NodeMCU: Getting Started with 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=\"influxdb what it is\" 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<p>For a more in-depth introduction to InfluxDB, check the following tutorials before proceeding:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-influxdb\/\">ESP32: Getting Started with InfluxDB<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-influxdb\/\">ESP8266: Getting Started with InfluxDB<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"create-influxdb-account\">Setting Up Influx DB<\/h2>\n\n\n\n<p>Set up InfluxDB. You have two options:<\/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> (compatible with creating dashboards)<\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-influxdb\/\" title=\"\">Creating a serverless account<\/a> (<a href=\"https:\/\/docs.influxdata.com\/influxdb\/cloud-serverless\/reference\/cli\/influx\/dashboards\/\" target=\"_blank\" rel=\"noopener\" title=\"\">not compatible with dashboards<\/a>)<\/li>\n<\/ul>\n\n\n\n<p>After setting up your account, you can proceed to the next section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"load-data-influxdb\">Loading Data in InfluxDB<\/h2>\n\n\n\n<p><strong><strong>1)<\/strong> Click on <strong><strong> Load Data<\/strong> <\/strong><\/strong>icon and select <strong><strong><strong>Sources<\/strong><\/strong><\/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=\"750\" height=\"442\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-sources.png?resize=750%2C442&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB Load Dara Sources\" class=\"wp-image-128149\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-sources.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-sources.png?resize=300%2C177&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>2)<\/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\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"409\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-client-libraries-arduino.png?resize=750%2C409&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB Load Data Arduino Client\" class=\"wp-image-128150\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/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\/2022\/05\/influxdb-client-libraries-arduino.png?resize=300%2C164&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>3)<\/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\/2022\/05\/Arduino-client-Create-Bucket-InfluxDB-cloud.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"460\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/Arduino-client-Create-Bucket-InfluxDB-cloud.png?resize=750%2C460&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB Cloud Arduino Initialize Client\" class=\"wp-image-128152\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/Arduino-client-Create-Bucket-InfluxDB-cloud.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/Arduino-client-Create-Bucket-InfluxDB-cloud.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<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>4)<\/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=\"647\" height=\"398\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-creating-bucket-esp8266.png?resize=647%2C398&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB Cloud Creating ESP8266 bucket\" class=\"wp-image-128164\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-creating-bucket-esp8266.png?w=647&amp;quality=100&amp;strip=all&amp;ssl=1 647w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-creating-bucket-esp8266.png?resize=300%2C185&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 647px) 100vw, 647px\" \/><\/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>5)<\/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\"><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=\"Arduino Configure InfluxDB Profile\" 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\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\">* 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 for you that you could 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=\"ESP8266-influxdb\">ESP32\/ESP8266 Send Sensor Readings to InfluxDB<\/h2>\n\n\n\n<p>In this section, we&#8217;ll program the ESP32 and ESP8266 boards to send BME280 temperature, humidity, and pressure readings to InfluxDB.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>For this project, you need the following parts*:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32<\/a> or<a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\" rel=\"noreferrer noopener\"> ESP8266<\/a> board (read <a href=\"https:\/\/makeradvisor.com\/esp32-vs-esp8266\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32 vs ESP8266<\/a>);<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\" rel=\"noreferrer noopener\">BME280<\/a> or any other sensor you&#8217;re familiar with;<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard<\/a>;&nbsp; &nbsp; &nbsp; &nbsp; <a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\">&nbsp;<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a>.<\/li>\n<\/ul>\n\n\n\n<p>* you can also test the project with random values instead of sensor readings, or you can use any other sensor you&#8217;re familiar with.<\/p>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>In this tutorial, we&#8217;ll send BME280 sensor readings to InfluxDB. So, you need to wire the BME280 sensor to your board. Follow one of the next schematic diagrams.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">ESP32 with BME280<\/h4>\n\n\n\n<p>We&#8217;re going to use I2C communication with the BME280 sensor module. Wire the sensor to the default ESP32 SCL (<span class=\"rnthl rntclblue\">GPIO 22<\/span>) and SDA (<span class=\"rnthl rntclgreen\">GPIO 21<\/span>) pins, as shown in the following schematic diagram.<\/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=\"675\" height=\"670\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=675%2C670&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BME280 Sensor Temperature Humidity Pressure Wiring Diagram Circuit\" class=\"wp-image-99755\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?w=675&amp;quality=100&amp;strip=all&amp;ssl=1 675w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=300%2C298&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\">Not familiar with the BME280 with the ESP32? Read this tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\"><strong>ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)<\/strong><\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">ESP8266 with BME280 <\/h4>\n\n\n\n<p>We&#8217;re going to use I2C communication with the BME280 sensor module. For that, wire the sensor to the ESP8266&nbsp;SDA (<span class=\"rnthl rntclgreen\">GPIO 4<\/span>)&nbsp;and&nbsp;SCL (<span class=\"rnthl rntclblue\">GPIO 5<\/span>)&nbsp;pins, as shown in the following schematic diagram.<\/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=\"675\" height=\"531\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/07\/ESP8266-NodeMCU-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit.png?resize=675%2C531&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU BME280 Sensor Temperature Humidity Pressure Wiring Diagram Circuit\" class=\"wp-image-98049\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/07\/ESP8266-NodeMCU-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit.png?w=675&amp;quality=100&amp;strip=all&amp;ssl=1 675w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/07\/ESP8266-NodeMCU-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit.png?resize=300%2C236&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\">Not familiar with the BME280 with the ESP8266? Read this tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\"><strong>ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)<\/strong><\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Libraries<\/h3>\n\n\n\n<p>For this project, you need to install the following libraries:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/tobiasschuerg\/InfluxDB-Client-for-Arduino\" target=\"_blank\" rel=\"noreferrer noopener\">InfluxDB Arduino Client Library<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit BME280 Library<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit Unified Sensor Library<\/a><\/li>\n<\/ul>\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 <strong>ESP8266 Influxdb library by Tobias Sh\u00fcrg<\/strong>.<\/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=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Install-Influxdb-Client-Arduino-IDE.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install InfluxDB Library Arduino IDE\" class=\"wp-image-110610\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Install-Influxdb-Client-Arduino-IDE.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Install-Influxdb-Client-Arduino-IDE.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Install-Influxdb-Client-Arduino-IDE.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\"><strong>Note: <\/strong> we are using ESP8266 Boards <strong>version 3.0.1<\/strong> and ESP32 Boards <strong>version 2.0.1<\/strong> Check your boards&#8217; version in <strong>Tools <\/strong>&gt; <strong>Board <\/strong>&gt; <strong>Boards Manager<\/strong>. Then, search for <strong>ESP8266<\/strong> or <strong>ESP32<\/strong> and upgrade to one of those versions. (I found some issues with the newest 3.0.2 and 2.0.2 versions)<\/p>\n\n\n\n<ol start=\"3\"><li>Follow the same instructions to install the <strong>Adafruit BME280<\/strong> Library and <strong>Adafruit Unified Sensor<\/strong> Library.<\/li><\/ol>\n\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 or ESP8266 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> by 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<p>Follow the same procedure for the Adafruit BME280 library and Adafruit Unified Sensor library.<\/p>\n\n\n\n<p>Your <span class=\"rnthl rntliteral\">plaformio.ini<\/span> file should look as follows (we also added a line to change the Serial Monitor baud rate to 115200).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>monitor_speed = 115200\nlib_deps = \n\ttobiasschuerg\/ESP8266 Influxdb@^3.12.0\n\tadafruit\/Adafruit BME280 Library@^2.2.2\n\tadafruit\/Adafruit Unified Sensor@^1.1.5<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Send Sensor Readings to InfluxDB\u2014Code<\/h3>\n\n\n\n<p>Copy the following code to the Arduino IDE or to the <span class=\"rnthl rntliteral\">main.cpp<\/span> file if you&#8217;re using VS Code with the PlatformIO extension. The code is compatible with both the ESP32 and ESP8266 boards.<\/p>\n\n\n\n<p>This code is based <a href=\"https:\/\/github.com\/tobiasschuerg\/InfluxDB-Client-for-Arduino\/blob\/master\/examples\/BasicWrite\/BasicWrite.ino\" target=\"_blank\" rel=\"noreferrer noopener\">on this library example<\/a>. We made a few modifications to include the BME280 sensor readings.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Rui Santos\r\n  Complete project details at our blog: https:\/\/RandomNerdTutorials.com\/\r\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\r\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n*\/\r\n\/\/ Based on this library example: https:\/\/github.com\/tobiasschuerg\/InfluxDB-Client-for-Arduino\/blob\/master\/examples\/SecureBatchWrite\/SecureBatchWrite.ino\r\n\r\n#include &lt;Arduino.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;Adafruit_Sensor.h&gt;\r\n#include &lt;Adafruit_BME280.h&gt;\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  #define WIFI_AUTH_OPEN ENC_TYPE_NONE\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 authentication token (Use: InfluxDB UI -&gt; Load Data -&gt; Tokens -&gt; &lt;select token&gt;)\r\n#define INFLUXDB_TOKEN &quot;REPLACE_WITH_YOUR_TOKEN&quot;\r\n\/\/ InfluxDB v2 organization id (Use: InfluxDB UI -&gt; Settings -&gt; Profile -&gt; &lt;name under tile&gt; )\r\n#define INFLUXDB_ORG &quot;REPLACE_WITH_YOUR_ORG&quot;\r\n\/\/ InfluxDB v2 bucket name (Use: InfluxDB UI -&gt; Load Data -&gt; Buckets)\r\n#define INFLUXDB_BUCKET &quot;SENSOR&quot;\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 sensorReadings(&quot;measurements&quot;);\r\n\r\n\/\/BME280\r\nAdafruit_BME280 bme; \/\/ I2C\r\n\r\nfloat temperature;\r\nfloat humidity;\r\nfloat pressure;\r\n\r\n\/\/ Initialize BME280\r\nvoid initBME(){\r\n  if (!bme.begin(0x76)) {\r\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring!&quot;);\r\n    while (1);\r\n  }\r\n}\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  \/\/Init BME280 sensor\r\n  initBME();\r\n  \r\n  \/\/ Add tags\r\n  sensorReadings.addTag(&quot;device&quot;, DEVICE);\r\n  sensorReadings.addTag(&quot;location&quot;, &quot;office&quot;);\r\n  sensorReadings.addTag(&quot;sensor&quot;, &quot;bme280&quot;);\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  \/\/ Get latest sensor readings\r\n  temperature = bme.readTemperature();\r\n  humidity = bme.readHumidity();\r\n  pressure = bme.readPressure()\/100.0F;\r\n\r\n  \/\/ Add readings as fields to point\r\n  sensorReadings.addField(&quot;temperature&quot;, temperature);\r\n  sensorReadings.addField(&quot;humidity&quot;, humidity);\r\n  sensorReadings.addField(&quot;pressure&quot;, pressure);\r\n\r\n  \/\/ Print what are we exactly writing\r\n  Serial.print(&quot;Writing: &quot;);\r\n  Serial.println(client.pointToLineProtocol(sensorReadings));\r\n  \r\n  \/\/ Write point into buffer\r\n  client.writePoint(sensorReadings);\r\n\r\n  \/\/ Clear fields for next usage. Tags remain the same.\r\n  sensorReadings.clearFields();\r\n\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\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_BME280.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, the database URL, token, organization, and bucket name. Also, don&#8217;t forget to insert your timezone. <a href=\"https:\/\/github.com\/nayarsystems\/posix_tz_db\/blob\/master\/zones.csv\" target=\"_blank\" rel=\"noreferrer noopener\">Check this document to search for your timezone<\/a> in the right format.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>Start by including the required libraries and setting the <span class=\"rnthl rntliteral\">DEVICE<\/span> name accordingly to the selected board (<span class=\"rnthl rntliteral\">ESP32<\/span> or <span class=\"rnthl rntliteral\">ESP8266<\/span>).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Arduino.h&gt;\n#include &lt;Wire.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;Adafruit_BME280.h&gt;\n\n#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  #define WIFI_AUTH_OPEN ENC_TYPE_NONE\n#endif\n\n#include &lt;InfluxDbClient.h&gt;\n#include &lt;InfluxDbCloud.h&gt;<\/code><\/pre>\n\n\n\n<p>Insert your network credentials on the following variables so that the ESP32 or ESP8266 boards can connect to the internet using your local network.<\/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 \"REPLACE_WITH_YOUR_BUCKET_NAME\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Setting your Timezone<\/h4>\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<h4 class=\"wp-block-heading\">InfluxDB Client<\/h4>\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<\/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<h4 class=\"wp-block-heading\">Point<\/h4>\n\n\n\n<p>Then, we create a <span class=\"rnthl rntliteral\">Point<\/span> instance called <span class=\"rnthl rntliteral\">sensorReadings<\/span>. The point will be called <span class=\"rnthl rntliteral\">measurements<\/span> on the database. Later in the code, we can refer to that point (<span class=\"rnthl rntliteral\">sensorReadings<\/span>) to add tags and fields.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Point sensorReadings(\"measurements\");<\/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<h4 class=\"wp-block-heading\">BME280 Variables<\/h4>\n\n\n\n<p>Create an <span class=\"rnthl rntliteral\">Adafruit_BME280<\/span> instance called <span class=\"rnthl rntliteral\">bme<\/span> on the default ESP I2C pins.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Adafruit_BME280 bme; \/\/ I2C<\/code><\/pre>\n\n\n\n<p>Create variables to save the temperature, humidity, and pressure readings.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float temperature;\nfloat humidity;\nfloat pressure;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">initBME() function<\/h4>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">initBME()<\/span> function initializes the BME280 sensor. We&#8217;ll call it later in the <span class=\"rnthl rntliteral\">setup()<\/span> to initialize the sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Initialize BME280\nvoid initBME(){\n  if (!bme.begin(0x76)) {\n    Serial.println(\"Could not find a valid BME280 sensor, check wiring!\");\n    while (1);\n  }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">setup()<\/h4>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor for debugging purposes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Initialize 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>Call the <span class=\"rnthl rntliteral\">initBME()<\/span> function to initialize the BME280 sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/Init BME280 sensor\ninitBME();<\/code><\/pre>\n\n\n\n<p>Add tags to your data using <span class=\"rnthl rntliteral\">addTag()<\/span>. We&#8217;re adding the device name, the name of the sensor, and the location of the sensor. You may add other tags that might be useful for your specific project.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>sensorReadings.addTag(\"device\", DEVICE);\nsensorReadings.addTag(\"location\", \"office\");\nsensorReadings.addTag(\"sensor\", \"bme280\");<\/code><\/pre>\n\n\n\n<p>Synchronize time, which is necessary for certificate validation.<\/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>Check the connection to the InfluxDB server and print any error messages in case the connection fails:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Check server connection\nif (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<h4 class=\"wp-block-heading\">loop()<\/h4>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, we&#8217;ll send the sensor readings to InfluxDB every 10 seconds.<\/p>\n\n\n\n<p>We get temperature, humidity, and pressure readings:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>temperature = bme.readTemperature();\nhumidity = bme.readHumidity();\npressure = bme.readPressure()\/100.0F;<\/code><\/pre>\n\n\n\n<p>And we add those readings as fields to our point (database data row).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Add readings as fields to point\nsensorReadings.addField(\"temperature\", temperature);\nsensorReadings.addField(\"humidity\", humidity);\nsensorReadings.addField(\"pressure\", pressure);<\/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(sensorReadings));<\/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(sensorReadings)<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>client.writePoint(sensorReadings);<\/code><\/pre>\n\n\n\n<p>Clear the fields to be ready for usage in the next loop.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>sensorReadings.clearFields();<\/code><\/pre>\n\n\n\n<p>New data is written to the database every 10 seconds.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.println(\"Wait 10s\");\ndelay(10000);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration\u2014Visualizing your Data<\/h2>\n\n\n\n<p>After inserting all the required settings on the code, you can upload it to your ESP32\/ESP8266 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\/ESP8266 board selected in <strong>Tools <\/strong>&gt; <strong>Board<\/strong>.<\/li>\n\n\n\n<li>Check your ESP32\/ESP8266 boards installation version in <strong>Tools <\/strong>&gt; <strong>Board <\/strong>&gt; <strong>Boards Manager<\/strong> &gt; <strong>ESP8266<\/strong> or <strong>ESP32<\/strong>. Select version <strong>3.0.1<\/strong> for ESP8266 or version <strong>2.01<\/strong> for ESP32 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 ESP on-board RESET 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=\"1052\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-send-sensor-readings-ESP32.png?resize=1052%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP Send BME280 Sensor Readings to InfluxDB\" class=\"wp-image-110760\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-send-sensor-readings-ESP32.png?w=1052&amp;quality=100&amp;strip=all&amp;ssl=1 1052w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-send-sensor-readings-ESP32.png?resize=300%2C126&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-send-sensor-readings-ESP32.png?resize=1024%2C431&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-send-sensor-readings-ESP32.png?resize=768%2C323&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1052px) 100vw, 1052px\" \/><\/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=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-data-explorer.png?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"influxDB data explorer\" class=\"wp-image-128160\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/05\/influxdb-data-explorer.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-data-explorer.png?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Now, you can visualize your data. Start by selecting the bucket you want. Then, we need to add filters to select our data. Select the <strong>measurement<\/strong> under the <strong>_measurement <\/strong>field, the device and the location. Then, you can select the temperature, humidity, or pressure values. You can also select all readings if you want to plot them all on the same chart.<\/p>\n\n\n\n<p>After making the query, click on the SUBMIT button. This will display your data in your chosen format. In the upper left corner, you can select different ways to visualize the data. You can also click on the CUSTOMIZE button to change the color of the series.<\/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=\"320\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-ESP32-ESP8266-Temperature-Data-Explorer.png?resize=750%2C320&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Data Explorer InfluxDB\" class=\"wp-image-110762\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-ESP32-ESP8266-Temperature-Data-Explorer.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-ESP32-ESP8266-Temperature-Data-Explorer.png?resize=300%2C128&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>You can create a dashboard to show multiple data visualizations in different formats (gauges, histogram, single stat, etc.) or different data on the same page. For example, multiple charts to show temperature, humidity, and pressure, and boxes to show the current measurements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating a Dashboard<\/h3>\n\n\n\n<p class=\"rntbox rntcred\">This section is not compatible with <a href=\"https:\/\/docs.influxdata.com\/influxdb\/cloud-serverless\/reference\/cli\/influx\/dashboards\/\" target=\"_blank\" rel=\"noopener\" title=\"\">InfluxdDB serverless<\/a>. You must use InfluxDB 2 (running on a Raspberry Pi, for example\u2014<a href=\"https:\/\/randomnerdtutorials.com\/install-influxdb-2-raspberry-pi\/\" title=\"\">see this post to set InfluxDB on Raspberry Pi<\/a>.)<\/p>\n\n\n\n<p>Click on the <strong>Dashboard <\/strong>icon.<\/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-dashboard-icon.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"47\" height=\"45\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/02\/influxdb-dashboard-icon.png?resize=47%2C45&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-128158\"\/><\/a><\/figure><\/div>\n\n\n<p>Then on <strong>Create Dashboard<\/strong> &gt; <strong>New dashboard<\/strong>.<\/p>\n\n\n\n<p>Add a cell. Make the query to get your data and select the visualization you want. Give a name to the cell, for example, <strong>Office Temperature(ESP32)<\/strong>. You can also click on the <strong>Customize <\/strong>button to customize the graph (we suggest selecting different colors for temperature, humidity, and pressure). Finally, click on the <strong>\u2713<\/strong> icon in the top right corner to add the visualization as a cell to your dashboard.<\/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=\"317\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-ESP32-ESP8266-Temperature-Cell.png?resize=750%2C317&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"InfluxDB ESP Temperature Dashboard cell\" class=\"wp-image-110766\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-ESP32-ESP8266-Temperature-Cell.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/InfluxDB-ESP32-ESP8266-Temperature-Cell.png?resize=300%2C127&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Repeat the same process for the other readings (humidity, and pressure). You can also add a single stat to show the current values of each reading.<\/p>\n\n\n\n<p>I have the ESP32 and ESP8266 running the same code simultaneously, so I created a dashboard that shows the readings of each board.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"551\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-ESP8266-Sensor-Readings-Dashboard.png?resize=750%2C551&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Sensor Readings Dashboard InfluxDB\" class=\"wp-image-110767\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-ESP8266-Sensor-Readings-Dashboard.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/ESP32-ESP8266-Sensor-Readings-Dashboard.png?resize=300%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>You can move your cells to different positions and organize the dashboard in a way that makes sense for you. You can also customize the way the data is refreshed and how many data points you want to see (up to the past 30 days).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to send multiple sensor readings to InfluxDB. InfluxDB adds a timestamp to all data rows (point).<\/p>\n\n\n\n<p>As an example, we used a BME280 sensor, but you can easily modify the example to use any other sensor or add more sensors. You can also run this example on multiple boards to monitor the temperature, humidity, and pressure in different places\u2014don&#8217;t forget to add different tags to identify the places or the boards.<\/p>\n\n\n\n<p>We hope you found this tutorial useful. What other projects would you like to see using InfluxDB? Let us know in the comments section.<\/p>\n\n\n\n<p>Learn more about the ESP32 and ESP8266 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\/home-automation-using-esp8266\/\">Home Automation using ESP8266<\/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<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\">Free ESP8266 Projects and Tutorials<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll learn how to send BME280 sensor readings to InfluxDB using the ESP32 or ESP8266 boards. InfluxDB is a time series database. Each record on the database &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32\/ESP8266: Send BME280 Sensor Readings to InfluxDB\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-sensor-bme280-influxdb\/#more-110725\" aria-label=\"Read more about ESP32\/ESP8266: Send BME280 Sensor Readings to InfluxDB\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":110729,"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":[276,281,277,299,264],"tags":[],"class_list":["post-110725","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-esp32-project","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-ESP8266-BME280-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\/110725","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=110725"}],"version-history":[{"count":24,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/110725\/revisions"}],"predecessor-version":[{"id":155507,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/110725\/revisions\/155507"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/110729"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=110725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=110725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=110725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}