Introduction

We will use MQTT protocol to send and get data from NodeMCU ,Browser or Mobile APP will send control signal to DHT11 sensor and monitor humidity and temperature through Internet.When the MQTT Dashboard sends a D command, the monitor window shows the temperature and humidity.

Hardware:

Software:

NodeMCU DHT11 sensor
3.3v VCC
D3 DATA
GND Ground

Upload Sketch

Upload Sketch

Connect the NodeMCU to computer via USB cable,open Node_mcu_dht11by using Arduino IDE(Version1.6.4+):

Edit the code to fit your own WiFi and MQTT settings as following operations:

1)Hotspot Configration:

const char* ssid = “your_hotspot_ssid”;

const char* password = “your_hotspot_password”;

Find above code line,put your own ssid and password on there.

2)MQTT  Server  Address Setting

const char* mqtt_server = “broker.mqtt-dashboard.com”;

You can use your own MQTT broker URL or IP address to set above mqtt_server value. You can also use some famous free MQTT server to test the project such as  “broker.mqtt-dashboard.com”,  “iot.eclipse.org” etc.

3)MQTT Client Settings

If your MQTT broker require clientID,username and password authentication,you need to change

if (client.connect(clientId.c_str()))

to

if (client.connect(clientId,userName,passWord)) //put your clientId/userName/passWord here

If not,just keep them as default.

After do that,choose the coresponding board type and port type as below,then upload the sketch to the NodeMCU.

MQTT Client Settings

About how to config the MQTT client,check this link.

Topics Settings:

Sketch Running Result

Once the upload is successful, open monitor window and you will see the result

DHT11 sensor shows temperature and humidity

Remote MQTT Client Settings

command message to publish

Result

D

When NodeMCU receives message “D”, it will show humidity and temperature

0 or other character

When NodeMCU receives message “0”,pelese print S in your phone for bmp180

If you send a D command on the MQTT Dashboard, the serial port will show temperature and humidity. Sending 0 or other characters will prompt you to enter D.

or directly Download the app from IOT MQTT Dashboard Android APP

Client Id should be anything which is not blank,
Server must be same as mqtt_server variable value in code
port must be 1883
After completes the required fields, click “CREATE” button

firendly name should be anything which is not blank,

Topic fills in the dht11 already defined in the code

After completes the required fields, click “CREATE” button

Running Result

When the D command is entered on the PUBLISH interface of the mobile phone’s MQTT Dashboard

In monitor window, you will see the following result

When you enter characters other than D on the MQTT Dashboard.

The following results are displayed in the monitor window.