Jump to content




[Openccsensors]How To Send Info Over Rednet?



7 replies to this topic

#1 cartmen180

  • Members
  • 10 posts

Posted 15 August 2013 - 04: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 :)

#2 Nikki

  • Members
  • 7 posts

Posted 15 August 2013 - 09: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.c...k/json/json.lua

#3 Xfel

    Peripheral Designer

  • Members
  • 515 posts

Posted 29 August 2013 - 03: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.

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 29 August 2013 - 09:50 AM

Or just send your table, no serialization needed.

#5 Mitchfizz05

  • Members
  • 125 posts
  • LocationAdelaide, Australia

Posted 30 August 2013 - 11:09 PM

View PostLyqyd, on 29 August 2013 - 09:50 AM, said:

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

#6 electrodude512

  • Members
  • 167 posts
  • LocationEastern USA

Posted 12 September 2013 - 03:57 PM

View PostLyqyd, on 29 August 2013 - 09:50 AM, said:

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?

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 12 September 2013 - 04: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.

#8 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 12 September 2013 - 04: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users