How to use Lua script for data formatting for Data to Server

Is there any documentation available for the Lua Script capability when using Data to server. I would like to minimize the size of the json. currently the format that my input will spit out is something along the lines of [{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:01+0000”,“date”:“08\\/10\\/2025 11:16:01”,“data”:“110”,“ip”:“”,“name”:“outdoor_airtemp”,“addr”:27,“bserver_id”:1,“full_addr”:“300027”,“server_name”:“HvacInstance”,“timestamp”:1759922161,“size”:7},{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:01+0000”,“date”:“08\\/10\\/2025 11:16:01”,“data”:“1”,“ip”:“”,“name”:“compressor_1a_running_status”,“addr”:3028,“bserver_id”:1,“full_addr”:“303028”,“server_name”:“HvacInstance”,“timestamp”:1759922161,“size”:8},{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:01+0000”,“date”:“08\\/10\\/2025 11:16:01”,“data”:“1”,“ip”:“”,“name”:“compressor_2a_status”,“addr”:3030,“bserver_id”:1,“full_addr”:“303030”,“server_name”:“HvacInstance”,“timestamp”:1759922161,“size”:9},{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:03+0000”,“date”:“08\\/10\\/2025 11:16:03”,“data”:“110”,“ip”:“”,“name”:“outdoor_airtemp”,“addr”:27,“bserver_id”:1,“full_addr”:“300027”,“server_name”:“HvacInstance”,“timestamp”:1759922163,“size”:7},{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:03+0000”,“date”:“08\\/10\\/2025 11:16:03”,“data”:“1”,“ip”:“”,“name”:“compressor_1a_running_status”,“addr”:3028,“bserver_id”:1,“full_addr”:“303028”,“server_name”:“HvacInstance”,“timestamp”:1759922163,“size”:8},{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:03+0000”,“date”:“08\\/10\\/2025 11:16:03”,“data”:“1”,“ip”:“”,“name”:“compressor_2a_status”,“addr”:3030,“bserver_id”:1,“full_addr”:“303030”,“server_name”:“HvacInstance”,“timestamp”:1759922163,“size”:9},{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:05+0000”,“date”:“08\\/10\\/2025 11:16:05”,“data”:“110”,“ip”:“”,“name”:“outdoor_airtemp”,“addr”:27,“bserver_id”:1,“full_addr”:“300027”,“server_name”:“HvacInstance”,“timestamp”:1759922165,“size”:7},{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:05+0000”,“date”:“08\\/10\\/2025 11:16:05”,“data”:“1”,“ip”:“”,“name”:“compressor_1a_running_status”,“addr”:3028,“bserver_id”:1,“full_addr”:“303028”,“server_name”:“HvacInstance”,“timestamp”:1759922165,“size”:8},{“server_id”:1,“date_iso_8601”:“2025-10-08T11:16:05+0000”,“date”:“08\\/10\\/2025 11:16:05”,“data”:“1”,“ip”:“”,“name”:“compressor_2a_status”,“addr”:3030,“bserver_id”:1,“full_addr”:“303030”,“server_name”:“HvacInstance”,“timestamp”:1759922165,“size”:9}]regardless of what i put inside of the lua script. I tried the script below but it didnt change anything

local json = require(“luci.jsonc”)
function handle_format_request(data)
local grouped = {}
for _, point in ipairs(data) do
if type(data) == “table” then
local ts = point[“timestamp”]
if grouped[ts] == nil
grouped[ts] = {}
grouped[ts][point[“name”]] = point[“data”]
end
end
local result = {}
for ts, fields in pairs(grouped) do
fields[“timestamp”] = ts
table.insert(result, fields)
end
return json.stringify(result)

i also tried returning a hardcoded string which also didnt change what was being sent to the server. any doucmentation on where to look for possible error outputs or what the format of the data table would be pretty helpful. Ive tried looking through the output of logread when you ssh into the teltonika but that didnt provide anything of relevance. I am using a rut 956 with firmware RUT9M_R_00.07.16.6

Greetings,

The issue could be related to how the device handles Lua scripting within the Data to Server function, as it may not be applying the script as expected. If you’d like, I can reach out to our R&D team to ask whether they could provide additional insight or support for this case, though I can’t guarantee their involvement due to other ongoing priorities.

Regards,
M.

This topic was automatically closed after 60 days. New replies are no longer allowed.