Closed cezarg1410 closed 6 months ago
Hi, the -3 looks like a timeout coming from the ArduinoHttpClient. Also, it looks due to the ssl handshake failing.
I have had this before and fixed when using ArduinoHttpClient the call to client.connectionKeepAlive() before startRequest is called. Although technically this shouldn't be necessary.
Also, check your ArduinoHttpClient and SSLClient timeout values and play at adjusting them to longer. Maybe go higher and work back.
Your post request structure for using the ArduinoHttpClient looks good.
With TinyGsm is tend to log out a connection strength operator periodically as well to help diagnose connection issues.
Hi, I'm also working on with sim800L model modul with sending json request to googleapis.com. But I couldn't build proper structure of POST request.
This is my working structure with another library. How can I implement this structure with sslclient.h library
SerialMon.println("Performing HTTP POST request...");
String body = "{\"considerIP\":false,\"wifiAccessPoints\":" + getWifisJSON() + "}";
String request = "POST " + String(googleApiUrl_) + "?key=" + googleApiKey_ + " HTTP/1.1\r\n";
request += "Host: " + String(googleApisHost_) + "\r\n";
request += "User-Agent: ESP32\r\n";
request += "Content-Type:application/json\r\n";
request += "Content-Length:" + String(body.length()) + "\r\n";
request += "Connection: keep-alive\r\n\r\n";
request += body;
client.println(request);
I couldnt use this code with client.post() function. Can anybody help?
Hi, @ilgarbenli I have used this lib with SIM800L and ArduinoHttpClient successfully A LOT.
Just using client.post() method (look at ArduinoHttpClient examples.
Using client.write() only
And also (my favourite method for completeness, structure and clarity) using a complex and explicit use of ArduinoHttpClient - one of their example shows this. Pretty sure you are better off in this order.
Then do your check for response codes and client availability, etc... and read your responseBody() as a String() (personally yuk!) or as bytes (client.read) into a buffer.
The steps above - a good habit is to check return value of any non void function. E.g. client.write returning 0 would mean no bytes were written.
Also, good to get familiar with response codes like -2 or -3. Have a look in the ArduinoHttpClient itself, they are defined in there and can refer more often to TLS layer issues caused by poor connection. One of these codes has not come from the server!
Hope that helps
@RobertByrnes thank you for your respond. I tried several things and couldn't make it unfortunately. I guess I'm doing something wrong with my code. I'll open new issue of mine with my full of code. Would you review it when you have a chance
@cezarg1410 what is resource in client.post(resource); ?
Resource = "/something"
As in https://api.example.com/something
You have already given the host when you connected in the connect method as "api.example.com" so now the endpoint or resource is "/something"
Resource = "/something"
As in https://api.example.com/something
You have already given the host when you connected in the connect method as "api.example.com" so now the endpoint or resource is "/something"
Thank you for your respond and thank you for your help. My code is working now.
Unfortunately - no luck for me. I tried option with connectionKeepAlive() but it does not change anything. SSL Handshake should be fine - i am able to POST identical request from postman without issues.
Looks like, the library or the sim7600 is not able to handle the client certificate - when i remove those two lines:
secure_presentation_layer.setCertificate(client_crt);
secure_presentation_layer.setPrivateKey(client_key);
then it works fine every time (of course i am getting then HTTP 403 response because my server requires proper client certificate).
I updated all libraries (TinyGSM, SSLClient and ArduinoHttpClient) to the newest versions and something has changed. Now i am getting -3 error every single time : D
I am starting to loose hope :) Looks like i should resign from authenticating client with its certificate, but obviously i would rather not to do it - it is in my opinion the best and the most secure method for exposing API to the internet.
@cezarg1410 may it works for your case? https://github.com/Samorange1/Connect-ESP32-to-Firebase-via-GSM it bypass ssl connecction with a server
Thanks for that! Looks interesting, will get deep dive into it
Thanks for that! Looks interesting, will get deep dive into it
please keep contact together, It worked for me. But also I'm struggling about 403 forbidden issue for another client. Maybe we can help together
any updates?
No luck for me. I decided to remove client certificate authentication from my solution and instead i am using API token authentication on my rest API with HTTPS. It works just fine and i stopped wasting time trying to make it working.
solved by v1.2.0
Hello, I have really strange issue when trying to make HTTP POST with SSL from ESP32 with SIM7600G. The thing is it works from time to time. Probably 1-2 out of 10 calls are successfull. For the rest the library returns -2 or -3 status code.
I can also add, that using that code without SSL auth works perfectly. Also using WiFiClientSecure works really fine.
Here is my full code:
Ane the result: