Upload files to 'flow-gate-monitor'
This commit is contained in:
parent
ffbaeb3a71
commit
5ba0334134
4
flow-gate-monitor/config.json
Normal file
4
flow-gate-monitor/config.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"PC_ID": "example_pc",
|
||||
"WH_URL": "https://discord.com/api/aaaaaaaaaa"
|
||||
}
|
36
flow-gate-monitor/startup.lua
Normal file
36
flow-gate-monitor/startup.lua
Normal file
|
@ -0,0 +1,36 @@
|
|||
local file = fs.open("config.json", "r")
|
||||
local config = textutils.unserializeJSON(file.readAll())
|
||||
file.close()
|
||||
|
||||
local PC_ID = config["PC_ID"]
|
||||
local WH_URL = config["WH_URL"]
|
||||
|
||||
print("@============@")
|
||||
print("| No touchy! |")
|
||||
print("@============@")
|
||||
print("")
|
||||
print("ID: " .. PC_ID)
|
||||
|
||||
function alert()
|
||||
local success = false
|
||||
while not success do
|
||||
local res = http.post(
|
||||
WH_URL .. '?wait=true',
|
||||
'{"embeds": [ { "title": "Program exited", "author": { "name": "' .. PC_ID .. '" }, "color": 16711680 } ] }',
|
||||
{ ['Content-Type'] = 'application/json' },
|
||||
false
|
||||
)
|
||||
if res ~= nil then
|
||||
success = true
|
||||
else
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
shell.run("sus")
|
||||
print("Restarting.")
|
||||
alert()
|
||||
sleep(5)
|
||||
end
|
72
flow-gate-monitor/sus.lua
Normal file
72
flow-gate-monitor/sus.lua
Normal file
|
@ -0,0 +1,72 @@
|
|||
local gate = peripheral.wrap("top")
|
||||
local meth = peripheral.getMethods("top")
|
||||
|
||||
-- Load config.json
|
||||
local file = fs.open("config.json", "r")
|
||||
local config = textutils.unserializeJSON(file.readAll())
|
||||
file.close()
|
||||
|
||||
local PC_ID = config["PC_ID"]
|
||||
local WH_URL = config["WH_URL"]
|
||||
|
||||
|
||||
while true do
|
||||
local low = gate.getSignalLowFlow()
|
||||
local high = gate.getSignalHighFlow()
|
||||
|
||||
if not fs.exists("data.json") then
|
||||
local data = textutils.unserializeJSON('{ "low": '.. low ..', "high": '.. high ..' }')
|
||||
local file = fs.open("data.json", "w")
|
||||
file.write(textutils.serialiseJSON(data))
|
||||
file.close()
|
||||
end
|
||||
|
||||
local file = fs.open("data.json", "r")
|
||||
local json = textutils.unserializeJSON(file.readAll())
|
||||
file.close()
|
||||
|
||||
if json.low ~= low then
|
||||
local success = false
|
||||
while not success do
|
||||
local res = http.post(
|
||||
WH_URL .. '?wait=true',
|
||||
'{"embeds": [ { "title": "Flow limit changed (low)", "author": { "name": "' .. PC_ID .. '" }, "description": "Flow rate (low): ' .. json.low .. ' RF/t -> ' .. low ..' RF/t", "color": 16747013 } ] }',
|
||||
{ ['Content-Type'] = 'application/json' },
|
||||
false
|
||||
)
|
||||
if res ~= nil then
|
||||
success = true
|
||||
else
|
||||
print("POST request failed; retrying")
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
json.low = low
|
||||
end
|
||||
|
||||
if json.high ~= high then
|
||||
local success = false
|
||||
while not success do
|
||||
local res = http.post(
|
||||
WH_URL .. '?wait=true',
|
||||
'{"embeds": [ { "title": "Flow limit changed (high)", "author": { "name": "' .. PC_ID .. '" }, "description": "Flow rate (high): ' .. json.high .. ' RF/t -> ' .. high ..' RF/t", "color": 16747013 } ] }',
|
||||
{ ['Content-Type'] = 'application/json' },
|
||||
false
|
||||
)
|
||||
if res ~= nil then
|
||||
success = true
|
||||
else
|
||||
print("POST request failed; retrying")
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
json.high = high
|
||||
end
|
||||
|
||||
local file = fs.open("data.json", "w")
|
||||
file.write(textutils.serialiseJSON(json))
|
||||
file.close()
|
||||
|
||||
sleep(1)
|
||||
end
|
||||
|
Loading…
Reference in a new issue