Fetching esc telemetry using LUA scripts

Hi,
i’m trying to build a lua script where it will report messages / warnings if there is an issue in esc runtime in telemetry of
vbat, curr, rpm and temp.

till now im unable to read esc telemetry, attaching the latest script.
looking forward to resolve this issue
Thanks

– Function to send ESC usage times to the GCS for multiple channels
function send_esc_usage_times()
– Check if the esc object is available
if esc then
gcs:send_text(6, “ESC object is available”)
– Iterate over desired ESC channels
for channel = 1, 4 do – Adjust the range according to the number of ESCs you have
local esc_usage_seconds = esc:get_usage_seconds(channel)
if esc_usage_seconds then
gcs:send_text(6, string.format(“ESC%d Usage Time: %.2f seconds”, channel, esc_usage_seconds))
else
gcs:send_text(3, string.format(“Error: Unable to read usage time for ESC%d”, channel))
end
end
else
gcs:send_text(3, “Error: ESC telemetry not available”)
end

-- Schedule this function to run again after 1000 milliseconds (1 second)
return send_esc_usage_times, 1000

end

– Return the function to start the periodic execution
return send_esc_usage_times()