Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap('right')
- local connectionURL = "ws://51.83.42.69:9898/"
- local ws, err = http.websocket(connectionURL)
- cube = {}
- if not ws then
- return printError(err)
- end
- ws.send(textutils.serializeJSON({type='MESSAGE',data={'ComputerCraft Connected !'}}))
- local _, url, response, isBinary = os.pullEvent("websocket_message")
- if url == connectionURL then
- print(response)
- end
- function name()
- data = modem.getNamesRemote()
- end
- function check()
- number = 0
- for i=0,500 do
- if data[i] == nil then
- else
- cube[i] = peripheral.wrap(data[i])
- number = number + 1
- end
- end
- end
- function get()
- Energy = {}
- MEnergy = {}
- for i=1,number do
- Energy[i] = cube[i].getEnergy()
- MEnergy[i] = cube[i].getEnergyCapacity()
- end
- end
- function send()
- ws.send(textutils.serializeJSON({type='INT',data={name=data,energy=Energy,menergy=MEnergy}}))
- end
- while true do
- name()
- check()
- get()
- send()
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement