SIM7500-LTE-Shield icon indicating copy to clipboard operation
SIM7500-LTE-Shield copied to clipboard

SIM7600 HTTP AT Commands not sending

Open Wolfleader101 opened this issue 1 year ago • 0 comments

Hello,

I am following the AT command manual for the SIM7600 to make a HTTP Request to my server, however It never connects to my server using the HTTP AT commands and nothing shows up on wireshark.

After: AT+HTTPACTION=1, i get OK, but then after the timeout i get a 714 error code (Connect socket failed) I am unsure why

If i setup a TCP connection and use CIPSEND, it shows up in wireshark.

Here is my code:

void PostImage(const char *host, const char *resource, int port, const char *uuid, const char *name, uint8_t *payload,
               size_t length) {
    // start https
    Serial.println("Closing any previous HTTPS sessions");
    sendCommandWaitforMatch("AT+HTTPTERM", "OK");

    Serial.println("starting HTTPS...");
    ATCommandResponse started = sendCommandWaitforMatch("AT+HTTPINIT", "OK");

    Serial.println(started ? "HTTPS started" : "HTTPS start failed");
    if (!started) {
        return;
    }

    //! look into caveat for this
    ATCommandResponse setUrl = sendCommandWaitforMatch(
        String(String("AT+HTTPPARA=\"URL\",\"") + "http://" + host + resource + ":" + port + "\"").c_str(), "OK",
        1000U);

    Serial.println(setUrl ? "HTTPS URL set" : "HTTPS URL set failed");

    ATCommandResponse setContentType =
        sendCommandWaitforMatch("AT+HTTPPARA=\"CONTENT\",\"multipart/form-data; boundary=----boundary\"", "OK");

    Serial.println(setContentType ? "HTTPS Content-Type set" : "HTTPS Content-Type set failed");

    ATCommandResponse setConnTimeout = sendCommandWaitforMatch("AT+HTTPPARA=\"CONNECTTO\",20", "OK");
    ATCommandResponse setRecTimeout = sendCommandWaitforMatch("AT+HTTPPARA=\"RECVTO\",10", "OK");

    //! 153600 max size
    //  image id
    //  total size

    String imageHead = String("----boundary\r\n") +
                       "Content-Disposition: form-data; name=\"image\"; "
                       "filename=\"PotWatcherImage.jpg\"\r\nContent-Type: image/jpeg\r\n";

    String imageIdHead = String("----boundary\r\n") + "Content-Disposition: form-data; name=\"imageId\"\r\n\r\n";

    String totalSizeHead = String("----boundary\r\n") + "Content-Disposition: form-data; name=\"totalSize\"\r\n\r\n";

    String tail = "\r\n----boundary--\r\n";

    // perform POST
    Serial.println("Performing HTTP POST request...");

    size_t body_size = imageIdHead.length() + String(name).length() + totalSizeHead.length() + String(length).length() +
                       imageHead.length() + length + tail.length();

    Serial.println(String("Sending length of: ") + body_size);

    ATCommandResponse startSend =
        sendCommandWaitforMatchRetry(String(String("AT+HTTPDATA=") + body_size + ",10000").c_str(), "DOWNLOAD");

    Serial.println(String("Start send: ") + String(startSend == ATCommandResponse::Status::OK));

    Serial.println("Sending Payload");

    sendString(imageIdHead.c_str());
    sendString(name);

    sendString(totalSizeHead.c_str());
    sendString(String(length).c_str());

    sendString(imageHead.c_str());

    uint8_t *fbBuf = payload;
    size_t remaining = length;
    while (remaining > 0) {
        size_t chunkSize = std::min(remaining, (size_t)TINY_GSM_RX_BUFFER);
        sendData(fbBuf, chunkSize);
        fbBuf += chunkSize;
        remaining -= chunkSize;
    }

    Serial.println("Sending Tail");
    sendCommandWaitforMatch(tail.c_str(), "OK");

    ATCommandResponse sendRequest = sendCommandWaitforMatch("AT+HTTPACTION=1", "+HTTPACTION:", 20000U);

    ATCommandResponse readHead = sendCommandWaitforMatchRetry("AT+HTTPHEAD", "OK");

    // close https
    Serial.println("Close HTTPS session");
    ATCommandResponse close = sendCommandWaitforMatch("AT+HTTPTERM", "OK");

Output:

Closing any previous HTTPS sessions
AT+HTTPTERM
OK

starting HTTPS...
AT+HTTPINIT
OK

HTTPS started
AT+HTTPPARA="URL","http://xx.x.xx.x/api/img:3000"
OK

HTTPS URL set
AT+HTTPPARA="CONTENT","multipart/form-data; boundary=----boundary"
OK

HTTPS Content-Type set
AT+HTTPPARA="CONNECTTO",20
OK

AT+HTTPPARA="RECVTO",10
OK

Performing HTTP POST request...
Sending length of: 280
AT+HTTPDATA=280,10000
DOWNLOAD

Start send: 1
Sending Payload
Sending Tail
----boundary
Content-Disposition: form-data; name="imageId"


image12
----boundary
Content-Disposition: form-data; name="totalSize"


6
----boundary
Content-Disposition: form-data; name="image"; filename="PotWatcherImage.jpg"
Content-Type: image/jpeg

hello␀
----bo
OK

AT+HTTPACTION=1
OK





















+HTTPACTION: 1,714,0
AT+HTTPHEAD
ERROR

AT+HTTPHEAD
ERROR

AT+HTTPHEAD
ERROR

Close HTTPS session
AT+HTTPTERM
OK

Wolfleader101 avatar Jan 04 '23 01:01 Wolfleader101