Jump to content




openccsensors help with reading mfsu


  • You cannot reply to this topic
7 replies to this topic

#1 tvc

  • Members
  • 35 posts

Posted 31 May 2013 - 09: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.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 31 May 2013 - 10: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.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 May 2013 - 10: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.

#4 tvc

  • Members
  • 35 posts

Posted 31 May 2013 - 10:45 PM

View PostLyqyd, on 31 May 2013 - 10:14 PM, said:

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

#5 CoderPuppy

  • Members
  • 121 posts

Posted 31 May 2013 - 10:48 PM

You need to add os.loadAPI('ocs/apis/sensor') above the sensor.wrap

#6 tvc

  • Members
  • 35 posts

Posted 31 May 2013 - 10:50 PM

View PostCoderPuppy, on 31 May 2013 - 10:48 PM, said:

You need to add os.loadAPI('ocs/apis/sensor') above the sensor.wrap
/facepalm

#7 tvc

  • Members
  • 35 posts

Posted 31 May 2013 - 10:53 PM

View PostLyqyd, on 31 May 2013 - 10:14 PM, said:

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

#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 01 June 2013 - 01: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






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users