Seithan / EasyNextionLibrary

A simple library for Nextion display that uses only four functions. You can easily benefit from Nextion's wide range of features and advantages in just a few easy steps. The library uses a custom protocol that can prove to be a powerful tool for advanced users as it can be easily modified to meet one’s needs.
MIT License
117 stars 30 forks source link

ESP32 reboots #61

Open puhycz opened 1 year ago

puhycz commented 1 year ago

Hello,

I use EasyNextionLibrary for connect ESP32 with Nextion display. It crashes when I press touch buttons. One or two press is ok, but many presses or quick press again crash. I call myNex.NextionListen(); every 50ms.

Thanks, Jan.

Debug trace:

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

Core 1 register dump: PC : 0x00000000 PS : 0x00060130 A0 : 0x800fd058 A1 : 0x3ffd7e30 A2 : 0x3ffc88d8 A3 : 0x0001303d A4 : 0x00013080 A5 : 0x00060123
A6 : 0x00060120 A7 : 0x00000001 A8 : 0x800fd07c A9 : 0x00000054 A10 : 0x00000001 A11 : 0x3ffd7e2f A12 : 0x00000001 A13 : 0x10624dd3
A14 : 0x00000001 A15 : 0x003fffff SAR : 0x0000000a EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x40090f84 LEND : 0x40090f8e LCOUNT : 0x00000000

Backtrace: 0xfffffffd:0x3ffd7e30 0x400fd055:0x3ffd7e50 0x400dd11d:0x3ffd7e70

0 0xfffffffd:0x3ffd7e30 in ?? ??:0

1 0x400fd055:0x3ffd7e50 in EasyNex::NextionListen() at lib/Easy Nextion Library/src/EasyNextionLibrary.cpp:340

2 0x400dd11d:0x3ffd7e70 in nextionUpdate(void*) at src/thread_nextionUpdate.cpp:348

ELF file SHA256: e10a9f359f05384c

E (6371) esp_core_dump_flash: Core dump flash config is corrupted! CRC=0x7bd5c66f instead of 0x0 Rebooting... ets Jun 8 2016 00:22:57

`void nextionUpdate(void* pvParameters) { for (;;) {
nexChange=0; myNex.NextionListen();
cntNextion++; if (cntNextion == 1) {
if (getNexBl()) { myNex.writeNum("dim", MAX_NEXTION_BACKLIGHT); } else { if (nexBlTimer > 0) { int dimmerShadow = map(nexBlTimer, 0, MAX_NEXTION_BACKLIGHT_TIMER, 0, MAX_NEXTION_BACKLIGHT); myNex.writeNum("dim", dimmerShadow); } else { myNex.writeNum("dim", 0); nexBlTimer = 0; } nexBlTimer--; } }

    if (cntNextion == 2&&nexChange!=11) {
        myNex.writeNum("t1.bco", thermostat_getD() ? 64512 : 65535); // doma
        myNex.writeNum("t3.bco", thermostat_getK() ? 64512 : 65535); // kancelar
        myNex.writeStr("t4.txt", String(temperature_get(ID_CIDLA_REG), 2) + String(" °C")); // doma
        myNex.writeStr("t5.txt", String(temperature_get(ID_CIDLA_EKV), 2) + String(" °C")); // venku
        myNex.writeStr("t6.txt", String(temperature_get(ID_CIDLA_KANCELAR), 2) + String(" °C")); // kamcelar            
    }
    if (cntNextion == 3&&nexChange!=11) {
        myNex.writeStr("t11.txt", String(getAqIn()) + " AQI"); // AQI IN
        myNex.writeStr("t10.txt", String(getAqOut()) + " AQI"); // AQI OUT
        myNex.writeNum("t11.bco", aqiIndexColor(getAqIn())); // AQi IN COLOR
        myNex.writeNum("t10.bco", aqiIndexColor(getAqOut())); // AQi OUT COLOR
        myNex.writeStr("t13.txt", getWindString());
        myNex.writeStr("t14.txt", (String(getSpotreba()) + String("W")));
        myNex.writeStr("t15.txt", FVEPretok() ? String("je přebytek") : String("není přebytek"));
        myNex.writeNum("t15.bco", FVEPretok() ? 2016 : 63488);            
    }
    if (cntNextion == 4||nexChange==11) {            
        myNex.writeStr("t16.txt", String(thermostat_get_temperatureD()) + String(" °C"));
        myNex.writeStr("t18.txt", String(thermostat_get_temperatureK()) + String(" °C"));            
    }
    if (cntNextion == 5&&nexChange!=11) {
        myNex.writeStr("t42.txt", String(temperature_get(ID_CIDLA_AND), 2) + String(" °C"));
        myNex.writeStr("t43.txt", String(temperature_get(ID_CIDLA_ANN), 2) + String(" °C"));
        myNex.writeStr("t44.txt", String(temperature_get(ID_CIDLA_ANS), 2) + String(" °C"));
        myNex.writeNum("j1.val", natopeniAN());
        myNex.writeStr("t23.txt", HDOStatus() ? "HDO levný" : "HDO drahý");
        myNex.writeNum("t23.bco", HDOStatus() ? 13633 : 65000);
        myNex.writeStr("t12.txt", return_realTime());
        myNex.writeStr("t21.txt", topit() ? String("Topit") : String("Netopit"));            
    }
    if (cntNextion == 6&&nexChange!=11) {
        // plasty / komunal
        if (getGlobalDayNumber() == 2 || getGlobalDayNumber() == 3) {
            if (getGlobalWeekNumber() % 2 == 0) {
                myNex.writeStr("t24.txt", "Plasty");
                myNex.writeNum("t24.bco", 65504); //žlutá

            } else {
                myNex.writeStr("t24.txt", "Komunál");
                myNex.writeNum("t24.bco", 50712); //šedá
            }

        } else {
            myNex.writeStr("t24.txt", "");
            myNex.writeNum("t24.bco", 65535); // bílá
        }

        if (getGlobalPaper()) {
            myNex.writeStr("t25.txt", "Papír");
            myNex.writeNum("t25.bco", 1055); // modrá
        } else {
            myNex.writeStr("t25.txt", "");
            myNex.writeNum("t25.bco", 65535);
        }

        if (getGlobalBio()) {
            myNex.writeStr("t26.txt", "Bio");
            myNex.writeNum("t26.bco", 41605); // hnědá
        } else {
            myNex.writeStr("t26.txt", "");
            myNex.writeNum("t26.bco", 65535);
        }            
    }
    if (cntNextion == 7&&nexChange!=11) {
        myNex.writeStr("t27.txt", String("Týden ") + getGlobalWeekNumber());
        myNex.writeStr("t28.txt", return_weekDay());
        myNex.writeNum("j0.val", natopeniTUV());
        myNex.writeStr("t40.txt", String(temperature_get(ID_CIDLA_TUVD), 2) + String(" °C"));
        myNex.writeStr("t41.txt", String(temperature_get(ID_CIDLA_TUVN), 2) + String(" °C"));            
    }
    if (cntNextion == 8) {

        String kdoTopi = "Netopí se";

        if (topiKrb()) {
            kdoTopi = "Krb topí";
        }
        if (topiPlyn()) {
            kdoTopi = "Plyn topí";
        }
        if (antFast()) {
            kdoTopi = "A. nádrž topí";
        }
        if (antFast() && topiKrb()) {
            kdoTopi = "Krb a AN topí";
        }
        myNex.writeStr("t22.txt", kdoTopi);

        myNex.writeNum("t29.bco", ventilKRBState() ? 13633 : 65535);
        myNex.writeNum("t30.bco", ventilTUVState() ? 13633 : 65535);
        myNex.writeNum("t37.bco", ventilANState() ? 13633 : 65535);
        myNex.writeNum("t38.bco", cerpadloANStatus() ? 13633 : 65535);
        myNex.writeStr("t39.txt", String((int)ekvitherm()) + "/" + String((int)temperature_get(ID_CIDLA_OVZC)) + "/" + String((int)temperature_get(ID_CIDLA_KRBVODA)));
        myNex.writeNum("t31.bco", ventilStateDoma() ? 13633 : 65535);
        myNex.writeNum("t32.bco", ventilStateFirma() ? 13633 : 65535);
        myNex.writeNum("t36.bco", ventilStateChodba() ? 13633 : 65535);
        myNex.writeNum("t33.bco", cerpadloTUVStatus() ? 13633 : 65535);
        myNex.writeNum("t34.bco", cerpadloKRBStatus() ? 13633 : 65535);
        myNex.writeNum("t35.bco", cerpadloOVStatus() ? 13633 : 65535);            
        cntNextion = 0;
    }       
    taskYIELD();
    vTaskDelay(pdMS_TO_TICKS(50));

}

}

void nextion_begin(void) { myNex.begin(115200);

xTaskCreatePinnedToCore(
    nextionUpdate, // Function that should be called
    "nextionUpdate", // Name of the task (for debugging)
    8000, // Stack size (bytes)
    NULL, // Parameter to pass
    8, // Task priority
    NULL, // Task handle
    app_cpu // core

);

}`

and here is trigger for buttons:

`void trigger9() {

/* Create a button on Nextion
 * Write in the Touch Release Event of the button
 * this command:    printh 23 02 54 09
 * Every time the button is pressed, the trigger0() function will run
 * and the code inside will be executed once
 */
nexBlTimer = MAX_NEXTION_BACKLIGHT_TIMER;
nexChange = 11;
float tempTmp = thermostat_get_temperatureD() + 0.5;
thermostat_setD(tempTmp);

// myNex.writeStr("t16.txt", String(tempTmp) + String(" °C"));
// mySerialPrintLn(F("TD+"));

}

void trigger10() {

/* Create a button on Nextion
 * Write in the Touch Release Event of the button
 * this command:    printh 23 02 54 0A
 * Every time the button is pressed, the trigger0() function will run
 * and the code inside will be executed once
 */
nexBlTimer = MAX_NEXTION_BACKLIGHT_TIMER;
nexChange = 11;
float tempTmp = thermostat_get_temperatureD() - 0.5;
thermostat_setD(tempTmp);
// myNex.writeStr("t16.txt", String(tempTmp) + String(" °C"));
// mySerialPrintLn(F("TD-"));

}

void trigger11() {

/* Create a button on Nextion
 * Write in the Touch Release Event of the button
 * this command:    printh 23 02 54 0B
 * Every time the button is pressed, the trigger0() function will run
 * and the code inside will be executed once
 */
nexBlTimer = MAX_NEXTION_BACKLIGHT_TIMER;
nexChange = 11;
float tempTmp = thermostat_get_temperatureK() + 0.5;
thermostat_setK(tempTmp);
// myNex.writeStr("t18.txt", String(tempTmp) + String(" °C"));
// mySerialPrintLn(F("TK+"));

}

void trigger12() {

/* Create a button on Nextion
 * Write in the Touch Release Event of the button
 * this command:    printh 23 02 54 0C
 * Every time the button is pressed, the trigger0() function will run
 * and the code inside will be executed once
 */

nexBlTimer = MAX_NEXTION_BACKLIGHT_TIMER;
nexChange = 11;
float tempTmp = thermostat_get_temperatureK() - 0.5;
thermostat_setK(tempTmp);

// myNex.writeStr("t18.txt", String(tempTmp) + String(" °C"));
// mySerialPrintLn(F("TK-"));

}`

Seithan commented 1 year ago

Hello, Please try changing this file in the library's source files trigger.zip

puhycz commented 11 months ago

Yes, I tested it and it is ok. Many thaks.