POST request ESP32 with SIM7000

JGLJGL
Posts: 2
Joined: Mon Dec 09, 2019 9:06 am

POST request ESP32 with SIM7000

Postby JGLJGL » Sun Dec 29, 2019 9:34 am

Hi, I'm new and not able to make a POSTt request.
I'm working with the arduino IDE and attached to the ESP32 a SIM7000E.
I 've tried the "SIM7000-LTE-Shield-master"->"ESP32_LTE_Demo" , but not being able to make it work (POST request).

Here it is what I have:
Code:

Code: Select all

void loop() {

 Serial.print(F("FONA> "));
 
  while (! Serial.available() ) {
    if (fona.available()) {
      Serial.write(fona.read());
    }
  }
          // Post data to website
  
        uint16_t statuscode;
        int16_t length;
        char url[150];
        char data[150];


        flushSerial();
        Serial.println(F("NOTE: in beta! Use simple websites to post!"));
        Serial.println(F("URL to post (e.g. httpbin.org/post):"));
        Serial.print(F("http://")); readline(url, 79);
        Serial.println(url);
        Serial.println(F("Data to post (e.g. \"foo\" or \"{\"simple\":\"json\"}\"):"));
        readline(data, 79);
        Serial.println(data);

        Serial.println(F("****"));
        if (!fona.HTTP_POST_start(url, F("text/plain"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
          Serial.println("Failed!");

        }
        while (length > 0) {
          while (fona.available()) {
            char c = fona.read();

#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
            loop_until_bit_is_set(UCSR0A, UDRE0); // Wait until data register empty.
            UDR0 = c;
#else
            Serial.write(c);
#endif

            length--;
            if (! length) break;
          }
        }
        Serial.println(F("\n****"));
        fona.HTTP_POST_end();
        

      
// flush input
  flushSerial();
  while (fona.available()) {
    Serial.write(fona.read());
  }
}
Serial monitor response:

Code: Select all

12:10:28.794 -> NOTE: in beta! Use simple websites to post!
12:10:28.794 -> URL to post (e.g. httpbin.org/post):
12:10:28.794 -> http://www.atesens.com/post
12:10:40.286 -> Data to post (e.g. "foo" or "{"simple":"json"}"):
12:10:43.242 -> password
12:10:43.242 -> ****
12:10:43.276 ->     ---> AT+HTTPTERM
12:10:43.311 ->     <--- OK
12:10:43.346 ->     ---> AT+HTTPINIT
12:10:43.381 ->     <--- OK
12:10:43.416 ->     ---> AT+HTTPPARA="CID"
12:10:43.449 ->     <--- OK
12:10:43.482 ->     ---> AT+HTTPPARA="UA"
12:10:43.515 ->     <--- OK
12:10:43.582 ->     ---> AT+HTTPPARA="URL"
12:10:43.615 ->     <--- OK
12:10:43.649 ->     ---> AT+HTTPPARA="REDIR"
12:10:43.682 ->     <--- OK
12:10:43.751 ->     ---> AT+HTTPSSL=1
12:10:43.785 ->     <--- ERROR
12:10:43.785 -> Failed!

Who is online

Users browsing this forum: No registered users and 43 guests