This is some basic code that I scratched together as soon as I found the pocket computers. Using the wireless modem and the rednet api, I was able to create a simple command based protocol. The application works by starting the client side of the code on a wireless turtle, and then connecting to that turtle with the remote program on the pocket computer. Once in the pocket computer, a list of commands will be shown and all keyboard input will be directed to the turtle.
Instructions:
- Start “client” on the turtle
- Start “remote” on the pocket computer and input the turtle ID (printed on start of “client”)
- You can reconnect as many times as you want, and you can have as many remotes for one turtle as you want
For Client: GYYPGizn
For Remote: gKe06v1M
Client Side v1.0
local sSide = "right"
print("Turtle running on Channel "..os.getComputerID())
rednet.open(sSide)
while true do
local id, msg = rednet.receive(1)
if msg then
if msg == "Init" then
rednet.send(id, "Good")
else
msg = tonumber(msg)
if msg == 16 then
print("Stopping")
rednet.close(sSide)
return
elseif msg == 30 then turtle.turnLeft()
elseif msg == 32 then turtle.turnRight()
elseif msg == 17 then turtle.forward()
elseif msg == 31 then turtle.back()
elseif msg == 57 then turtle.up()
elseif msg == 42 then turtle.down()
elseif msg == 21 then turtle.digUp()
elseif msg == 35 then turtle.dig()
elseif msg == 49 then turtle.digDown()
elseif msg == 22 then turtle.placeUp()
elseif msg == 36 then turtle.place()
elseif msg == 50 then turtle.placeDown()
else print("Unknown command "..msg)
end
end
end
end
Remote Side v1.0
local tArgs = {...}
local channel = 0
local sSide = "back"
-- Get Channel Number
print("What channel?")
channel = tonumber(read())
-- Connect
print("Connecting to "..channel)
rednet.open(sSide)
rednet.send(channel, "Init")
local id, msg = rednet.receive(1)
if not msg or id ~= channel then
print("Could not connect")
return
end
-- Print commands
print("Commands:")
print("Q - Disconnect/Quit")
print("WASD - Move/Turn")
print("Space- Move Up")
print("Shift- Move Down")
print("Y - Mine Up")
print("H - Mine")
print("N - Mine Down")
print("U - Place Up")
print("J - Place")
print("M - Place Down")
-- Program Loop
while true do
local event, sc = os.pullEvent("key")
if sc == 16 then
rednet.send(channel, sc)
print("Closing")
rednet.close(sSide)
return
elseif sc == 17 or
sc == 30 or
sc == 31 or
sc == 32 or
sc == 42 or
sc == 57 or
sc == 21 or
sc == 22 or
sc == 35 or
sc == 36 or
sc == 49 or
sc == 50 then
rednet.send(channel, sc)
end
end
Licensing:
General Public License (GPL): You can use it how you want, but with credit to the original author (CodeMonkey42).