-
Notifications
You must be signed in to change notification settings - Fork 7.6k
HTTPClient.h not compatible with TinyGsm? #4196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
HTTPClient will only work with a WiFiClient. You might try my PR #3848, that handles the HTTP protocol by directly manipulating the Client passed into the constructor, however I never tried it with TinyGsm. |
Thanks @Jeroen88 , I'll give it a try! |
Hi @Jeroen88 , at first try isn't working. I'll debug a little more and share the results. It's just a post so if someone know another solution to be share, will be welcome! |
Sim800 has a http client also using AT commands. If I recall correctly tinygsm itself may have a http client as well (that uses these AT commands). If I recall correctly Sim800 only supports http,no https, so the server you're connecting to should allow unsecured http connections |
@Jeroen88 Exactly, I'm using an HTTP server to manage POST. First I made a code to test HTTP GET with your library. Success Rate is bad, changing setTimeout (up to 100000) appears not to affect on nothing, error -1 comes just a couple of seconds later.
Now... HTTP POST has a more acceptable success rate around 50%. (Also with setTimeout at 100000, and getting -1 error a couple of seconds later).
Maybe a fuction to retry connection? or maybe wait a bit more? Thanks!! |
I have no access to my computer now, so I can not check anything before next week. I understand correctly that sometimes it works? That means that in principle it is possible to make http requests over a Sim800 connection. |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
How do you added external library? |
I used <ArduinoHttpClient.h> instead <HTTPClient.h> |
Do you know how to add external library? |
Hi bgondell! Did you resolve the issue and got success to send data via GSM? |
I used <ArduinoHttpClient.h> instead <HTTPClient.h>, split the data in 1024-bits, send the 1024-bit parts and finally the last part is sended at last in another code because it can be less than 1024-bits. My very very ugly but working code:
|
Thank you very much for your answer budy!
Your solution is a very good one; congrats!
I found a very nice solution that worked very well using ArduinoJson.h and
TinyGsmClient.h
Basically this is the code:
//JSON doc generation and serialization
StaticJsonDocument<384> doc;
doc["api_key"] = apiKeyValue;
doc["sensor"] = "Reflections";
doc["value1"] = (parsedStrings[0]);
doc["value2"] = (parsedStrings[1]);
doc["value3"] = (parsedStrings[2]);
doc["value4"] = (parsedStrings[3]);
doc["value5"] = (parsedStrings[4]);
doc["value6"] = (parsedStrings[5]);
doc["value7"] = (parsedStrings[6]);
doc["value8"] = (parsedStrings[7]);
doc["value9"] = (parsedStrings[8]);
doc["value10"] = (parsedStrings[9]);
doc["value11"] = (parsedStrings[10]);
serializeJson(doc, jsonOutput);
// Prepare your HTTP POST request data (Temperature in
Celsius degrees)
String httpRequestData = jsonOutput;
//JSON Transmission 2 the server
client.print(String("POST ") + resource + " HTTP/1.1\r\n");
client.print(String("Host: ") + server + "\r\n");
client.println("Connection: close");
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(httpRequestData.length());
client.println();
client.println(httpRequestData);
unsigned long timeout = millis();
while (client.connected() && millis() - timeout < 10000L) {
// Print available data (HTTP response from server)
while (client.available()) {
char c = client.read();
SerialMon.print(c);
timeout = millis();
}
}
SerialMon.println();
// Close client and disconnect
client.stop();
…On Wed, Aug 24, 2022 at 3:12 PM bgondell ***@***.***> wrote:
I used <ArduinoHttpClient.h> instead <HTTPClient.h>, split the data in
1024-bits, send the 1024-bit parts and finally the last part is sended at
last in another code because it can be less than 1024-bits.
My very very ugly but working code:
if ((data.length() <= 1024) || USE_WIFI) { Serial.println("Sending one
package"); http.post(resource, contentType, data); } else { // split and
sent 1024-bit parts uint8_t temp[1025]; int chunks = (data.length() /
1024); Serial.print("Big packet, spliting in
");Serial.print(chunks);Serial.println(" parts.");
http.startRequest(resource, "POST", "application/json", data.length()); for
(int i = 0; i < chunks; i++) { data.substring( i * 1024 , ((i + 1) * 1024)
).getBytes(temp, 1025); Serial.println((char*)temp); http.write(temp,
1024); delay(10); } int lastpiece = data.length() - (chunks * 1024) + 1; if
(lastpiece > 0) { uint8_t temp2[lastpiece]; data.substring(chunks *
1024).getBytes(temp2, lastpiece); //Last piece of data
Serial.println((char*)temp2); http.write(temp2, lastpiece); }
—
Reply to this email directly, view it on GitHub
<#4196 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A2PS2ZGAVZO26ZROQ74RRQTV2YUU7ANCNFSM4PFBZGUQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Hardware:
Board: ESP32 Dev Module v1
Core Installation version: 1.0.4
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Windows 10
Description:
Summary: Code works fine on WiFi, but on GPRS it crash. Given examples works fine also.
Modem: SIM800L
TinyGSM version: 0.10.5 (latest on Library Manager)
Note: First versions of code used ArduinoHTTPClient.h, which actually worked on Wifi/GPRS, but entire code was very different (not only the part on using Wifi or GPRS). Then I've changed to HTTPClient.h because code had others problems related to data, not communication itself.
Code: < related code because full code has 900 lines >
The last line (line 234) is when ESP32 Crash.
Expected result - This is what happens if use WIFI : Working Fine
Actual result : This is what happens if use GPRS: (xQueueGenericReceive)- assert failed!
Debug
Exception Decoder Tool:
The text was updated successfully, but these errors were encountered: