Skip to main content

How to use Lua scripts

First use

For Lua scripting, I suggest utilizing Visual Studio Code with the Lua extension installed (sumneko). This extension enables autocomplete functionality, leveraging our helper.lua file for enhanced productivity. It's essential to avoid modifying the helper.lua file to prevent potential issues in the future. To begin programming, create a dedicated folder to store your Lua scripts. Add our helper.lua file to this folder. When your code is finalized, load the script onto our inverter, ensuring not to include helper.lua in the upload (u can only load one script on the inverter). For debugging purposes, utilize IO.Print() or IO.Write().

image.png

 

Error 0x06070010 when loading a script may indicate Lua object 0x2040 0x01 isn't set to 1. To resolve, ensure proper access level in Configurator to unlock this feature. If you do not have the proper access level contact us.

image.png

image.png


Best practices

For further insights and practical tips, I recommend exploring "Programming in Lua," available at: Programming in Lua. Authored by experts in the field, this comprehensive resource offers invaluable guidance for Lua developers. It's worth noting that the entire topic is accessible free of charge as of April 24, 2024.

Minimizing Global Variables

In Lua scripting, it's imperative to exercise caution with global variables to prevent memory exhaustion and script failures, especially on embbeded systems. Emphasizing the utilization of local variables whenever possible is paramount. By minimizing global variable usage, we mitigate the risk of memory overflow and enhance script performance.

Example:

myGlobalVaribale = 10  --Global variable
local myLocalVaribale = 10  --Local variable

Issues

If IO.Print() isn't functioning, it may signal an outdated firmware version. Firmware 0x10C01 lacks support, while 0x10D02 enables the function.