Monitoring Temperature & Humidity on LOTODA App With NodeMCU-ESP8266 or ESP32 Mini Kit.

by LOTODA in Circuits > Wireless

830 Views, 4 Favorites, 0 Comments

Monitoring Temperature & Humidity on LOTODA App With NodeMCU-ESP8266 or ESP32 Mini Kit.

Page01_OK.PNG

Have you ever wanted to have sensors scattered all around your house and garden monitoring their temperature and humidity regularly? We'd like to share with you one solution of LOTODA IoT platform, you easily create a DIY IoT project with some LOTODA's resouces for free such as mobile app, application on your laptop and some Arduino libraries, In this instructable, we used the NodeMCU ESP8266 or MH-ET live ESP32 Mini kit with AM2301 sensor to send data (Temperature & Humidity) to LOTODA's IoT server and use the LOTODA mobile app to monitoring it. Excited? Let’s get started!

​Getting Started

Untitled Sketch_bb_md.png
ESP32 Sketch_bb_md.png
mh.png
dien-tu-360-95c67cad-4300-4262-8e90-9024e938804d.jpg
HCSENS0026_DHT21_Diagram.png

First for wiring, connecting AM2301 sensor to ESP8266 NodeMCU or ESP32, it is fairly simple. Now place the sensor on to your breadboard besides NodeMCU.

Connect Vcc pin on the sensor to the 3.3V pin on the NodeMCU and ground (GND) to ground (GND).

Also connect Data pin on the sensor to D1 pin of the ESP8266 NodeMCU or IO5 pin of ESP32 Mini Kit.

And finally, we need to place a pull-up resistor of 10KΩ between Vcc and data line to keep it HIGH for proper communication between sensor and NodeMCU.

Red = Vcc 3.3v (left)

Yellow = Data line (middle)

Black = Ground (right)

Getting Started With LOTODA IoT Platform

Page02.PNG

These steps for registering and connecting the LOTODA app to the LOTODA IoT Platform.

First, you'll need to create a LOTODA Account after you download the LOTODA App on Android phone or iOS phone, see more detials at website https://lotoda.vn, in case you already have one. We recommend using a real email address because it need for the email comfirmation and you will get some two credential keys for connecting device or mobile app to LOTODA IoT Platform.

Email Confirmation and Some ID Keys of IoT LOTODA

Page03.PNG

After you register one account on LOTODA mobile app, you'll get two emails, first email for confirmation and second email for your ID keys in order to connecting some things to IoT LOTODA.

1. In the first comfirmation email: you please click on button "Verify Email" for activate your account, now you can log into your LOTODA mobile app successfully.

2. In the second ID keys email: including two ID keys which they are similar as username and password for authentication on LOTODA IoT server.

As you know LOTODA IoT Platform is working based on MQTT (Mesage Queuing Telemetry Transport) protocol. MQTT protocol specializes in low bandwidth, high latency environments, it is an ideal protocol for machine-to-machine (M2M) communication, if you are familarly with MQTT, you are able to use it easily.

Log Into the LOTODA App and Connecting It to IoT LOTODA Service

Page04.PNG

After you’ve successfully logged into your account, please go to the "Settings" menu, and then you copy and paste your username ID key and password ID key from your email into the LOTODA app as picture above.

And then click on "Connect ..." button to connecting to LOTODA MQTT broker as picture above.

the status is "Connected ..." that mean the IoT LOTODA service is connected successfully.

Installing and Running Code on NodeMCU.

PlatformIO_01.PNG

After you’ve successfully logged into your account and connecting the LOTODA mobile app successfully.

Next, downloading LOTODA library & DHT sensor library. In the LOTODA library, you can see some examples for references.

Full code sources at here, open it on Visual Studio Code IDE with installed PlatformIO:

- Download for NodeMCU-8266: https://github.com/lotoda/LOTODA_Am2301_Esp8266

- Download for ESP32 Mini Kit: https://github.com/lotoda/LOTODA_Am2301_Esp32

Now let’s take a look at the example sketch for NodeMCU.

Notice there are three key components that you will need to include for connecting NodeMCU to LOTODA IoT platform:

1. String useridkey = ""; - specific username for authentication to connect to MQTT server of LOTODA platform. It's also prefixes of topic of each connection.

2. String passidkey = ""; - specific password for authentication to connect to MQTT server of LOTODA platform.

3. String deviceid = ""; - specific to your device ID, enter anythings by yourself, for example at here is "id1001" on NodeMCU ESP8266, make sure it's different with each your device.

And there are two key components that you will need to include for connecting to your WiFi network:

1. char* ssid = "ssid"; - specific to the network that we are connecting to (network name).

2. char* password = "password"; - specific to the WiFi network we are connecting to (password).

Full code at here:

#include <LOTODA.h>
#include "DHT.h"
#include <Wire.h>

#ifdef ESP8266
  #include <ESP8266WiFi.h>
#endif

#ifdef ESP32
  #include <WiFi.h>
#endif

/**
 * AM2301 sensor parameters.
 */
#define DHTPIN 5
#define DHTTYPE DHT21  //For DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);

/**
 * WiFi parameters.
 */
const char* ssid      = "ssid";
const char* password  = "password";
WiFiClient client;

/**
 * Initialize the connection with the cloud.
 */
String useridkey    = "xxxxxxxxxx";
String passidkey  = "yyyyyyyyyyyyyyyyyyyyy";
String deviceid      = "id1001";
LOTODA lotoda = LOTODA(useridkey, passidkey, deviceid);

void setup() {
    Serial.begin(115200);
    delay(10);

    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(50);
        Serial.print(".");
    }
    Serial.println("");

    // Initialize AM2301 sensor.
    dht.begin();
    /**
     * Set the debug printer (optional).
     */
    lotoda.setDebugPrinter(&Serial);
    /**
     * Set the connect client.
     */
    lotoda.setConnectClient(&client);
}

void loop() {
    lotoda.loop();
    /**
     * Read and Send AM2301 Sensor's value.
     */
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    if (isnan(h) || isnan(t)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }
    lotoda.publishSensorJsonValueTwo("Temperature", t, "Humidity", h);
}

Add New Device in List of Devices

Page05.PNG

Now let’s move on to the interesting stuff!

After you’ve successfully logged into your account, start by creating a new device in the "List of Devices" menu. Click on "+ADD" menu, and choose "DeviceType #2".

You see that new device is added, next you click on "edit" button to in order to enter some information of this device.

Add New Device in List of Devices (cont.)

Page06.PNG

Now, at window of edit of your device, you enter some infomation of your device. Enter the Device ID (deviceid), as the example here is "id1001", you make sure to use deviceid as your coding on MCU.

And then click on Submit and OK. Done.

You just added your device with deviceid is "id1002" (replacing this different value on each your device).

Add New Widget in Dashboard

Page07.PNG

Go to "Dashboard" menu, add the widget name is "L.T.D Guage Chart" as the picture above. At this widget, you click on "Edit" icon to edit this widget.

Add New Widget in Dashboard (cont.)

Page08.PNG

At window of Widget settings of two gauge chart, you enter some information of this widget as following:

In the first guage widget:

- Title is "Temperature"

- Unit is oC

- Device ID: please choose the Device ID which you added it in List of Devices. For example is "id1001".

- JSON field is "Temperature" (like inside your code)

in the second guage widget:

- Title is "Humidity"

- Unit is %H

- Device ID: please choose the Device ID which you added it in List of Devices. For example is "id1001"

- JSON field is "Humidity" (like inside your code)

And click on Submit and OK. Done

Display Temperature and Humidity at Dashboard

Page09.PNG
photo6140702931834481810.jpg
photo6140702931834481807.jpg

The result as the picture above.

Video for Demo