How can I include a body while sending a POST request using HTTP AT commands with a SIM7000A module and an Arduino?

  arduino, at-command, c++, http

I’m crossposting this from where I posted it on the Arduino forum in hopes that maybe someone here has an answer. I am working on a project that involves sending POST requests to a Twilio function using an Arduino Uno and a SIMCOM SIM7000A breakout board using AT commands. So far with the Uno, I can only POST an empty request that contains headers but no body. The following code is a test sketch where I am POSTing to a RequestBin repository.

#include <AltSoftSerial.h>

unsigned char data = 0;
AltSoftSerial SIM7000;
char incomingChar;


void setup() {

  Serial.begin(9600);
  SIM7000.begin(19200);

  // put your setup code here, to run once:
  SIM7000.print("AT+CMGF=1r");  //put in text mode
  delay(100);
  SIM7000.print("AT+CGDCONT=1"IP","super"r"); //create profile.  "super" is APN for twilio super sim
  delay(1000);
  SIM7000.print("AT+COPS=1,2,"310410"r"); //log on to AT&T network
  delay(5000);
  SIM7000.print("AT+SAPBR=3,1,"APN","super"r"); //create SAPBR profile.  same APN.
  delay(300);
  SIM7000.print("AT+SAPBR=1,1r");
  delay(2000);
  Serial.println("Setup complete.  Module should be online and fast-blinkingn from successful SAPBR profile setup.n Entering loop.  Send "CHECK" to test POST");
}

void loop() {


  SIM7000.print("AT+CMGLr");

  if (SIM7000.available() > 0) {
    incomingChar = SIM7000.read();
    if (incomingChar == 'C') {
      delay(10);
      Serial.print(incomingChar);
      incomingChar = SIM7000.read();
      if (incomingChar == 'H') {
        delay(10);
        Serial.print(incomingChar);
        incomingChar = SIM7000.read();
        if (incomingChar == 'E') {
          delay(10);
          Serial.print(incomingChar);
          incomingChar = SIM7000.read();
          if (incomingChar == 'C') {
            delay(10);
            Serial.print(incomingChar);
            incomingChar = SIM7000.read();
            if (incomingChar == 'K') {
              delay(10);
              Serial.print(incomingChar);
              incomingChar = "";
              Serial.println(F("nGOOD CHECK"));
              Serial.println(F("SENDING POST REQUEST NOW")) ;
              sendText();
              Serial.println("POST SENT");
              return;
            }
          }
        }
      }
    }
  }
  incomingChar = "";
  return;
}

void sendText()
{


  SIM7000.print("AT+HTTPINITr");
  delay(1000);
  getResponse();
  SIM7000.print("AT+HTTPPARA="CID",1r");
  delay(1000);
  getResponse();
  SIM7000.print("AT+HTTPPARA="URL","http://engt62k9mgbgo.x.pipedream.net"r");
  delay(1000);
  getResponse();
  SIM7000.print("AT+HTTPPARA="CONTENT","text/plain"r");
  delay(1000);
  getResponse();
  SIM7000.print("AT+HTTPDATA=100,5000rn");
  delay(100);
  getResponse();
  SIM7000.print(""TEST MESSAGE"rn");
  SIM7000.print("rn");
  delay(5000);
  getResponse();
  SIM7000.print("AT+HTTPACTION=1r");
  delay(1000);
  getResponse();
  SIM7000.print("AT+HTTPTERMr");
  getResponse();
}

void getResponse()
{
  if (SIM7000.available())
  {
    while (SIM7000.available())
    {
      data = SIM7000.read();
      Serial.write(data);
    }
    data = 0;
  }
}
//NOV 3 2020, note: need to include AT command AT+CMGD=0,4 for routinely deleting messages
//message storage limited and not automatically overwritten

I’ve included the output on the Serial monitor below.

Output on Serial Monitor

I’m thinking that the problem lies between

SIM7000.print("AT+HTTPDATA=100,5000rn");

and

SIM7000.print("AT+HTTPACTION=1r");

You can see on the output where it prompts for DOWNLOAD, but the "TEST MESSAGE" that I try to insert here doesn’t go. I’ve also attached a screenshot of the RequestBin output to show that it’s showing up as an empty POST with nothing but headers and a content length of 0. Output in RequestBin

When I’ve done similar POST requests using the same SIM7000A module with the same AT commands on PuTTY via USB, all I have to do is enter my text during the time specified in the AT+HTTPDATA command and hit enter. Whatever I enter during that time as it says "DOWNLOAD" shows up as the body of my POST. But I have as of yet been unable to do the same using the Uno.
Any help you can offer is much appreciated.

Source: Windows Questions C++

LEAVE A COMMENT