Dragino is an IoT device with embed Linux. It is a low cost, open hardware Linux motherboard for micro-controllers. It has USB host port and has full Ethernet and 802.11 b/g/n WiFi capabilities.

Requirements

Dragino modules are the same as Arduino YÚN, so we’ll use the same Yun library for them

Use the Arduino 1.6.5 version or newer with the Dragino.

Setup

1.- Connect your Dragino to the power supply, be careful to use the correct DC adaptor of Dragino.

2.- Check for an unsecure wifi network starting with “Dragino”.

3.- Connect to this network and enter 192.168.240.1 into a web broswer to see the configuration page of the Dragino. The default password is “arduino”

4.- Once you’re connected click on “system”

5.- Specify the Wireless Parameters of your Wi-Fi connection, then press “configure & restart”. This may take several minutes.

6.- Download the UbidotsYUN library here

7.- Go to the Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library

8.- Select the .ZIP file of UbidotsYUN and then “Accept” or “Choose”

9.- Close the Arduino IDE and open it again.

 This library creates a Ubidots Data Source named YUN when you send variables. There the library will save your variables.

Send values to Ubidots

To send multiple values you can use our example in our library or copy the next code and do not forget to change set there your TOKEN

// This example is to save a variable to the Ubidots API

/****************************************
 * Include Libraries
 ****************************************/
#include <UbidotsYUN.h>

/****************************************
 * Define Constants
 ****************************************/
#define TOKEN "YOUR_TOKEN_HERE"
#define VARIABLE_LABEL "temperature"  // Change for your variable label desired

Ubidots client(TOKEN);

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

//Put here your auxiliar functions

/****************************************
 * Main Functions
 ****************************************/
void setup() {
  client.init();
  Serial.begin(9600);
}

void loop() {
  float value = analogRead(A0);
  client.add(VARIABLE_LABEL, value); // Change for your variable name
  client.sendAll();
  delay(1000);
}

Get one value from Ubidots

To get the last value of a variable from Ubidots, go to Sketch -> Examples -> UbidotsYUN library and select the “UbidotsGetValue” example.

// This example is to obtain a variable value from Ubidots

/****************************************
 * Include Libraries
 ****************************************/
#include <UbidotsYUN.h>

/****************************************
 * Define Constants
 ****************************************/
#define TOKEN "YOUR_TOKEN_HERE"
#define DEVICE_LABEL "yun" // Assign the device label where the variable desired is located
#define VARIABLE_LABEL "temperature" // Assign the variable label desired to obtain data

Ubidots client(TOKEN);

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

//Put here your auxiliar functions

/****************************************
 * Main Functions
 ****************************************/
void setup() {
  client.init();
  Serial.begin(9600);
}

void loop() {
  float value = client.getValue(DEVICE_LABEL, VARIABLE_LABEL);
  Serial.print("the value obtained is: ");
  Serial.println(value);
  /* Print value with 5 decimal points precision */
  //Serial.println(value, 5);
  delay(5000);
}

Send a value with latitude and longitude

// This example is to save a variable with context to the Ubidots API

/****************************************
 * Include Libraries
 ****************************************/
#include <UbidotsYUN.h>

/****************************************
 * Define Constants
 ****************************************/
#define TOKEN "YOUR_TOKEN_HERE"
#define VARIABLE_LABEL "position"  // Change for your variable label desired

char str_lat[15];
char str_lng[15];

Ubidots client(TOKEN);

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

//Put here your auxiliar functions

/****************************************
 * Main Functions
 ****************************************/
void setup() {
  client.init();
  Serial.begin(9600);
}

void loop() {
 
  char context[50];
 
  float lat = 25.761681; // Assign the Latitude desired
  float lng = -80.191788; // Assign the Longitude desired
 
  /* float value is copied onto str_lat/str_lng */
  dtostrf(lat, 4, 6, str_lat);
  dtostrf(lng, 4, 6, str_lng);
 
  /* Build the coordinates context to be sent*/
  sprintf(context, "lat=%s\\$lng=%s", str_lat, str_lng);
  /* Send variable with coordinates context to Ubidots*/
  client.add(VARIABLE_LABEL, 1, context);
  client.sendAll();
  delay(1000);
}

The library has a feature to add extra information inside of a variable. In the next example, the code will send a Temperature value and inside of the variable will be saved an extra information: latitude and longitude.

Ubidots has a widget to show the position in a map. To show the position this widget need to receive the latitude and longitude in a specific format. The format is “lat” for latitude and “lng” for longitude.

Did this answer your question?