Jump to content




Monitor Storage tanks lua script


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

#1 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 17 September 2014 - 07:33 PM

I fount a script that's used to monitor the amounts and totals in a storage tank. The mainprog works. How ever the program used for monitoring the tank seems to give me a nil error in line 27 and i was hoping some one mite have an idea why and how to fix this error. here's the line and the full code it below.

tanksTable = val.getTanks("WhatIsThis") -- Line 27

----------

    -- Valve, Monitor & Wireless Modem
    local val = peripheral.wrap("back")
    local mon = peripheral.wrap("top")
    local wmod = peripheral.wrap("bottom")
	
    local warning = 20	   -- Warning level in %
    local cap			    -- Tank capacity
    local amount			 -- Amount liquid in tank
    local percentfull	    -- Percent liquid in tank
    local lastpercent = 1000 -- Percent last loop
    local sendmsg		    -- Message to send
    local sleeptime		  -- How long to sleep
    local sendFreq = 3	   -- Modem Frequency
    local content = "Water"  -- What is in tank?
    -- Make sure frequency match the main computer
	
    -- Set warning lamp to off
    redstone.setOutput("right", false)
	
	
    -- Main prog loop, never stop
    while true do
	  mon.clear()
	  mon.setCursorPos(1,1)
	
	  -- Fill table with data from tank valve
	  tanksTable = val.getTanks("WhatIsThis") -- Line 27
	  maintank = tanksTable[1]
	
	  -- Get values for tank capacity and amount
	  cap = maintank.capacity / 1000   -- in buckets
	  amount = maintank.amount    -- in millibuckets
	
	  -- If tank is empty, to avoid math issues with 0
	  if amount == nil then
	    amount = 0
	    percentfull = 0
	  else
	    -- Use math.floor to convert to integers
	    amount = math.floor(amount / 1000)
	    percentfull = math.floor(100 * amount / cap)
	  end
	
	  -- Self explanatory :)/>
	  mon.write(content)
	  mon.setCursorPos(1,2)
	  mon.write("Amount: " ..amount .."/"..cap .." B.")
	  mon.setCursorPos(1,3)
	  mon.write("Amount: " ..percentfull .."%  ")
	
	  -- Check for change since last loop 
	  if percentfull == lastpercent then
	    print("Still " ..percentfull .. "%, nothing sent.")
	  else
	    -- If value changed, send to main!
	    sendmsg = content ..": " ..percentfull .." %"
	    wmod.transmit(sendFreq,0,sendmsg)
	    print("Sent: " ..sendmsg)
	  end
	
	  -- Save for next loop
	  lastpercent = percentfull
	
	  -- Warning control, local lamp
	  mon.setCursorPos(1,5)
	
	  if percentfull < warning then
	    redstone.setOutput("right", true)
	    mon.write("Less than " ..warning .."% full")
	    sleep(1)
	    redstone.setOutput("right", false)
	    sleeptime = 1
	  else
	    -- Above warning level, sleep longer
	    mon.write("More than " ..warning .."% full")
	    sleeptime = 10
	  end
	
	  -- Sleep either 1 or 10 seconds
	  sleep(sleeptime)   
    end



#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 17 September 2014 - 08:08 PM

Try changing "WhatIsThis" to "unknown" - that *might* fix it, otherwise you may need to specify a direction ("north", "south", "east", "west", "up", "down"). The only other things I can see that might be an issue are:

1. Is the device that val is being used to wrap actually on the back?
2. Is getTanks() a valid call?

If it's not one of those, I'll have to defer to one of the more seasoned pros...

#3 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 17 September 2014 - 08:09 PM

More than likely getTanks() isn't a valid function, try using
for key,value in pairs(peripheral.getMethods("back")) do
  print(key.."   :   "..value)
end

Edit: half ninja'd

Edited by Dragon53535, 17 September 2014 - 08:10 PM.


#4 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 17 September 2014 - 08:39 PM

Nothing worked. so I tried your idea Dragon, and I get only 2 options back.

getAdvanceMethodsData
listMethods.

Can you guys tell me what to do. I don't know what to do or how to use those commands or functions. I'm still learning.

#5 ShadowDisruptor

  • Members
  • 74 posts

Posted 17 September 2014 - 08:56 PM

Are you sure you have all the correct mods to use this script?

#6 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 17 September 2014 - 09:09 PM

Hope. I'm not sure of any thing, I'm all so new to this. I fount this. It's an older tutorial. https://www.youtube....h?v=X-owrYlGCXI

He didn't say any thing about any requirements. So maybe you can see some thing I didn't.

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 18 September 2014 - 01:39 AM

If those are the only two methods the peripheral provides, there is an incompatibility somewhere, most likely in the versions of OpenP and the mod providing the tank. You would need versions of both mods that are intended to work together.

#8 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 18 September 2014 - 01:42 AM

with OpenP, tank information should be returned using peripheral.getTankInfo(). This would return the amount, capacity, and fluid name and rawname.

#9 Bomb Bloke

    Hobbyist Coder

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

Posted 18 September 2014 - 01:44 AM

Though he already established that function isn't available. Which likely has a lot to do with him using MC 1.7.10. Beta software, and all that.

As I was saying, you might consider using a comparator instead. It's either that or waiting for a ton of updates, or downgrading to something stable.

#10 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 18 September 2014 - 01:49 AM

In my experience OpenP for 1.7.10 doesn't work with/support CC 1.64pr4

Edited by Dog, 18 September 2014 - 01:49 AM.


#11 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 18 September 2014 - 02:50 AM

OpenCCSensors is only version 1.6.4 of minecraft and I have the bata version of OpenP. It's beta all so. The problem is that they don't have a list of all the methods for the OpenP mod. It was a dream. I thought it would be great if i could monitor my tanks from the network control room.

#12 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 18 September 2014 - 03:50 AM

View Posticeman11a, on 17 September 2014 - 09:09 PM, said:

Hope. I'm not sure of any thing, I'm all so new to this. I fount this. It's an older tutorial. https://www.youtube....h?v=X-owrYlGCXI

He did update the tutorial in another video 10 days ago, he also put it in the description of that video. https://www.youtube.com/watch?v=G24i4Lbtau0

#13 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 18 September 2014 - 09:50 AM

Well it looks like he's using OpenP for MC 1.6.4. So maybe what I'm trying to do haven't been added in this version of OpenP. I see that the code was changed as it was in a earlier post. I still have the same problem on the same line. I get getting a nil value error

SO I'll have to check with openP and see just what they added and so. I'll have to contact the coders and see if i can find out just what's going on. I'll have to see if I can find an OpenP IRC chat room all so.

Guys, If any of you have an idea or 2, please let me know.

#14 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 18 September 2014 - 10:33 AM

Here's what I fount,

OpenPeripheral 1.7 is not functional. We give no guarantee that unreleased snapshots are functional.

So I guess I'm screwed.

#15 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 18 September 2014 - 06:43 PM

From what I have done and what I learned. That most of the openperipheral doesn't have more then 1/2 of what it should have. I should be able to use a chest and that doesn't seem to work all so. So I need a list of what openperipheral has and what it supports. If any one has some ideas please let me know. In the mean time I'm going to try the IRC chat channel and see if I can get some real help this time.

#16 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 18 September 2014 - 09:31 PM

I didn't think to look at the configure file. There's 5 blocks.

glassesbridge -- All ready been playing with this block
peripheralproxy
pim
sensor
ticketmachine

Can some one tell me how to use these in CC = Computercraft. using the lua code. Oh and how do I report bugs. I see that the ink is missing for the ticket machine.

#17 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 18 September 2014 - 10:02 PM

From what I've learned about OpenPeripheral for 1.7.10, it's non-functional as far as peripherals are concerned. I believe they're waiting on a stable release of ComputerCraft before they finish up those features. I just saw Dan200 work through some bug reports lately, so it's possible we may see a new pr5 version soon. With that, a new OpenPeripheral as well.

#18 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 19 September 2014 - 04:10 AM

From what I saw in the config files. There's only 5 blocks that work. I been playing with them and trying to learn and it's not easy. It's just going to take a lot of time. Due to the fact that I can't find help with them, Here's a list of the 5 blocks openP does have working,

glasses bridge
peripheralproxy
pim
sensor
ticketmachine -- This one the ink is missing. So I can't even play with it.

#19 Bomb Bloke

    Hobbyist Coder

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

Posted 19 September 2014 - 05:35 AM

View Posticeman11a, on 19 September 2014 - 04:10 AM, said:

Due to the fact that I can't find help with them,

If you haven't tried it already, give the docs script a go:

openp/docs <peripheralSide>

openp/docs <peripheralSide> <functionName>

View Posticeman11a, on 19 September 2014 - 04:10 AM, said:

ticketmachine -- This one the ink is missing. So I can't even play with it.

I'd sorta expect it to take vanilla squid ink?

#20 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 19 September 2014 - 11:00 AM

1) Thanks how ever, That doesn't give me samples on how to use the methods. That's where my problem is. I don't know what to do.

2) I'd sorta expect it to take vanilla squid ink? (I can't find any thing related to a vanilla squid ink)

I need to find some one that can help with some small samples. If I can monitor the pressure in a pipe. Then why can't I monitor the energy in a cable or conduit. See openp is limited on what it can do until a stable release of CC is released,

I was on irc chat last night until I2 midnight looking and no one wants to help. I been spending hours searching google for samples and only finding samples that are years old, and out dated. Let me show you some thing.

p = peripheral.wrap("back")
while true do
x = p.getPressure()
print("Current pressure " .. x)
if x < 4 then
rs.setOutput("right", true)
print("Pressure low, Starting Engines")
else
rs.setOutput("right", false)
end
sleep(5)
end

This small sample monitors the pressure in a pipe from the back. Well why can't I do the same thing with energy. I know there's a way to do it. I just haven't figured it out yet.

I want to be able to use the computer and monitor. I want to be able to use openp all so. Getting the info for the monitor is all ready online. The problem is that openp is not well documented with samples.

If you have any ideas please provide links.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users