#include <src/publishers/UbidotsPublisher.h>
UbidotsPublisher
class
The UbidotsPublisher subclass of dataPublisher for publishing data to the Ubidots data portal at https:/
Base classes
- class dataPublisher
- The dataPublisher class is a virtual class used by other publishers to distribute data online.
Constructors, destructors, conversion operators
- UbidotsPublisher()
- Construct a new Ubidots Publisher object with no members set.
- UbidotsPublisher(Logger& baseLogger, uint8_t sendEveryX = 1, uint8_t sendOffset = 0) explicit
- Construct a new Ubidots Publisher object.
- UbidotsPublisher(Logger& baseLogger, Client* inClient, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
- Construct a new Ubidots Publisher object.
- UbidotsPublisher(Logger& baseLogger, const char* authentificationToken, const char* deviceID, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
- Construct a new Ubidots Publisher object.
- UbidotsPublisher(Logger& baseLogger, Client* inClient, const char* authentificationToken, const char* deviceID, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
- Construct a new Ubidots Publisher object.
- ~UbidotsPublisher() virtual
- Destroy the EnviroDIY Publisher object.
Public functions
- String getEndpoint(void ) override
- Get the destination for published data - generally the host name of the data receiver.
- void setToken(const char* authentificationToken)
- Set the device authentication token.
- uint16_t calculateJsonSize()
- Calculates how long the outgoing JSON will be.
- void printSensorDataJSON(Stream* stream)
- This generates a properly formatted JSON for Ubidots and prints it to the input Arduino stream object.
- void printUbidotsRequest(Stream* stream)
- This prints a fully structured post request for the Ubidots API to the specified stream.
- void begin(Logger& baseLogger, Client* inClient, const char* authentificationToken, const char* deviceID)
- Begin the publisher - linking it to the client and logger.
- void begin(Logger& baseLogger, const char* authentificationToken, const char* deviceID)
- Begin the publisher - linking it to the logger but not attaching a client.
- int16_t publishData(Client* outClient) override
- Utilize an attached modem to open a a TCP connection to the Ubidots API and then stream out a post request over that connection.
Portions of the POST request to Ubidots
- static const char* postEndpoint protected
- The endpoint.
- static const char* ubidotsHost protected
- The host name.
- static const int ubidotsPort protected
- The host port.
- static const char* tokenHeader protected
- The token header text.
- static const char* contentLengthHeader protected
- The content length header text.
- static const char* contentTypeHeader protected
- The content type header text.
The begining of the JSON object for Ubidots
- static const char* payload protected
- The JSON initial characters.
Function documentation
UbidotsPublisher(Logger& baseLogger, uint8_t sendEveryX = 1, uint8_t sendOffset = 0) explicit
Construct a new Ubidots Publisher object.
Parameters | |
---|---|
baseLogger | The logger supplying the data to be published |
sendEveryX | Currently unimplemented, intended for future use to enable caching and bulk publishing |
sendOffset | Currently unimplemented, intended for future use to enable publishing data at a time slightly delayed from when it is collected |
UbidotsPublisher(Logger& baseLogger, Client* inClient, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
Construct a new Ubidots Publisher object.
Parameters | |
---|---|
baseLogger | The logger supplying the data to be published |
inClient | An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance |
sendEveryX | Currently unimplemented, intended for future use to enable caching and bulk publishing |
sendOffset | Currently unimplemented, intended for future use to enable publishing data at a time slightly delayed from when it is collected |
UbidotsPublisher(Logger& baseLogger, const char* authentificationToken, const char* deviceID, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
Construct a new Ubidots Publisher object.
Parameters | |
---|---|
baseLogger | The logger supplying the data to be published |
authentificationToken | The authentication token from Ubdots, either the Organization's Integration Token (under Users > Organization menu, visible by Admin only) OR the STEM User's Device Token (under the specific device's setup panel). |
deviceID | The device API Label from Ubidots, derived from the user-specified device name. |
sendEveryX | Currently unimplemented, intended for future use to enable caching and bulk publishing |
sendOffset | Currently unimplemented, intended for future use to enable publishing data at a time slightly delayed from when it is collected |
UbidotsPublisher(Logger& baseLogger, Client* inClient, const char* authentificationToken, const char* deviceID, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
Construct a new Ubidots Publisher object.
Parameters | |
---|---|
baseLogger | The logger supplying the data to be published |
inClient | An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance |
authentificationToken | The authentication token from Ubdots, either the Organization's Integration Token (under Users > Organization menu, visible by Admin only) OR the STEM User's Device Token (under the specific device's setup panel). |
deviceID | The device API Label from Ubidots, derived from the user-specified device name. |
sendEveryX | Currently unimplemented, intended for future use to enable caching and bulk publishing |
sendOffset | Currently unimplemented, intended for future use to enable publishing data at a time slightly delayed from when it is collected |
String getEndpoint(void ) override
Get the destination for published data - generally the host name of the data receiver.
Returns | String The URL or HOST to receive published data |
---|
void setToken(const char* authentificationToken)
Set the device authentication token.
Parameters | |
---|---|
authentificationToken | The authentication token from Ubdots, either the Organization's Integration Token (under Users > Organization menu, visible by Admin only) OR the STEM User's Device Token (under the specific device's setup panel). |
uint16_t calculateJsonSize()
Calculates how long the outgoing JSON will be.
Returns | uint16_t The number of characters in the JSON object. |
---|
void printSensorDataJSON(Stream* stream)
This generates a properly formatted JSON for Ubidots and prints it to the input Arduino stream object.
Parameters | |
---|---|
stream | The Arduino stream to write out the JSON to. |
void printUbidotsRequest(Stream* stream)
This prints a fully structured post request for the Ubidots API to the specified stream.
Parameters | |
---|---|
stream | The Arduino stream to write out the request to. |
void begin(Logger& baseLogger, Client* inClient, const char* authentificationToken, const char* deviceID)
Begin the publisher - linking it to the client and logger.
Parameters | |
---|---|
baseLogger | The logger supplying the data to be published |
inClient | An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance |
authentificationToken | The authentication token from Ubdots, either the Organization's Integration Token (under Users > Organization menu, visible by Admin only) OR the STEM User's Device Token (under the specific device's setup panel). |
deviceID | The device API Label from Ubidots, derived from the user-specified device name. |
This can be used as an alternative to adding the logger and client in the constructor. This is slightly "safer" because we expect the publishers to be created in the "global scope" and we cannot control the order in which objects in that global scope will be created. That is, we cannot guarantee that the logger will actually be created before the publisher that wants to attach to it unless we wait to attach the publisher until in the setup or loop function of the main program. In reality, it is very unlikely that this is necessary.
void begin(Logger& baseLogger, const char* authentificationToken, const char* deviceID)
Begin the publisher - linking it to the logger but not attaching a client.
Parameters | |
---|---|
baseLogger | The logger supplying the data to be published |
authentificationToken | The authentication token from Ubdots, either the Organization's Integration Token (under Users > Organization menu, visible by Admin only) OR the STEM User's Device Token (under the specific device's setup panel). |
deviceID | The device API Label from Ubidots, derived from the user-specified device name. |
This can be used as an alternative to adding the logger and client in the constructor. This is slightly "safer" because we expect the publishers to be created in the "global scope" and we cannot control the order in which objects in that global scope will be created. That is, we cannot guarantee that the logger will actually be created before the publisher that wants to attach to it unless we wait to attach the publisher until in the setup or loop function of the main program. In reality, it is very unlikely that this is necessary.
int16_t publishData(Client* outClient) override
Utilize an attached modem to open a a TCP connection to the Ubidots API and then stream out a post request over that connection.
Parameters | |
---|---|
outClient | An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance |
Returns | int16_t The http status code of the response. |
This depends on an internet connection already having been made and a client being available.