Menu Close

PUBLISH data on Ubidots using NodeMCU ESP8266

This tutorial of Robo India is a basic tutorial to connect and publish data on 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 PUBLISH  data to 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

3 . Dowload PubSubClient library

4. open arduino IDE

5.Add both libraries to IDE

6.open PUBLISH example of library

7.Add token from ubidots

8.Open ubidots create Device

add Device Name and Device Label

9. Add variables

5.coding

you may download code from here

#include "UbidotsESPMQTT.h"
#include<PubSubClient.h>
/****************************************
 * Define Constants
 ****************************************/
#define TOKEN "********" // Your Ubidots TOKEN
#define WIFINAME "******" //Your SSID
#define WIFIPASS "******" // 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);
  }

void loop() {
  // put your main code here, to run repeatedly:
  if(!client.connected()){
      client.reconnect();
      }

  // Publish values to 2 different data sources
 for(int i=0;i<50;i++)
 {
      client.add("testvalues",i); //Insert your variable Labels and the value to be sent
      client.ubidotsPublish("tutorial");
 
 
  client.loop();
  delay(20000);
  }
}

6. Output

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

Buy this kit on Amazon: 

Buy this kit on Robo India: click here

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