Multiple Rednet signals
#1
Posted 31 December 2013 - 02:05 PM
What is the best way to send multiple rednet signals to one computer.
Example
1 turtle sends rednet signal to computer, computer displays info
Once it displays the data it reads the next turtle
Basically i want it to recieve both signals all the time keeping the display program up todate, I tried many things done some searching but haven't really came across much.
I recive one singal and moves on to the next and keeps repeating it.
I thought about addin an additonal wireless modem but the way i have things setup that would be a little hard since i have monitors on the top and sides, modem on the back and bundled cable on the bottom and putting it in the front would make it hard to access the computer
#2
Posted 31 December 2013 - 03:19 PM
ihatetn931, on 31 December 2013 - 02:05 PM, said:
What is the best way to send multiple rednet signals to one computer.
Example
1 turtle sends rednet signal to computer, computer displays info
Once it displays the data it reads the next turtle
Basically i want it to recieve both signals all the time keeping the display program up todate, I tried many things done some searching but haven't really came across much.
I recive one singal and moves on to the next and keeps repeating it.
I thought about addin an additonal wireless modem but the way i have things setup that would be a little hard since i have monitors on the top and sides, modem on the back and bundled cable on the bottom and putting it in the front would make it hard to access the computer
Extra modems make no difference.
The parallel API may be useful to you.
#3
Posted 31 December 2013 - 04:21 PM
One of the turltes (both have same code)
I'm gonna have a look at the parallel api will prolly have to rewrite my entire code to make it work as you can tell by the code, it sucks, all done by trial and error.
I want each turtle to write on it's own monitor, one writes on the left and the other writes on the right (on the recieve computer)
Edited by ihatetn931, 31 December 2013 - 05:43 PM.
#4
Posted 31 December 2013 - 06:41 PM
I'd also say that having the turtles sending in new data constantly is excessive (I'd have them use a sleep(1) instead of a sleep(0) at the very least, and make that sleep statement execute regardless as to whether the turtles are in debug mode), but that's up to you.
Anyway, I'd recommend taking these lines from the top of your server script:
local incomingID,message = rednet.receive() local reData = textutils.unserialize(message)
... and turn them into just local declarations for now:
local incomingID,message,reData
Now at the top of the checkData() function:
function checkData()
incomingID,message = rednet.receive()
reData = textutils.unserialize(message)
if incomingID == 2 then
.
.
.
And remove the rednet pulls from your checkReactorHeat/checkBreederHeat functions:
-------------------Reactor
function checkReactorHeat()
return reData.Heat
end
--print("Reactor check done")
-------------------Breeder
function checkBreederHeat()
return reData.Heat
end
--print("Breeder check done")
(I assume you're using those functions with the graph API correctly; I've not meddled with it myself).
Now you're checking to see which system the data came from before you work with it, as opposed to checking which system the last set of data came from before pulling in a new set from who-knows-what source.
Edit: It's probably worth mentioning that rednet messages come in as events. Most functions that pull items from the event queue grab whatever event's're next in line there and discards them until it finds what it wants, which will obviously cause other event-reliant functions to malfunction if you try to use them together. For example, sleep() relies on the event queue for a timer event, and rednet.receive() wants a rednet_message event - so a computer that uses sleep will "miss" any rednet messages sent to it until it sleeping, after which it'll act like those messages were never received.
As far as I can tell your server script doesn't have this problem, but I thought it worth mentioning. The parallel API is a good way around this issue if it DOES come up, as each function you run in parallel gets it own copy of the event queue - meaning one function can pull what it likes from its copy without affecting what the other can see.
Edited by Bomb Bloke, 31 December 2013 - 06:55 PM.
#5
Posted 31 December 2013 - 08:03 PM
I ended up having to add one more rednet.recieve so it recieves the MaxHeat of the reactors, since it only needed to get it once i didn't have to put it in a loop plus i couldn't figure out how to put it in a loop and the graph update cause when i put the grLeft and grRight above the draws in checkData the graphs wouldn't update, and if i took them out and put them above the function i would get a nil value so the graphs wouldn't draw. Unless i am missin somthing, it would be nice for the MaxHeat to update on it's own so when i put heat plates in it i don't have to restart the program for it to update the maxheat
incomingID,message = rednet.receive()
reData = textutils.unserialize(message)
local grLeft = graph.new (monleft, {checkReactorHeat } , { "Reactor1 Heat" } , {gradient1} , {0 }, {reData.MaxHeat}, true)
local grRight = graph.new(monright, {checkBreederHeat}, {"Breeder1 Heat"}, {gradient1}, {0}, {reData.MaxHeat}, true)
-------------------
function checkData()
incomingID,message = rednet.receive()
reData = textutils.unserialize(message)
if incomingID == 2 then
--local grLeft = graph.new (monleft, {checkReactorHeat } , { "Reactor1 Heat" } , {gradient1} , {0 }, { reData.MaxHeat }, true)
grLeft:draw()
else if incomingID == 3 then
--local grRight = graph.new(monright, {checkBreederHeat}, {"Breeder1 Heat"}, {gradient1}, {0}, {reData.MaxHeat}, true)
grRight:draw()
end
end
end
#6
Posted 31 December 2013 - 10:34 PM
local MaxHeat = {reData.MaxHeat}
local grLeft = graph.new (monleft, {checkReactorHeat } , { "Reactor1 Heat" } , {gradient1} , {0 }, MaxHeat, true)
local grRight = graph.new(monright, {checkBreederHeat}, {"Breeder1 Heat"}, {gradient1}, {0}, MaxHeat, true)
-------------------
function checkData()
incomingID,message = rednet.receive()
reData = textutils.unserialize(message)
MaxHeat[1] = reData.MaxHeat
.
.
.
This is, however, making pure assumptions as to how the graph API works - it may not hang on to its version of the pointer, and only keep the original value that was in the table at the time you defined the new graph. But I suppose it's either this or call graph.new again whenever you notice that value needs to be updated.
#7
Posted 31 December 2013 - 11:13 PM
grLeft.max[1] = newValue
#8
Posted 31 December 2013 - 11:28 PM
So i can add heat-capacity reactor plating without having to change the max heat manually it would do it it's self.
It worked before i change the code to the suggestion Bomb Bloke gave me, it would automatically update the MaxHeat in the graph.
I just like everything being automatic, it makes doing stuff much easier
#9
Posted 01 January 2014 - 08:14 AM
He's also saying that you can indeed have your script tweak that maximum value if the graph API doesn't do it the way you want. For eg:
function checkData() incomingID,message = rednet.receive() reData = textutils.unserialize(message) if grLeft.max[1] ~= reData.MaxHeat then grLeft.max[1] = reData.MaxHeat grRight.max[1] = reData.MaxHeat end if incomingID == 2 then . . .
One thing I'm scratching my head over, do the turtles have different sensors installed or something? I've not played with that type of turtle (or ever set up a reactor for that matter), but I'm beginning to suspect you've both got them monitoring the same system, sending in copies of the same data, and cherry-picking what info to pay attention to from each turtle. Or do their sensors really gather different things?
#10
Posted 01 January 2014 - 12:01 PM
I am gonna give that a try, 1 question would the
local grLeft = graph.new (monleft, {checkReactorHeat } , { "Reactor1 Heat" } , {gradient1} , {0 }, {reData.MaxHeat}, true)
Go in checkData() or above it if i use that code.
Sorry for being such a pain, trying to get how lua works nshit, i know other progamming langs and computercraft is the first time i really messed with lua.
Edit
Nevermind i figured it out, thank you both for the help.
Edited by Lyqyd, 01 January 2014 - 11:38 PM.
#11
Posted 01 January 2014 - 05:10 PM
#12
Posted 01 January 2014 - 05:45 PM
#13
Posted 01 January 2014 - 10:58 PM
I'm use to pawn scripting, it kinda the same but the way it works is diffrent and the way functions work are diffrent
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users












