Closed shanedoolane closed 10 months ago
The problem was that http client instance was not being passed a valid reference to the gsmClient
instance
I think this is because gsmClient i was using not initialized with a modem properly.
// main.cpp
TinyGsm modem = cellFunctions.modem;
TinyGsmClient gsmClient = cellFunctions.gsmClient;
// cellFunctions.h
class CellFunctions
{
public:
CellFunctions(HardwareSerial &serialGsmRef, HardwareSerial &SerialATRef, StreamDebugger &debugger);
.
.
.
TinyGsm modem; // instance of TinyGsm modem class
TinyGsmClient gsmClient; // instance of the TinyGsm client class to use with mqtt
};
// getMQTTEndpoint.cpp
bool MQTTEndpoint::getMQTTEndpoint(Client &client)
{
char final_url[256];
sprintf(final_url, "http://%s/api/firmware/%s/", domain, apiKey);
bool endpoint_found = false;
while (!endpoint_found)
{
HttpClient http(client, domain, 80);
http.setTimeout(10000);
int err = http.get(final_url);
if (err != 0)
{
Logger.logMessage(LOG_LEVEL_ERROR, "HTTP GET not successful");
}
err = http.responseStatusCode();
Logger.logMessage(LOG_LEVEL_DEBUG, "The HTTP Response code is: %d", err);
if (err >= 300 || err < 200)
{
Logger.logMessage(LOG_LEVEL_ERROR, "Failed to get MQTT Endpoint due to bad HTTP response code");
delay(30000);
continue;
}
String payload = http.readString();
//main.cpp
TinyGsm modem = cellFunctions.modem;
TinyGsmClient gsmClient(modem); // here i actually pass the modem to the gsmClient before using the client to call getMQTTEndpoint
What type of issues is this?
What are you working with?
Modem: SIM7000G Main processor board: ESP32 TinyGSM version:
vshymanskyy/TinyGSM@^0.11.7
Code:
Scenario, steps to reproduce
TCP connection to server appears sucessful due to the dumped AT commands and checking the server lock i can see a 200 response from the module's IP. However the
ArduinoHTTPClient
is returning -3 error code for timeout. I can see the 509 byte response from the request but ArduinoHTTPClient isn't getting the data for some reason.Server response log:
Expected result
the HTTP response is passed to HTTPClient with
http.responseStatusCode()
=200Actual result
http.responseStatusCode();
= -3 indicating that the response has timed out even though server returned 200Debug and AT command log