From cc24c429ee7909e3c5d8c70a92fe15d66b87db41 Mon Sep 17 00:00:00 2001 From: Derrick Marlow Date: Tue, 11 Feb 2020 10:28:33 -0800 Subject: [PATCH] Set Server URL, Set Insecure Add method to set custom server URL and call setInsecure() function in connection client. --- src/internal/esp8266/ParseClient.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/internal/esp8266/ParseClient.cpp b/src/internal/esp8266/ParseClient.cpp index 9cad668..f41f185 100644 --- a/src/internal/esp8266/ParseClient.cpp +++ b/src/internal/esp8266/ParseClient.cpp @@ -81,6 +81,7 @@ static void sendAndEchoToSerial(WiFiClientSecure& client, const char *line) { ParseClient::ParseClient() { memset(applicationId, 0, sizeof(applicationId)); memset(clientKey, 0, sizeof(clientKey)); + memset(serverURL, 0, sizeof(serverURL)); memset(installationId, 0, sizeof(installationId)); memset(sessionToken, 0, sizeof(sessionToken)); memset(lastPushTime, 0, sizeof(lastPushTime)); @@ -110,6 +111,15 @@ void ParseClient::begin(const char *applicationId, const char *clientKey) { restoreKeys(); } +void ParseClient::setServerURL(const char *serverURL) { + Serial.print("setting serverURL("); + Serial.print(serverURL ? serverURL : "NULL"); + Serial.println(")"); + if(serverURL) { + strncpy(this->serverURL, serverURL, sizeof(this->serverURL)); + } +} + void ParseClient::setInstallationId(const char *installationId) { if (installationId) { if (strcmp(this->installationId, installationId)) @@ -201,8 +211,10 @@ ParseResponse ParseClient::sendRequest(const String& httpVerb, const String& htt int retry = 3; bool connected; + + client.setInsecure(); - while(!(connected = client.connect(PARSE_API, SSL_PORT)) && retry--) { + while(!(connected = client.connect(serverURL, SSL_PORT)) && retry--) { Serial.printf("connecting...%d\n", retry); yield(); } @@ -220,7 +232,7 @@ ParseResponse ParseClient::sendRequest(const String& httpVerb, const String& htt snprintf(buff, sizeof(buff) - 1, "%s %s HTTP/1.1\r\n", httpVerb.c_str(), httpPath.c_str()); } sendAndEchoToSerial(client, buff); - snprintf(buff, sizeof(buff) - 1, "Host: %s\r\n", PARSE_API); + snprintf(buff, sizeof(buff) - 1, "Host: %s\r\n", serverURL); sendAndEchoToSerial(client, buff); snprintf(buff, sizeof(buff) - 1, "X-Parse-Client-Version: %s\r\n", CLIENT_VERSION); sendAndEchoToSerial(client, buff);