From 9bd6cd94c880adc1166105f7b0cc1225de82b0ec Mon Sep 17 00:00:00 2001 From: "navid.sassan" Date: Fri, 2 Apr 2021 17:10:22 +0200 Subject: [PATCH] removed concept of a master --- energy_control | 4 +++- redstone_toggle | 16 +++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/energy_control b/energy_control index 83e4f78..ceae146 100644 --- a/energy_control +++ b/energy_control @@ -1,3 +1,5 @@ +local hostname = "pocket_computer" .. os.getComputerID() + redstone_toggle_id = 50 de_store_mon_id = nil @@ -91,7 +93,7 @@ for i = 1, #sides do end rednet.open(modemSide) -rednet.host("rmm", "master") +rednet.host("rmm", hostname) parallel.waitForAny(poll, recv, key_watcher) rednet.close(modemSide) diff --git a/redstone_toggle b/redstone_toggle index 83ba38d..b686032 100644 --- a/redstone_toggle +++ b/redstone_toggle @@ -27,36 +27,36 @@ function recv() local cmd_fn, err = loadstring(data[2]) if not cmd_fn then print("Failed to compile '" .. data[2] .. "': " .. err) - rednet.send(master, "Failed to compile '" .. data[2] .. "': " .. err) + rednet.send(id, "Failed to compile '" .. data[2] .. "': " .. err) else local success, output = pcall(cmd_fn) if success then if output then print("Command output from '" .. data[2] .. "': " .. dump(output)) - rednet.send(master, "Command output from '" .. data[2] .. "': " .. dump(output)) + rednet.send(id, "Command output from '" .. data[2] .. "': " .. dump(output)) else print("There is no command output from '" .. data[2] .. "'") - rednet.send(master, "There is no command output from '" .. data[2] .. "'") + rednet.send(id, "There is no command output from '" .. data[2] .. "'") end else print("Runtime error: " .. output) - rednet.send(master, "Runtime error: " .. output) + rednet.send(id, "Runtime error: " .. output) end end end elseif type(data) == 'string' then if data == 'ping' then print("Pong!") - rednet.send(master, "Pong!") + rednet.send(id, "Pong!") elseif data == 'toggle' then local output_state = not redstone.getInput("back") redstone.setOutput("back", output_state) print("Toggled output to: " .. tostring(output_state)) - rednet.send(master, "Toggled output to: " .. tostring(output_state)) + rednet.send(id, "Toggled output to: " .. tostring(output_state)) elseif data == 'get_state' then local output_state = redstone.getInput("back") print("Output state: " .. tostring(output_state)) - rednet.send(master, {'output_state', output_state}) + rednet.send(id, {'output_state', output_state}) end end end @@ -72,7 +72,6 @@ function lever_input() local output_state = not redstone.getInput("back") redstone.setOutput("back", output_state) print("Toggled output to: " .. tostring(output_state)) - rednet.send(master, "Toggled output to: " .. tostring(output_state)) end sleep(1) end @@ -88,7 +87,6 @@ end rednet.open(modemSide) rednet.host("rmm", hostname) -master = rednet.lookup("rmm", "master") parallel.waitForAny(recv, lever_input)