HTTPS Connection Refused
Posted: Sun Jun 14, 2020 7:14 pm
I have been unable to POST an application/json payload to AWS API Gateway from the NodeMCU-12e. The same post works from Paw and curl. Here is the curl command:
I've changed the domain name, but everything else is the same. I get a 200 from this call, both from curl and from Paw.
Now my Arduino code (I use PlatformIO if that matters):
I consistently get an ERROR: -1 (connection refused) from the POST call. If I call connected() after the begin() call, and it returns false. I do not get False from begin, it appears to think everything is okay.
The same code uses NTPClient to get the time and that works fine, so I feel reasonably confident that my WiFi is working.
One more bit of detail in case it matters: The POST is to an AWS API Gateway endpoint, implemented as a POST (just passes through data to DynamoDB PutItem). I not currently have Auth or any kind of API key requirement turned on for the service, as you can see in the curl command above.
Thanks for any pointers you can give me, been beating my head against this all day.
Cheers,
Ron
Code: Select all
curl -d '{"timestamp":"000000000","power": 3.45,"ambientTemp":22.5,"soilTemp":20.8125,"lightLevel":871.4843}' -H "Content-Type: application/json" -X POST https://api.mydomain.com/storereadings
I've changed the domain name, but everything else is the same. I get a 200 from this call, both from curl and from Paw.
Now my Arduino code (I use PlatformIO if that matters):
Code: Select all
String json;
serializeJson(doc, json);
if ((WiFi.status() == WL_CONNECTED)) {
HTTPClient http;
WiFiClientSecure client;
if (!http.begin(client, "https://api.mydomain.com/storereadings")) {
Serial.println("BEGIN FAILED...");
}
http.addHeader("Content-Type", "application/json");
int code = http.POST(json);
if (code < 0) {
Serial.print("ERROR: ");
Serial.println(code);
}
else {
// Read response
http.writeToStream(&Serial);
Serial.flush();
}
// Disconnect
http.end();
}
else {
Serial.println("****** NO WIFI!!");
}
I consistently get an ERROR: -1 (connection refused) from the POST call. If I call connected() after the begin() call, and it returns false. I do not get False from begin, it appears to think everything is okay.
The same code uses NTPClient to get the time and that works fine, so I feel reasonably confident that my WiFi is working.
One more bit of detail in case it matters: The POST is to an AWS API Gateway endpoint, implemented as a POST (just passes through data to DynamoDB PutItem). I not currently have Auth or any kind of API key requirement turned on for the service, as you can see in the curl command above.
Thanks for any pointers you can give me, been beating my head against this all day.
Cheers,
Ron