ESP32: abort() was called at PC

Hi guys, I've been attempting at reading from a POST request via an API using ESP32 Wrover.

But after each read, the chip reboots.

Here's the error message:

abort() was called at PC 0x4016512a on core 1

Backtrace: 0x400838bd:0x3ffb2080 0x4008efc9:0x3ffb20a0 0x40094341:0x3ffb20c0 0x4016512a:0x3ffb2140 0x400d2d62:0x3ffb21e0 0x400d2e2d:0x3ffb2250 0x400e8e59:0x3ffb2290

ELF file SHA256: b1c15bf399b45d38

Rebooting...

ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0xee

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:1

load:0x3fff0030,len:1344

load:0x40078000,len:13964

load:0x40080400,len:3600

entry 0x400805f0

Here's the code:

#include <WiFiManager.h>  
#include <string.h>
#include <WiFiClient.h>
//#include <time.h>
#include <stdlib.h>
#include <ArduinoJson.h>
#include <HTTPClient.h>


String response;


void init_WiFi() {
  WiFi.mode(WIFI_STA);  // explicitly set mode, esp defaults to STA+AP
  // it is a good practice to make sure your code sets wifi mode how you want it.

  // put your setup code here, to run once:


  //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wm;


  // reset settings - wipe stored credentials for testing
  // these are stored by the esp library
  //wm.resetSettings();

  // Automatically connect using saved credentials,
  // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
  // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
  // then goes into a blocking loop awaiting configuration and will return success result

  bool res;
  // res = wm.autoConnect(); // auto generated AP name from chipid
  // res = wm.autoConnect("AutoConnectAP"); // anonymous ap
  res = wm.autoConnect("Vortex", "123");  // password protected ap

  if (!res) {
    Serial.println("Failed to connect");
    // ESP.restart();
  } else {
    //if you get here you have connected to the WiFi
    Serial.print("Connected to: ");
    Serial.println(WiFi.SSID());
    Serial.println("connected...yeey :)");
  }
}





HTTPClient http;
// Define the JSON body
String jsonBody = 
  "{"
    "\"Inputs\": {"
      "\"WebServiceInput0\": ["
        "{"
          "\"symboling\": 3,"
          "\"normalized-losses\": 1.0,"
          "\"make\": \"alfa-romero\","
          "\"fuel-type\": \"gas\","
          "\"aspiration\": \"std\","
          "\"num-of-doors\": \"two\","
          "\"body-style\": \"convertible\","
          "\"drive-wheels\": \"rwd\","
          "\"engine-location\": \"front\","
          "\"wheel-base\": 88.6,"
          "\"length\": 168.8,"
          "\"width\": 64.1,"
          "\"height\": 48.8,"
          "\"curb-weight\": 2548,"
          "\"engine-type\": \"dohc\","
          "\"num-of-cylinders\": \"four\","
          "\"engine-size\": 130,"
          "\"fuel-system\": \"mpfi\","
          "\"bore\": 3.47,"
          "\"stroke\": 2.68,"
          "\"compression-ratio\": 9,"
          "\"horsepower\": 111,"
          "\"peak-rpm\": 5000,"
          "\"city-mpg\": 21,"
          "\"highway-mpg\": 27"
        "}"
      "]"
    "},"
    "\"GlobalParameters\": {}"
  "}";




String API_Read() {
  Serial.println("Log: API reading..");

  String serverPath = "(redacted)/score";
  http.begin(serverPath);

  // Set the header
  String Auth = "(redacted)";
  http.addHeader("Authorization", "Bearer " + Auth);
  http.addHeader("Content-Type", "application/json");


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

  if (httpResponseCode > 0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    String payload = http.getString();
    Serial.println("Log: Response: " + payload);
    Serial.println("Log: Data successfully retrieved.");
    //delay(5000);
    yield();
  } else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }

  // Free resources
  http.end();
  Serial.println("Log: Http request end.");
  //delay(5000);
  yield();
}

Here's the main code:

#include "WiFiManager.h"
#define Indicator 2



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



void loop() {
  
  Serial.println(API_Read());
  delay(5000);
}

Can anyone point out any mistakes in my handling?

Thanks.
Vizier87

String serverPath = (redacted)/score";

initial quotes are missing

Oh, I assure you that's not the problem. The code was edited out for privacy purposes, but the quotes are paired actually in the original code. Thanks for the reply though.

I edited the original post anyway just to avoid confusion.

Well, good news. Using PlatformIO via VSCode helped by pointing out issues with the code. It turns out the function I used should have a return value... But it compiled anyway in the ARduino IDE.

Phew.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.