hi tetonika tim,
i try to read/write I/O pin and send to server.
this i try the code,
local PERIOD_SEC = 60 – samakan dengan Period di Collection
local HM_FILE = “/etc/hm_total.txt” – file penyimpan HM total
local equipment_id = “HT111” – ID genset / alat
local function read_hm()
local f = io.open(HM_FILE, “r”)
if not f then return 0 end
local v = f:read(“*n”)
f:close()
return v or 0
end
local function save_hm(v)
local f = io.open(HM_FILE, “w”)
if f then
f:write(string.format(“%.3f”, v))
f:close()
end
end
local status_genset = tonumber(data[“input1”]) or 0 – 1 = ON, 0 = OFF
local hm_total = read_hm()
if status_genset == 1 then
– jika genset ON selama PERIOD_SEC detik
hm_total = hm_total + (PERIOD_SEC / 3600.0)
save_hm(hm_total)
end
local trigger_genset = (status_genset == 1) and “1” or “0”
local t = os.date(“*t”) – waktu lokal router
local datetime = string.format(“%04d-%02d-%02d %02d:%02d:%02d”,
t.year, t.month, t.day, t.hour, t.min, t.sec)
local lat_val = tonumber(data[“latitude”] or 0) or 0
local lon_val = tonumber(data[“longitude”] or 0) or 0
local latitude = string.format(“%.6f”, lat_val)
local longitude = string.format(“%.6f”, lon_val)
local temp = “34.45”
local humy = “75.0”
local json = string.format(
[[{
“equipment_id”: “%s”,
“trigger_genset”: “%s”,
“status_genset”: “%d”,
“hm”: “%.3f”,
“latitude”: “%s”,
“longitude”: “%s”,
“temp”: “%s”,
“humy”: “%s”,
“datetime”: “%s”
}]],
equipment_id,
trigger_genset,
status_genset,
hm_total,
latitude,
longitude,
temp,
humy,
datetime
)
return json
but it not working,
what i mis.?
regard,