#include <src/dataPublisherBase.h>
dataPublisher
class
The dataPublisher class is a virtual class used by other publishers to distribute data online.
A dataPublisher is a abstract concept. It is something that "watches" the logger for new data and correctly formats and sends that data to some online web service.
Derived classes
- class DreamHostPublisher
- The DreamHostPublisher subclass of dataPublisher is for publishing data to the Stroud Center's now-deprecated DreamHost based live sensor data system.
- class EnviroDIYPublisher
- The EnviroDIYPublisher subclass of dataPublisher for publishing data to the Monitor My Watershed/EnviroDIY data portal at http:/
/ data.enviroDIY.org. - class ThingSpeakPublisher
- The ThingSpeakPublisher subclass of dataPublisher for publishing data to ThingSpeak using the MQTT protocol.
- class UbidotsPublisher
- The UbidotsPublisher subclass of dataPublisher for publishing data to the Ubidots data portal at https:/
/ ubidots.com.
Constructors, destructors, conversion operators
- dataPublisher()
- Construct a new data Publisher object untied to any logger or client.
- dataPublisher(Logger& baseLogger, int sendEveryX = 1) explicit
- Construct a new data Publisher object using a single client created on the TinyGSM based logger modem.
- dataPublisher(Logger& baseLogger, Client* inClient, int sendEveryX = 1)
- Construct a new data Publisher object.
- ~dataPublisher() virtual
- Destroy the data Publisher object - no action is taken.
Public functions
- void setClient(Client* inClient)
- Set the Client object.
- void attachToLogger(Logger& baseLogger)
- Attach the publisher to a logger.
- void setSendInterval(int sendEveryX)
- Sets the interval (in units of the logging interval) between attempted data transmissions.
- void begin(Logger& baseLogger, Client* inClient)
- Begin the publisher - linking it to the client and logger.
- void begin(Logger& baseLogger)
- Begin the publisher - linking it to the logger but not attaching a client.
- String getEndpoint(void) -> String pure virtual
- Get the destination for published data - generally the host name of the data receiver.
- int16_t publishData(Client* outClient) -> int16_t pure virtual
- Open a socket to the correct receiver and sends out the formatted data.
- int16_t publishData() -> int16_t virtual
- Open a socket to the correct receiver and send out the formatted data.
- int16_t sendData(Client* outClient) -> int16_t deprecated in v0.22.5 virtual
- Retained for backwards compatibility; use publishData(Client* outClient) in new code.
- int16_t sendData() -> int16_t deprecated in v0.22.5 virtual
- Retained for backwards compatibility; use publishData() in new code.
- String parseMQTTState(int state) -> String
- Translate a PubSubClient code into a String with the code explanation.
Protected static functions
- static void txBufferInit(Client* outClient)
- Initialize the TX buffer to be empty and start writing to the given client.
- static void txBufferAppend(const char* data, size_t length)
- Append the given data to the TX buffer, flushing if necessary.
- static void txBufferAppend(const char* s)
- Append the given string to the TX buffer, flushing if necessary.
- static void txBufferAppend(char c)
- Append the given char to the TX buffer, flushing if necessary.
- static void txBufferFlush()
- Write the TX buffer contents to the initialized stream and also to the debugging port.
Protected static variables
- static char txBuffer
- The buffer for outgoing data.
- static Client* txBufferOutClient
- The pointer to the client instance the TX buffer is writing to.
- static size_t txBufferLen
- The number of used characters in the TX buffer.
- static const char* getHeader
- the text "GET "
- static const char* postHeader
- the text "POST "
- static const char* HTTPtag
- the text " HTTP/1.1"
- static const char* hostHeader
- the text "\r\nHost: "
Protected variables
- Logger* _baseLogger
- The internal pointer to the logger instance to be used.
- Client* _inClient
- The internal pointer to the client instance to be used.
- int _sendEveryX
- Interval (in units of the logging interval) between attempted data transmissions. Not respected by all publishers.
Function documentation
dataPublisher:: dataPublisher()
Construct a new data Publisher object untied to any logger or client.
dataPublisher:: dataPublisher(Logger& baseLogger,
int sendEveryX = 1) explicit
Construct a new data Publisher object using a single client created on the TinyGSM based logger modem.
Parameters | |
---|---|
baseLogger | The logger supplying the data to be published |
sendEveryX | Interval (in units of the logging interval) between attempted data transmissions. Not respected by all publishers. |
dataPublisher:: dataPublisher(Logger& baseLogger,
Client* inClient,
int sendEveryX = 1)
Construct a new data 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 | Interval (in units of the logging interval) between attempted data transmissions. Not respected by all publishers. |
void dataPublisher:: setClient(Client* inClient)
Set the Client object.
Parameters | |
---|---|
inClient | A pointer to an Arduino client instance |
Gives the publisher a client instance to use to "print" data.
void dataPublisher:: attachToLogger(Logger& baseLogger)
Attach the publisher to a logger.
Parameters | |
---|---|
baseLogger | A reference to the ModularSensors logger instance |
The publisher must be tied to a data loger to provide it with the data to be published.
void dataPublisher:: setSendInterval(int sendEveryX)
Sets the interval (in units of the logging interval) between attempted data transmissions.
Parameters | |
---|---|
sendEveryX | Interval (in units of the logging interval) between attempted data transmissions. Not respected by all publishers. |
void dataPublisher:: begin(Logger& baseLogger,
Client* inClient)
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 |
This can be used as an alternative to adding the logger and client in the constructor.
String dataPublisher:: getEndpoint(void) pure
virtual
Get the destination for published data - generally the host name of the data receiver.
Returns | String The URL or HOST to receive published data |
---|
int16_t dataPublisher:: publishData(Client* outClient) pure
virtual
Open a socket to the correct receiver and sends out the formatted data.
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 result of publishing data. May be an http response code or a result code from PubSubClient. |
This depends on an internet connection already having been made and a client being available.
int16_t dataPublisher:: publishData() virtual
Open a socket to the correct receiver and send out the formatted data.
Returns | int16_t The result of publishing data. May be an http response code or a result code from PubSubClient. |
---|
This depends on an internet connection already having been made and either a client having been linked to the publisher or a logger modem having been linked to the logger linked to the publisher.
int16_t dataPublisher:: sendData(Client* outClient) virtual deprecated in v0.22.5
Retained for backwards compatibility; use publishData(Client* outClient) in new code.
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 result of publishing data. May be an http response code or a result code from PubSubClient. |
int16_t dataPublisher:: sendData() virtual deprecated in v0.22.5
Retained for backwards compatibility; use publishData() in new code.
Returns | int16_t The result of publishing data. May be an http response code or a result code from PubSubClient. |
---|
String dataPublisher:: parseMQTTState(int state)
Translate a PubSubClient code into a String with the code explanation.
Parameters | |
---|---|
state | A result code returned by a PubSubClient action |
Returns | String The meaning of the code |
static void dataPublisher:: txBufferInit(Client* outClient) protected
Initialize the TX buffer to be empty and start writing to the given client.
Parameters | |
---|---|
outClient | The client to transmit to. |
static void dataPublisher:: txBufferAppend(const char* data,
size_t length) protected
Append the given data to the TX buffer, flushing if necessary.
Parameters | |
---|---|
data | The data start pointer. |
length | The number of bytes to add. |
static void dataPublisher:: txBufferAppend(const char* s) protected
Append the given string to the TX buffer, flushing if necessary.
Parameters | |
---|---|
s | The null-terminated string to append. |
static void dataPublisher:: txBufferAppend(char c) protected
Append the given char to the TX buffer, flushing if necessary.
Parameters | |
---|---|
c | The char to append. |