This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cartmen180's profile picture

[Openccsensors]How To Send Info Over Rednet?

Started by cartmen180, 15 August 2013 - 03:20 PM
cartmen180 #1
Posted 15 August 2013 - 05:20 PM
Hello everyone,

I have started using openCCsensors and what i want to do is use the information i get from machines to display on a monitor.
For example the stored energy in various storage devices or heat in a couple of reactors.

When i use the sensorview program I can see the information but I have no clue how to send it to my control room.
Is there a wiki or tutorial i am missing?

This is my setup:
- advanced computer with monitors in a "control room"
- computers with sensors to read my nuclear reactors
- all the computer are hooked up with wireless modems

What i want to do:
send the energy output and heat readings to the control room.


any help would be greatly appreciated :)/>
Nikki #2
Posted 15 August 2013 - 10:59 PM
You can use JSON or a text format, though json would be the best.

Use either http://dkolf.de/src/...on-lua.fsl/home or the computercraft one, http://www.computerc...-computercraft/

Use a timer/sleep to get data every x seconds, then send it with something like this:
rednet.send(<computer id>, json.encode(sensorData))

Then on the computer you want to receive it, something like this would be used:

-- Load the file which could have been saved under 'dkjson'
os.loadAPI('dkjson')

-- Open rednet on the side, for this example it'll be right
rednet.open('right')

while true do
  local event, id, text = os.pullEvent()
  if event == "rednet_message" then
	local sensorData = json.decode(text);
-- Display it somehow
  end
end

In the end you could modify 'sensorview' to use the data received over rednet, but this should be a good start for you :)/>

Edit: I might have misled you with dkjson, last I saw it worked, but I guess not!

Use this instead - https://raw.github.com/luaforge/json/master/trunk/json/json.lua
Xfel #3
Posted 29 August 2013 - 04:43 AM
or you can use the lua native format and don't have to use extra apis. just take textutils.serialize and textutils.deserialize.
Lyqyd #4
Posted 29 August 2013 - 10:50 AM
Or just send your table, no serialization needed.
Mitchfizz05 #5
Posted 31 August 2013 - 12:09 AM
Or just send your table, no serialization needed.
You can do that? I thought you can only send strings.
Well I've learnt something new today. :D/>
electrodude512 #6
Posted 12 September 2013 - 04:57 PM
Or just send your table, no serialization needed.
Cool! When was that added? Can I send any type, even a function or userdata or a table with functions in it?
Lyqyd #7
Posted 12 September 2013 - 05:11 PM
Not sure what you mean by userdata. I don't know about functions, but if they work, they should still work if they're inside a table.
Bubba #8
Posted 12 September 2013 - 05:28 PM
Unfortunately you can't send functions or metatables over rednet. If you put the functions in a table then that index disappears, leaving the rest of the table unaffected.