vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.93k stars 715 forks source link

TinyGsmClientSecure Post Succesful but Response Scrambled #533

Open weyersma opened 3 years ago

weyersma commented 3 years ago

[X] I have read the Troubleshooting section of the ReadMe

What type of issues is this?

[ ] Request to support a new module

[ ] Bug or problem compiling the library [X] Bug or issue with library functionality (ie, sending data over TCP/IP) [ ] Question or request for help

What are you working with?

Modem: SIM800L on ESP32 (TTGO) Main processor board: ESP32 TinyGSM version: Code:

Scenario, steps to reproduce

Complete a Post to a HTTPS Site using TinyGsmClientSecure

Expected result

Successful Post

Actual result

Sometimes I get a successful result. Other times it comes back with a reverse question mark, more question marks or characters not displayed

Debug and AT command log

I get an error when activating this command. The code that I am using to send the information is below: Serial Speed set to 9600 RX Buffer to 1024 The post works perfectly, it is only the response that is scrambled

    if (!sclient.connect(serverAWS, portAWS)) 
    {
      SerialUSB.println(" fail");
    }
    else 
    {
      // Making an HTTP POST request
      SerialUSB.println("Performing HTTP POST request...");
      // Prepare your HTTP POST request data (Temperature in Celsius degrees)

      sclient.print(String("POST ") + resourceAWS + " HTTP/1.1\r\n");
      sclient.print(String("Host: ") + serverAWS + "\r\n");
      sclient.println("Connection: close");
      sclient.println("Content-Type: application/json");
      sclient.print("Content-Length: ");
      sclient.println(httpPostData.length());
      sclient.println();
      sclient.println(httpPostData);
      unsigned long timeout = millis();
      String response = "";
      long int time = millis();
      while ((time + 10000) > millis())
      {
          while (sclient.available())
          {
              char c = sclient.read();
              response += c;
          }
      }
      SerialUSB.println(response);
    }

Connecting to APN: internetGPRS OK {"api_key":"CF7XWY01B7DHR0YD","field1":"4115","field2":"5104","field3":"20.50","field4":"56.00","field5":"0","field6":"0","field7":"0"} Performing HTTP POST request 2...

Performing HTTP POST request 3... ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ Send Failure. Retry number: 1Done with HTTP POST request... Server disconnected

GPRS disconnected

SRGDamia1 commented 3 years ago

Usually scrambled characters are from mis-matched baud rates or bit-banging/software serial. If your data is being received correctly (AWS? ThingSpeak?) and you don't care about the response I would adjust your code to ignore your response and let it be. If you do care about the response, I'd suggest you switch to "hardware" serial if you can and also try tweaking your baud rate (SIM800 defaults to 9600 but can go up to 460800) to see if the communication is more stable. Use the modem.setBaudRate(#) command (AT+IPR) rather than doing any auto-bauding.