Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("json")
- function wrapPs(peripheralName)
- periTab = {}
- sideTab = {}
- if peripheralName == nil then
- print("Fehler")
- end
- local peripherals = peripheral.getNames()
- local i2 = 1
- for i = 1, #peripherals do
- if peripheral.getType(peripherals[i]) == peripheralName then
- periTab[i2] = peripheral.wrap(peripherals[i])
- sideTab[i2] = peripherals[i]
- i2 = i2 + 1
- end
- end
- if periTab ~= {} then
- return periTab, sideTab
- else
- return nil
- end
- function getPSide(peripheralName)
- if peripheralName == nil then
- print("Fehler")
- end
- local peripherals = peripheral.getNames()
- local i = 1
- while i < #peripherals and peripheral.getType(peripherals[i]) ~= peripheralName do
- i = i + 1
- end
- if peripheral.getType(peripherals[i]) == peripheralName then
- return peripherals[i]
- else
- return nil
- end
- end
- end
- --define webserver
- os.loadAPI("connect")
- --local ws,err = http.websocket("ws://"..connect.code..".ngrok.io")
- local ws,err = http.websocket("ws://"..connect.code)
- --wrap neural interface
- local ni=wrapPs("manipulator")
- if ni==nil then
- ni=wrapPs("neuralInterface")
- end
- --functions
- function eval(command)
- fp = fs.open("eval", "w")
- fp.write(command)
- fp.close()
- shell.run("eval")
- shell.run("rm eval")
- end
- function sendStringToWS(txt)
- ws.send(txt)
- end
- function sendArrayToWS(txt)
- ws.send(txt)
- end
- function getID()
- local cplabel=os.getComputerLabel()
- if cplabel==nil then
- cplabel=""
- end
- return cplabel..os.getComputerID()
- end
- function sendIDToWS()
- sendArraytoWS(json.encode({id=getID()}))
- end
- function sendStringInPackets(txt)
- maxPacket=100000
- for i=1, math.floor(#txt/maxPacket)+1 do
- sendStringToWS(string.sub((i-1)*maxPacket,i*maxPacket))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement