Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- startup.lua
- function websocketLoop()
- local ws, err = http.websocket("ws://localhost:8080/turtle")
- if err then
- print(err)
- elseif ws then
- ws.send("turtleId=" .. os.getComputerID())
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("== Bee#" .. os.getComputerID() .. " ==")
- print("fuel: " .. turtle.getFuelLevel())
- ws.send("next")
- local message = ws.receive()
- if message == nil then
- break
- end
- local command = load(message)
- local status, result = pcall(command)
- ws.send(textutils.serialize({status = status, result = result}))
- os.sleep(2)
- end
- end
- if ws then
- ws.close()
- end
- end
- while true do
- local status, res = pcall(websocketLoop)
- term.clear()
- term.setCursorPos(1, 1)
- if res == 'Terminated' then
- print("Shutting down...")
- os.sleep(1)
- print("done.")
- break
- end
- print("-- no connection to hive --")
- os.sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement