In "System Management -> Auto Provisioning", there's a section for "Lua Script Update". Is it possible to run a lua script that will restart my obi200 daily?
I had an online lua code generator create the following script for me however I don't know if it's correct beyond the ip address, admin password and time that needs to be changed.
Lua Code Generator:
https://codingfleet.com/code-generator/lua/https://onecompiler.com/lua/42mpucgty-- obi200_daily_restart.lua
-- This script restarts an obi200 device at a specified time each day
local http = require("socket.http")
local ltn12 = require("ltn12")
local os = require("os")
-- Configuration
local OBI_IP = "192.168.1.124" -- Replace with your obi200's IP address
local OBI_PASSWORD = "admin" -- Replace with your obi200's admin password
local RESTART_HOUR = 11 -- Hour to restart (24-hour format)
local RESTART_MINUTE = 30 -- Minute to restart
-- Function to restart the obi200
local function restart_obi200()
local url = string.format("http://%s/reboot.cgi", OBI_IP)
local request_body = string.format("page=reboot&password=%s", OBI_PASSWORD)
local response_body = {}
local request, code, response_headers = http.request{
url = url,
method = "POST",
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
["Content-Length"] = #request_body
},
source = ltn12.source.string(request_body),
sink = ltn12.sink.table(response_body)
}
if code == 200 then
print("obi200 restart command sent successfully")
else
print("Failed to send restart command. HTTP Status: " .. tostring(code))
end
end
-- Main loop
while true do
local current_time = os.date("*t")
-- Check if it's time to restart
if current_time.hour == RESTART_HOUR and current_time.min == RESTART_MINUTE then
print("It's time to restart the obi200")
restart_obi200()
-- Wait for 60 seconds to avoid multiple restarts
os.execute("sleep 60")
end
-- Wait for 30 seconds before checking again
os.execute("sleep 30")
end