% --[[ Status.htm (Charging_points module) ]]-- local chp = require "luci.model.charging_points" local fs = require "nixio.fs" local utl = require "luci.util" local dsp = require "luci.dispatcher" local mUtl = require "luci.moreUtils" local os = require "os" local path = luci.dispatcher.context.requestpath local user, serialnumber, hw_model = chp.whoami(path) local parameters = {} local sections = {} local gmod, amod local modules = {} -- Load modules if user ~= "user" then gmod = require "luci.model.global_variables" amod = require "luci.model.ocpp_variables" modules = {gmod, amod} else gmod = require "luci.model.user_global_variables" modules = {gmod} end ------------------------------------------------------------------------------------------------------------------------- local path = dsp.context.requestpath serialnumber = mUtl.get_serialnumber() local method if serialnumber then local maestre = mUtl.identify_pseudo_maestre( path[3] or serialnumber ) if maestre == true then method = path[3] or serialnumber else method = path[3] end end if utl.ubus(method, "get_configuration") == nil then local p = utl.ubus() for k, v in pairs (p) do if string.sub(v,1,1) == "6" and #v == 12 then method = v end end end local model = mUtl.model(serialnumber) local config, config_ort, config_o, tbl = {}, {}, {}, {conn={}} local rv1 = {conn={}, rest={}} local stat = utl.ubus(method, "get_status") if stat then for sec, opt in pairs (stat) do local secn = {} local rv = {} for i, mod in ipairs(modules) do for j, k in ipairs(mod.runTime) do local ocpp = {} if opt[serialnumber] then ocpp = opt[serialnumber] if type(ocpp[k]) == "boolean" then if ocpp[k] ~= nil then rv[#rv+1] ={ key = translate(k), value = translate(tostring(ocpp[k]) or "NIL") } end else if ocpp[k] ~= nil then rv[#rv+1] ={ key = translate(k), value = translate(tostring(ocpp[k]) or "NIL") } end end end if type(opt[k]) == "boolean" then if opt[k] ~= nil then rv[#rv+1] ={ key = translate(k), value = translate(tostring(opt[k]) or "NIL") } end else if opt[k] ~=nil and type(opt[k]) == "number" and opt[k] % 1 ~= 0 then opt[k] = string.format("%.2f",opt[k]) end if model == "F" and k == "power" and opt[k] ~= nil then if opt[k] < 20 then opt[k] = 0 end end if opt[k] ~= nil then rv[#rv+1] ={ key = translate(k), value = translate(tostring(opt[k]) or "NIL") } end end end end if sec ~= "ocpp" and sec ~= "modbusserver" and sec ~= "swupdate" and sec ~= "extpwrmeter" and sec ~= "smartchargingd" and sec ~= "powerstack" then if #rv > 0 then table.insert(tbl.conn, sec) table.insert(rv1.conn, rv) end elseif sec ~= "smartchargingd" then if #rv > 0 then table.insert(tbl, sec) secn[sec] = rv table.insert(rv1.rest, secn) end end end end local soap = utl.ubus(serialnumber, "get_configuration") if soap and soap.ocpp and soap.ocpp.backend_url then backend = soap.ocpp.backend_url if string.sub(backend, 1,2) ~= "ws" then soap = true end end if mUtl.identify_pseudo_maestre( path[3] or serialnumber ) == false and soap == true then stat = utl.ubus(serialnumber, "get_status") elseif mUtl.identify_pseudo_maestre( path[3] or serialnumber ) == false and soap == false then stat = utl.ubus(path[3], "get_status") end if stat and stat.ocpp and mUtl.identify_pseudo_maestre( path[3] or serialnumber ) == false then for sec, opt in pairs (stat.ocpp) do if type(opt) == "table" and sec == (path[3] or serialnumber) then local ocpp = {} ocpp = opt local rv = {} local secn = {} for i, mod in ipairs(modules) do for j, k in ipairs(mod.runTime) do if type(ocpp[k]) == "boolean" then if ocpp[k] ~= nil then rv[#rv+1] ={ key = translate(k), value = translate(tostring(ocpp[k]) or "NIL") } end else if ocpp[k] ~= nil then rv[#rv+1] ={ key = translate(k), value = translate(tostring(ocpp[k]) or "NIL") } end end end end if #rv > 0 then table.insert(tbl, "ocpp") secn["ocpp"] = rv table.insert(rv1.rest, secn) end end end end local all_status = utl.ubus(method,"get_status") local all_status_translate = {} for k , v in pairs (all_status) do local opts = {} for z , t in pairs (v) do local val if type(t) ~= "table" then opts[translate(z)] = translate(tostring(t)) else for n, m in pairs (t) do if z == (path[3] or serialnumber) then opts[translate(n)] = translate(tostring(m)) end end end end opts["translated_name"] = translate(k) all_status_translate[k] = opts end if luci.http.formvalue("status") == "1" then luci.http.prepare_content("application/json") luci.http.write_json(all_status_translate) return end %> <%+header%>