174 posts
Posted 17 January 2013 - 09:58 AM
Ok I am not a lua programmer so i am coming here trying to get some idea of how to program a wireless sensor turtle so that it reads the sensor data from openCCSensors and then transmits over the redstone network.
8543 posts
Posted 17 January 2013 - 10:09 AM
You'd want to grab the data from the sensor, then serialize the table and send it via rednet. Something like:
local data = sensor.call("left", "getTargetDetails", "0,0,-2")
rednet.send(12, textutils.serialize(data))
Use textutils.unserialize on the other end to get the data back into table form.
174 posts
Posted 17 January 2013 - 10:25 AM
You'd want to grab the data from the sensor, then serialize the table and send it via rednet. Something like:
local data = sensor.call("left", "getTargetDetails", "0,0,-2")
rednet.send(12, textutils.serialize(data))
Use textutils.unserialize on the other end to get the data back into table form.
Awesome. Will try.
174 posts
Posted 17 January 2013 - 10:54 AM
You'd want to grab the data from the sensor, then serialize the table and send it via rednet. Something like:
local data = sensor.call("left", "getTargetDetails", "0,0,-2")
rednet.send(12, textutils.serialize(data))
Use textutils.unserialize on the other end to get the data back into table form.
Ok I have my turtle set up. Now to set up the monitor I would just have to have to do something like this:
function update()
data = textutils.unserialize(rednet.receive())
return data.Stored
end
That would work right?
8543 posts
Posted 17 January 2013 - 11:05 AM
Not quite. The first return of rednet.receive is the ID of the sender. You'd want something more like:
local id, message = rednet.receive()
local data = textutils.unserialize(message)
if data then --make sure we got a serialized table, not some other rednet traffic.
print(data.Stored)
end
174 posts
Posted 17 January 2013 - 11:07 AM
Not quite. The first return of rednet.receive is the ID of the sender. You'd want something more like:
local id, message = rednet.receive()
local data = textutils.unserialize(message)
if data then --make sure we got a serialized table, not some other rednet traffic.
print(data.Stored)
end
Just figured that out myself! ^w^ Code is working PERFECTLY now! Just had to make it flush the sending computer's id.
Here was my final code:
mon = peripheral.wrap("right")
rednet.open("left")
function update()
c,data,d = rednet.receive()
dataRaw = textutils.unserialize(data)
return dataRaw.Stored
end
graphI = graph.new(mon, update, "EU Tank", nil, 0, 10000000)
while true do
graphI:draw()
sleep(0.5)
end