local H = html:new({})
local light = sensor:new("Light")
local sensors = {
Light=0
}
local h = http:service('192.168.0.52',8080,function (req,url,remote,params,body)
-- No blocking IO operations allowed inside requesz handler!!!
print('HTTP REQ');
print(req..' '..url..' '..inspect(remote)..' '..inspect(params))
return H:html(
H:head(),
H:body({
H:h1("Sensor Monitor"),
H:h2("Supported Sensors"),
H:ol(sensor:all()),
H:h2("Sensor Table"),
H:table({"Sensor","Value","Unit"},{
{"Time",time(),"ms" },
{"Light",sensors.Light,"dig" },
})
}))
end)
local sense = coroutine.create(function ()
-- Blocking IO operations allowed here!
while true do
sensors.Light=light:read()
sleep(500)
end
end)
coroutine.resume(sense)
print("HTTP")