This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
tvc's profile picture

openccsensors help with reading mfsu

Started by tvc, 31 May 2013 - 08:37 PM
tvc #1
Posted 31 May 2013 - 10:37 PM
I want to read no joke 100 mfsu and display current power over max.

is there a way to read them all at once or do i need to write a program that takes the current value for each mfsu current power assign it to a variable then add them all up.
Lyqyd #2
Posted 31 May 2013 - 11:14 PM

local euSense = sensor.wrap("top") --# change to sensor side.
while true do
  local total, totalCap = 0, 0
  for target in pairs(euSense.getTargets()) do
    if target.Capacity == 10000000 then
      total = total + target.Stored
	  totalCap = totalCap + target.Capacity
    end
  end
  print(total.." / "..totalCap)
  sleep(0.5)
end

If you want it to only do it once, take out the very last end, the while true do, and the sleep.
Bomb Bloke #3
Posted 31 May 2013 - 11:15 PM
Methinks 100 MFSUs might be overkill, yes? An Adjustable Energy Storage Unit holds 10x what they do, while a Inter-Dimensional Storage Unit stores 100x.
tvc #4
Posted 31 May 2013 - 11:45 PM

local euSense = sensor.wrap("top") --# change to sensor side.
while true do
  local total, totalCap = 0, 0
  for target in pairs(euSense.getTargets()) do
	if target.Capacity == 10000000 then
	  total = total + target.Stored
	  totalCap = totalCap + target.Capacity
	end
  end
  print(total.." / "..totalCap)
  sleep(0.5)
end

If you want it to only do it once, take out the very last end, the while true do, and the sleep.

i get an error. startup:1: attempt to index ? (a nil value) and yes my sensor is on top
CoderPuppy #5
Posted 31 May 2013 - 11:48 PM
You need to add os.loadAPI('ocs/apis/sensor') above the sensor.wrap
tvc #6
Posted 31 May 2013 - 11:50 PM
You need to add os.loadAPI('ocs/apis/sensor') above the sensor.wrap
/facepalm
tvc #7
Posted 31 May 2013 - 11:53 PM

local euSense = sensor.wrap("top") --# change to sensor side.
while true do
  local total, totalCap = 0, 0
  for target in pairs(euSense.getTargets()) do
	if target.Capacity == 10000000 then
	  total = total + target.Stored
	  totalCap = totalCap + target.Capacity
	end
  end
  print(total.." / "..totalCap)
  sleep(0.5)
end

If you want it to only do it once, take out the very last end, the while true do, and the sleep.

all you get its a loop of 0/0
Lyqyd #8
Posted 01 June 2013 - 02:54 AM
That's because I did it wrong! Give this a shot:


os.loadAPI("ocs/apis/sensor")
local euSense = sensor.wrap("top") --# change to sensor side.
while true do
    local total, totalCap = 0, 0
    for target in pairs(euSense.getTargets()) do
        local details = euSense.getTargetDetails(target)
        if details.Capacity == 10000000 then
            total = total + details.Stored
            totalCap = totalCap + details.Capacity
        end
    end
    print(total.." / "..totalCap)
    sleep(0.5)
end