esp32 crushes constantly on http.POST

BBBaruch
Posts: 2
Joined: Tue Jun 01, 2021 12:08 pm

esp32 crushes constantly on http.POST

Postby BBBaruch » Tue Jun 01, 2021 12:21 pm

Hi,
I'm new to arduino and don't realy know how to debug my issue.
I have an ESP32-WROOM-32, and trying to send data to mysql DB through php web page.
The arduino crushes and restarting when getting to the http.POST command. (when I removing this command it dosent crush)
and the post command works fine from the PC.

I'm adding my code that I gethered on the web.

Code: Select all

#include <WiFi.h>
#include <HTTPClient.h>

const char* ssid     = "ssid";
const char* password = "password";
const char* serverName = "myIP/post-esp-data.php";
String apiKeyValue = "eF5Aj53b3j84A";

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  //Check WiFi connection status
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;

    // Your Domain name with URL path or IP address with path
    http.begin(serverName);

    // Specify content-type header
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");

    // Prepare your HTTP POST request data
    String httpRequestData = "api_key=" + apiKeyValue + "&in1=" + "1"
                             + "&in2=" + "1" + "&in3=" + "1" + "";
    Serial.print("httpRequestData: ");
    Serial.println(httpRequestData);

    // Send HTTP POST request
    int httpResponseCode = http.POST(httpRequestData);

    if (httpResponseCode > 0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    // Free resources
    http.end();
  }
  else {
    Serial.println("WiFi Disconnected");
  }
  //Send an HTTP POST request every 30 seconds
  delay(2000);
}
and there is the debug info

Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400d3b6a PS : 0x00060430 A0 : 0x800d3bf8 A1 : 0x3ffb1e10
A2 : 0x3ffb1f14 A3 : 0x00000000 A4 : 0x000000ff A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00000000 A9 : 0x3ffb1df0
A10 : 0x3ffb1e1c A11 : 0x00000000 A12 : 0x0000002f A13 : 0x00000000
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x00000018 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x400013f9 LEND : 0x4000140d LCOUNT : 0xfffffff6

Backtrace: 0x400d3b6a:0x3ffb1e10 0x400d3bf5:0x3ffb1e40 0x400d3cb3:0x3ffb1e80 0x400d3ccc:0x3ffb1ea0 0x400d1d3e:0x3ffb1ec0 0x400d5508:0x3ffb1fb0 0x40088f6d:0x3ffb1fd0

PC: 0x400d3b6a: HTTPClient::connect() at C:\Users\YedaENG1\AppData\Local\Arduino15\packages\industrialshields\hardware\esp32\1.1.2\libraries\HTTPClient\src\HTTPClient.cpp line 984
EXCVADDR: 0x00000000

Decoding stack results
0x400d3b6a: HTTPClient::connect() at C:\Users\YedaENG1\AppData\Local\Arduino15\packages\industrialshields\hardware\esp32\1.1.2\libraries\HTTPClient\src\HTTPClient.cpp line 984
0x400d3bf5: HTTPClient::sendRequest(char const*, unsigned char*, unsigned int) at C:\Users\YedaENG1\AppData\Local\Arduino15\packages\industrialshields\hardware\esp32\1.1.2\libraries\HTTPClient\src\HTTPClient.cpp line 537
0x400d3cb3: HTTPClient::POST(unsigned char*, unsigned int) at C:\Users\YedaENG1\AppData\Local\Arduino15\packages\industrialshields\hardware\esp32\1.1.2\libraries\HTTPClient\src\HTTPClient.cpp line 478
0x400d3ccc: HTTPClient::POST(String) at C:\Users\YedaENG1\AppData\Local\Arduino15\packages\industrialshields\hardware\esp32\1.1.2\libraries\HTTPClient\src\HTTPClient.cpp line 483
0x400d1d3e: loop() at C:\Users\YedaENG1\Documents\iduino\test_wifi_IS/test_wifi_IS.ino line 41
0x400d5508: loopTask(void*) at C:\Users\YedaENG1\AppData\Local\Arduino15\packages\industrialshields\hardware\esp32\1.1.2\cores\industrialshields\main.cpp line 37
0x40088f6d: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143

any help and explanation will really help. Thanks

lbernstone
Posts: 666
Joined: Mon Jul 22, 2019 3:20 pm

Re: esp32 crushes constantly on http.POST

Postby lbernstone » Tue Jun 01, 2021 3:43 pm

HTTPClient::begin expects a URL, not a bare server name. It uses the protocol to determine which port to use.

BBBaruch
Posts: 2
Joined: Tue Jun 01, 2021 12:08 pm

Re: esp32 crushes constantly on http.POST

Postby BBBaruch » Wed Jun 02, 2021 5:35 am

Thanks alot.
That really helped.

Who is online

Users browsing this forum: Google [Bot] and 60 guests