Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/internal/esp8266/ParseClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand Down