Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if http then
- print("HTTP is enabled!")
- else
- print("HTTP is disabled! Stopping!")
- return -1
- end
- local openUrl = "ws://192.168.0.126"
- msgCheck = nil
- running = false
- local ws, err
- function moveDataAccept (action)
- print(action)
- if action then
- local fullAction = "return("..action..")"
- local fun = assert(loadstring(fullAction))
- local res = fun()
- print(res)
- ws.send(res)
- end
- end
- while true do
- -- ws, err = http.websocket(openUrl)
- repeat
- ws, err = http.websocket(openUrl)
- if ws then
- print("Websocket opened!")
- running = true
- ws.send('{"myType": "mining_turtle"}')
- while running do
- if pcall(function ()
- local msg = ws.receive()
- moveDataAccept(msg)
- end) then
- -- print("Success")
- else
- print("Error!")
- running = false
- end
- end
- -- running = false
- print("Stopped!")
- pcall(function()
- ws.close()
- end)
- else
- print(err)
- sleep(5)
- end
- until not true
- end
Add Comment
Please, Sign In to add comment