I tried a different approach this time. I open each channel, and tell the slave that the master is listening, then wait for a response, then close. Updated code below, haven't tested this yet.
Master:
http://pastebin.com/wyPP35E7Spoiler
--Program for base control and HUD display.
--Master program
--Functions
function clearBoiler()
boilerInfo.setOpacity(0)
boilerTitle.setText(" ")
boilerTemp.setText(" ")
end
function clearTurbine()
turbineInfo.setOpacity(0)
turbineTitle.setText(" ")
turbineMaintenence.setText(" ")
end
function clearEngergyCell1()
energyCell1Info.setOpacity(0)
energyCell1Title.setText(" ")
energyCell1Text.setText(" ")
end
function clearEngergyCell2()
energyCell2Info.setOpacity(0)
energyCell2Title.setText(" ")
energyCell2Text.setText(" ")
end
--Peripherals
glass = peripheral.wrap("left")
modem = peripheral.wrap("top")
--Variable definitions
-- y : Starting yPos for user names.
-- usertitle : Title text in user box. Configurable.
name1 = "Liquid Fueled Boiler "
name2 = "Steam Turbine "
name3 = "Energy Cell "
--HUD Object Initialization (None display)
glass.clear()
boilerInfo = glass.addBox( 12, 195, glass.getStringWidth( name1 )+7, 34, 0xfb0000, 0)
boilerTitle = glass.addText( 15, 200, " ", 0 )
boilerTemp = glass.addText( 20, 210, " ", 0 )
turbineInfo = glass.addBox( 12, 95, glass.getStringWidth( name2 )+7, 34, 0xfb0000, 0)
turbineTitle = glass.addText( 15, 100, " ", 0 )
turbineMaintenance = glass.addText( 15, 110, " ", 0 )
energyCell1Info = glass.addBox( 23, 15, glass.getStringWidth( name3 )+7, 24, 0x17c92c, 0)
energyCell1Title = glass.addText( 25, 20, " ", 0 )
energyCell1Text = glass.addText( 25, 30, " ", 0 )
energyCell2Info = glass.addBox( 23, 25, glass.getStringWidth( name3 )+7, 24, 0x17c92c, 0)
energyCell2Title = glass.addText( 25, 30, " ", 0 )
energyCell2Text = glass.addText( 25, 40, " ", 0 )
--Wireless Channel Documentation
boilerChannel = 10
turbineChannel = 20
mfsu1Channel = 30
mfsu2Channel = 31
energyCell1Channel = 40
energyCell2Channel = 41
--Program
while true do
local usertitle = glass.addText( 15, 42, "Connected Users:", 0xffffff )
users = glass.getUsers()
local y = 50
for k, v in pairs(users) do --Updating User list
glass.addText(25, y, tostring(v), 0xffffff )
y = y + 10
end
modem.open(boilerChannel)
modem.transmit( boilerChannel, boilerChannel, "Go" ) --Tells slave it's listening
event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message") --Waits for slave to respond.
if message == "High" then
boilerInfo.setOpacity(0)
boilerTitle.setText(" ")
boilerTemp.setText(" ")
else
boilerInfo.setOpacity(.15)
boilerTitle.setText( name1 )
boilerTemp.setText( message )
end
modem.close(boilerChannel)
modem.open(turbineChannel)
modem.transmit( turbineChannel, turbineChannel, "Go" ) --Tells slave it's listening
event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message") --Waits for slave to respond.
if message == "TurbineBad" then
turbineInfo.setOpacity(.15)
turbineTitle.setText( name2 )
turbineMaintenance.setText("Needs Maintenance!")
elseif message == "TurbineGood" then
turbineInfo.setOpacity(0)
turbineTitle.setText(" ")
turbineMaintenance.setText(" ")
end
modem.close(turbineChannel)
modem.open(energyCell1Channel)
modem.transmit( energyCell1Channel, energyCell1Channel, "Go" ) --Tells slave it's listening
event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message") --Waits for slave to respond.
if message == "Low" then
energyCell1Info.setOpacity(.15)
energyCell1Title.setText( name2 )
energyCell1Text.setText("Energy Low!")
elseif message == "Good" then
energyCell1Info.setOpacity(0)
energyCell1Title.setText(" ")
energyCell1Text.setText(" ")
end
modem.close(energyCell1Channel)
modem.open(energyCell2Channel)
modem.transmit( energyCell2Channel, energyCell2Channel, "Go" ) --Tells slave it's listening
event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message") --Waits for slave to respond.
if message == "Low" then
energyCell2Info.setOpacity(.15)
energyCell2Title.setText( name2 )
energyCell2Text.setText("Energy Low!")
elseif message == "Good" then
energyCell2Info.setOpacity(0)
energyCell2Title.setText(" ")
energyCell2Text.setText(" ")
end
modem.close(energyCell2Channel)
sleep(.1)
end
Slave:
http://pastebin.com/aRUfv6kBSpoiler
--Boiler Slave
--Peripheral wrapping
boiler = peripheral.wrap("left")
modem = peripheral.wrap("top")
--Variable Definition
boilerChannel = 10
--Program
modem.open( boilerChannel )
while true do
event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message")
if boiler.getTemperature() < "1000" then
modem.transmit( boilerChannel, boilerChannel, boiler.getTemperature() )
else
modem.transmit( boilerChannel, boilerChannel, "High" )
end
end