-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.lua
30 lines (26 loc) · 961 Bytes
/
run.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local SERVER = 'http://crosby.cluster.recurse.com:3000'
function roomAssert(facts, cb)
http.post(SERVER..'/assert', 'Content-Type: application/json\r\n',
sjson.encode({facts=facts}),
cb or function (a, b) print(a, b) end)
end
function roomRetract(facts, cb)
http.post(SERVER..'/retract', 'Content-Type: application/json\r\n',
sjson.encode({facts=facts}),
cb or function (a, b) print(a, b) end)
end
local mac = wifi.sta.getmac()
roomAssert({'"'..mac..'" got ip "'..wifi.sta.getip()..'"',
'mcuManager is active'}, function (status, x)
if status == -1 then print(status, x) return end
-- Check the ADC and assert its value every so often.
local adctmr = tmr.create()
local seq = 0
adctmr:alarm(100, tmr.ALARM_SEMI, function ()
roomAssert({'"'..mac..'" has analog value '..adc.read(0)..' @ '..seq}, function (status, x)
if status == -1 then print(status, x) return end
seq = seq + 1
adctmr:start()
end)
end)
end)