Continuous Rebooting of ESP32

Hi everyone, I am trying to run my LoRa e5 and ESP32 Receiver Setup and connect it to WiFi to upload the data to the cloud. But after I reuploaded my code, my ESP32 seems to reboot continuously right after connecting to the WiFi and calling AT Commands in the void setup(). I have no idea why this happened.

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

Core  1 register dump:
PC      : 0x4008ab7d  PS      : 0x00060b30  A0      : 0x801889d9  A1      : 0x3ffb2090  
A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3ffb2190  
A10     : 0x00000002  A11     : 0x3f40a124  A12     : 0x00000002  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4008ab7d  LEND    : 0x4008ab8d  LCOUNT  : 0xffffffff  


Backtrace: 0x4008ab7a:0x3ffb2090 0x401889d6:0x3ffb20a0 0x400d2ba3:0x3ffb2160 0x400d3eda:0x3ffb2210 0x400ff3b8:0x3ffb2270 0x4008fe2a:0x3ffb2290




ELF file SHA256: f3e77edc14590df7

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:1448
load:0x40078000,len:14844
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3356
entry 0x4008059c

Above is the error message for your reference. And below is my code.

#include <ArduinoJson.h>
#include <cmath> //Library for performing Math Functions (e.g. sqrt, atan, etc.)
#include <WiFi.h>
#include<Firebase_ESP_Client.h>
#include "addons/TokenHelper.h"
#include "addons/RTDBHelper.h"

static char recv_buf[512];
static int led = 2;
int intData[7];
float floatData[7];
bool signupOK = false;

int lightSensor, pressure, year, month, day, hour, emergencyStatus;
float temp, hum, dpt, latitude, longitude, altitude, angleX, angleY;

FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;

#define WIFI_SSID "he"
#define WIFI_PASSWORD "1hantud10"
#define API_KEY "AIzaSyDncrOjQ1-EQtVWZI-Ogh7ZRLZBQEaktDQ"
#define DATABASE_URL "https://weatherdatadb-ca0a3-default-rtdb.asia-southeast1.firebasedatabase.app/"

static int at_send_check_response(char *p_ack, int timeout_ms, char *p_cmd, ...)
{
    int ch;
    int num = 0;
    int index = 0;
    int startMillis = 0;
    va_list args;
    memset(recv_buf, 0, sizeof(recv_buf));
    va_start(args, p_cmd);
    Serial2.print(p_cmd);
    Serial.print(p_cmd);
    va_end(args);
    delay(200);
    startMillis = millis();
 
    if (p_ack == NULL)
        return 0;
 
    do
    {
        while (Serial2.available() > 0)
        {
            ch = Serial2.read();
            recv_buf[index++] = ch;
            Serial.print((char)ch);
            delay(2);
        }
 
        if (strstr(recv_buf, p_ack) != NULL)
            return 1;
 
    } while (millis() - startMillis < timeout_ms);
    Serial.println();
    return 0;
}

int recvPraseInt(char *p_msg)
{
    if (p_msg == NULL)
    {
        Serial.println("Received null");
        return 0;
    }

    char *p_start = NULL;
    char data[128];       // To hold the received bytes as characters
    int bytes_len = 0;

    p_start = strstr(p_msg, "RX"); // Find the "RX" keyword in the message
    if (p_start && (1 == sscanf(p_start, "RX \"%127[^\"]\"", data)))
    {
        // Calculate the length of the hex string
        bytes_len = strlen(data);
        Serial.print("Data received as hex string: ");
        Serial.println(data);

        // Convert the hex string to an integer
        unsigned int result = 0;
        sscanf(data, "%X", &result);

        // Print the received bytes (optional, to show the bytes)
        Serial.print("Received Bytes: ");
        for (int i = 0; i < bytes_len / 2; i++)
        {
            Serial.print((result >> (8 * (bytes_len / 2 - 1 - i))) & 0xFF, HEX);
            Serial.print(" ");
        }
        Serial.println();

        return result;
    }
}

int recvPraseFloat(char *p_msg){
  if (p_msg == NULL)
    {
        Serial.println("Received null");
        return 0;
    }

    char *p_start = NULL;
    char data[128];       // To hold the received bytes as characters
    int bytes_len = 0;

    p_start = strstr(p_msg, "RX"); // Find the "RX" keyword in the message
    if (p_start && (1 == sscanf(p_start, "RX \"%127[^\"]\"", data)))
    {
        // Calculate the length of the hex string
        bytes_len = strlen(data);
        Serial.print("Data received as hex string: ");
        Serial.println(data);

        // Convert the hex string to bytes
        uint8_t bytes[4];
        sscanf(data, "%02X%02X%02X%02X", &bytes[3], &bytes[2], &bytes[1], &bytes[0]);

        // Union to convert bytes to float
        union {
            float floatValue;
            uint8_t bytes[4];
        } floatUnion;

        floatUnion.bytes[0] = bytes[0];
        floatUnion.bytes[1] = bytes[1];
        floatUnion.bytes[2] = bytes[2];
        floatUnion.bytes[3] = bytes[3];

        // Print the received float value
        Serial.print("Converted Float: ");
        Serial.println(floatUnion.floatValue);

        return floatUnion.floatValue;

    }

}
 
void setup(void)
{
    Serial.begin(115200);
    pinMode(led, OUTPUT);
    digitalWrite(led, LOW);
    Serial2.begin(9600, SERIAL_8N1, 17, 16);

    WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
    Serial.print("Connecting to WiFi");
    while (WiFi.status() != WL_CONNECTED){
      Serial.print(".");
      delay(300);
    }

  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  /* Assign the api key (required) */
  config.api_key = API_KEY;

  /* Assign the RTDB URL (required) */
  config.database_url = DATABASE_URL;

  /* Sign up */
  if (Firebase.signUp(&config, &auth, "", "")){
    Serial.println("ok");
    signupOK = true;
  }else{
    Serial.printf("%s\n", config.signer.signupError.message.c_str());
  }

  config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
  
  Firebase.begin(&config, &auth);
  Firebase.reconnectWiFi(true);

  Serial.print("Serial2 LOCAL TEST\r\n");
  at_send_check_response("+AT: OK", 100, "AT\r\n");
  delay(1000);
  at_send_check_response("+MODE: TEST", 1000, "AT+MODE=TEST\r\n");
  delay(1000);
  at_send_check_response("+TEST", 1000, "AT+TEST=RFCFG,915,SF12,125,12,15,14,ON,OFF,OFF");
  delay(1000);
  at_send_check_response("+TEST: RXLRPKT", 5000, "AT+TEST=RXLRPKT\r\n");
  delay(200);
  digitalWrite(led, HIGH);

}
 
void loop(void)
{
      
      for(int i=0; i<7; i++){

        int ret = at_send_check_response("+TEST: RX", 2000, "");

        Serial.println("Received Successfully");
        
        intData[i] = recvPraseInt(recv_buf);     

        delay(2000);
      }

      for (int i =0; i<7; i++) {
        Serial.println(intData[i]);
      }

      for(int i=0; i<7; i++){
        int ret = at_send_check_response("+TEST: RX", 2000, "");

        Serial.println("Received Successfully");
        
        intData[i] = recvPraseFloat(recv_buf);     

        delay(2000);

      }

      for (int i =0; i<7; i++) {

        Serial.println(floatData[i]);
      
      }
        
      emergencyStatus = intData[0];
      altitude = floatData[0];
      latitude = floatData[1];
      longitude = floatData[2];
      month = intData[1];
      day = intData[2];
      year = intData[3];
      hour = intData[4];
      pressure = intData[5];
      angleX = floatData[4];
      angleY = floatData[3];
      temp = floatData[5];
      hum = floatData[6];
      lightSensor = intData[6];

      float rSensor = float(1023-lightSensor)*10/lightSensor;
      Serial.print("RSensor: ");
      Serial.println(rSensor);
      dpt = temp - ((100-hum)/5);

      writetoFirebase(altitude, latitude, longitude, month, day, year, hour, pressure, angleX, angleY, temp, hum, lightSensor, dpt, emergencyStatus);

      delay(1000);
      
}

void writetoFirebase(float alt, float lat, float lng, int month, int day, int year, int hour, int pressure, float angleX, float angleY, float temp, float hum, int lightSensor, float dpt, int emergencyStatus){
  if (Firebase.ready() && signupOK){
    
    // Write altitude
    if (Firebase.RTDB.setFloat(&fbdo, "BuoyData/altitude", alt)){
      Serial.println("PASSED");
      Serial.print("Altitude:  ");
      Serial.println(alt);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write latitude
    if (Firebase.RTDB.setFloat(&fbdo, "BuoyData/latitude", lat)){
      Serial.println("PASSED");
      Serial.print("Latitude: ");
      Serial.println(lat);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write longitude
    if (Firebase.RTDB.setFloat(&fbdo, "BuoyData/longitude", lng)){
      Serial.println("PASSED");
      Serial.print("Longitude: ");
      Serial.println(lng);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write month
    if (Firebase.RTDB.setInt(&fbdo, "WeatherData/Month", month)){
      Serial.println("PASSED");
      Serial.print("Month: ");
      Serial.println(month);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write Day
    if (Firebase.RTDB.setInt(&fbdo, "WeatherData/Day", day)){
      Serial.println("PASSED");
      Serial.print("Day: ");
      Serial.println(day);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write Year
    if (Firebase.RTDB.setInt(&fbdo, "WeatherData/Year", year)){
      Serial.println("PASSED");
      Serial.print("Year: ");
      Serial.println(year);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write Hour
    if (Firebase.RTDB.setInt(&fbdo, "WeatherData/Hour", hour)){
      Serial.println("PASSED");
      Serial.print("Hour: ");
      Serial.println(hour);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write Pressure
    if (Firebase.RTDB.setInt(&fbdo, "WeatherData/Pressure", pressure)){
      Serial.println("PASSED");
      Serial.print("Pressure: ");
      Serial.println(pressure);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write AngleX
    if (Firebase.RTDB.setFloat(&fbdo, "BuoyData/AngleX", angleX)){
      Serial.println("PASSED");
      Serial.print("AngleX: ");
      Serial.println(angleX);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write AngleY
    if (Firebase.RTDB.setFloat(&fbdo, "BuoyData/AngleY", angleY)){
      Serial.println("PASSED");
      Serial.print("AngleY: ");
      Serial.println(angleY);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write Temperature
    if (Firebase.RTDB.setFloat(&fbdo, "WeatherData/Temperature", temp)){
      Serial.println("PASSED");
      Serial.print("Temperature: ");
      Serial.println(temp);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write Humidity
    if (Firebase.RTDB.setFloat(&fbdo, "WeatherData/Humidity", hum)){
      Serial.println("PASSED");
      Serial.print("Relative Humidity: ");
      Serial.println(hum);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write Light Intensity
    if (Firebase.RTDB.setInt(&fbdo, "WeatherData/Light", lightSensor)){
      Serial.println("PASSED");
      Serial.print("Light Intensity: ");
      Serial.println(lightSensor);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write DewPoint Temperature
    if (Firebase.RTDB.setFloat(&fbdo, "WeatherData/DewPoint", dpt)){
      Serial.println("PASSED");
      Serial.print("Dew Point Temperature: ");
      Serial.println(dpt);
    }
    else {
      Serial.println("FAILED");
      Serial.println("REASON: " + fbdo.errorReason());
    }

    //Write Emergency Status
    if (Firebase.RTDB.setFloat(&fbdo, "ButtonStatus/isPressed", emergencyStatus)){
          Serial.println("PASSED");
          Serial.println("PATH: " + fbdo.dataPath());
          Serial.println("TYPE: " + fbdo.dataType());
    } 
    else {
          Serial.println("FAILED");
          Serial.println("REASON: " + fbdo.errorReason());
    }

  }
}

What is the last Serial message that is printed ?

Is there a particular reason why you have swapped the RX & TX default pins for UART 2 ?

The format for the modified initialization is

Serial2.begin(BAUD, CONFIG, RXD2, TXD2);

and the default rx pin is GPIO 16 and the default tx pin is GPIO 17.

You can swap them if you like i am just curious as to why and if you connections are correct.