#1
Posted 18 June 2015 - 07:07 PM
#2
Posted 18 June 2015 - 07:38 PM
#3
Posted 18 June 2015 - 08:15 PM
Dog, on 18 June 2015 - 07:38 PM, said:
#4
Posted 18 June 2015 - 08:31 PM
xTheChosen0ne, on 18 June 2015 - 08:15 PM, said:
xTheChosen0ne, on 18 June 2015 - 08:15 PM, said:
Edited by Dog, 18 June 2015 - 08:37 PM.
#5
Posted 18 June 2015 - 09:13 PM
Dog, on 18 June 2015 - 08:31 PM, said:
xTheChosen0ne, on 18 June 2015 - 08:15 PM, said:
xTheChosen0ne, on 18 June 2015 - 08:15 PM, said:
When i simply make "shell.run(program name)" at the end of the loop, it works fine first, but after a few minutes there is a java problem. I "solved" the problem like this, with reboot:
Computer at MFE:
os.loadAPI("ocs/apis/sensor") mySensor = sensor.wrap("top") position = "0,0,-1" details = mySensor.getTargetDetails(position) kapazitaet = details.Capacity stand = details.Stored grenze = 30000 schleife = 1 while schleife > 0 do rednet.open("right") if stand <= grenze then rednet. broadcast("alarm") elseif stand > grenze then rednet.broadcast("ok") end sleep(1) shell.run("reboot") end
My Computer, which receive the messages and react on:
rednet.open("bottom") id, message = rednet.receive() write ("Status: ") if id == 15 and message == "alarm" then rs.setOutput("back", true) print("Kritisch. Eigenversorgung aktiviert.") end if id == 15 and message == "ok" then rs.setOutput("back", false) print("OK") end sleep(3) shell.run("reboot")
Both programs are made as startup
Edited by xTheChosen0ne, 18 June 2015 - 09:21 PM.
#6
Posted 18 June 2015 - 09:57 PM
Let's start with the MFE program. First, you don't need to specify a value and compare that value to create an infinite loop. Instead of this...
schleife = 1 while schleife > 0 do --# code... end
You can just do this
while true do --# code end
Next all the code that needs to repeat should be moved inside that loop. Think about which lines of code need to only be run once, and which ones need to repeat over and over. You want to put the non-repeating code above the loop and all the repeating code inside the loop. Try making those changes to your MFE program (we'll get to the second program after we finish the first) and post your results. We'll go from there.
Edited by Dog, 18 June 2015 - 10:01 PM.
#7
Posted 19 June 2015 - 08:53 AM
Dog, on 18 June 2015 - 09:57 PM, said:
Let's start with the MFE program. First, you don't need to specify a value and compare that value to create an infinite loop. Instead of this...
schleife = 1 while schleife > 0 do --# code... end
You can just do this
while true do --# code end
Next all the code that needs to repeat should be moved inside that loop. Think about which lines of code need to only be run once, and which ones need to repeat over and over. You want to put the non-repeating code above the loop and all the repeating code inside the loop. Try making those changes to your MFE program (we'll get to the second program after we finish the first) and post your results. We'll go from there.
Well, first, it seemed to work. But there is following problem: He just test the status, when i activate the program. So, when the MFE has more than 30000 EU at the moment, when i start the program, it ALWAYS send "ok" (also, when he gets under 30000 meanwhile). And when the MFE has equal or less than 30000 EU at the moment, when i start the program, it ALWAYS send "alarm" (also, when he gets 30000+ meanwhile).
That's not what i want to reach. The loop itself seems to work.
My code:
os.loadAPI("ocs/apis/sensor") mySensor = sensor.wrap("top") position = "0,0,-1" details = mySensor.getTargetDetails(position) kapazitaet = details.Capacity stand = details.Stored grenze = 30000 rednet.open("right") while true do rednet.open("right") if stand <= grenze then rednet. broadcast("alarm") sleep(1) end if stand > grenze then rednet.broadcast("ok") sleep(1) end end
Edited by xTheChosen0ne, 19 June 2015 - 09:31 AM.
#8
Posted 19 June 2015 - 10:25 AM
However, thats the working code for the MFE-Computer now!:
os.loadAPI("ocs/apis/sensor") mySensor = sensor.wrap("top") position = "0,0,-1" while true do details = mySensor.getTargetDetails(position) kapazitaet = details.Capacity stand = details.Stored grenze = 30000 rednet.open("right") if stand <= grenze then rednet. broadcast("alarm") sleep(1) end if stand > grenze then rednet.broadcast("ok") sleep(1) end end
How's about the 2nd program now?
Edited by xTheChosen0ne, 19 June 2015 - 11:00 AM.
#9
Posted 19 June 2015 - 02:49 PM
Now, the same applies to the second program. You don't want it to reboot, but you want it to run forever. So, think about which code needs to run once and which code needs to be in the loop. You'll use the same thing (while true do) you did last time.
#10
Posted 19 June 2015 - 05:32 PM
Dog, on 19 June 2015 - 02:49 PM, said:
Now, the same applies to the second program. You don't want it to reboot, but you want it to run forever. So, think about which code needs to run once and which code needs to be in the loop. You'll use the same thing (while true do) you did last time.
Alright, big thank you to you All is working like it should, now, thank you
#11
Posted 19 June 2015 - 06:37 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users