Skip to main content
All CollectionsUser Guides
Connect Particle Mesh devices to Ubidots
Connect Particle Mesh devices to Ubidots

Integrate Particle's Mesh devices to Ubidots using their Mesh network and cloud protocols such HTTP, TCP/UDP or Particle Webhooks

David Sepúlveda avatar
Written by David Sepúlveda
Updated over 3 months ago

"In the past, building beyond a single-point connection required high-cost hardware solutions and software implementations to connect the in-between spaces needed for device to device communication. As IoT platforms have matured, they have started to embrace a low-power, low-cost alternative that can bridge the gaps between these devices: wireless mesh networks.

Particle Mesh is a wireless mesh network technology built on Thread networking protocol, and designed to connect the spaces in between existing Wi-Fi and cellular deployments with local networks that are low-cost, secure, and ultra-reliable.

Traditional IoT devices that use Wi-Fi and cellular connectivity depend on the cloud to relay messages between devices. This works great when you’re making a standalone product – but sometimes you need more than that. Particle Mesh development kits aren’t just connected to the Internet, they’re gateways to the Internet and create a local wireless mesh that other devices can join. These devices work together to ensure that messages get where they’re going, and power products that aren’t possible or economically feasible with Wi-Fi and cellular connectivity. Particle Mesh gives every IoT device a local network to understand and connect with the world around it, ensuring products have the information they need to sound the alarm when it matters most"
                                                                                                – Quoted from Particle's blog


Following up, this article will guide you through the process of integrating Particle Mesh devices to forward data from a Particle Endpoint or Gateway, known as Xenon and Argon/Boron, respectively, to Ubidots using one of the supported IoT cloud protocols in Ubidots library for Particle, namely HTTP, TCP/UDP or Particle Webhooks.

Requirements

1. Device Setup

Step 1: Setup and claim your Particle Mesh Devices:

– Particle Argon/Boron/Xenon: claim and setup your Mesh devices.
– Quickstart guide for Mesh device: follow Particle Quickstart guides here.

Step 2: Create New App

In the Particle Build Web IDE, create a new app. For additional details in how to "Create New App," simply click here and follow the simple 3 step process.

NOTE: We titled this guide's project "Myapp". Whichever name you select, you will need to refer to the same name throughout your project. Whenever you see "Myapp," know this is a reference to your Particle IDE application. 

Step 3: Add Ubidots library to "Myapp" project:

  • Go to the Libraries option on the right side panel

  • Search "Ubidots"

  • Select Ubidots Library
    NOTE: Be aware not to choose UbidotsMQTT Library

  • Click on "INCLUDE IN PROJECT".

  • Select the project to include the library in. In this case "Myapp".

  • Click on "CONFIRM".

2. Ubidots Library: Mesh Instance and Cloud Protocol Selection.

Ubidots' library for Particle devices is a light-weight firmware that utilizes in-code Instance Declaration and Cloud Protocol Selection with standard method invoking to both wrap Particle's Mesh protocol and Send data to Ubidots using any of supported cloud protocols. 

For Example: 

Instance Declaration: This type of instance only applies for Mesh-capable devices from particle.

  • Mesh: Ubidots ubidots(UBI_TOKEN, UBI_MESH); 

Using the instance above, your device is authenticated with Ubidots cloud using the UBI_TOKEN  (TOKENS) and indicates the library your device is Mesh capable by the UBI_MESH flag.

Cloud Protocol Selection: once the Ubidots instances is declared to indicate the device is going to handle Mesh network messages, the library also requires an additional command to indicate which cloud protocol among the available, HTTP, TCP or UDP, will be used to forward data to Ubidots. 

  • HTTP: ubidots.setCloudProtocol(UBI_HTTP); 

  • TCP: ubidots.setCloudProtocol(UBI_TCP); 

  • UDP: ubidots.setCloudProtocol(UBI_UDP); 

Any of these lines should be invoked in your firmware's setup() function as follows:

void setup() {
    ubidots.setCloudProtocol(UBI_HTTP);
}

NOTE: Be aware not to use the method setCloudProtocol(iotProtocol) in Xenon devices as these do not have internet connection capabilities, only the Argon/Boron are allowed to call it.

For additional information about Ubidots library for Particle devices refer to our GitHub repository.

3. Send data to Ubidots through Mesh and HTTP, TCP or UDP.

In the below examples you'll find sample codes to integrate to Ubidots from Particle Mesh Devices through the mentioned protocols mentioned above. 

This section will be splitted in 2. First part makes reference to the code needed in the Particle Mesh gateway, that is, the Argon/Boron devices, to handle the Mesh network and forward all messages coming from the Xenon Endpoints to Ubidots using the selected cloud protocol. Secondly, we have the code necessary in the Xenon Enpoint to read an analog port and send it through the Mesh network to the gateway.

NOTE: You will need to create two separate Apps in the Particle IDE following the steps 2 and 3 in section "1. Device Setup"

A. Steps for Particle Mesh Gateways: Argon/Boron

Step 1: Copy and paste the below code in your "MyAppMeshGateways" project.
Step 2: Enter a valid TOKEN from your Ubidots account.
Step 3: Choose Protocol by comment/uncomment the appropriate method in the setup() function.
Step 4: Uncomment line 38 if you want to see debug messages on the serial monitor.
Step 5: Verify the code.
Step 6: Flash the code to your Particle gateway device.

/****************************************
 * Include Libraries
 ****************************************/

#include "Ubidots.h"

/****************************************
 * Define Instances and Constants
 ****************************************/

#ifndef UBIDOTS_TOKEN
#define UBIDOTS_TOKEN "....." //Put here your Ubidots TOKEN
#endif

Ubidots ubidots(UBIDOTS_TOKEN, UBI_INDUSTRIAL, UBI_MESH);

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

// Put here your auxiliar functions

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

void setup() {
  Serial.begin(115200);
  /*
    Uncomment ONE of the following lines to choose a different cloud Protocol to send data
    [DEFAULT] = UBI_TCP
  */
  // ubidots.setCloudProtocol(UBI_HTTP);
  // ubidots.setCloudProtocol(UBI_TCP);
  // ubidots.setCloudProtocol(UBI_UDP);

  // Uncomment this line for printing debug messages
  // ubidots.setDebug(true);
}

void loop() {
    ubidots.meshLoop();
}


B. Steps for Particle Mesh Endpoints: Xenon

Step 1: Copy and paste the below code in your "MyAppMeshEndpoints" project.
Step 2: Enter a valid TOKEN from your Ubidots account, and a VARIABLE_LABEL.
Step 3: Uncomment line 30 if you want to see debug messages on the serial monitor.
Step 4: Verify the code.
Step 5: Flash the code to your Particle endpoint device.
Step 6: Check your Ubidots account.

/****************************************
 * Include Libraries
 ****************************************/

#include "Ubidots.h"

/****************************************
 * Define Instances and Constants
 ****************************************/

#ifndef UBIDOTS_TOKEN
#define UBIDOTS_TOKEN "...."  // Put here your Ubidots TOKEN
#define VARIABLE_LABEL "...." // Put here your Ubidots VARIABLE LABEL
#endif

Ubidots ubidots(UBIDOTS_TOKEN, UBI_INDUSTRIAL, UBI_MESH);

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

// Put here your auxiliar functions

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

void setup() {
  Serial.begin(115200);
  // ubidots.setDebug(true);  // Uncomment this line for printing debug messages
}

void loop() {
  float value = analogRead(A0);
  Serial.println("Adding value");
  ubidots.add(VARIABLE_LABEL, value);
  ubidots.meshPublishToUbidots();
  Serial.println("finished");
  delay(5000);
}

4. Send data to Ubidots through Mesh and Particle Webhooks.

Using Particle Webhooks to forward data from your Xenon endpoints to Ubidots, first passing through a Mesh gateways as the Argon or Boron, requires to create a webhook on your particle console. Follow the bellow step to do so:

Step 1: Go to your Particle account, login and create a "New Integration"
Step 2: Go to your particle console and choose Integrations.
Step 3: Select "New Integration"
Step 4:
Select "Webhook"
Step 5: Name
the new Webhook
Step 6: Add the sample URL below
Webhook URL:

https://industrial.api.ubidots.com/api/v1.6/devices/{{{PARTICLE_DEVICE_ID}}}

IMPORTANT NOTE: We're going to automatically call and assign the Device ID of the Particle Device to ensure the device label in Ubidots remains unique. To do this we're going to use the pre-defined key available from Particle:{{{PARTICLE_DEVICE_ID}}} This call will automatically assign to the URL the ID of the device which triggered the webhook.

Step 7: Select "POST" Method
Step 8: Select "Custom Body" Request Format
Step 9: Make the Webhook available to ALL the devices from your account by choosing "Any"

Step 10: Select ADVANCED SETTING

  • Complete the text editor with as below:

{{{PARTICLE_EVENT_VALUE}}}
  • In the HTTP Headers options of the settings, complete as seen below:

X-Auth-Token | YOUR_UBIDOTS_TOKEN_HERE
Content-Type | application/json

To find your Ubidots TOKEN refer here.

Step 11: CREATE WEBHOOK and verify data is being streamed to Ubidots.


After creating Particle Webhooks in your console, then here's the coding portion of this section. Follow the two sets of code steps below: one for the gatewats and the second for the endpoint:

A. Steps for Particle Mesh Gateways: Argon/Boron

Step 1: Copy and paste the below code in your "MyAppMeshGateways" project.
Step 2: Enter a valid TOKEN from your Ubidots account.
Step 3: Choose Protocol by comment/uncomment the appropriate method in the setup() function.
Step 4: Uncomment line 38 if you want to see debug messages on the serial monitor.
Step 5: Verify the code.
Step 6: Flash the code to your Particle gateway device.

/****************************************
 * Include Libraries
 ****************************************/

#include "Ubidots.h"

/****************************************
 * Define Instances and Constants
 ****************************************/

#ifndef UBIDOTS_TOKEN
#define UBIDOTS_TOKEN "....." //Put here your Ubidots TOKEN
#endif

Ubidots ubidots(UBIDOTS_TOKEN, UBI_INDUSTRIAL, UBI_MESH);

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

// Put here your auxiliar functions

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

void setup() {
  Serial.begin(115200);

  ubidots.setCloudProtocol(UBI_PARTICLE);

  // Uncomment this line for printing debug messages
  // ubidots.setDebug(true);
}

void loop() {
    ubidots.meshLoop();
}


B. Steps for Particle Mesh Endpoints: Xenon

Step 1: Copy and paste the below code in your "MyAppMeshEndpoints" project.
Step 2: Enter a valid TOKEN from your Ubidots account.
Step 3: Uncomment line 30 if you want to see debug messages on the serial monitor.
Step 4: Make sure the line ubidots.meshPublishToUbidots("Ubidots"); input your Webhook name. In our case is "Ubidots"
Step 5: Verify the code.
Step 6: Flash the code to your Particle endpoint device.
Step 7: Check your Ubidots account.

/****************************************
 * Include Libraries
 ****************************************/

#include "Ubidots.h"

/****************************************
 * Define Instances and Constants
 ****************************************/

#ifndef UBIDOTS_TOKEN
#define UBIDOTS_TOKEN "...."  // Put here your Ubidots TOKEN
#define VARIABLE_LABEL "...." // Put here your Ubidots VARIABLE LABEL
#endif

Ubidots ubidots(UBIDOTS_TOKEN, UBI_INDUSTRIAL, UBI_MESH);

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

// Put here your auxiliar functions

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

void setup() {
  Serial.begin(115200);
  // ubidots.setDebug(true);  // Uncomment this line for printing debug messages
}

void loop() {
  float value = analogRead(A0);
  Serial.println("Adding value");
  ubidots.add(VARIABLE_LABEL, value);
  ubidots.meshPublishToUbidots("Ubidots");
  Serial.println("finished");
  delay(5000);
}


Other users also found helpful: 

Did this answer your question?