ModularSensors > Classes > dataPublisher > EnviroDIYPublisher
ModularSensors > Modules > Supported Data Endpoints > EnviroDIYPublisher


EnviroDIYPublisher class

The EnviroDIYPublisher subclass of dataPublisher for publishing data to the Monitor My Watershed/EnviroDIY data portal at http://data.enviroDIY.org.

Base classes

class dataPublisher
The dataPublisher class is a virtual class used by other publishers to distribute data online.

Constructors, destructors, conversion operators

EnviroDIYPublisher()
Construct a new EnviroDIY Publisher object with no members set.
EnviroDIYPublisher(Logger& baseLogger, uint8_t sendEveryX = 1, uint8_t sendOffset = 0) explicit
Construct a new EnviroDIY Publisher object.
EnviroDIYPublisher(Logger& baseLogger, Client* inClient, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
Construct a new EnviroDIY Publisher object.
EnviroDIYPublisher(Logger& baseLogger, const char* registrationToken, const char* samplingFeatureUUID, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
Construct a new EnviroDIY Publisher object.
EnviroDIYPublisher(Logger& baseLogger, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)
Construct a new EnviroDIY Publisher object.
~EnviroDIYPublisher() 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* registrationToken)
Set the site registration token.
uint16_t calculateJsonSize()
Calculates how long the outgoing JSON will be.
void printSensorDataJSON(Stream* stream)
This generates a properly formatted JSON for EnviroDIY and prints it to the input Arduino stream object.
void printEnviroDIYRequest(Stream* stream)
This prints a fully structured post request for Monitor My Watershed/EnviroDIY to the specified stream.
void begin(Logger& baseLogger, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID)
Begin the publisher - linking it to the client and logger.
void begin(Logger& baseLogger, const char* registrationToken, const char* samplingFeatureUUID)
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 EnviroDIY/ODM2DataSharingPortal and then stream out a post request over that connection.

Portions of the POST request to EnviroDIY

static const char* postEndpoint protected
The endpoint.
static const char* enviroDIYHost protected
The host name.
static const int enviroDIYPort 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.

Portions of the JSON object for EnviroDIY

static const char* samplingFeatureTag protected
The JSON feature UUID tag.
static const char* timestampTag protected
The JSON feature timestamp tag.

Function documentation

EnviroDIYPublisher(Logger& baseLogger, uint8_t sendEveryX = 1, uint8_t sendOffset = 0) explicit

Construct a new EnviroDIY 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

EnviroDIYPublisher(Logger& baseLogger, Client* inClient, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)

Construct a new EnviroDIY 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

EnviroDIYPublisher(Logger& baseLogger, const char* registrationToken, const char* samplingFeatureUUID, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)

Construct a new EnviroDIY Publisher object.

Parameters
baseLogger The logger supplying the data to be published
registrationToken The registration token for the site on the Monitor My Watershed data portal.
samplingFeatureUUID The sampling feature UUID for the site on the Monitor My Watershed data portal.
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

EnviroDIYPublisher(Logger& baseLogger, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID, uint8_t sendEveryX = 1, uint8_t sendOffset = 0)

Construct a new EnviroDIY 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
registrationToken The registration token for the site on the Monitor My Watershed data portal.
samplingFeatureUUID The sampling feature UUID for the site on the Monitor My Watershed data portal.
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

StringgetEndpoint(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

voidsetToken(const char* registrationToken)

Set the site registration token.

Parameters
registrationToken The registration token for the site on the Monitor My Watershed data portal.

uint16_tcalculateJsonSize()

Calculates how long the outgoing JSON will be.

Returns uint16_t The number of characters in the JSON object.

voidprintSensorDataJSON(Stream* stream)

This generates a properly formatted JSON for EnviroDIY and prints it to the input Arduino stream object.

Parameters
stream The Arduino stream to write out the JSON to.

voidprintEnviroDIYRequest(Stream* stream)

This prints a fully structured post request for Monitor My Watershed/EnviroDIY to the specified stream.

Parameters
stream The Arduino stream to write out the request to.

voidbegin(Logger& baseLogger, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID)

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
registrationToken The registration token for the site on the Monitor My Watershed data portal.
samplingFeatureUUID The sampling feature UUID for the site on the Monitor My Watershed data portal.

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.


voidbegin(Logger& baseLogger, const char* registrationToken, const char* samplingFeatureUUID)

Begin the publisher - linking it to the logger but not attaching a client.

Parameters
baseLogger The logger supplying the data to be published
registrationToken The registration token for the site on the Monitor My Watershed data portal.
samplingFeatureUUID The sampling feature UUID for the site on the Monitor My Watershed data portal.

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_tpublishData(Client* outClient) override

Utilize an attached modem to open a a TCP connection to the EnviroDIY/ODM2DataSharingPortal 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.