Dragino is an IoT device with embed Linux. It is a low cost, open hardware Linux motherboard for micro-controllers with full Ethernet and 802.11 b/g/n WiFi capabilities.
Requirements
Step-by-Step
Setting up the Dragino
Setting up the Arduino IDE
Sending (POST) Data to Ubidots
Receiving (GET) Data from Ubidots
Summary
1. Setting up the Dragino
1. Connect your Dragino to the power supply, be careful to use the correct DC adaptor of Dragino.
2. Using your computer, scan for the unsecure Arduino-Yun wifi network to begin setting up the “Dragino”.
3. Connect to the free network and open a new web browser. In the browser, enter 192.168.240.1
into URL bar. This command will open the configuration page of the Dragino. The default password for the Dragino device is “arduino”.
4. Once connected to the device via the web browser, click on “system”
5. Specify the Wireless Parameters of your secure Wi-Fi connection, then press “configure & restart”. This may take several minutes to complete, please be patient.
2. Setting up the Arduino IDE
Dragino modules are the same as Arduino YÚN, so we’ll use the same Ubidots Arduino Yun library when working with the Dragino.
1. Download the Ubidots Arduino YUN Library and install it using the Arduino IDE. For a detailed explanation of how to install libraries using the Arduino IDE, please refer to this guide
3. Sending (POST) Data to Ubidots
With the following sample code you will be able to post the ANALOG readings taken from Dragino analog port A0.
1. To post your first dot to Ubidots from the Dragino, open the Arduino IDE and paste the sample code below. Once you have pasted the code, you will need to assign your unique Ubidots TOKEN where indicated in the sample code.
// 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);
}
2. Verify your code within the Arduino IDE. To do this, in the top left corner of our Arduino IDE you will see the "Check Mark" icon; press it to verify your code.
3. Upload the code into your Dragrino. To do this, choose the "right-arrow" icon beside the "check mark" icon.
4. To verify the connectivity of the device and that data is being sent, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to see the connectivity logs.
5. Confirm your data in Ubidots. Return to your Ubidots account to see the posted data in your Ubidots account, automatically having created a new device, called "yun" and any variables sent via the device's code.
If you desire to assign a different device name or label to your device, you can adjust them directly in setup
of your code in the following lines:
To change the Device Name:
client.setDeviceName("New_name");
To change the Device label:
client.setDeviceLabel("New_label");
4. Receiving (GET) Data from Ubidots
With the following sample code you will be able to get a value from Ubidots to start controlling any asset you desire with your hardware.
1. To begin getting values from Ubidots, open the Arduino IDE and paste the sample code below. Once you have pasted the code, be sure to assign the following parameters:
Device Label of the device containing the variable you want to GET.
Variable Label of the variable you want to GET.
// 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 "device_label_here" // Assign the device containing the variable you want to GET
#define VARIABLE_LABEL "variable_label_here" // Assign the variable you want to GET
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);
}
2. Verify & Upload the code into the board following the same steps provided in the POST step above.
3. To verify the connectivity of the device and that the data is being received, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to see the connectivity logs.
4. In the Serial Monitor, you will see the last value received in Ubidots of the variable specified in the programming code used in the device.
5. Summary
With this simple tutorial you are able to POST & GET data to/from Ubidots with the ease of the Arduino IDE and a Dragino. If your wish to find more examples to handle context or timestamp values in your request checkout Ubidots documentation with the Arduino YUN library used by clicking here.
Now its time to create Ubidots Dashboards to visualize your data and deploy your IoT solution! Happy Hacking! :)
Other readers have also found useful...