Kernel panic. Never happened with Arduino. Confused

Milando
Posts: 2
Joined: Sun Apr 25, 2021 4:40 pm

Kernel panic. Never happened with Arduino. Confused

Postby Milando » Sun Apr 25, 2021 5:09 pm

Hi. I am new to the esp32. I figured I would never use an Arduino again if I can have so much more power and features in the esp32. However, when I wrote a sketch to power my x10 home security system I get kernel panics (and some unexpected behavior like a routine to inexplicably change, as if I pressed a button). This is a two part question: 1) are the Arduino chips superior in stability? I have never had a kernel panic on an Arduino. If the sketch loads, it runs. If yes, I am going back to arduino 2) looking at my code below, does anyone see a reason why it would panic or why a sub-routine initiated by a button press would turn itself off? Thank you kindly. PS: I am using the Arduino IDE.
PS: This idiotic forum does limit size so I have to post my code in 2 postings

Code: Select all

#include <ESP32Time.h>
ESP32Time rtc;

#include <x10.h>
#include <x10constants.h>


#define zcPin 2//2
#define dataPin 19//13
#define repeatTimes 2

x10 myHouse;

int switch1Pin = 18;//23;
int switch2Pin = 5;//33;
int switch3Pin = 17;//25;

int led = 4;//27;
int led2 = 0;//14;
volatile int blinkToken = 0;
int var = 0;
int varMonths = 0;
int varHour = 0;

void patternHome1() {/*MAKE THINNER*/
  Serial.println("patterhome1 started");
  if ((varHour == 0) && (rtc.getMinute() == 31)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }
  if ((varHour == 0) && (rtc.getMinute() == 32)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }
  if ((varHour == 0) && (rtc.getMinute() == 37)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
    myHouse.write(HOUSE_B, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
  }
  if ((varHour == 0) && (rtc.getMinute() == 42)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }
  if ((varHour == 0) && (rtc.getMinute() == 43)) {
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }

  if ((varHour == 0) && (rtc.getMinute() == 44)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
  }
  if ((varHour == 1) && (rtc.getMinute() == 14)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
    myHouse.write(HOUSE_B, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
  }
  if ((varHour == 1) && (rtc.getMinute() == 18)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }
  if ((varHour == 1) && (rtc.getMinute() == 40)) {
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
    myHouse.write(HOUSE_B, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
  }

  if ((varHour == 2) && (rtc.getMinute() == 11)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
  }
  if ((varHour == 2) && (rtc.getMinute() == 17)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
  }

  if ((varHour == 2) && (rtc.getMinute() == 32)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }

  if ((varHour == 2) && (rtc.getMinute() == 33)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }

  if ((varHour == 4) && (rtc.getMinute() == 13)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
  }
  if ((varHour == 4) && (rtc.getMinute() == 16)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
  }

  if ((varHour == 4) && (rtc.getMinute() == 26)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }

  if ((varHour == 4) && (rtc.getMinute() == 28)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }

  if ((varHour == 6) && (rtc.getMinute() == 55)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }

  if ((varHour == 7) && (rtc.getMinute() == 12)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }

  if ((varHour == 7) && (rtc.getMinute() == 37)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }

  if ((varHour == 7) && (rtc.getMinute() == 42)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }

  if ((varHour == 8) && (rtc.getMinute() == 4)) {
  }

  if ((varHour == 20) && (rtc.getMinute() == 2)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
  }

  if ((varHour == 20) && (rtc.getMinute() == 7)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
    myHouse.write(HOUSE_B, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
  }

  if ((varHour == 20) && (rtc.getMinute() == 23)) {
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }

  if ((varHour == 20) && (rtc.getMinute() == 51)) {
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }

  if ((varHour == 21) && (rtc.getMinute() == 13)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
    myHouse.write(HOUSE_B, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
  }

  if ((varHour == 21) && (rtc.getMinute() == 34)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
  }
  if ((varHour == 21) && (rtc.getMinute() == 48)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, ON, repeatTimes);
  }
  if ((varHour == 21) && (rtc.getMinute() == 51)) {
    myHouse.write(HOUSE_A, UNIT_1, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }

  if ((varHour == 23) && (rtc.getMinute() == 36)) {
    myHouse.write(HOUSE_A, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_A, OFF, repeatTimes);
  }

  if ((varHour == 23) && (rtc.getMinute() == 51)) {
    myHouse.write(HOUSE_B, UNIT_2, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, OFF, repeatTimes);
  }

  if ((varHour == 23) && (rtc.getMinute() == 56)) {
    myHouse.write(HOUSE_B, UNIT_3, repeatTimes);
    myHouse.write(HOUSE_B, ON, repeatTimes);
  }
}

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Kernel panic. Never happened with Arduino. Confused

Postby ESP_Sprite » Mon Apr 26, 2021 4:11 am

I have put your code inside a code block and I've removed your other two topics. Frankly, if your code exceeds the forum posting limit, you should really re-think the way you're writing it. This goes double because you're presumably hoping people will go through it to see what you did wrong. In case you absolutely are not willing to refactor it, I suggest you post it on pastebin.com or some other file hoster, or to attach the sources to your post as an attachment (though you may need more posts here before that's enabled).

Yes, the ESP32 has hardware in it that is able to spot that your code is doing something wrong and it will throw a panic then. Arduino (as in: Arduino Uno, the common devboard using an AVR processor) does not have this hardware, so your software is free to act up, with undefined effects: with a bit of luck, your code mangles some unused memory and everything will keep on running; with less luck, some important memory gets subtly corrupted causing some very hard to trace bugs a long time later. As we have the hardware for it, we prefer to throw a panic as it makes it much clearer something is going wrong and much easier to track back the problem to its source.

Milando
Posts: 2
Joined: Sun Apr 25, 2021 4:40 pm

Re: Kernel panic. Never happened with Arduino. Confused

Postby Milando » Thu May 06, 2021 2:24 pm

Thank you for your very useful reply. I now understand that the Arduino is not superior to the ESP32 but that I have only been lucky not to have had any issues ever. One suggestion I would like to make is to fix the Arduino IDE to only allow code to be uploaded to the ESP32 which is perfect. That would eliminate any kernel panics. I wish I could switch all my projects to ESP32 only but I do not know how to avoid kernel panics and, as mentioned, I never had an issue with Arduino. In fact, I switched this project over to the Arduino and it runs flawlessly. Not sure what to say but appreciating of all comments addressing this dilemma less experienced people like me have. Thanks again.

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

Re: Kernel panic. Never happened with Arduino. Confused

Postby lbernstone » Thu May 06, 2021 4:52 pm

We are working on a wetware upgrade. Once complete, you will receive an invitation for OEM upgrades at your local Soylent Industries facility.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Kernel panic. Never happened with Arduino. Confused

Postby ESP_Sprite » Fri May 07, 2021 12:07 am

That would eliminate any kernel panics.
You seem to view kernel panics as bad. We view it as preferable to hard-to-find errors that result in undefined behaviour and uncaught bugs that can lead to remotely exploitable devices (as most ESP devices will end up connected to the Internet).

Who is online

Users browsing this forum: No registered users and 62 guests