diff --git a/src/publishers/EnviroDIYPublisher.cpp b/src/publishers/EnviroDIYPublisher.cpp index b362df6e9..b734722bc 100644 --- a/src/publishers/EnviroDIYPublisher.cpp +++ b/src/publishers/EnviroDIYPublisher.cpp @@ -18,9 +18,6 @@ // Constant values for post requests // I want to refer to these more than once while ensuring there is only one copy // in memory -const char* EnviroDIYPublisher::postEndpoint = "/api/data-stream/"; -const char* EnviroDIYPublisher::enviroDIYHost = "data.envirodiy.org"; -const int EnviroDIYPublisher::enviroDIYPort = 80; const char* EnviroDIYPublisher::tokenHeader = "\r\nTOKEN: "; const char* EnviroDIYPublisher::contentLengthHeader = "\r\nContent-Length: "; const char* EnviroDIYPublisher::contentTypeHeader = @@ -31,15 +28,25 @@ const char* EnviroDIYPublisher::timestampTag = "\",\"timestamp\":["; // Constructors -EnviroDIYPublisher::EnviroDIYPublisher() : dataPublisher() {} +EnviroDIYPublisher::EnviroDIYPublisher() : dataPublisher() { + setHost("monitormywatershed.org"); + setPath("/api/data-stream/"); + setPort(80); +} EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, int sendEveryX) : dataPublisher(baseLogger, sendEveryX) { _logBuffer.setNumVariables(_baseLogger->getArrayVarCount()); + setHost("monitormywatershed.org"); + setPath("/api/data-stream/"); + setPort(80); } EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient, int sendEveryX) : dataPublisher(baseLogger, inClient, sendEveryX) { _logBuffer.setNumVariables(_baseLogger->getArrayVarCount()); + setHost("monitormywatershed.org"); + setPath("/api/data-stream/"); + setPort(80); } EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, const char* registrationToken, @@ -49,6 +56,9 @@ EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, setToken(registrationToken); _baseLogger->setSamplingFeatureUUID(samplingFeatureUUID); _logBuffer.setNumVariables(_baseLogger->getArrayVarCount()); + setHost("monitormywatershed.org"); + setPath("/api/data-stream/"); + setPort(80); } EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient, const char* registrationToken, @@ -58,11 +68,45 @@ EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient, setToken(registrationToken); _baseLogger->setSamplingFeatureUUID(samplingFeatureUUID); _logBuffer.setNumVariables(_baseLogger->getArrayVarCount()); + setHost("monitormywatershed.org"); + setPath("/api/data-stream/"); + setPort(80); } // Destructor EnviroDIYPublisher::~EnviroDIYPublisher() {} +// Returns the data destination +String EnviroDIYPublisher::getHost(void) { + return String(enviroDIYHost); +} + +// Returns the data destination +void EnviroDIYPublisher::setHost(const char* host) { + enviroDIYHost = host; +} + +// Returns the data destination +String EnviroDIYPublisher::getPath(void) { + return String(enviroDIYPath); +} + +// Returns the data destination +void EnviroDIYPublisher::setPath(const char* endpoint) { + enviroDIYPath = endpoint; +} + +// Returns the data destination +int EnviroDIYPublisher::getPort(void) { + return enviroDIYPort; +} + +// Returns the data destination +void EnviroDIYPublisher::setPort(int port) { + enviroDIYPort = port; +} + + void EnviroDIYPublisher::setToken(const char* registrationToken) { _registrationToken = registrationToken; } @@ -217,7 +261,7 @@ int16_t EnviroDIYPublisher::flushDataBuffer(Client* outClient) { // copy the initial post header into the tx buffer txBufferAppend(postHeader); - txBufferAppend(postEndpoint); + txBufferAppend(enviroDIYPath); txBufferAppend(HTTPtag); // add the rest of the HTTP POST headers to the outgoing buffer diff --git a/src/publishers/EnviroDIYPublisher.h b/src/publishers/EnviroDIYPublisher.h index 1f301a920..12bd93ef9 100644 --- a/src/publishers/EnviroDIYPublisher.h +++ b/src/publishers/EnviroDIYPublisher.h @@ -107,9 +107,49 @@ class EnviroDIYPublisher : public dataPublisher { // Returns the data destination String getEndpoint(void) override { - return String(enviroDIYHost); + return String(enviroDIYHost) + String(enviroDIYPath); } + /** + * @brief Get the EnviroDIY/Monitor My Watershed web host + * + * @return *String* The EnviroDIY/Monitor My Watershed web host + */ + String getHost(void); + + /** + * @brief Set the EnviroDIY/Monitor My Watershed web host + * + * @param host The EnviroDIY/Monitor My Watershed web host + */ + void setHost(const char* host); + + /** + * @brief Get the EnviroDIY/Monitor My Watershed API path + * + * @return *String* The EnviroDIY/Monitor My Watershed API path + */ + String getPath(void); + /** + * @brief Set the EnviroDIY/Monitor My Watershed API path + * + * @param endpoint The EnviroDIY/Monitor My Watershed API path + */ + void setPath(const char* endpoint); + + /** + * @brief Get the EnviroDIY/Monitor My Watershed API port + * + * @return *int* The EnviroDIY/Monitor My Watershed API port + */ + int getPort(void); + /** + * @brief Set the EnviroDIY/Monitor My Watershed API port + * + * @param port The EnviroDIY/Monitor My Watershed API port + */ + void setPort(int port); + // Adds the site registration token /** * @brief Set the site registration token @@ -178,9 +218,9 @@ class EnviroDIYPublisher : public dataPublisher { * * @{ */ - static const char* postEndpoint; ///< The endpoint - static const char* enviroDIYHost; ///< The host name - static const int enviroDIYPort; ///< The host port + const char* enviroDIYPath; ///< The api path + const char* enviroDIYHost; ///< The host name + int enviroDIYPort; ///< The host port static const char* tokenHeader; ///< The token header text static const char* contentLengthHeader; ///< The content length header text static const char* contentTypeHeader; ///< The content type header text