Menu Close

SUBSCRIBE data from Ubidots using NodeMCU ESP8266

This tutorial of Robo India is a basic tutorial to connect and subscribe data from Ubidots Application using NodeMCU ESP8266 to Development Platform over MQTT.

1. Introduction

This tutorial explains how to connect a NodeMCU wifi development board to the MQTT. By following this guide you will be able to SUBSCRIBE  data from Ubidots using the NodeMCU ESP8266 module.

2. Hardware required

S.No.ItemQuantity
1NodeMCU 1
2Breadboard 1
3 Micro USB 1

3.Circuit

4.Software Setup:

steps for software setup

1.Signup on ubidots

2.Download ubidotsMQTTESP library -1

3.Dowload PubSubClient library-2

4.open arduino IDE

5.Add both libraries to IDE

6.open SUBSCRIBE example of library

7.Add token from ubidots

8.Open ubidots create Device and add Variables.

click on add button to create device and choose blank.

click on device when device is created ,add click on add new widget, choose slider.

Open dashboard click on slider.

1:-click on add variable.

2:-choose the device you created.

3:- choose the widget you want to add on your slider.

Now if you change the values on this slider you will get the same change in output monitor.

How to get ubidots token?->click on your profile in the right corner:->click on API Credentials.

Copy your token from here.

5.coding

you may download code from here

/****************************************
 * Include Libraries
 ****************************************/
#include “UbidotsESPMQTT.h”
#include <PubSubClient.h>

/****************************************
 * Define Constants
 ****************************************/
#define TOKEN “A1E-DEb67qiQPtT7MHMMM**********P” // Your Ubidots TOKEN
#define WIFINAME “RoboIn*****” //Your SSID
#define WIFIPASS “786#****” // Your Wifi Pass

Ubidots client(TOKEN);

/****************************************
 * Auxiliar Functions
 ****************************************/

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print(“Message arrived [“);
  Serial.print(topic);
  Serial.print(“] “);
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

/****************************************
 * Main Functions
 ****************************************/

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  client.setDebug(true); // Pass a true or false bool value to activate debug messages
  client.wifiConnection(WIFINAME, WIFIPASS);
  client.begin(callback);
  client.ubidotsSubscribe(“esp8266-1″,”temperature”); //Insert the dataSource and Variable’s Labels
  }

void loop() {
  // put your main code here, to run repeatedly:
  if(!client.connected()){
      client.reconnect();
      client.ubidotsSubscribe(“esp8266-1″,”temperature”); //Insert the dataSource and Variable’s Labels
      }
  client.loop();
  }

6. Output

After successful uploading of the code, output will display on the ubidots Devices

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply