Skip to Main Content
PolyU Library

i-Space: Student Project - Real Time Weather Monitoring Station

Consisting of the Digital Makerspace, Digital Visualisation Room and Studios

Internet of Things: Real Time Weather Monitoring Station

Real Time Weather Monitoring Station

An Internet-of-Thing (IoT) component can be configured to collect real-time environmental data by integrating NodeMCU ESP8266 development board with a temperature and humidity sensor DHT11. The student used an Arduino IDE program to set up a small scale weather monitoring station which indicate the real-time and historical environmental data over the IoT platform ThingsBoard. The procedure is available here, which shows you how to set up the real time weather monitoring station with simple IoT components.

Components

IoT Server Platform

Open Source IoT Platform - ThingsBoard

IoT Controller (Available to borrow)

Arduino UNO

Temperature and humidity sensor - DHT11

NodeMCU ESP8266 development board

Resources

Procedures and Source Code (Arduino IDE code)

ThingsBoard Installation Guide: Windows / other operating systems

ThingsBoard Setup Guide and JSON file

Arduino Setup Guide

The temperature and humidity sensor send the data to ThingsBoard and the sensor data is plotted as graphical statistics.

 

Student

Kemp Isabel Madeleine

Department of Computing

(April 2021)

Procedures and Source Code

Part 1 Procedure

1) Board Setup

Note:
Each pin in the DHT11 has a special use, the 3 pins are called “SVG” collectively. The “S” is equivalent to “DATA”, which outputs both temperature and humidity through serial data. “V” is equivalent to “VCC”, a power of 3.5V to 5.5V is supplied. “G” is equivalent to “GND” or “GROUND” which is connected to the ground of the circuit.


Instructions:
      i) Connect “S” to “D2”
     ii) Connect “V” to “3V3”
    iii) Connect “G” to “GND”

 

Node MCU Pinout

 

 

Completed

2) ThingsBoard Installation & Dashboard Setup
          Installation Instruction: Windows/ other operating systems
          Setup:
             i) Download the JSON file
            ii) Follow the instruction


3) Source Code
          Download Arduino IDE code


4) Arduino Installation & Setup
          Follow the instruction

 

Data Visualization

To access the telemetry data,
          i) Go to “Devices” section
         ii) Choose the device profile “ESP8266 Demo Device”
        iii) Click “Latest telemetry”

 

To access the dashboard,
         i) Go to “Dashboard”
        ii) Click “ESP8266 DHT11: Temperature & Humidity Demo Dashboard”
       iii) The output should be shown as below

Part 2 Source Code for Arduino IDE

    #include "DHT.h"

       #include <ESP8266WiFi.h>

       #include <ThingsBoard.h>

       //input wifi credentials

       #define WIFI_AP "Isabel Love Bella"

       #define WIFI_PASSWORD "11112222"

       int status = WL_IDLE_STATUS;

       unsigned long lastSend;

       //input thingsboard access token and IP address

       #define TOKEN "ltJhusW41LTBuQIvBEnJ"

       char thingsboardServer[] = "172.20.10.2";

       WiFiClient wifiClient;

       ThingsBoard tb(wifiClient);

       // set up DHT11

       #define DHTPIN 4

       #define DHTTYPE DHT11

       DHT dht(DHTPIN, DHTTYPE);

       //Connect to WiFi

       void setup() {

         Serial.begin(115200);

         dht.begin();

         delay(10);

         InitWiFi();

         lastSend = 0;

       }

       //if can connect to thingsboard, proceed to getting temperature and humidity data

       //if cannot connect to wifi, keep reconnecting

       void loop() {

         if ( !tb.connected() ) {

           reconnect();

         }

         if ( millis() - lastSend > 1000 ) { // Update and send only after 1 seconds

           getAndSendTemperatureAndHumidityData();

           lastSend = millis();

         }

         tb.loop();

       }

       //getting the humidity and temperature data from DHT11

       void getAndSendTemperatureAndHumidityData()       {

         Serial.println("Collecting temperature data.");

         // Reading temperature or humidity takes about 250 milliseconds!

         float humidity = dht.readHumidity();

         // Read temperature as Celsius (the default)

         float temperature = dht.readTemperature();

         // Check if any reads failed and exit early (to try again).

         if (isnan(humidity) || isnan(temperature)) {

           Serial.println("Failed to read from DHT sensor!");

           return;

         }

         Serial.println("Sending data to ThingsBoard:");

         Serial.print("Humidity: ");

         Serial.print(humidity);

         Serial.print(" %\t");

         Serial.print("Temperature: ");

         Serial.print(temperature);

         Serial.println(" *C ");

         tb.sendTelemetryFloat("temperature", temperature);

         tb.sendTelemetryFloat("humidity", humidity);

       }

       //connecting to wifi

       //if connection fails, it will try to reconnect

       void InitWiFi()    {

         Serial.println("Connecting to AP ...");

         // attempt to connect to WiFi network

         WiFi.begin(WIFI_AP, WIFI_PASSWORD);

         while (WiFi.status() != WL_CONNECTED) {

           delay(500);

           Serial.print(".");

         }

         Serial.println("Connected to AP");

       }

       //when thingsboard connection fails, they will keep trying to reconnect.

       //but if your wifi credentials are wrong, or unstable, it usually fails to reconnect.

       //advice is to check your wifi credentials

       //computer that runs arduino is using the same wifi credentials, as the one you typed on your computer

       void reconnect() {

         // Loop until we're reconnected

         while (!tb.connected()) {

           status = WiFi.status();

           if ( status != WL_CONNECTED) {

             WiFi.begin(WIFI_AP, WIFI_PASSWORD);

             while (WiFi.status() != WL_CONNECTED) {

               delay(500);

               Serial.print(".");

             }

             Serial.println("Connected to AP");

           }

           Serial.print("Connecting to ThingsBoard node ...");

           if ( tb.connect(thingsboardServer, TOKEN) ) {

             Serial.println( "[DONE]" );

           } else {

             Serial.print( "[FAILED]" );

             Serial.println( " : retrying in 5 seconds]" );

             // Wait 5 seconds before retrying

             delay( 5000 );

           }

 }

       }

 

Part 3 Reference

DHT11–Temperature and Humidity Sensor: https://components101.com/dht11-temperature-sensor
Humiture Sensor Module: http://wiki.sunfounder.cc/index.php?title=Humiture_Sensor_Module
NodeMCU: https://en.wikipedia.org/wiki/NodeMCU
Thingsboard: https://thingsboard.io/
Temperature upload over MQTT using ESP8266 and DHT22 sensor: https://thingsboard.io/docs/samples/esp8266/temperature/ 

Click here to download procedures and source code