Skip to main content
All CollectionsConnect your Devices
Connect a LinkIt Smart 7688 Duo to Ubidots over MQTT
Connect a LinkIt Smart 7688 Duo to Ubidots over MQTT

Learn to setup and connect the LinkIt Smart 7688 board with Ubidots over MQTT.

Sergio M avatar
Written by Sergio M
Updated over a week ago

The LinkIt Smart 7688 Duo is an open development board based on MT7688 and ATmega32u4. This board is compatible with YUN sketches, Smart Duo has an OpenWrt Linux distribution. The hardware comes pre-installed with many software packages for IoT devices, including support for Python, Node.js and C language.

By following this guide you will be able to publish & subscribe data to/from Ubidots using LinkIt Smart 7688 Duo in just a couple of minutes.

Requirements

Step-by-Step

  1. Hardware/System Setup

  2. Send (PUBLISH) Data to Ubidots

  3. Receive (SUBSCRIBE) Data from Ubidots

  4. Summary

1. Hardware/System Setup 

This guide is uses the Windows OS, if your working with MAC or Linex, please go to this link to find the hardware and system step that matches your OS.

1. Download and install PuTTY

2. To be able to establish the communication with the board using your computer you will need to install the drivers required. Please, refer this page to download the drivers based on your preferred OS.

If you are having problems with the latest driver, try installing an older version here.

3. Will all the drivers downloaded, install them by clicking the installer downloaded with the drivers. 

4. Establish the connection with the board by connecting the USB to TTL adapter with the LinkIt Smart board following the table below. 

5.  After establish the connection, connect the USB port to your computer. Then, open the device manager of your Windows computer and notice the COM port assigned. The port number may vary on different computers with multiple ports.

6. Launch the PuTTY terminal and enter the COM port number of the USB device found in the device manager. Then, click on the Serial radio button and type 57600 in Speed field. To finish, press "Open"

7. Now you are able to access to the LinkIt Smart using serial communication. 

With the Putty console terminal already open and having access to the LinkIt Board, it's now time to set up the system to create the scripts which are going to be in charge of the publish and subscribe requests to/from Ubidots.

8. Run the commands below in the Putty console terminal. 

opkg update
opkg install node
npm install mqtt --save


IMPORTANT NOTE:
If you have any trouble following the steps above, please refer to this guide for additional details for each step across different OS.

2. Send (PUBLISH) Data to Ubidots 

1. Create and run a JS script in the putty console terminal. To create the script, write the following command:

nano ubidots_publish.js

2. Then, in the new editor window paste the code below and assign your Ubidots TOKEN where is indicated. 

const mqtt = require("mqtt");

const TOKEN = "xxxxxxxxxxxx";
const DEVICE_LABEL = "my-new-device";
const BROKER = 'mqtt://industrial.api.ubidots.com';
const TOPIC = `/v1.6/devices/${DEVICE_LABEL}`;

let payload = {"my-sensor": 71};
payload = JSON.stringify(payload);

var client  = mqtt.connect(BROKER, {username: TOKEN, password:""});
client.publish(TOPIC, payload, {'qos': 1, 'retain': true},
    function (error, response) {
        console.log(response);
    });

To finish, save the changes just made. 

3. Run the script by running the command below:

node ubidots_publish.js

At this point you should be able to see data published in your Ubidots account inside a device called "my-new-device".

3. Receive (SUBSCRIBE) Data from Ubidots

1. Create and run a JS script in the putty console terminal. To create the script, write the following command:

nano ubidots_subscribe.js

2. Then, in the new editor window, paste the code below. Once you have pasted the code, be sure to assign the following parameters:

const mqtt = require("mqtt");

const TOKEN = "xxxxxxxxxxxx";
const DEVICE_LABEL = "my-new-device";
const VARIABLE_LABEL = "my-sensor";
const BROKER = 'mqtt://industrial.api.ubidots.com';

var client  = mqtt.connect(BROKER, {username: TOKEN, password:""});
client.subscribe({"/v1.6/devices/my-new-device/my-sensor/lv": 1}, function(err, granted) {
    console.log(granted);
});

client.on('message', function(topic, message, packet) {
    //here you can process updates from the broker
});

To finish, save the changes just made. 

3. Run the script by running the command below:

node ubidots_subscribe.js

At this point, you will be able to see in the Putty console terminal the the last value of the variable specified in the code that was received in Ubidots

4. Summary

With this simple tutorial you are able to PUBLISH & SUBSCRIBE data to/from Ubidots with the ease of the LinkIt Smart 7688 Duo. If your desire handle more information like context or timestamp to your request refer to the Ubidots MQTT API Reference.

Now its time to create Ubidots Dashboards to visualize your data and deploy your IoT solution!  Happy Hacking! :) 

Other readers have also found useful...

Did this answer your question?