Post your best Lua script examples here

User avatar
By Brick01
#42339 Hi everybody.

Have a litte Problem with my NodeMCU and a 2.2" TFT Display (UCG lib).

I build a new Firmware with all Modules i need (and some bigger fonts). Flashing to the Node was no problem.
But when i start the skript the Node crashes after different times. When i try the Code completely without ucg-code
it works for hours, but when i use the Display Node crashes .. sometimes after 10 sec. sometimes after 60 sec... sometimes
after one hour...

i will pin up the code.. perhaps i have a big mistake in it.. i'm new with Node and Lua.. so please .. be fair :)

Thanks for your help...

Here some pic's..

IMG_9362.JPG

IMG_9364.JPG





Brick
Attachments
rename .lua
(3.43 KiB) Downloaded 771 times
rename .lua
(4.17 KiB) Downloaded 797 times
User avatar
By devsaurus
#42473 Please provide more information about your setup and the fail mode:
  • which module & flash size
  • firmware version
  • have you compiled the files to *.lc or are you running *lua files?
  • error message when crash occurs
  • if the crash triggers a firmware reboot: first output on UART (at 74880 baud)
User avatar
By Brick01
#42499 Hi devsaurus,

Ok,
Modul: NodeMCU 1.0 (the black one) .. Flash Size : 4MB
Firmware: the original NodeMCU-Firmware (git clone
https://github.com/nodemcu/nodemcu-firmware.git)
with the following Modules: (user_modules.h)
Code: Select all//#define LUA_USE_MODULES_ADC
//#define LUA_USE_MODULES_BIT
//#define LUA_USE_MODULES_BMP085
//#define LUA_USE_MODULES_CJSON
//#define LUA_USE_MODULES_COAP
//#define LUA_USE_MODULES_CRYPTO
#define LUA_USE_MODULES_DHT
//#define LUA_USE_MODULES_ENDUSER_SETUP // USE_DNS in dhcpserver.h needs to be enabled for this module to work.
#define LUA_USE_MODULES_FILE
#define LUA_USE_MODULES_GPIO
//#define LUA_USE_MODULES_HX711
#define LUA_USE_MODULES_I2C
//#define LUA_USE_MODULES_MQTT
#define LUA_USE_MODULES_NET
#define LUA_USE_MODULES_NODE
#define LUA_USE_MODULES_OW
//#define LUA_USE_MODULES_PWM
//#define LUA_USE_MODULES_RC
//#define LUA_USE_MODULES_RTCFIFO
//#define LUA_USE_MODULES_RTCMEM
//#define LUA_USE_MODULES_RTCTIME
//#define LUA_USE_MODULES_SNTP
#define LUA_USE_MODULES_SPI
#define LUA_USE_MODULES_TMR
//#define LUA_USE_MODULES_TSL2561
//#define LUA_USE_MODULES_U8G
#define LUA_USE_MODULES_UART
#define LUA_USE_MODULES_UCG
#define LUA_USE_MODULES_WIFI
//#define LUA_USE_MODULES_WS2801
//#define LUA_USE_MODULES_WS2812

and additional the following fonts: (ucg_config.h)
Code: Select all#define UCG_FONT_TABLE                              \
    UCG_FONT_TABLE_ENTRY(font_7x13B_tf)             \
    UCG_FONT_TABLE_ENTRY(font_fub42_hf)             \
    UCG_FONT_TABLE_ENTRY(font_fub30_hf)             \
    UCG_FONT_TABLE_ENTRY(font_helvB08_hf)           \
    UCG_FONT_TABLE_ENTRY(font_helvB10_hf)           \
    UCG_FONT_TABLE_ENTRY(font_helvB12_hf)           \
    UCG_FONT_TABLE_ENTRY(font_helvB18_hf)           \
    UCG_FONT_TABLE_ENTRY(font_ncenB24_hf)           \
    UCG_FONT_TABLE_ENTRY(font_ncenR12_hf)           \
    UCG_FONT_TABLE_ENTRY(font_ncenR14_hf)
#undef UCG_FONT_TABLE_ENTRY


the files where compiled to .lua

Error messag, i use the ESPlorer: "none"

and the last point you post: didn't know what you mean ?

i think the problem could be the "clear.screen()" function..
if i don't switch the pages (i have three) than it works ok,
but when i trigger a page refresh (with the button) in 80%
of the time, the system crashes... without an error.. sometimes
only the Display hangs.. sometimes the whole Node reboots..

Next thing, that's not ok: i can't interact with NodeMCU if
the code is running.. e.g "node.restart()" or "node.heap()"
wont work.. i have to reboot with the button on the Node himself.
if i send "node.restart()" i get an timeout... so, perhaps i have
a loop in my code ? so the Node will not response to any commands..

but i can't find it..

Cheers Brick
User avatar
By devsaurus
#42573 Maybe your code keeps the CPU busy for too long and the watchdog timer bites you in the end. The absence of any error message is typically an indication for the watchdog. This would also explain why you don't see a response to interactive commands.

First of all, you could check for the watchdog by executing after boot:
Code: Select allprint(node.bootreason())

The return codes are explained in node.bootreason(). 2 and 6 indicate an external reset while 2 and 3 tell you that the watchdog triggered the reset.

To get a feeling where time is spent in your code, add a few print(tmr.now()) to the routines. Maybe these show already that the 5s timer delay is too short to finish one loop...