Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reactor = "BigReactors-Reactor_1"
- capacitor = "enderio:advanced_capacitor_bank_1"
- state_home_channel = 1
- control_channel = 3
- states = {
- ["BigReactor"] = {
- ["state"] = false
- },
- ["Capacitor"] = {
- ["charge"] = 0
- },
- }
- control_reactors = {
- ["BigReactor"] = false,
- ["FissionReactor"] = false
- }
- modem_reactor = peripheral.wrap("left")
- modem_capacitor = peripheral.wrap("right")
- modem_wireless = peripheral.wrap("back")
- modem_wireless.open(control_channel)
- capacity = modem_capacitor.callRemote(capacitor, "getEnergyCapacity")
- print("Battery Capacity: ", capacity)
- states["BigReactor"]["state"] = modem_reactor.callRemote(reactor, "getActive")
- print("Reactor state: ", states["BigReactor"]["state"])
- states["Capacitor"]["charge"] = (modem_capacitor.callRemote(capacitor, "getEnergy")/capacity)*100
- print("Capacitor charge: ", states["Capacitor"]["charge"])
- -- Send states to server
- -- print(("Sending to server: "), states)
- modem_wireless.transmit(state_home_channel, 65535, states)
- local function handleMessages()
- -- Receive control commands and handle reactor
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- control_reactors = message
- print("Received control message")
- print("BigReactor: ", control_reactors["BigReactor"])
- end
- local function handleProgram()
- states["BigReactor"]["state"] = modem_reactor.callRemote(reactor, "getActive")
- print("Reactor state: ", states["BigReactor"]["state"])
- states["Capacitor"]["charge"] = (modem_capacitor.callRemote(capacitor, "getEnergy")/capacity)*100
- print("Capacitor charge: ", states["Capacitor"]["charge"])
- -- Send states to server
- -- print(("Sending to server: "), states)
- modem_wireless.transmit(state_home_channel, 65535, states)
- sleep(1)
- if control_reactors["BigReactor"] == true then
- print("Turning on Reactor.")
- modem_reactor.callRemote(reactor, "setActive", true)
- elseif control_reactors["BigReactor"] == false then
- print("Turning off Reactor.")
- modem_reactor.callRemote(reactor, "setActive", false)
- end
- end
- ---------------------------------------------------------------------------------------
- while true do
- parallel.waitForAny(handleProgram,handleMessages)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement