ESP8266 NodeMCU MQTT – Publish BME280 Sensor Readings (Arduino IDE)

Learn how to publish BME280 sensor readings (temperature, humidity and pressure) via MQTT with the ESP8266 to any platform that supports MQTT or any MQTT client. As an example, we’ll publish sensor readings to Node-RED Dashboard and the ESP8266 will be programmed using Arduino IDE.

ESP8266 NodeMCU MQTT Publish BME280 Sensor Readings Arduino IDE

Recommended reading: What is MQTT and How It Works

Project Overview

The following diagram shows a high-level overview of the project we’ll build.

ESP8266 NodeMCU BME280 Publish Readings Node-Red MQTT How it works and project overview
  • The ESP8266 requests temperature readings from the BME280 sensor;
  • The temperature readings are published in the esp/bme280/temperature topic;
  • Humidity readings are published in the esp/bme280/humiditytopic;
  • Pressure readings are published in the esp/bme280/pressure topic;
  • Node-RED is subscribed those topics;
  • Node-RED receives the sensor readings and displays them on gauges;
  • You can receive the readings in any other platform that supports MQTT and handle the readings as you want.

Prerequisites

Before proceeding with this tutorial, make sure you check the following prerequisites.

Arduino IDE

We’ll program the ESP8266 using Arduino IDE, so make sure you have the ESP8266 add-on installed.

MQTT Broker

Installing Mosquitto MQTT broker Raspberry Pi

To use MQTT, you need a broker. We’ll be using Mosquitto broker installed on a Raspberry Pi. Read How to Install Mosquitto Broker on Raspberry Pi.

You can use any other MQTT broker, including a cloud MQTT broker. We’ll show you how to do that in the code later on.

If you’re not familiar with MQTT make sure you read our introductory tutorial: What is MQTT and How It Works.

MQTT Libraries

To use MQTT with the ESP8266 we’ll use the Async MQTT Client Library.

Installing the Async MQTT Client Library

  1. Click here to download the Async MQTT client library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get async-mqtt-client-master folder
  3. Rename your folder from async-mqtt-client-master to async_mqtt_client
  4. Move the async_mqtt_client folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Alternatively, you can go to Sketch > Include Library > Add . ZIP library and select the library you’ve just downloaded.

Installing the ESPAsync TCP Library

To use MQTT with the ESP8266, you also need the ESPAsync TCP library.

  1. Click here to download the ESPAsync TCP client library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get ESPAsyncTCP-master folder
  3. Rename your folder from ESPAsyncTCP-master to ESPAsyncTCP
  4. Move the ESPAsyncTCP folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Alternatively, you can go to Sketch > Include Library > Add . ZIP library and select the library you’ve just downloaded.

BME280 Sensor Libraries

To get readings from the BME280 sensor module, we’ll use the Adafruit_BME280 library. You also need to install the Adafruit_Sensor library. Follow the next steps to install the libraries in your Arduino IDE:

1. Open your Arduino IDE and go to Sketch Include Library > Manage Libraries. The Library Manager should open.

2. Search for “adafruit bme280 ” on the Search box and install the library.

Installing BME280 library in Arduino IDE

To use the BME280 library, you also need to install the Adafruit Unified Sensor. Follow the next steps to install the library in your Arduino IDE:

3. Search for “Adafruit Unified Sensor“in the search box. Scroll all the way down to find the library and install it.

Installing Adafruit Unified Sensor Driver library

After installing the libraries, restart your Arduino IDE.

To learn more about the BME280 sensor, read: ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)

Parts Required

For this tutorial you need the following parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Schematic Diagram

Wire the BME280 to the ESP8266 as shown in the following schematic diagram with the SDA pin connected to GPIO 4 and the SCL pin connected to GPIO 5.

ESP8266 NodeMCU BME280 Temperature humidity Pressure sensor connected I2C schematic circuit diagram

Code

Copy the following code to your Arduino IDE. To make it work for you, you need to insert your network credentials as well as the MQTT broker details.

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp8266-nodemcu-mqtt-publish-bme280-arduino/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>

#define WIFI_SSID "REPLACE_WITH_YOUR_SSID"
#define WIFI_PASSWORD "REPLACE_WITH_YOUR_PASSWORD"

// Raspberri Pi Mosquitto MQTT Broker
#define MQTT_HOST IPAddress(192, 168, 1, XXX)
// For a cloud MQTT broker, type the domain name
//#define MQTT_HOST "example.com"
#define MQTT_PORT 1883

// Temperature MQTT Topics
#define MQTT_PUB_TEMP "esp/bme280/temperature"
#define MQTT_PUB_HUM "esp/bme280/humidity"
#define MQTT_PUB_PRES "esp/bme280/pressure"

// BME280 I2C
Adafruit_BME280 bme;
// Variables to hold sensor readings
float temp;
float hum;
float pres;

AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;

WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;

unsigned long previousMillis = 0;   // Stores last time temperature was published
const long interval = 10000;        // Interval at which to publish sensor readings

void connectToWifi() {
  Serial.println("Connecting to Wi-Fi...");
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}

void onWifiConnect(const WiFiEventStationModeGotIP& event) {
  Serial.println("Connected to Wi-Fi.");
  connectToMqtt();
}

void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
  Serial.println("Disconnected from Wi-Fi.");
  mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
  wifiReconnectTimer.once(2, connectToWifi);
}

void connectToMqtt() {
  Serial.println("Connecting to MQTT...");
  mqttClient.connect();
}

void onMqttConnect(bool sessionPresent) {
  Serial.println("Connected to MQTT.");
  Serial.print("Session present: ");
  Serial.println(sessionPresent);
}

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
  Serial.println("Disconnected from MQTT.");

  if (WiFi.isConnected()) {
    mqttReconnectTimer.once(2, connectToMqtt);
  }
}

/*void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
  Serial.println("Subscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
  Serial.print("  qos: ");
  Serial.println(qos);
}

void onMqttUnsubscribe(uint16_t packetId) {
  Serial.println("Unsubscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}*/

void onMqttPublish(uint16_t packetId) {
  Serial.print("Publish acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}

void setup() {
  Serial.begin(115200);
  Serial.println();
  
  // Initialize BME280 sensor 
  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
  
  wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
  wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);

  mqttClient.onConnect(onMqttConnect);
  mqttClient.onDisconnect(onMqttDisconnect);
  //mqttClient.onSubscribe(onMqttSubscribe);
  //mqttClient.onUnsubscribe(onMqttUnsubscribe);
  mqttClient.onPublish(onMqttPublish);
  mqttClient.setServer(MQTT_HOST, MQTT_PORT);
  // If your broker requires authentication (username and password), set them below
  //mqttClient.setCredentials("REPlACE_WITH_YOUR_USER", "REPLACE_WITH_YOUR_PASSWORD");
  
  connectToWifi();
}

void loop() {
  unsigned long currentMillis = millis();
  // Every X number of seconds (interval = 10 seconds) 
  // it publishes a new MQTT message
  if (currentMillis - previousMillis >= interval) {
    // Save the last time a new reading was published
    previousMillis = currentMillis;
    // New BME280 sensor readings
    temp = bme.readTemperature();
    //temp = 1.8*bme.readTemperature() + 32;
    hum = bme.readHumidity();
    pres = bme.readPressure()/100.0F;
    
    // Publish an MQTT message on topic esp/bme280/temperature
    uint16_t packetIdPub1 = mqttClient.publish(MQTT_PUB_TEMP, 1, true, String(temp).c_str());                            
    Serial.printf("Publishing on topic %s at QoS 1, packetId: %i ", MQTT_PUB_TEMP, packetIdPub1);
    Serial.printf("Message: %.2f \n", temp);

    // Publish an MQTT message on topic esp/bme280/humidity
    uint16_t packetIdPub2 = mqttClient.publish(MQTT_PUB_HUM, 1, true, String(hum).c_str());                            
    Serial.printf("Publishing on topic %s at QoS 1, packetId: %i ", MQTT_PUB_HUM, packetIdPub2);
    Serial.printf("Message: %.2f \n", hum);

    // Publish an MQTT message on topic esp/bme280/pressure
    uint16_t packetIdPub3 = mqttClient.publish(MQTT_PUB_PRES, 1, true, String(pres).c_str());                            
    Serial.printf("Publishing on topic %s at QoS 1, packetId: %i ", MQTT_PUB_PRES, packetIdPub3);
    Serial.printf("Message: %.3f \n", pres);
  }
}

View raw code

How the Code Works

The following section imports all the required libraries.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>

Include your network credentials on the following lines.

#define WIFI_SSID "REPLACE_WITH_YOUR_SSID"
#define WIFI_PASSWORD "REPLACE_WITH_YOUR_PASSWORD"

Insert the Raspberry Pi IP address, so that the ESP8266 connects to your broker.

#define MQTT_HOST IPAddress(192, 168, 1, 106)

If you’re using a cloud MQTT broker, insert the broker domain name, for example:

#define MQTT_HOST "example.com"

Define the MQTT port.

#define MQTT_PORT 1883

The temperature, humidity and pressure will be published on the following topics:

#define MQTT_PUB_TEMP "esp/bme280/temperature"
#define MQTT_PUB_HUM "esp/bme280/humidity"
#define MQTT_PUB_PRES "esp/bme280/pressure"

Initialize a Adafruit_BME280 object called bme.

Adafruit_BME280 bme;

The temp, hum and pres variables will hold the temperature, humidity and pressure values from the BME280 sensor.

float temp;
float hum;
float pres;

Create an AsyncMqttClient object called mqttClient to handle the MQTT client and timers to reconnect to your MQTT broker and router when it disconnects.

AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;

WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;

Then, create some auxiliary timer variables to publish the readings every 10 seconds. You can change the delay time on the interval variable.

unsigned long previousMillis = 0;  // Stores last time temperature was published
const long interval = 10000;       // Interval at which to publish sensor readings

MQTT functions: connect to Wi-Fi, connect to MQTT, and Wi-Fi events

We haven’t added any comments to the functions defined in the next code section. Those functions come with the Async Mqtt Client library. The function’s names are pretty self-explanatory.

For example, the connectToWifi() connects your ESP8266 to your router:

void connectToWifi() {
  Serial.println("Connecting to Wi-Fi...");
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}

The connectToMqtt() connects your ESP8266 to your MQTT broker:

void connectToMqtt() {
  Serial.println("Connecting to MQTT...");
  mqttClient.connect();
}

The onMqttConnect() function runs after starting a session with the broker.

void onMqttConnect(bool sessionPresent) {
  Serial.println("Connected to MQTT.");
  Serial.print("Session present: ");
  Serial.println(sessionPresent);
}

MQTT functions: disconnect and publish

If the ESP8266 loses connection with the MQTT broker, it calls the onMqttDisconnect function that prints that message in the serial monitor.

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
  Serial.println("Disconnected from MQTT.");
  if (WiFi.isConnected()) { 
    xTimerStart(mqttReconnectTimer, 0);
  }
}

When you publish a message to an MQTT topic, the onMqttPublish() function is called. It prints the packet id in the Serial Monitor.

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
  Serial.println("Disconnected from MQTT.");

  if (WiFi.isConnected()) {
    mqttReconnectTimer.once(2, connectToMqtt);
  }
}

Basically, all these functions that we’ve just mentioned are callback functions. So, they are executed asynchronously.

setup()

In the setup(), initialize the BME280 sensor.

if (!bme.begin(0x76)) {
  Serial.println("Could not find a valid BME280 sensor, check wiring!");
  while (1);
}

The next two lines create handlers that will allow both the MQTT broker and Wi-Fi connection to reconnect, in case the connection is lost.

wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);

Finally, assign all the callbacks functions. This means that these functions will be executed automatically when needed. For example, when the ESP8266 connects to the broker, it automatically calls the onMqttConnect() function, and so on.

mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
//mqttClient.onSubscribe(onMqttSubscribe);
//mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(MQTT_HOST, MQTT_PORT);

Broker Authentication

If your broker requires authentication, uncomment the following line and insert your credentials (username and password).

mqttClient.setCredentials("REPlACE_WITH_YOUR_USER", "REPLACE_WITH_YOUR_PASSWORD");

Finally, connect to Wi-Fi.

connectToWifi();

loop()

In the loop(), you create a timer that will allow you to get new readings from the BME280 sensor and publishing them on the corresponding topic every 10 seconds.

unsigned long currentMillis = millis();
// Every X number of seconds (interval = 10 seconds) 
// it publishes a new MQTT message
if (currentMillis - previousMillis >= interval) {
  // Save the last time a new reading was published
  previousMillis = currentMillis;
  // New BME280 sensor readings
  temp = bme.readTemperature();
  //temp = 1.8*bme.readTemperature() + 32;
  hum = bme.readHumidity();
  pres = bme.readPressure()/100.0F;

Learn more about getting readings from the BME280 sensor: ESP8266 with BME280 Temperature, Humidity and Pressure Sensor Guide.

Publishing to topics

To publish the readings on the corresponding MQTT topics, use the next lines:

uint16_t packetIdPub1 = mqttClient.publish(MQTT_PUB_TEMP, 1, true, String(temp).c_str());
uint16_t packetIdPub2 = mqttClient.publish(MQTT_PUB_HUM, 1, true, String(hum).c_str());
uint16_t packetIdPub3 = mqttClient.publish(MQTT_PUB_PRES, 1, true, String(pres).c_str());

Basically, use the publish() method on the mqttClient object to publish data on a topic. The publish() method accepts the following arguments, in order:

  • MQTT topic (const char*)
  • QoS (uint8_t): quality of service – it can be 0, 1 or 2
  • retain flag (bool): retain flag
  • payload (const char*) – in this case, the payload corresponds to the sensor reading

The QoS (quality of service) is a way to guarantee that the message is delivered. It can be one of the following levels:

  • 0: the message will be delivered once or not at all. The message is not acknowledged. There is no possibility of duplicated messages;
  • 1: the message will be delivered at least once, but may be delivered more than once;
  • 2: the message is always delivered exactly once;
  • Learn about MQTT QoS.

Uploading the code

With your Raspberry Pi powered on and running the Mosquitto MQTT broker, upload the code to your ESP8266.

Open the Serial Monitor at a baud rate of 115200 and you’ll see that the ESP8266 starts publishing messages on the topics we’ve defined previously.

ESP8266 NodeMCU Publish BME280 Sensor Readings MQTT Serial Monitor

Preparing Node-RED Dashboard

The ESP8266 is publishing temperature readings every 10 seconds on the esp/bme280/temperature, esp/bme280/humidity, and esp/bme280/pressure topics. Now, you can use any dashboard that supports MQTT or any other device that supports MQTT to subscribe to those topics and receive the readings.

As an example, we’ll create a simple flow using Node-RED to subscribe to those topics and display the readings on gauges.

If you don’t have Node-RED installed, follow the next tutorials:

Having Node-RED running on your Raspberry Pi, go to your Raspberry Pi IP address followed by :1880.

http://raspberry-pi-ip-address:1880

The Node-RED interface should open. Drag three MQTT in nodes, and three gauge nodes to the flow.

Node-RED Drag 6 Nodes MQTT In nodes and Gauges

Click the MQTT node and edit its properties.

MQTT In Node ESP8266 Publish Temperature Node-RED Flow

The Server field refers to the MQTT broker. In our case, the MQTT broker is the Raspberry Pi, so it is set to localhost:1883. If you’re using a Cloud MQTT broker, you should change that field.

Insert the topic you want to be subscribed to and the QoS. This previous MQTT node is subscribed to the esp/bme280/temperature topic.

Click on the other MQTT in nodes and edit its properties with the same server, but for the other topics: esp/bme280/humidity and esp/bme280/pressure.

Click on the gauge nodes and edit its properties for each reading. The following node is set for the temperature readings. Edit the other chart nodes for the other readings.

ESP8266 NodeMCU Gauge Temperature Node-RED Flow

Wire your nodes as shown below:

ESP8266 NodeMCU MQTT Publish Temperature Humidity Pressure Node-RED Flow

Finally, deploy your flow (press the button on the upper right corner).

Deploy Node-RED button

Alternatively, you can go to Menu > Import and copy the following to your Clipboard to create your Node-RED flow.

[{"id":"5a45b8da.52b0d8","type":"mqtt in","z":"b01416d3.f69f38","name":"","topic":"esp/bme280/temperature","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":310,"y":60,"wires":[["3042e15e.80a4ee"]]},{"id":"3042e15e.80a4ee","type":"ui_gauge","z":"b01416d3.f69f38","name":"","group":"37de8fe8.46846","order":2,"width":0,"height":0,"gtype":"gage","title":"Temperature","label":"ºC","format":"{{value}}","min":0,"max":"40","colors":["#00b500","#f7df09","#ca3838"],"seg1":"","seg2":"","x":590,"y":60,"wires":[]},{"id":"8ff168f0.0c74a8","type":"mqtt in","z":"b01416d3.f69f38","name":"","topic":"esp/bme280/humidity","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":300,"y":140,"wires":[["29251f29.6687c"]]},{"id":"29251f29.6687c","type":"ui_gauge","z":"b01416d3.f69f38","name":"","group":"37de8fe8.46846","order":2,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"%","format":"{{value}}","min":"30","max":"100","colors":["#53a4e6","#1d78a9","#4e38c9"],"seg1":"","seg2":"","x":580,"y":140,"wires":[]},{"id":"294f7eea.999d72","type":"mqtt in","z":"b01416d3.f69f38","name":"","topic":"esp/bme280/pressure","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":300,"y":220,"wires":[["58610d70.bb9764"]]},{"id":"58610d70.bb9764","type":"ui_gauge","z":"b01416d3.f69f38","name":"","group":"37de8fe8.46846","order":4,"width":0,"height":0,"gtype":"gage","title":"Pressure","label":"hPa","format":"{{value}}","min":0,"max":"1200","colors":["#b366ff","#8000ff","#440088"],"seg1":"","seg2":"","x":580,"y":220,"wires":[]},{"id":"8db3fac0.99dd48","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"37de8fe8.46846","type":"ui_group","z":"","name":"BME280","tab":"53b8c8f9.cfbe48","order":1,"disp":true,"width":"6","collapse":false},{"id":"53b8c8f9.cfbe48","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

View raw code

Demonstration

Go to your Raspberry Pi IP address followed by :1880/ui.

http://raspberry-pi-ip-address:1880/ui

You should get access to the current BME280 sensor readings on the Dashboard. You can use other dashboard-type nodes to display the readings on different ways.

ESP8266 NodeMCU MQTT Publish Temperature Humidity Pressure Node-RED Dashboard

That’s it! You have your ESP8266 board publishing BME280 temperature, humidity and pressure readings to Node-RED via MQTT.

Wrapping Up

MQTT is a great communication protocol to exchange small amounts of data between devices. In this tutorial you’ve learned how to publish temperature, humidity and pressure readings from a BME280 sensor with the ESP8266 to different MQTT topics. Then, you can use any device or home automation platform to subscribe to those topics and receive the readings.

Instead of a BME280, you can use any a different sensor:

We hope you’ve found this tutorial useful. If you want to learn more about the ESP8266, take a look at our resources:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

25 thoughts on “ESP8266 NodeMCU MQTT – Publish BME280 Sensor Readings (Arduino IDE)”

  1. Nice tutorial! What is the difference between this MQTT Library and the PubSubClient?
    I did the webserver with BME280 for the webpage (https://randomnerdtutorials.com/esp8266-dht11dht22-temperature-and-humidity-web-server-with-arduino-ide/) with the conditions in my Observatory. I went back and added the PubSubClient to publish the info also. I can now connect to IO.Adafruit.com from anywhere and see the temperature and humidity by my telescope.

    Reply
    • Hello Deyvid,
      Yes, you can have the Mosquitto MQTT broker installed in your computer:

      mosquitto.org/download/

      It works in any operating systems, however I recommend using a RPi because it’s the easiest way to have a dedicated device always powered on to run the Mosquitto broker.

      I hope that helps!
      Regards,
      Rui

      Reply
  2. Excelente proyecto. Si quisiera enviar mas de 2 sensores a un mismo terminal MQTT, donde tendría que hacer el cambio en el código, en el tópico?

    Muchas gracias por la ayuda.

    Reply
  3. NICE, I got is working! I’ve just starting with Node-Red, so, I wanted to work through the UI rather than Import the Node-RED flow. Only issue I ran into was that where was no TAB “Home” or Name BMS280.

    Maybe add a step, image for this.

    Thanks for all the hard work and long hours you put into your videos and tutorials!!!

    Reply
    • Hi.
      Thanks for your feedback.
      Yes, you’re right. That step is not in the tutorial.
      I need to add a note about that.
      Regards,
      Sara

      Reply
  4. Worked for me. Very good explaination, i think i will go on with such projects. The reasons are such good websites and people that really want to help others. Hope to see more of such good tutorials in the future. In the last time i’ve learned lots of new things.

    Really good work both of you!

    Greetings from Germany

    Reply
  5. Hello Rui and Sara,
    it’s a great guide and everything works great too.
    I am currently trying to send the mqtt data to telegraf via mosquitto and then save it in influxDB and display it with grafana. I can’t find the right settings for telegraf.
    Can you help me there?
    Thank you Ralf

    Reply
  6. hi ,, i was trying to apply the node red flow but i cant find the gauge node at all.

    what should i do ?

    waiting for your kind reply.

    Reply
  7. Thank you for this great description! implemented this on my very 1st ESP8266 project and it is working very well. I even added a few more sensors and respective topics to publish. Now the next step is to subscribe to topics. The code has commented sections which seem to handle just what I need. Are there any samples which show how to a subscrib to topic? A link would be just great. Thank you.

    Reply
  8. Hello Rui
    Nice description. I am working with BMP280 where I can publish Temperature, Pressure and Altitude.
    What is the diff. between AsyncMQTTClient and ArduinoMqttClient ?
    Can I use ArduinoMqttClient ?
    Regards
    Prof.K.R.Rao

    Reply
  9. Not sure how I missed getting the IP address needed.

    I’m using a small form factor PC running Ubuntu

    // Change the variable to your Raspberry Pi IP address, so it connects to your MQTT broker
    const char* mqtt_server = “REPLACE_WITH_YOUR_RPI_IP_ADDRESS”;

    Question is how to obtain the URL on the NODE-RED host ?

    Reply
    • Hi.
      Open a Terminal window on your Raspberry Pi.
      Then, run the following command
      hostname -I
      It will return the RPi IP address.
      Regards,
      Sara

      Reply
  10. I have my ESP8266 + BMP280 + Raspberry Pi4. The code runs great. but seems to stop after an hour and the MQTT server does not receive the data. And the node-red dashboard just stops updating with the final data.

    Any ideas ? also thanks for this great tutorial, its very easy to understand.

    Reply
  11. Great tutorial, many thanks! This is my first temperature sensor project and I am currently struggling to use your code example with deep sleep in order to run the sensor on batteries. I have read the deep sleep tutorial but I am not sure where to put the respective command without getting stuck at “connecting to WiFi…”. I guess the code will have to be rearranged but that is currently beyond my capabilities.

    Reply
  12. Thanks! great tutorial, I got it up and running right away. I have a question though, is there any way to publish rounded numbers to MQTT so the trailing numbers after the decimal point are removed? I’ve been trying different methods but nothing seems to work.

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.