ubidots / ubidots-particle

Library for uploading Particle devices to Ubidots
MIT License
10 stars 19 forks source link
mqtt particle tcp ubidots udp

Particle

Here you will learn how to send data to Ubidots using Particle Photon or Electron devices. You just need the variable label and value that you want to send along with an Ubidots valid TOKEN. In addition you're able to get the last value of a variable from your Ubidots account.

Requirements

Setup

  1. Set up WiFi connection to the photon. There are two ways to do this:
  2. After claiming your Photon and setting up your Ubidots account, let's go to Particle's Web IDE.
    • In the Particle's Web IDE create a new app and set the name.
    • Go to the library tab.
    • In contributed library write Ubidots and select the Ubidots library.
    • Click on INCLUDE IN APP. And return to "MYAPP.ino"

This library creates by default new Data Source. The name of this data source will be "Particle" by default, and his label will be you Particle ID.

The default method is TCP, if you want to change it go to the features sections and follow the example.

Warning: About Particle Mesh

After the announcement of the deprecation of the Particle Mesh IoT protocol, as Particle is no longer producing Mesh units, Ubidots has decided to stop to support it out of the box in this library. If you need to still use the Mesh IoT protocol in your project in conjunction with our library, please compile your project through the Particle CLI with the version v3.1.4 of this library.

Documentation

Constructor

Ubidots

Ubidots(char* token, UbiServer server, IotProtocol iot_protocol)

Creates an Ubidots instance.

NOTES

Methods

void add(char *variable_label, float value, char *context, unsigned long dot_timestamp_seconds, unsigned int dot_timestamp_millis)

Adds a dot with its related value, context and timestamp to be sent to a certain data source, once you use add().

Important: The max payload lenght is 700 bytes, if your payload is greater it won't be properly sent. You can see on your serial console the payload to send if you call the setDebug(bool debug) method and pass a true value to it.

float get(const char* device_label, const char* variable_label)

Returns as float the last value of the dot from the variable. IotProtocol getCloudProtocol()

std::map<int, float> tcpMap getMultipleValues(const char* deviceLabel, const char* variableLabels)

Returns an ordered map list with the values retrieved for the provided variable labels. The values can be accesed by index, starting at position 0, and are mapped to every variable label set in the comma separated array.

void addContext(char *key_label, char *key_value)

Adds to local memory a new key-value context key. The method inputs must be char pointers. The method allows to store up to 10 key-value pairs.

void getContext(char *context)

Builds the context according to the chosen protocol and stores it in the context char pointer.

void setDebug(bool debug);;

Make available debug messages through the serial port.

bool send(const char* device_label, const char* device_name, PublishFlags flags);

Sends all the data added using the add() method. Returns true if the data was sent.

IotProtocol getCloudProtocol();

Retrieves the actual cloud protocol used to send data from the Mesh gateway.

Examples

Refer to the examples folder