Skip to content

allthingstalk/arduino-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Version v1.1

What's new?

  • Support for Binary payloads using our ABCL language
  • Support for CBOR messages
  • NodeMCU WiFi example (for both sensing and actuation)
  • Linkit One examples (basic and GPS example)
  • Option to set device credentials globally or locally

Hardware

This SDK is for Arduino and Arduino compatible boards, such as

  • Arduino Leonardo
  • Arduino Ethernet
  • LinkitOne http://download.labs.mediatek.com/package_mtk_linkit_index.json
  • NodeMCU http://arduino.esp8266.com/stable/package_esp8266com_index.json

Installation

Download the source code and unzip and copy the content to your arduino libraries folder (usually found at /libraries) or import the library folders directly using the Arduino IDE under Sketch > Include Library > Add .ZIP library (repeat this step for each of the libraries: ATT_IOT, pubsubclient and ArduinoJson)

Device credentials

You can either set them globally, using the same credentials for all sketches using the sdk.
Or you can set them locally in a specific sketch, overriding the global settings.

You can find these credentials under your device at AllThingsTalk in the SETTINGS > Authentication tab.

Depending on how you initialize the device object in your sketch, the global or local credentials will be used.

  • ATT_IOT device("your_device_id", "your_device_token"); will use the provided local credentials.
  • ATT_IOT device; will use the global credentials from the keys.h file

Open the keys.h file on your computer and enter your deviceid and devicetoken.

/****
 * Enter your AllThingsTalk device credentials below
 */
#ifndef KEYS_h
#define KEYS_h

const char* DEVICE_ID = "your_device_id";
const char* DEVICE_TOKEN = "your_device_token";

#endif

Payloads and sending data

There are three ways to send your data to AllThingsTalk

  • Standard json
  • Cbor payload
  • Binary payload

Standard json will send a single datapoint to a single asset. Both Cbor and Binary allow you to construct your own payload. The former is slightly larger in size, the latter requires a small decoding file (example) on the receiving end.

Single asset

Send a single datapoint to a single asset using the send(value, asset) functions. Value can be any primitive type integer, float, boolean or String. For example

ATT_IOT device;
  device.send(String(25), "counter");

Cbor

ATT_IOT device;
CborBuilder payload(device);  // Construct a payload object
  payload.reset();
  payload.map(1);  // Set number of datapoints in payload
  payload.addInteger(25, "counter");
  payload.send();

Binary payload

Using the AllThingsTalk ABCL language, you can send a binary string containing datapoints of multiple assets in a single message. The example below shows how you can easily construct and send your own custom payload.

Make sure you set the correct decoding file at AllThingsTalk. Please check our documentation and the included experiments for examples.

ATT_IOT device;
PayloadBuilder payload(device);  // Construct a payload object
  payload.reset();
  payload.addInteger(25);
  payload.addNumber(false);
  payload.addNumber(3.1415926);
  payload.send();

Examples

All examples can be found in the arduino-sdk/libraries/ATT_IOT/examples/ folder.
Please note the minor board specific settings below.

Arduino Ethernet / Leonardo

Depending on the board, make sure you use the correct Ethernet library in your sketch.

  • Arduino Ethernet #include <Ethernet.h>
  • Arduino Leonardo #include <Ethernet2.h>

NodeMCU

The example will show you how to send data from the NodeMCU to AllThingsTalk as well as the other way around, actuating the onboard LED from the cloud.

Make sure you fill in your network credentials in the setup() method of the sketch

// Enter your WiFi credentials here!
setupWiFi("your_wifi_ssid", "your_wifi_password");
//

Linkit One

In the ATT_IOT.h file, comment the following line // #include <EthernetClient.h>

Newer versions of the Arduino IDE may conflict with the Linkit One. Arduino IDE version 1.6.5 is tested and will work with the provided examples.