The Duo is a tiny Wi-Fi and BLE hardware development kit that comes with Particle’s firmware by default. The allows us to use Particle’s development environment and enjoy its ease of use, community examples and libraries.

Requirements

Setup

1.- Connect the RedBear Duo to a PC via USB port. If you use Windows please follow the Windows Driver Installation Guide to install the driver for Duo.

2.- Install a Serial port terminal.

  • For Windows you can download PuTTy or also install HyperTerminal, Tera Term, Arduino Serial Monitor(No line ending).
  • For MAC or Linux users install “screen”, then type in your terminal the following code, where xxx is your Duo serial port:
screen /dev/ttyxxx


3.- Type “v” on the terminal to check RedBear version.

4.- Type “i” on the terminal, ReadBear will print the device ID, please copy it, you will need it to claim the device to the particle cloud.

5.- Now type “w” on the terminal to set WiFi credentials, Duo will ask your for your SSID, security type and password.

If everything is ready, Duo will leave Listening Mode and try to connect to the AP; the RGB LEG should flash green. If the Duo connects to the AP successfully, it will perform a soft reset to restart. Otherwise, the Duo will enter Listening Mode again for you to re-enter the Wi-Fi credentials.

 If you are using PuTTY or other serial terminal, when the Duo performs a reset, it disconnect from the terminal and the serial port may not be valid any more. You need to close the serial port, then press the on-board RESET button and open the serial port again to restore the communication with Duo.

Claim your RedBear Duo in Particle Cloud

  1. Go to Particle.
  2. Click on Devices -> ADD NEW DEVICE.
  3. Paste the ID that you copy in the previous step (Setup). Then click on CLAIM A DEVICE.

Now your RedBear Duo is added to the Particle Cloud.

Include Ubidots library

  1. Click on Libraries -> Community Libraries and type “Ubidots”.
  2. Click on Ubidots library.
  3. Click on INCLUDE IN APP.
  4. Select the APP and then click ADD TO THIS APP.

Now you’re ready to connect to the Ubidots cloud.

Get one value from Ubidots

To get the last value of a variable from Ubidots, go to Included Libraries and click on UBIDOTS and select UbidotsGetValue.cpp, copy it and paste to MYAPP.ino

// This example is to get the last value of variable from the Ubidots API

#include "Ubidots.h"

#define TOKEN "Your_Token_Here"  // Put here your Ubidots TOKEN
#define DATA_SOURCE_TAG "Your_Data_Source_Tag"  // Put here your data source name

Ubidots ubidots(TOKEN);

void setup() {
    Serial.begin(115200);
}
void loop() {
    float value;
    value = ubidots.getValueWithDatasource(DATA_SOURCE_TAG, "Variable_Name");
    Serial.println(value);
    delay(5000);
}

Send values to Ubidots

To send values to Ubidots, go to Included Libraries and clic on UBIDOTS and select UbidotsSendValues.cpp, copy it and paste to MYAPP.ino

The function “setDataSourceLabel” only supports alphanumeric characters and these: “.” “:” “-” “_”. If this function is not used, the library will set Particle’s Core ID as the default name.

// This example is to get the last value of variable from the Ubidots API

// This example is to save multiple variables to the Ubidots API with TCP method

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

#include "Ubidots.h"


/****************************************
 * Define Constants
 ****************************************/

#define TOKEN "Your_Token"  // Put here your Ubidots TOKEN

Ubidots ubidots(TOKEN);


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

//Put here your auxiliar functions


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

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

void loop() {
    float value1 = analogRead(A0);
    float value2 = analogRead(A1);
    float value3 = analogRead(A2);
    ubidots.add("Variable_Name_One", value1);  // Change for your variable name
    ubidots.add("Variable_Name_Two", value2);
    ubidots.add("Variable_Name_Three", value3);
    ubidots.sendAll();
    delay(5000);
}

Send GPS position

The library has a feature to add extra information inside a variable. In this example, the code will send a Temperature value with extra information: latitude and longitude.

Ubidots has a widget to display a real time position in a map. The widget looks for “lat” and “lng” keys inside the context key of the variable’s values.

To send GPS position to Ubidots, go to Included Libraries and clic on UBIDOTS and select UbidotsSendValuesWithContext.cpp, copy it and paste to MYAPP.ino

// This example is to save multiple variables with context to the Ubidots API with TCP method


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

#include "Ubidots.h"


/****************************************
 * Define Constants
 ****************************************/

#define TOKEN "Your_Token"  // Put here your Ubidots TOKEN

Ubidots ubidots(TOKEN);


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

//Put here your auxiliar functions


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

void setup() {
    Serial.begin(115200);
}
void loop() {
    float value1 = analogRead(A0);
    char context[25];
    sprintf(context, "lat=1.2343$lng=132.1233"); //Sends latitude and longitude for watching position in a map
    ubidots.add("Variable_Name_One", value1, context);  // Change for your variable name
    ubidots.sendAll();
    delay(5000);
}

Send values with timestamap

To send values with timestamp to Ubidots, go to Included Libraries and clic on UBIDOTS and select UbidotsSendValuesWithTimestamp.cpp, copy it and paste to MYAPP.ino

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

#include "Ubidots.h"


/****************************************
 * Define Constants
 ****************************************/

#define TOKEN "Your Ubidots TOKEN"  // Put here your Ubidots TOKEN

Ubidots ubidots(TOKEN);


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

//

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


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


void loop() {
    float value1 = analogRead(A0);
    unsigned long t = ubidots.ntpUnixTime(); // calculates your actual timestamp in SECONDS

    ubidots.add("test-1", value1);  // Change the first argumento for your var's label
    ubidots.add("test-2", value1, NULL, t-20000);  // Sends a value with a custom timestamp
    ubidots.add("test-3", value1);

    // Sends variables 'test-1' and 'test-2' with your actual timestamp,
    // variable 'test-2' will be send with its custom timestamp
    ubidots.sendAll(t);
    delay(5000);
}

More Library Functions

Set UDP protocol

Ubidots Particle library has a function to set transmission method of data, with this function you can change from TCP method to UDP method.

ubidots.setMethod(TYPE_UDP);

Example using setMethod Function:

// This example allow send data using UDP protocol

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

#include "Ubidots.h"


/****************************************
 * Define Constants
 ****************************************/

#define TOKEN "Your_Token_Here"  // Put here your Ubidots TOKEN


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

//Put here your auxiliar functions


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

Ubidots ubidots(TOKEN);

void setup() {
    Serial.begin(115200);
    /*
    TYPE_UDP is used to send data using UDP method
    if you don't call this function, the library automatically
    set as TCP
    */
    ubidots.setMethod(TYPE_UDP);
}
void loop() {
    float value1 = analogRead(A0);
    float value2 = analogRead(A1);
    float value3 = analogRead(A2);
    ubidots.add("Variable_Name_One", value1);  // Change for your variable name
    ubidots.add("Variable_Name_Two", value2);
    ubidots.add("Variable_Name_Three", value3);
    ubidots.sendAll();
    delay(5000);
}
Did this answer your question?