bigblueman
bigblueman

Reputation: 41

How to fix Guru Meditation Error: Core 1 panic'ed (LoadProhibited) error

I am trying to write code for the ESP32 chip where it takes in readings from a DHT22 sensor, packages it into a json file, and then sends it to a Flask server. Everything works just fine up until I try to POST, where I get the following error:

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

I have tried an exhaustive search on this issue to no avail, and I have no idea what is going on. Would anyone be able to give insight on how to fix this issue?

This is my Arduino code:

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

#define DHTTYPE DHT22

const char* ssid = "ssid";
const char* password = "password";

uint8_t sensor = 16;
DHT dht(sensor, DHTTYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
  WiFi.begin(ssid, password);

  while(WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting...");
  }
  Serial.println("Connected!");
}

void loop() {
  if(WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin("http://192.168.10.5:8090/");
    http.addHeader("Content-Type", "text/plain");
    Serial.println("Began http on Flask");

    const int cap = JSON_OBJECT_SIZE(2);
    StaticJsonDocument<cap> doc;
    Serial.println("Created json document");

    doc["temperature"] = dht.readTemperature();
    doc["humidity"] = dht.readHumidity();
    Serial.println("Read temperature and humidity correctly");

    char output[256];
    serializeJsonPretty(doc, output);
    Serial.println(output);
    
    //Code will give back error after trying to POST
    int httpCode = http.POST(output);
    Serial.println("Got httpCode");
    if(httpCode > 0) {
      Serial.println(httpCode);
    } else Serial.println("Error in Connection");
    http.end();
  }
  delay(10000);
}

There are print statements here that will print out various things depending on how far it gets into the code. It prints out the json document just fine, but does not print out "Got httpCode". Below is my code for the Flask server:

from flask import Flask, request
app = Flask(__name__)

@app.route('/', methods = ['POST'])
def hello():
    req = request.get_json()
    print(req)
    return "Thanks", 200

if __name__ == "__main__":
    app.run(host = '0.0.0.0', port = 8090)

Thank you in advance for the help.

Upvotes: 3

Views: 51075

Answers (4)

user28583434
user28583434

Reputation: 1

You basically get the LoadProhibited error when your accessing index or anything which is out of bound. Check for correct initialisation and definitions before accessing them.

Upvotes: 0

Miguel Tom&#225;s
Miguel Tom&#225;s

Reputation: 1911

I'm having a similar kind of error on my ESP32 libraries i've been prototyping recently (see here https://github.com/aeonSolutions/aeonlabs-ESP32-C-Base-Firmware-Libraries#readme) when I initialize the measurements class.

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

Core  1 register dump:
PC      : 0x4200a746  PS      : 0x00060b30  A0      : 0x820052d9  A1      : 0x3fcebb40  
A2      : 0x00000000  A3      : 0x3fcf30a8  A4      : 0x3fcf75c4  A5      : 0x3fcf6888  
A6      : 0x3fcf655c  A7      : 0x3c13ea43  A8      : 0x8200a746  A9      : 0x3fcebb20  
A10     : 0x00000006  A11     : 0x00000004  A12     : 0x00000078  A13     : 0x0000002c  
A14     : 0x0000002b  A15     : 0x0000e100  SAR     : 0x0000000c  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400556d5  LEND    : 0x400556e5  LCOUNT  : 0xfffffffe  


Backtrace: 0x4200a743:0x3fcebb40 0x420052d6:0x3fcebc00 0x42030726:0x3fcebc90

in EXCVADDR: 0x00000008 usually means a null pointer kind of error. Check your code for uninitialized variables.

In this particular case of mine, the MEASUREMENTS_CLASS was not initialized, and although calling a member function/method still works, the very first line of code with a variable assignment crashes the code with the error above. To solve it I only needed to initializer the class properly from:

#include "measurements.h"
MEASUREMENTS_CLASS* measurements;

to

#include "measurements.h"
MEASUREMENTS_CLASS* measurements = new MEASUREMENTS_CLASS();

Upvotes: 1

I also got this error while using WebSockets.

It turned out that the buffer(declared globally) that I used for receiving messages was appending new messages instead of overwriting the pre-existing contents in it. So, an illegal memory-write attempt was made and the device panicked and rebooted.

Solution: I simply declared the buffer locally inside the onWebSocketEvent() function and the problem of overwriting was solved as the buffer was getting re-declared on every event preventing illegal memory-write attempt. The device never panicked ever again.

Upvotes: 3

sirDeniel
sirDeniel

Reputation: 43

I experienced a Guru error in the middle of a callback, the reason for that is because the micro is running out of memory. The solution was getting rid of unused libraries and using pointers instead of creating local variables.

Upvotes: 1

Related Questions