I am trying to figure out how to use lua scripts with the data to server service. Is there an example somewhere on how to use it?
What I am trying to do is to write a lua script that is able to read a value from a modbus RTU unit (for example a digital poweer meter) every 15 seconds and send a POST call or an MQTT data if the last value read differs from the previous value by more than 10%.
Hi, I am working on a similar problem. This is the sample, that could be downloaded from the WebUI. The script can be customized via Visual Studio. However I haven’t tried it yet. Also I don’t know if this specific function has to called at some specific point or if it works on itself.
--Available variabes:
-- data_sender.section - config section name
-- data_sender.version - LUA plugin version
-- env - data to be formated
--
--String value must be returned
function handle_format_request(data)
local key, value
local result = ""
for key, value in pairs(data) do
result = result .. "\"" .. key .. "\": \"" .. value .. "\","
end
return "{" .. result .. "}"
end