-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeWorksSender.lua
More file actions
49 lines (37 loc) · 1.1 KB
/
CompositeWorksSender.lua
File metadata and controls
49 lines (37 loc) · 1.1 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- Copyright (c) 2025 Jonas Costa Campos
-- Sender script for a CompositeWorks Microcontroller (https://github.com/jonasCCa/CompositeWorks)
ticks = 0
ticksToPost = 60 // property.getNumber("frequency")
port = math.floor(property.getNumber("port"))
id = property.getText("ID")
local f = false
compositeNumber = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
compositeBool = {f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}
response = false
function onTick()
ticks = ticks + 1
if ticks >= ticksToPost then
ticks = 0
local n = ""
local b = ""
for i=1,32 do
compositeNumber[i] = input.getNumber(i)
compositeBool[i] = input.getBool(i)
n = n..compositeNumber[i]
if compositeBool[i] == true then
b = b.."1"
else
b = b.."0"
end
if i < 32 then
n = n..","
b = b..","
end
end
async.httpGet(port, "/postComposite?id="..id.."&n="..n.."&b="..b)
end
output.setBool(1, response)
end
function httpReply(port, request_body, response_body)
response = response_body == "OK"
end