Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandle

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d1de0  PS      : 0x00060630  A0      : 0x800d1eb4  A1      : 0x3ffb1cd0  
A2      : 0x00000000  A3      : 0x3ffb1d1f  A4      : 0x00000001  A5      : 0x00000001  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x00000000  
A10     : 0x00000000  A11     : 0x3ffcbc7c  A12     : 0x00000050  A13     : 0x00000001  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000008  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

Backtrace: 0x400d1de0:0x3ffb1cd0 0x400d1eb1:0x3ffb1cf0 0x4015bfe2:0x3ffb1d10 0x400d5065:0x3ffb1d40 0x400d50fd:0x3ffb1d60 0x400d36a1:0x3ffb1d80 0x400d3b9f:0x3ffb1e20 0x400d3bef:0x3ffb1e60 0x400d3c13:0x3ffb1e80 0x400d19d2:0x3ffb1ea0 0x400d1b75:0x3ffb1f90 0x400d5f9d:0x3ffb1fb0 0x40088f69:0x3ffb1fd0

Rebooting...

Platform: WEMOS LOLIN32

Source code:

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

int ldr = 32; // Analog

long t = 0;

// Sensor variables
long lastBlink = 0;
int threshold = 512; // Arbitrary so far...
float duration = 0;
float W = -1.0;

// WiFi variables
const char* ssid = // MY SSID
const char* password = // MY PASSWORD
const char* serverName = // MY API ENDPOINT (POST)

int ldrValue = 0;

void setup() {
  WiFi.disconnect();
  Serial.begin(9600);

  WiFi.begin(ssid, password);
  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() {
  if (millis() - lastBlink > 1000) {
    ldrValue = analogRead(ldr);
    Serial.println(ldrValue);
    if (ldrValue > threshold) {
      t = millis(); // Freeze time.
      duration = (t - lastBlink) / 1000.0; // Calculate the time difference in seconds.
      lastBlink = t; // Update last blink time.

      // Calculate AVERAGE wattage since last blink.
      W = 3600.0 / (float)duration;
      
      print_power(duration, W);
      post(duration, W);
    }
  }
}

void print_power(float duration, float W) {
  Serial.print("Average power consumption for the last ");
  Serial.print(duration);
  Serial.print(" seconds was ");
  Serial.println(W);
}

void post(float duration, float W) {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin(serverName);
    http.addHeader("Content-Type", "application/json");

    String json = "{\"power\":";
    json += (int)W;
    json += "}";

    Serial.print("JSON = ");
    Serial.println(json);

    int httpResponseCode = http.POST(json);

    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);

    http.end();
  } else {
    Serial.println("WiFi Disconnected");
  }
}

I have a simple LDR hooked up to GPIO 32 and 3V to measure whenever a light pulse comes in. This works fine for an arbitrary (low) number of times, usually less than ten. It prints the JSON fine, the request is received on the server and the reply is processed fine by the ESP. But at some point it throws the error above. I’ve read things about watchdogs, stating that loops shouldn’t be frozen too long, but I don’t that is the cause here. Also I don’t think I have uninitialised variables causing a null pointer exception.

Any help would be greatly appreciated.

If you do not get help in a timely manner, Google “Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled”. I get over 2000 hits. Maybe the answer is there.

groundFungus:
If you do not get help in a timely manner, Google "Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled". I get over 2000 hits. Maybe the answer is there.

Thanks but I already cleared the entire front page, which is why I could rule out the Null Pointer Exception and loop freeze.

long t = 0;

// Sensor variables
long lastBlink = 0;

Likely not your problem, but all variables involved in millis() work should be unsigned long. Or, more explicitly uint32_t.

No one has a reply to this? Seems a fairly common issue on the internet.

Have you tried to decode the backtrace in order to find the code which causes the error?

You could try the Expressif forums if your in a hurry, they wrote the ESP32 Core for the Arduino IDE, so they ought to support it.