Script to read gas pulses from a CC dev board

 

Here's a script (in applet form) to count gas use from a Schlumberger R5 gas meter using a CC dev board attached to the RJ11 socket on the underside of the digital display.

The CC sensor (sensor.1 in my case) alternates between 0 and 500 watts output depending on the state of the reed switch in the meter. This script just counts up and records the pulses on the livebox. The switch opens/closes once per cu ft of gas consumed.

 

 

_______________________________________________________________________________________________________

Member for

16 years 10 months

brett

14 years 11 months ago

Making an operating system call just to write a value into a file is "heavy"

local cmd = string.format("echo '%s'>/etc/plugboard/gascuft", cumulativegas)
os.execute(cmd)

You can do the same in pure LUA which is more efficient - Its a little ODD that you use LUA for the READ but an OS call for the WRITE ?!

file = io.open("/etc/plugboard/gascuft","w+")
file:write(tostring(cumulativegas))
file:close()

OH another refinement.... You trigger the event and then check for a value.  Why not filter and only trigger when you have a value of 500?  Then you can compress this code down to something even more simpler.

local f = xap.Filter()
f:add("xap-header", "source", "dbzoo.livebox.CurrentCost:sensor.1")
f:add("xap-header","class","xAPBSC.event")
f:add("input.state","text","500")
f:callback(function() tempcount = tempcount + 1 end)

One more thing you should put xap.Timer construct inside the function init() you don't need to have it outside like you do, and this is actually not recommended as it will be activated as soon as the module is loaded and not when the module it actually initialized which isn't the same thing.

Hope these tips are useful.

UPDATE: I had a crack at writing the code for to so it exposes the GAS reading as a BSC endpoint, from here is very easy to pick the value up and feed it to Pachube for graphing.

One thing thou - I'm not sure that graphing an abolsute value is what you want to do - I woudl have thought that just the delta for each 5 min period would be better as this would give you a rolling consumption figure... anyway there is enough skeleton there to get you going ......

Brett

Attachments
gasApplet.lua (1.3 KB)

Member for

15 years 1 month

allanayr

14 years 11 months ago

Hey Brett, Thanks for this. I'm not sure that I quite understand BSC endpoints yet but I'm sure that your script will help with that. I confess that the file input/output stuff was just laziness! I picked the routine up from someone else's script and as it worked OK, in the spirit of "if it ain't broke don't fix it" I just used it as it stood. :-p

I'll give the script a run and see how it goes.

Member for

15 years 1 month

allanayr

14 years 11 months ago

Having run the script I get the following error:

 

Error Message: A xAP message received was malformed. The UID FF00D801 is setup as a subaddress but the Source address is not: dbzoo.livebox.gas
Received From: 192.168.0.2:3078

 

Now I'm in trouble!

Member for

16 years 10 months

brett

14 years 11 months ago

Easy fix make the source address be something like "dbzoo.livebox.gas:sensor"

Brett

Member for

15 years 10 months

g7pkf

14 years 11 months ago

For a CC digital development board :)

Member for

15 years

tickett

14 years 11 months ago

Allan, thanks for posting the script, and Brett for making some improvements.

I'm currently debating whether to use CC development boards to catch pulses from my gas and water meters or if a roomnode of some sort would be better. Any thoughts?

Using CC Dev Boards:

Pro- Cheap per board

Con- Limited number of channels available on currentcost (already using lots of IAM's etc)

Con- Extra hop via the currentcost

Using room node:

Pro- Can use a single node to count multiple device pulses

Con- A little pricier

Con- Extra hop via the hahcentral "node"

 

L

Member for

16 years 10 months

brett

14 years 11 months ago

I think using a separate board ie a modified hahnode might be the go this would decouple the unit from the CurrentCost.  This would give you more control locally for processing so that the information was only sent every minute or two.  An IAM on a CC unit would trigger every pulse and this is going to create a lot of RF noise and possibly interfere with other IAM's units and/or other RF devices.  Not to mentioned the additional load induced by xap-currentcost and subsequently Plugboard in having to deal with the incoming data for each generated pulse.  You really want to off load this capability to a remote processor (ie an AVR)

The HAH Node are also bi-directional RF which means you can have an ACK capability to make sure the Transmission was received by the base unit.  Something we do for the PIR movement sensor.  Something I'm not sure the IAM unit can do either.

Using a remote node you would expose at least a couple of endpoints.

gas:reading
gas:usage

Where the reading would be an aggregation of the usage its value could be persisted in the AVR's eeprom so it would not be lost on a power cycle.  Usage would be the number of ticks measured between reporting periods.  For the Reading you would need some mechanism for setting this value remotely from the HAH too, that is easy enough.

Just thoughts.

Brett

Member for

15 years 1 month

allanayr

14 years 11 months ago

Just a couple of thoughts on this. I searched the internet for methods of monitoring gas consumption and although I found a couple of commercial (and therefore quite expensive) methods of doing it, there seems to be a dearth of readily available methods out there.

Basically my solution was dictated by what I had available lying around. Hence an old modem cable and a CC dev board. I'm not claiming any elegance or sophistication but it does work, and it works now. (and with a little help from Brett it probably works better :-)

If this forum helps to create an elegant and sophisticated solution as a result then I'm sure that there will be much interest. I'm sure that room nodes are probably getting closer to that but if you want a "working  now" solution then many people seem to already use Current Cost and the dev boards are relatively cheap. You do, of course, have to be lucky enough to have a reed switch and RJ11 socket on your meter.

Glad to be able to at least start development route.

Member for

14 years 5 months

mark_baldwin

14 years 6 months ago

I have a CC dev board with a flip-flop. The flip-flop is set as the magnet passes the reed switch and is reset by the LED so I know the last pass of the magnet has been sent.

The dev board was a free gift from CC, the flip-flop was 32p and the reed switch was 99p from Map***

Now thanks to this script I can log my gas consumption.

Member for

16 years 5 months

BoxingOrange

14 years 6 months ago

Hi Mark,

Would you be able to provice details and a diagram that could be used to your gas monitor.  I already have the CC board, but would need to get and build the rest,

Thanks

Karl

Member for

14 years 5 months

mark_baldwin

14 years 6 months ago

Hi Karl

Here's the schematic I used.

The flip flop catches the pulse from the magnet and holds the output high until reset by the pulse to the LED (message sent). This means that the every pulse gets sent. The RC network is to ensure that only one pulse is sent if the magnet parks itself over the sensor.

Mark

Attachments
gasmonitor.jpg (49.75 KB)

Member for

16 years 5 months

BoxingOrange

14 years 6 months ago

Thanks for the diagram Mark, but I'm not an electrician, so just struggling with the pin numbers on the 4013.  I count 6 connections to it, but can only work out the following, (assuming first side of flip flop) :-

S - Set, pin 6 
Q - Q1, pin 1
R - Reset, pin 4
Set - (Vss, ground, pin 7)
CLR - ??
> - (Vdd, positive pin 14)

My chip is a CD4013BE, if you could fill in the blank and sort my mistakes out that would be great,

Thanks

Karl

Member for

14 years 5 months

mark_baldwin

14 years 6 months ago

Sorry about that Karl I assume everyone can read schematics sometimes :)

Hopefully this will help

The 300M resistor is something I added as I was getting a floating voltage from the LED, enough to trigger the reset.

Attachments
gas_interface.jpg (27.75 KB)