Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if peripheral.getType("left")=="modem" then
- rednet.open("left");
- end
- print("Connecting to ROCKO SERVO");
- local t=false;
- local previousPrints="";
- local hasErroredOut="";
- function getTurtleData()
- if not turtle then
- return;
- end
- local data="{\"inspect front\":"..""..textutils.serialize(textutils.serialize(select(2,turtle.inspect()) )or "air")..",";
- data=data.."\"inspect down\":"..""..textutils.serialize(textutils.serialize(select(2,turtle.inspectDown())) or "air")..",";
- data=data.."\"inspect up\":"..""..textutils.serialize(textutils.serialize(select(2,turtle.inspectUp())) or "air")..",";
- data=data.."\"getSelectedSlot\":"..""..textutils.serialize(turtle.getSelectedSlot() or "")..",";
- data=data.."\"getItemCount\":"..""..textutils.serialize(turtle.getItemCount() or "")..",";
- data=data.."\"getItemDetail\":"..""..textutils.serialize(textutils.serialize(turtle.getItemDetail()) or "")..",";
- data=data.."\"getFuelLevel\":"..""..textutils.serialize(turtle.getFuelLevel() or "")..",";
- data=data.."\"getFuelLimit\":"..""..textutils.serialize(turtle.getFuelLimit() or "")..",";
- data=data.."\"lastPrintResult\":"..""..textutils.serialize(textutils.serialize(previousPrints))..",";
- data=data.."\"hasErroredOut\":"..""..textutils.serialize(textutils.serialize(hasErroredOut)).."}";
- local msg = data;
- return msg;
- end
- while not t do
- local response=http.post(
- "http://andrei-rocko.rhcloud.com/turtle",
- "id="..textutils.urlEncode(os.getComputerLabel())
- .."&".. "data="..textutils.urlEncode(getTurtleData())
- )
- if response then
- local svalue=response.readAll();
- print (svalue);
- t=(tonumber(svalue)==1);
- end
- if not t then
- sleep(3);
- end
- end
- print("LINKED TO ROCKO SERVO");
- function loadingSym(x, y, wa)
- local oldx, oldy = term.getCursorPos();
- term.setCursorPos(x,y);
- write(wa);
- term.setCursorPos(oldx,oldy);
- end
- term.setCursorPos(1,2);
- term.clear();
- local loadingSymbolArr={"|","\\","-","/"}
- local counterHTTP=0;
- while true do
- loadingSym(1,1,loadingSymbolArr[(counterHTTP%4) +1 ]);
- counterHTTP= counterHTTP + 1;
- local response=http.post(
- "http://andrei-rocko.rhcloud.com/turtle",
- "id="..textutils.urlEncode(os.getComputerLabel()) .."&".. "whatDo="..textutils.urlEncode("1").."?data="..textutils.urlEncode(getTurtleData())
- )
- if response then
- local svalue=response.readAll();
- local f = loadstring(svalue);
- if f then
- setfenv(f, getfenv());
- local ok, msg = pcall(f);
- previousPrints=nil;
- hasErroredOut=not ok;
- if msg then
- previousPrints=msg;
- end
- if not ok then
- print(msg);
- end
- else
- print("buggy input from web?");
- end
- else
- loadingSym(1,1,"?");
- sleep(2);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement