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.
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.
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.
Ubidots(char* token, UbiServer server, IotProtocol iot_protocol)
UBI_INDUSTRIAL
], [Default] = UBI_INDUSTRIAL
. UBI_HTTP
, UBI_TCP
, UBI_UDP
, UBI_PARTICLE
], [Default] = UBI_TCP
. The IoT protocol that you will use to send or retrieve data.Creates an Ubidots instance.
NOTES
UBI_PARTICLE
sends data using webhooks, so make sure to follow the instructions to set up your webhook properly here.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);
PUBLIC
, PRIVATE
, WITH_ACK
, NO_ACK
]. Particle webhook 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.
Refer to the examples folder