Arduino-SIM800L-driver icon indicating copy to clipboard operation
Arduino-SIM800L-driver copied to clipboard

How to construct correct HTTP Headers for SIM800L-driver library

Open mitiay7 opened this issue 2 years ago • 7 comments

Dear Sir,

Please advise how to correctly construct headers which are consist from more than one parameter?

I'm trying to make GET request with two auth headers (X-Parse-Application-Id and X-Parse-REST-API-Key) to PARSE backend but getting 702 error. If I switch on extensive logging - getting the following error:

13:46:58.916 -> SIM800L : initiateHTTP() - Unable to define Headers 13:46:58.916 -> HTTP GET error 702

Now my string headers looks like this:

const char HEADERS_BACK4END[] = "X-Parse-Application-Id: MY_KEY_HERE\r\nX-Parse-REST-API-Key: MY_KEY_HERE";

I use \r\n to move second parameter on new line ))

Bet it is wrong, please advise correct way to send two headers to your library. Thank you very much in advance

Dmitry

mitiay7 avatar Sep 12 '21 10:09 mitiay7

Hi @mitiay7,

The header part has been implemented by @ztaras and I never had the need to use header in my applications.

In the pull request (https://github.com/ostaquet/Arduino-SIM800L-driver/pull/25#issuecomment-725900615), there is some insight about the construction of the headers; quoted below.

This should do the trick: sim800l->doGet("https://postman-echo.com/get?foo1=bar1&foo2=bar2", "Authorization:Basic aW50ZWdy...", 10000);

If you also want to send the Content-Type header, the line would look like this: sim800l->doGet("https://postman-echo.com/get?foo1=bar1&foo2=bar2", "Authorization:Basic aW50ZWdy...\\r\\nContent-Type:application/json", 10000);

Just replace the aW50ZWdy... part with whatever Postman generated for your username and password.

ostaquet avatar Nov 04 '21 14:11 ostaquet

@mitiay7, Please try using double back slash in between two headers, e.g.: sim800l->doGet("https://postman-echo.com/get?foo1=bar1&foo2=bar2", "Header-1:value1\\r\\nHeader-2:value2", 10000);

ztaras avatar Nov 04 '21 15:11 ztaras

Hi, I have the same issue but with just one header:

char* header = "auth_token:11111111-2222-3333-4444-555555555555"
uint16_t rc = sim800l->doPost(
    SIM_SERVER_URL,
    header,
    "application/json",
    "data",
    10000,
    10000
);
13:46:58.916 -> SIM800L : initiateHTTP() - Unable to define Headers
13:46:58.916 -> HTTP GET error 702

It seems to to stuck at SIM800L::initiateHTTP : line 327 sendCommand_P(AT_CMD_HTTPPARA_USERDATA, headers);

EndruK avatar Feb 28 '22 09:02 EndruK

I figured out that it is connected to the length of the char array - an array with more than 34 characters results in getting stuck. With <= 34 characters it works. char* header = "authtoken:123456789012345678901234" // works Could this be connected to message buffer sizes?

EndruK avatar Feb 28 '22 18:02 EndruK

I didn't see any buffer limits in this part of the code.

The message buffer is defined at the initialisation of the driver (constructor SIM800L::SIM800L(...)). What is the message buffer size you are using?

Can you enable debug mode to see the command going in and out of the module?

ostaquet avatar Mar 02 '22 13:03 ostaquet

Sim800 Object initialization is similar to the examples: sim800l = new SIM800L((Stream *)sim800l_serial, SIM_RST, 200, 512, (Stream*)&Serial);

Debug message for this part:

SIM800L : Send "AT+HTTPPARA="USERDATA","authtoken:1234567890abcdefghijklmnopqrstuvwxyz""
SIM800L : Receive timeout
SIM800L : initiateHTTP() - Unable to define Headers
HTTP POST error 702

EndruK avatar Mar 02 '22 14:03 EndruK

Ok after some research I finally figured out a solution. As described here the SIM800L module seems to have issues with automatic baud detection. Setting the baud rate manually solves all communication issues - even sending longer headers :)

AT+IPR=9600
AT&W

EndruK avatar Mar 10 '22 15:03 EndruK

As mentioned in the README, the project is no longer maintained as my module is broken. Thanks for reporting the issue.

ostaquet avatar Jun 02 '24 16:06 ostaquet