Cannot post JSON data to node.js API with ESP32

0

I can post JSON data from Postman to node.js API, but when I post JSON data from ESP32 board I get the 400 bad request code. There is no network or firewall problem and occasionly my ESP restarts randomly during process. Down below the code about the POST process is given.

    StaticJsonDocument<200> jsonBuffer;
    jsonBuffer["esp_uuid_blue"] = "21521783";
    serializeJson(jsonBuffer, postMessage);
    delay(100);
    Serial.println(postMessage);

    http.begin("http://foo:3001");  
    http.addHeader("Content-Type", "application/json");
    Serial.println("Debugger");
    int httpResponseCode = http.POST(postMessage);
    Serial.println("Debugger2");
    if (httpResponseCode > 0) {

      String response = http.getString(); //Get the response to the request

      Serial.println(httpResponseCode);   //Print return code
      Serial.println(response);           //Print request answer

    } else {

      Serial.print("Error on sending POST: ");
      Serial.println(httpResponseCode);

    }

Output from Serial

{"esp_uuid_blue":"21521783"}
Debugger
Debugger2
400

Output from Serial, sometimes restart occurs.

{"esp_uuid_blue":"21521783"}
Debugger
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d28c0  PS      : 0x00060030  A0      : 0x800d2994  A1      : 0x3ffb1c30  
A2      : 0x00000000  A3      : 0x3ffb1c7f  A4      : 0x00000001  A5      : 0x00000001  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x00000000  
A10     : 0x00000000  A11     : 0x3ffc85dc  A12     : 0x00000050  A13     : 0x0000ff00  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000008  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

Backtrace: 0x400d28c0:0x3ffb1c30 0x400d2991:0x3ffb1c50 0x4015cd72:0x3ffb1c70 0x400d5b11:0x3ffb1ca0 0x400d5ba9:0x3ffb1cc0 0x400d426e:0x3ffb1ce0 0x400d4a23:0x3ffb1d70 0x400d4a77:0x3ffb1db0 0x400d4a9d:0x3ffb1dd0 0x400d24f6:0x3ffb1df0 0x400d73b1:0x3ffb1fb0 0x400885fd:0x3ffb1fd0

Rebooting...

I am sure everything is working fine about API and I can post from Postman or from different IP's. Can you help me?

json
http
post
arduino
asked on Stack Overflow Sep 7, 2019 by Emre Kiratli

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0