ESP8266 programming for Cloud MQTT using Pubsubclient- Part 3

In this tutorial, I will walk you through the process of installing Pubsubclient library for ESP8266, and help you understand a simple program for sending data to cloud MQTT.

Please read my tutorial series on IOT.

If you are new to MQTT, then I recommend, you read this article first.

So lets get started.

You can download the complete project from my github.

Donwload

Part 1: Cloud MQTT

1. Create a Free Cloud MQTT account.

2. After going through the registration procedures, you need to create the cloud MQTT instance.

3. You will be presented with the following screen. Note down the highlighted.

4

Part 2: Arduino IDE

Here is a simple ESP8266 Program that uploads random numbers to the server. It also blinks the ESP blue LED, when it receives a -1 message.

1. Open the arduino IDE and copy paste the code.

Make sure to replace the data variables with your data.

2. You have to import the Pubsubclient Library for ESP8266. By default Arduino IDE has the Pubsubclient for Arduino Ethernet Shield. But this doesn’t work with ESP8266.

Download the pubsubclient files from here.

Copy paste the files from Pubsubclient folder into the Arduino’s library folder, like shown below.

5

Open up the serial monitor.

Upload the code onto ESP8266.

You can now see the logs, for the Wifi connection, MQTT connection and Temperature sensor values.

You can view the data online using the WebSocket console.

You can also send “-1” from the websocket console, to see the LED blinking.

In the next article, I will be discussing about the MQTT Ionic App, I build to monitor the data.

Please read my tutorial series on IOT.