Open-source IoT Platform

Device management, data collection, processing and visualization
for your IoT projects
Learn about Thingsboard

Monday, December 19, 2016

Temperature upload over MQTT using NodeMCU and DHT11 sensor

Thingsboard is an open-source server-side platform that allows you to monitor and control IoT devices. It is free for both personal and commercial usage and you can deploy it anywhere. If this is your first experience with the platform we recommend to review what-is-thingsboard page and getting-started guide.

This sample application performs collection of temperature and humidity values produced by DHT11 sensor. Collected data is pushed to Thingsboard for storage and visualization. The purpose of this application is to demonstrate Thingsboard data collection API and visualization capabilities.

The DHT11 sensor is connected to NodeMCU. NodeMCU push data to Thingsboard server via MQTT protocol. Data is visualized using built-in customizable dashboard. The application that is running on NodeMCU is written using Lua scripting language which is quite simple and easy to understand.

Once you complete this sample/tutorial, you will see your sensor data on the following dashboard.

image

Prerequisites

You will need to Thingsboard server up and running. Use either Live Demo or Installation Guide to install Thingsboard.

List of hardware and pinouts

image

image

  • 3 female-to-female jumper wires

Wiring schema

image

NodeMCU Pin DHT-11 Pin
NodeMCU 3.3V DHT-11 VCC
NodeMCU GND DHT-11 GND (-)
NodeMCU D5 DHT-11 Data (S)

Programming the NodeMCU device

We need to download and build firmware with Lua interpreter for NodeMCU. This process is described in official documentation and there are multiple way to do this. You can use cloud build service for this purpose, however, we will use Docker Image.

Firmware download

Use following commands to clone official github repository for NodeMCU firmware.

$ mkdir -p ~/samples/nodemcu
$ cd ~/samples/nodemcu
$ git clone https://github.com/nodemcu/nodemcu-firmware.git

There is ability to customize firmware by changing two files:

  • ~/samples/nodemcu/nodemcu-firmware/app/include/user_config.h - There is an ability to change default baud rate in.

Please find and update line below to specify custom baud rate.

...
#define BIT_RATE_DEFAULT BIT_RATE_115200
...
  • ~/samples/nodemcu/nodemcu-firmware/app/include/user_modules.h - Contains list of what kind of modules included by default.

In our case all necessary modules included by default. However, please check that these modules are uncommented.

...
define LUA_USE_MODULES_DHT
...
define LUA_USE_MODULES_MQTT
...

Building firmware using Docker

The easiest way to build nodemcu firmware is by using prepared docker container for that task.

Please visit docker installation page and install docker on your machine.

After installation you need to download docker image from docker hub by command:

$ sudo docker pull marcelstoer/nodemcu-build 

Eventually build the firmware by next command:

$ sudo docker run --rm -ti -v ~/samples/nodemcu/nodemcu-firmware:/opt/nodemcu-firmware marcelstoer/nodemcu-build

As the result binary firmware located in the ~/samples/nodemcu/nodemcu-firmware/bin folder.

Application source code

Our application consists of three .lua files:

  • config.lua - configuration file, where we define custom configuration. You need to modify this file in order to setup your wifi network parameters and address of Thingsboard server.
    • your wifi network SSID - name of the wifi network.
    • your wifi network password - password to the network.
    • thingsboard server ip - host where your thingsboard installation. Use “demo.thingsboard.io” if you are using live demo server.
    • thingsboard mqtt port - 1883 is the default value.
    • thingsboard access token - DHT11_DEMO_TOKEN is the default value that corresponds to pre-provisioned demo account.

    If you are using live demo server - get the access token for pre-provisioned “DHT11 Demo Device”.

  • dht11.lua - sending temperature and humidity every 10 seconds to thingsboard server via MQTT protocol.
  • init.lua - initalization file that contains config.lua:
resources/config.lua
wifi_mode = 1
wifi_ssid = "YOUR_WIFI_SSID_HERE"
wifi_pass = "YOUR_WIFI_PASSWORD_HERE"
mqtt_ip = "YOUR_THINGSBOARD_HOST_OR_IP_HERE"
mqtt_port = 1883
access_token = "DHT11_DEMO_TOKEN"

Flashing the firmware

Before flashing firmware we need to figure out what serial interface using to communicate with NodeMCU.

$ dmesg
...
[845270.901509] usb 3-3: ch341-uart converter now attached to ttyUSB0
...

In our case /dev/ttyUSB0 is used for communication.

In order to flash firmware for NodeMCU, please download and install following utilities

Upload nodemcu firmware using command:

$ sudo ./esptool.py -b 115200 write_flash --flash_mode dio --flash_size 32m 0x0 ~~/samples/nodemcu/nodemcu-firmware/bin/nodemcu_integer_master_*.bin --verify

Upload application files using following commands:

$ sudo ./luatool.py --port /dev/ttyUSB0 -b 115200 --src config.lua --dest config.lua -v
$ sudo ./luatool.py --port /dev/ttyUSB0 -b 115200 --src dht11.lua --dest dht11.lua -v
$ sudo ./luatool.py --port /dev/ttyUSB0 -b 115200 --src init.lua --dest init.lua -v

Troubleshooting

Sometimes you can observe frequent blinking of the blue led after firmware upload. This is probably related to missing initialization data. Use following command to fix this:

$ sudo ./esptool.py -b 115200 write_flash --flash_mode dio --flash_size 32m 0x3fc000 ~/samples/nodemcu/nodemcu-firmware/bin/esp_init_data_default.bin --verify

Sometimes you are not able to upload lua files. Try to reset device and executing command again within first 10 seconds after reset. If no success, try to delete init.lua code from NodeMCU:

$ sudo ./luatool.py --port /dev/ttyUSB0 -b 115200 --delete init.lua

Data visualization

In order to simplify this guide we have included “Temperature & Humidity Demo Dashboard” to the demo data that is available in each Thingsboard installation. Of course, you can modify this dashboard: tune, add, delete widgets, etc. You can access this dashboard by logging in as a tenant administrator. Use

in case of local Thingsboard installation.

Once logged in, open Dashboards->Temperature & Humidity Demo Dashboard page. You should observe demo dashboard with live data from your device (similar to dashboard image in the introduction).

Next steps

Browse other samples or explore guides related to main Thingsboard features:

Your feedback

If you found this article interesting, please leave your feedback in the comments section, post questions or feature requests on the forum and “star” our project on the github in order to stay tuned for new releases and tutorials.

54 comments :

  1. Prepare yourself to take your wardrobe for an overhaul without breaking the bank because of a wonderful piece of information – it is time to know about cider coupon code! It does not matter whether you fancy classic elegance, current fads, and casual chic. Check your chosen brand’s website, subscribe to its email newsletter, or keep abreast with its social media posts for these exclusive stylish offers by your favorite ladies’ wear manufacturers. Affordable high quality fashions are just few button presses. Pass on, your fashion discoveries, coupon/promo codes, and style notes to the community, and let’s help/empower each other to look fabulous for cheaper, better, and faster! Therefore, why don’t you do something

    ReplyDelete
    Replies
    1. Your ability to connect seemingly disparate elements within this theme is a true testament to your creative genius, resulting in geometry dash a comprehensive and holistic understanding that enriches the reader's perspective.

      Delete
  2. I rely on BetGuru 365 for their comprehensive and honest assessments of betting sites. Their detailed reviews, available at https://betguru365.com/ , provide an unparalleled depth of analysis. They meticulously examine each site’s offerings, from odds and markets to security measures. This dedication to providing accurate and trustworthy reviews makes BetGuru 365 an essential tool for anyone interested in online betting.

    ReplyDelete
  3. Uploading temperature via MQTT using NodeMCU and DHT11 sensors has greatly improved access speed. eggy car

    ReplyDelete
  4. The technology of their numbers is amazing Head Soccer

    ReplyDelete
  5. To upload temperature data over MQTT Bou's Revenge using a NodeMCU and a DHT11 sensor, you'll need to set up your hardware and software properly.

    ReplyDelete
  6. Thank you so much sharing article you always sharing very informative article which help new students thank you so much.

    Free Coupon Codes & Discounts

    ReplyDelete
  7. Purchasing a GPS tracker is mostly done for real-time tracking. Different tracking devices have different real-time GPS tracking capabilities. doodle baseball

    ReplyDelete
  8. The significant improvement in access speed via MQTT using NodeMCU and DHT11 sensors has greatly improved access speed. geometry dash

    ReplyDelete
  9. Real-time monitoring and effective IoT communication are made possible by uploading temperature data over MQTT with a NodeMCU and a DHT11 sensor. This configuration offers a dependable means of sending environmental data to distant servers for control and analysis. I’m currently working on my master dissertation and I am really starting to feel the pressure. I have been think about whether I should buy master dissertation help to ensure everything is perfect. Has anyone here tried this? Was it helpful for your dissertation process? All I want to do is make sure I am receiving what I need without missing any vital. If anyone has used this before, please let me learn how it was and if you believe it is worth the cost.

    ReplyDelete
  10. Whether you’re a casual gamer or a hardcore music enthusiast, Sprunked offers something truly special. Let’s dive into what makes this game a must-play.

    ReplyDelete
  11. The tunes can be altered to Fiddlebops suit any mood and are lovely. My obsession is making new music.

    ReplyDelete
  12. The graphics in Escape Road are stunning! The vibrant city streets and detailed vehicles create an immersive environment. It feels like I'm really in a high-speed chase, trying to outsmart the police. Each turn is filled with excitement!

    ReplyDelete
  13. A perfect blend of challenge and fun. Explore our Geometry Dash comprehensive guide and become a master of the game.

    ReplyDelete
  14. Minimalist Tap Road design but effective. It’s simple, yet the black background and neon accents give the game a sleek, modern feel.

    ReplyDelete
  15. In World Guesser the street view data is quite detailed. Guessing is so much more enjoyable when I can almost sense the local vibe of each place.

    ReplyDelete
  16. The ability to modify terrain Melon Playground weather, and character behavior adds depth to the gameplay, making every session unique and exciting.

    ReplyDelete
  17. Crafted for those who value durability and timeless design, this premium material delivers both style and substance. Whether you’re updating your wardrobe or enhancing your accessories, Zing leather offers the perfect blend of luxury and resilience. Discover the difference that true craftsmanship makes in every stitch and detail.

    ReplyDelete
  18. What do you think would happen if the sensor was off by just 1 second? In geometry arrow , even one wrong tap would cost you the game. Are you accurate enough?

    ReplyDelete
  19. Get top-tier car care at Kwik Kar Auto Dallas, your trusted destination for reliable auto repair and maintenance services. From oil changes and brake repairs to engine diagnostics and state inspections, our certified mechanics ensure your vehicle stays road-ready and running smoothly. Experience fast, friendly, and professional service tailored to your needs—right here in Dallas!

    ReplyDelete
  20. Spot-on guide for IoT headaches. Long hours parsing streams demand layers that don’t distract. Fresh colors like mint combat screen burnout beautifully. My analytics uniform? The Fear of God Essentials Mint Leaf Hoodie. Unrestricted movement meets mental clarity. Data never felt this cozy.

    ReplyDelete
  21. Monitoring temperature with NodeMCU and Thingsboard is fascinating! It reminds me of the thrill of navigating icy slopes in Snow Rider 3D. This project offers a practical way to learn about IoT, similar to mastering those challenging Snow Rider 3D levels. Gathering data via DHT11 and visualizing it is a valuable skill. This setup provides a hands-on experience for anyone curious about IoT and data collection.

    ReplyDelete
  22. Precision in data, much like in fashion design, relies on quality inputs and clear presentation to create meaningful impact. That same commitment to excellence and thoughtful construction can be found in pieces designed to perform beautifully in any context. Your technical walkthrough reminds me of how the Catherine Vincent Brooks Jacket combines meticulous detail with versatile elegance.

    ReplyDelete
  23. The more I think about it, the erome more impressed I am with how smooth this whole video was.

    ReplyDelete
  24. This is pretty cool! Seems like a straightforward guide to get temperature data flowing into ThingsBoard. I might actually give this a try for my next IoT project. Thanks for sharing! Do you want to play a lot of fun games on one website? Then come and click me at Playpharos

    ReplyDelete
  25. Cool tutorial! I'm definitely gonna try this out with my NodeMCU and DHT11. Sounds like a fun little project to get data up to Thingsboard. Thanks for the clear instructions! Classify AI text from major AI models, from ChatGPT to Gemini, Llama, Claude and more.at GPTDetect.ai

    ReplyDelete
  26. This is a cool tutorial! I've been wanting to try ThingsBoard for a while now. The step-by-step guide with NodeMCU and DHT11 seems like a great way to get started. I'll definitely give it a try! It can help you use the image-to-image function, the text-to-image function, or remove the background of your image.at Picool.ai

    ReplyDelete
  27. Wow, this ThingsBoard tutorial looks super useful! I've been wanting to try connecting sensors to IoT platforms, and this seems like a great, step-by-step guide. Definitely gonna give it a shot! Generate a random email address for you on the web page, fast and convenient at Tempmailpro

    ReplyDelete
  28. This is a cool tutorial! I'm excited to try connecting my DHT11 to Thingsboard. The steps seem pretty straightforward, and the docker image is a lifesaver. Hopefully, I can get my data visualized quickly! Do you want to use AI to write poems, do you want to write a poem for your loved ones, lovers and friends, then come quicklyAI Poem Generator

    ReplyDelete
  29. Cool tutorial! Looks like a great way to get started with IoT and Thingsboard. I'm definitely going to try this out with my NodeMCU. Thanks for the clear instructions! If you want to use AI tools, there are plenty of good AI tools out there Novatools

    ReplyDelete
  30. This looks like a really helpful guide for connecting sensors to ThingsBoard! I'm gonna try this out with my NodeMCU and see if I can get it working. Fingers crossed! Seems pretty straightforward. If you want to relax, we recommend it Wackyflip

    ReplyDelete
  31. Wow, this is a cool tutorial for connecting sensors to Thingsboard! Definitely gonna try this out with my NodeMCU. Hope it's as easy as it looks! If you like to play games, don't miss it Mergefellas

    ReplyDelete
  32. Cool tutorial! I've been looking for a simple way to get sensor data into ThingsBoard. This looks pretty straightforward. I'm gonna give it a try this weekend! Thanks for sharing! If you have date calculation requirements, or want to use the countdown function, welcome to Date Calculator Pro

    ReplyDelete
  33. Wow, this ThingsBoard tutorial looks super helpful! I've been wanting to try connecting my NodeMCU to a proper IoT platform. Definitely gonna give this a shot over the weekend! Thanks for sharing! If you want to play the fun Candy Clicker game, then come and experience it, and bring you a unique clicker journey Candy Clicker

    ReplyDelete
  34. This is a really neat tutorial! Looks like a fun project to try out with my NodeMCU. The steps seem pretty clear, I might give it a shot this weekend. Thanks for sharing! Do you want to experience a brand new life? Do you want to start from scratch? Choose the life you want? Then come here and play. Bitlife Unblocked

    ReplyDelete
  35. Cool tutorial! Seems like a pretty straightforward way to get temperature data into ThingsBoard. I might give this a try with my own NodeMCU project. Thanks for sharing!Do you feel that your actual age does not match your mental age, and want to test your mental age, then come quickly? Heart Age Calculator

    ReplyDelete
  36. Wow, this Thingsboard tutorial looks super helpful! Gonna try this out with my NodeMCU and DHT11. Hope I can get my temperature data showing up on that dashboard! Fingers crossed! Want to play a fun duck life game, there are many fun duck life to experience here Duck Life 3

    ReplyDelete
  37. Wow, this looks like a super helpful tutorial for getting started with ThingsBoard! I've been wanting to play around with IoT stuff, and this seems like a really straightforward way to do it. Definitely gonna give it a try! Want to generate a triangular prophecy diagram, Deltarune prophecy generator can do it for you, come here to try it.Deltarune prophecy generator

    ReplyDelete
  38. Cool tutorial! I've been looking for a simple way to integrate DHT11 with ThingsBoard. This looks pretty straightforward, I'll definitely give it a try. Thanks for sharing!
    If you want to play a new way to play Roblox, come and experience it here Steal Brainrot Online

    ReplyDelete
  39. This is a cool tutorial! I'm always looking for ways to connect my sensors to the cloud. ThingsBoard looks like a pretty powerful platform, might give it a try! Thanks for sharing! Want to use the latest AI image editing and want to make your images look better, then come and experience Qwen Image Edit

    ReplyDelete
  40. This is pretty cool! I've been looking for a simple tutorial on connecting sensors to ThingsBoard. The docker build method seems really helpful. Gonna give this a try this weekend! Want to split your pictures and make your pictures look better, come and experience it in Img Splitter

    ReplyDelete
  41. Cool! This is exactly what I was looking for. A clear and simple guide on how to connect DHT11 to Thingsboard using NodeMCU. I can finally monitor my room temperature remotely. Thanks! Do you want to play the original Roblox character click, want to release your stress, then come to A Shedletsky povto experience it

    ReplyDelete
  42. This looks pretty cool! I've been meaning to try Thingsboard for a while now. This tutorial seems like a good starting point to get some sensor data visualized quickly. I'm gonna give it a try! Do you want to keep a pet, do various things with it? Then come and play in Take Care Of Shadow Milk!

    ReplyDelete
  43. This is a cool tutorial! Seems like a great way to get started with IoT and ThingsBoard. I'm gonna try this out with my own DHT11 sensor. Thanks for sharing! Want to use AI to generate images or make your images look better, come and try Image to Image!

    ReplyDelete
  44. Wow, this is a cool tutorial! I've been wanting to try ThingsBoard with NodeMCU for a while. Looks pretty straightforward, gonna give it a shot this weekend! Thanks for sharing! Race Against Time in a Thrilling Escape at Escape Road

    ReplyDelete
  45. Wow, this is a pretty cool tutorial! I've been looking for something like this to get started with ThingsBoard. Definitely gonna give it a try this weekend. Thanks for sharing! Looking for a variety of different liquid glass effects, you can find a variety of different liquid glass effects to use in Liquid Glass HQ

    ReplyDelete
  46. Want to play Bloodmoney, which has been very popular lately, here you can play the latest Blood Money 2

    ReplyDelete
  47. Cool tutorial! I've been looking for a good guide on connecting DHT11 to Thingsboard. This seems pretty straightforward, I'm gonna give it a try! Thanks for sharing! Do you want to convert your fonts into all kinds of weird shapes, and want to make your fonts look better, then come and try Freaky Font Generator

    ReplyDelete
  48. Wow, this looks like a super useful tutorial for anyone playing around with IoT! I'm gonna try this out with my NodeMCU and see if I can get it working. Thanks for sharing! Want to play a fun point-and-click game experience with a wonderful story, then come and experience it in Lovemoney

    ReplyDelete
  49. Cool! This is a great tutorial for connecting IoT devices to ThingsBoard. Easy to follow steps even for beginners. Might give it a try myself! Seems like a fun project to build. If you want to play a fun and relaxing clicker game, come and experience it in 67 Clicker

    ReplyDelete
  50. Cool tutorial! Seems like a fun project to try out. Might give this a shot this weekend. Thanks for sharing! I've been looking for something like this to get started with ThingsBoard. Want to play a fun test game to test whether you are a robot or not, come and experience it in Im Not A Robot Game

    ReplyDelete
  51. This is a really cool tutorial! I've been looking for a simple way to connect my DHT11 to ThingsBoard. Seems pretty straightforward, might give it a try this weekend! Thanks for sharing! Want to describe your picture, or are you still worried about not knowing how to describe a picture, come to Image Describer to try it.

    ReplyDelete
  52. Wow, this tutorial looks really helpful for anyone starting with IoT projects! I love how detailed it is with the NodeMCU and DHT11 setup. Definitely gonna try this out this weekend! If you want to play the new Retro Bowl experience, try it out in Retro Bowl 26.

    ReplyDelete
  53. This is a cool tutorial! I've been looking for a good guide on using ThingsBoard with NodeMCU. This looks pretty straightforward, gonna try it out this weekend. Hope it works! Looking for fun puzzle games? Constantly embark on adventures to solve mysteries, right here at Dead Plate

    ReplyDelete