Jump to content

Recommended Posts

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

Posted

HURRAH! It works like a charm!

So, now if I want to add more computers, and have there stats displayed, all I have to do is copy paste this code again, and change the "cursorPos", id, and the message. Lets say I added the buffer state. the program would look something like this?

rednet.open("top")

local engine_state = false

mon = peripheral.wrap("back")

while true do

    event, id, message = os.pullEvent("rednet_message")

    if id == 17 then

        if message == "engines on" then

            engine_state = true

        elseif message == "engines off" then

            engine_state = false

        end

    end

 

    mon.clear()

    mon.setCursorPos(5,5)

    if engine_state == true then

        mon.write("Engines: On")

    else

        mon.write("Engines: Off")

    end

 

local buffer_state = false

while true do

    event, id, message = os.pullEvent("rednet_message")

    if id == 10 then

        if message == "buffer drain" then

            buffer_state = true

        elseif message == "buffer retain" then

            buffer_state = false

        end

    end

 

    mon.clear()

    mon.setCursorPos(5,7)

    if buffer_state == true then

        mon.write("Buffer: Drain")

    else

        mon.write("Buffer: Retain")

    end

 

end

end

Posted


rednet.open("top")

local engine_state = false

local buffer_state = false

mon = peripheral.wrap("back")

while true do

    event, id, message = os.pullEvent("rednet_message")

    if id == 17 then

        if message == "engines on" then

            engine_state = true

        elseif message == "engines off" then

            engine_state = false

        elseif message == "Buffer: Drain" then

            buffer_state = true

        elseif message == "Buffer: Retain" then

            buffer_state = false

        end

    end

 

    mon.clear()

    mon.setCursorPos(5,5)

    if engine_state == true then

        mon.write("Engines: On")

    else

        mon.write("Engines: Off")

    end

    mon.setCursorPos(5,7)

    if buffer_state == true then

        mon.write("Buffer: Drain")

    else

        mon.write("Buffer: Retain")

    end

end

The issue with your example is that you created two endless loops and only one could be active at a time. All of your computers sending and receiving messages via rednet should use the same rednet id.

Posted

Ah, I see your point. How do I change the rednet id's of my computers? Every computer has a different id, the only way I can think of to make the id's the same is to use one computer, which is not possible in this case.

Posted

in your sender's code:


rednet.send(21,"engines on")

That first argument is what id it's being sent by. Pick a number and just use it. The idea is one... implementation of rednet communication would use one rednet id, another (e.g. a completely separate and independent from this status monitor project) implementation would use another.

Posted

Because what is happening now is that the main computer is only recognizing the message being sent to it from computer 17. And all the other computers are sending to computer 21 (the main computer). So we need the main computer to recognize messages from multiple ids (computer numbers)

Posted

I think since there isn't a straight forward way to get the computer ID and that the computer ID can change if the computer is dismantled and replaced they opted for a different system of identifying the intended recipient. Rednet is a message bus meaning that it doesn't send to specific PCs it sends to any computer connected to the rednet network and each computer either reacts to it or doesn't depending on the code running on it.

Posted

Because what is happening now is that the main computer is only recognizing the message being sent to it from computer 17. And all the other computers are sending to computer 21 (the main computer). So we need the main computer to recognize messages from multiple ids (computer numbers)

What's happening is that only the one computer is sending it's update messages on rednet id (aka channel) 17 and that's the only one the monitor computer is listening to. You could make it listen to multiple but that's not necessary here. Just have all of your sending pcs use the same rednet id and you'll be fine.

Posted

Ok my mistake yet again. Contrary to what it may seem I'm not a CC programming expert. :D I hadn't done all my research on rednet. See This. You are correct that is the ID for the destined PC. There's two ways to fix this.


event, id, message = os.pullEvent("rednet_message")

if id == 17 then

-- do things

elseif id == 21 then

-- do other things

end



 

or if you use rednet.broadcast instead of rednet.send in your sending computers that WILL send to all attached computers. If you go this route remove the if id == whatever then line and one of the ends so that you're no longer checking what id contains.
Posted

I am using the broadcast method. The engine status seems to be working fine, but the buffer state does not. It is recognizing the signal, but it does not change what is displayed.

Posted

Here are my current codes

main code

rednet.open("top")

local engine_state = false

local buffer_state = false

mon = peripheral.wrap("back")

while true do

    event, id, message = os.pullEvent("rednet_message")

        if message == "engines on" then

            engine_state = true

        elseif message == "engines off" then

            engine_state = false

        elseif message == "Buffer: Drain" then

            buffer_state = true

        elseif message == "Buffer: Retain" then

            buffer_state = false

        end

 

    mon.clear()

    mon.setCursorPos(5,5)

    if engine_state == true then

        mon.write("Engines: On")

    else

        mon.write("Engines: Off")

    end

    mon.setCursorPos(60,5)

    if buffer_state == true then

        mon.write("Buffer: Drain")

    else

        mon.write("Buffer: Retain")

    end

end


 

Engine send code


rednet.open("left")

while true do

shell.run("clear")

if rs.getInput ("back") then

      rednet.broadcast("engines on")

else

    rednet.broadcast("engines off")

end

os.pullEvent("redstone")

end


 

Buffer send code


rednet.open("top")

while true do

 shell.run("clear")

 if rs.getInput ("front") then

      rednet.broadcast(21,"buffer drain")

 else

     rednet.broadcast(21,"buffer retain")

 end

 os.pullEvent("redstone")

end

end

Posted

  1. Remember that what a sender sends and what the monitor is testing for should be the same. Your buffer sender sends "buffer drain" and your monitor is looking for "Buffer: Drain". It's case sensitive. You could send anything really just as long as it matches the other side.
  2. Remove the 21, from your broadcast calls in the buffer sender's code.
Posted

As I understand it, the ComputerCraft Wireless RedNet allows computers to broadcast messages to eachother, and the Wired modems/cables function in the same manner.

The MineFactory Reloaded RedNet cables function like RedPower 2 Bundled cables, and ComputerCraft includes an API to access all 16 channels of the cables through 1 connection.

So essentially I'm saying it would be easiest to use analog wired redstone cables as opposed to Computercraft networking. That's how I'd do it.

I have to add: easiest, but not best. With rednet cabling, you have 16 channels of data, but with CC rednet, you can send and receive ANY message, which is far more flexible. Just sayin'.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Announcements

  • Anything claiming to be official Technic servers are not allowed here, for obvious reasons



×
×
  • Create New...