Adafruit CC3000 WiFi shield has a built in TCP/IP stack that allows it to communicate with external servers like Ubidots. Here you will learn how to send multiple variables to the Ubidots API and how to get the last value of Ubidots variable.

First of all follow this adafruit guide to assembly the CC3000 shield adafruit guide to assembly the CC3000 shield

Requirements

Please use Arduino IDE version 1.6.4 or higher.

Make sure your Arduino is powered by a 1 amp or higher rated external power supply when using with the CC3000! Powering an Arduino + CC3000 from a computer/laptop USB port will lead to unstable behavior and lockups because the USB port can’t supply enough power!

Setup

  1. Download the Adafruit_CC3000 library here.
  2. Download the UbidotsCC3000 library here
  3. Go to the Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library
  4. Select the .ZIP file of Ubidots_FONA and then “Accept” or “Choose”
  5. Do the same to add the Adafruit_FONA library.
  6. Close the Arduino IDE and open it again.

To use this library, put your Ubidots token and variable ID where indicated, as well as the WiFi settings. After uploading each example to your Arduino, open the Serial monitor to check the results. If no response is seen, try unplugging your Arduino and then plugging it again. Make sure the baud rate of the Serial monitor is set to the same one specified in your code.

Send values to Ubidots

To send multiple values to Ubidots, go to Sketch -> Examples -> Ubidots CC3000 library and select the “saveValues” example.

#include <UbidotsCC3000.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
//#include "utility/debug.h"  // Uncomment this line to set DEBUG on

#define WLAN_SSID       "OpenWRT"  // Your WiFi SSID, cannot be longer than 32 characters!
#define WLAN_PASS       "Your_pass_here"  // Replace it with your WiFi pass
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define TOKEN "Your_token_here"  // Replace it with your Ubidots token
#define VARLABEL_1 "Your_variable_label_here" // Replace it with your Ubidots' variable label
#define VARLABEL_2 "Your_variable_label_here" // Replace it with your Ubidots' variable label
#define VARLABEL_3 "Your_variable_label_here" // Replace it with your Ubidots' variable label

Ubidots client(TOKEN);

void setup() {
  Serial.begin(115200);
  client.initialize();
  client.wifiConnection(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);

}

void loop() {
  float value = analogRead(A0);
  float value2 = analogRead(A1);
  float value3 = analogRead(A2);
  client.add(VARLABEL_1,value);
  client.add(VARLABEL_2,value2);
  client.add(VARLABEL_3,value3);
  client.sendAll();
}

Get one value from Ubidots

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

#include <UbidotsCC3000.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
//#include "utility/debug.h"  // Uncomment this line to set DEBUG on

#define WLAN_SSID       "OpenWRT"  // Your WiFi SSID, cannot be longer than 32 characters!
#define WLAN_PASS       "Your_pass_here"  // Replace it with your WiFi pass
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define TOKEN "Your_token_here"  // Replace it with your Ubidots token
#define VARLABEL "Your_variable_label_here" // Replace it with your Ubidots' variable label

Ubidots client(TOKEN);

void setup() {
  Serial.begin(115200);
  client.initialize();
  client.wifiConnection(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);

}

void loop() {
  float value = client.getValue(VARLABEL);
}
Did this answer your question?