-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend_request.lua
73 lines (64 loc) · 1.89 KB
/
send_request.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- The script goes into the CC:Tweaked computer
function log(msg)
local time = os.epoch("local") / 1000
local time_str = os.date("%Y-%m-%d %T", time)
print(time_str.." "..msg)
end
function round(n)
return math.floor(n+0.5)
end
log("Starting program")
bridge = peripheral.find("meBridge")
while true do
quantities = {}
cat = bridge.listItems()
if cat ~= nil then
if type(cat) == "table" then
for _, thing in pairs(cat) do
strippedThing = { name = thing.name, amount = thing.amount, displayName = thing.displayName, type = "item" }
table.insert(quantities, strippedThing)
end
else
log("Error while processing AE:")
log(cat)
end
end
cat = bridge.listFluid()
if cat ~= nil then
if type(cat) == "table" then
for _, thing in pairs(cat) do
strippedThing = { name = thing.name, amount = round(thing.amount/1000), displayName = thing.displayName, type = "fluid" }
table.insert(quantities, strippedThing)
end
else
log("Error while processing AE:")
log(cat)
end
end
cat = bridge.listGas()
if cat ~= nil then
if type(cat) == "table" then
for _, thing in pairs(cat) do
strippedThing = { name = thing.name, amount = round(thing.amount/1000), displayName = thing.displayName, type = "gas" }
table.insert(quantities, strippedThing)
end
else
log("Error while processing AE:")
log(cat)
end
end
usageData = {
items = {
total = bridge.getTotalItemStorage(),
used = bridge.getUsedItemStorage()
},
fluid = {
total = bridge.getTotalFluidStorage(),
used = bridge.getUsedFluidStorage()
} -- no gas yet ):
}
allData = { usage = usageData, items = quantities }
http.post("http://localhost:5000/ae2", textutils.serialiseJSON(allData), {["Content-Type"]= "application/json"})
log("Request made. Now sleeping")
sleep(5)
end