RFXPower with W800 - Perl help required !

View: New views
10 Messages — Rating Filter:   Alert me  

RFXPower with W800 - Perl help required !

by declang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi folks,
I abandoned this a long time back but now want to sort it out.
I have the older RFXPower unit, and the W800 is getting 4 bytes from it.

From looking at the X10_W800 and X10_RF libs, I think I have a handle on how to do it, but I;m stuck with some perl

With the 4 bytes I get from the W800, I need to do the following:

Bytes 1 & 2: Reverse the order of the bits, The 2 bytes gives the recorded kwh counter value

Bytes 3 & 4: verify the address of the Transmitter (does not change ?? )

Probably best explained by example:
raw data from W800 :  10011000 10010110 0000000 00001111

So:
byte1 = 10011000 : reverse bits, gives 00011001 = 25 decimal
byte2 = 10010110 : reverse bits, gives 01101001 = 105 decimal

so, (25 * 256) + 105 = 6505 = counter value


Byte 3&4 = 00000000 00001111 = 15 = Address.

Now, how do I do that in perl ?

I know I should use pack & unpack, but I'm lost on how to do that !

Is it similar to the way the X10_RF_digimax210.pm does it ?

==================================================
sub rf_process_digimax210 {
    my($module, @bytes) = @_;

    my @rbytes;
    for (my $i = 0; $i < 4; $i++) {
        $rbytes[$i] = ord(pack("b8", unpack("b*", $bytes[$i])));
    }

    $device_id = $rbytes[0] * 256 + $rbytes[1];
}
=====================================================

or am I on the wrong track ?


Thanks,
Declan

Parent Message unknown Re: RFXPower with W800 - Perl help required !

by Bill Young :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Declan,

It looks like you need something like this:

$value   =   ord(pack("B8", unpack("b*", $bytes[0]))) * 256
            + ord(pack("B8", unpack("b*", $bytes[1])));
$address = $bytes[2] * 256 + $bytes[3];

Bill

declan wrote on 06/10/2008 06:48 AM:

> Hi folks,
> I abandoned this a long time back but now want to sort it out.
> I have the older RFXPower unit, and the W800 is getting 4 bytes from it.
>
>>From looking at the X10_W800 and X10_RF libs, I think I have a handle on how
> to do it, but I;m stuck with some perl
>
> With the 4 bytes I get from the W800, I need to do the following:
>
> Bytes 1 & 2: Reverse the order of the bits, The 2 bytes gives the recorded
> kwh counter value
>
> Bytes 3 & 4: verify the address of the Transmitter (does not change ?? )
>
> Probably best explained by example:
> raw data from W800 :  10011000 10010110 0000000 00001111
>
> So:
> byte1 = 11000100 : reverse bits, gives 00011001 = 25 decimal
> byte2 = 10111001 : reverse bits, gives 01101001 = 105 decimal
>
> so, (25 * 256) + 105 = 6505 = counter value
>
>
> Byte 3&4 = 00000000 00001111 = 15 = Address.
>
> Now, how do I do that in perl ?
>
> I know I should use pack & unpack, but I'm lost on how to do that !
>
> Is it similar to the way the X10_RF_digimax210.pm does it ?
>
> ==================================================
> sub rf_process_digimax210 {
>     my($module, @bytes) = @_;
>
>     my @rbytes;
>     for (my $i = 0; $i < 4; $i++) {
>         $rbytes[$i] = ord(pack("b8", unpack("b*", $bytes[$i])));
>     }
>
>     $device_id = $rbytes[0] * 256 + $rbytes[1];
> }
> =====================================================
>
> or am I on the wrong track ?
>
>
> Thanks,
> Declan


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: RFXPower with W800 - Perl help required !

by declang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bill Young wrote:
Declan,

It looks like you need something like this:

$value   =   ord(pack("B8", unpack("b*", $bytes[0]))) * 256
            + ord(pack("B8", unpack("b*", $bytes[1])));
$address = $bytes[2] * 256 + $bytes[3];
Thanks Bill. I'll try that & report back.

Re: RFXPower with W800 - Perl help required !

by declang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Bill Young wrote:
Declan,

It looks like you need something like this:

$value   =   ord(pack("B8", unpack("b*", $bytes[0]))) * 256
            + ord(pack("B8", unpack("b*", $bytes[1])));
$address = $bytes[2] * 256 + $bytes[3];

Nope. still not doing the reverse order of bits properly.

In my decode routine I have :

my @rev ;
$rev[0]=ord(pack("B8", unpack("b*", $nbytes[0])));
$rev[1]=ord(pack("B8", unpack("b*", $nbytes[1])));
$rev[2]=ord(pack("B8", unpack("b*", $nbytes[2])));
$rev[3]=ord(pack("B8", unpack("b*", $nbytes[3])));

&::print_log(sprintf ("nbytes   %b %b %b %b", $nbytes[0], $nbytes[1], $nbytes[2], $nbytes[3]));
&::print_log(sprintf ("reversed %b %b %b %b", $rev[0], $rev[1], $rev[2], $rev[3]));

which gives me :
18/06/08 08:09:23 PM nbytes 1111001 11101100 0 1111
18/06/08 08:09:23 PM rev 10001100 1001100 1100 10001100


From the X10_RF.pm, i get :
18/06/08 08:09:23 PM W800: 01111001 11101100 00000000 00001111
but then my nbytes[0,1,2,3] becomes :
18/06/08 08:09:23 PM nbytes 1111001 11101100 0 1111

... it is dropping the leading zeroes. is that my problem, or is that just the way %b prints with sprintf ?

Thanks for any pointers.

I've tried all sorts of combinations of pack & unpack with B8, B*, b8, b*, etc etc.










phone_minutes.pl with AT&T

by Mickey Argo-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Does anyone know the proper URL for AT&T to insert into phone_minutes.pl?
The Cingular one is no longer working.
 
Mickey Argo



-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: RFXPower with W800 - Perl help required !

by declang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Bill Young wrote:
Declan,

It looks like you need something like this:

$value   =   ord(pack("B8", unpack("b*", $bytes[0]))) * 256
            + ord(pack("B8", unpack("b*", $bytes[1])));
$address = $bytes[2] * 256 + $bytes[3];
Well, I gave up on that method. I don't fully understand the pack & unpack.

I solved it by making an 8-character string of the binary, then reversing it using substr.

I now have the correct address & value being logged to the print.log.

Now, how do I proceed to log this stuff to a rrd ?
I have the address & value being returned as the state, but then I'm lost again :(

Thanks.

Re: RFXPower with W800 - Perl help required !

by Gregg Liming :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Declan,

declang wrote:

> Now, how do I proceed to log this stuff to a rrd ?
> I have the address & value being returned as the state, but then I'm lost
> again :(

Do you mean, log this stuff via the RRD support built into mh?  If so,
perhaps the quickest option is to just directly manipulate the Weather
hash--which is automatically logged to the RRD database each minute
(assuming you've got all the RRD support enabled).  So, let's suppose
that we have some temperature device:

if ($outside_temp_device->state_now) {
    $Weather{TempOutdoor} = $outside_temp_device->state;
}

Naturally, you have to know all the various Weather hash keys.  Some are
special and other are "spares" (e.g., TempSpare1 and HumidSpare1).

Is this what you had in mind?

Gregg

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: RFXPower with W800 - Perl help required !

by Gregg Liming :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For some reason, I never saw this get routed back from sf.net.  So, I'm
resending.  Sorry if this is a double post.

Gregg Liming wrote:

> Hi Declan,
>
> declang wrote:
>
>> Now, how do I proceed to log this stuff to a rrd ?
>> I have the address & value being returned as the state, but then I'm lost
>> again :(
>
> Do you mean, log this stuff via the RRD support built into mh?  If so,
> perhaps the quickest option is to just directly manipulate the Weather
> hash--which is automatically logged to the RRD database each minute
> (assuming you've got all the RRD support enabled).  So, let's suppose
> that we have some temperature device:
>
> if ($outside_temp_device->state_now) {
>    $Weather{TempOutdoor} = $outside_temp_device->state;
> }
>
> Naturally, you have to know all the various Weather hash keys.  Some are
> special and other are "spares" (e.g., TempSpare1 and HumidSpare1).
>
> Is this what you had in mind?
>
> Gregg
>


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: RFXPower with W800 - Perl help required !

by declang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Gregg Liming wrote:
Do you mean, log this stuff via the RRD support built into mh?  If so,
perhaps the quickest option is to just directly manipulate the Weather
hash--which is automatically logged to the RRD database each minute
(assuming you've got all the RRD support enabled).  So, let's suppose
that we have some temperature device:

if ($outside_temp_device->state_now) {
    $Weather{TempOutdoor} = $outside_temp_device->state;
}

Naturally, you have to know all the various Weather hash keys.  Some are
special and other are "spares" (e.g., TempSpare1 and HumidSpare1).

Is this what you had in mind?
Yes, I presumed there was an easy way to add another rrd and I have been reading the weather rrd stuff, but there are so many things in there I get a bit lost following the code.

Ideally, I'd like to append each counter value to a csv and to an rrd.
The csv is so I can easily get it into openoffice calc to do some further manual messing around.
The rrd would be nice to get a quick visual history.
I'm getting a counter value every 30 seconds or so, so the rdd would give me a nice instant picture of my power usage.

Any more pointers, or should I have another read through the weather stuff & then ask again ?

Cheers.
Declan

Re: RFXPower with W800 - Perl help required !

by Gregg Liming :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

declang wrote:

> Ideally, I'd like to append each counter value to a csv and to an rrd.
> The csv is so I can easily get it into openoffice calc to do some further
> manual messing around.

Oh, I see.  Obviously the counter values are totally different than
would be appropriate for shoving into the *Spare hash entries.

> The rrd would be nice to get a quick visual history.
> I'm getting a counter value every 30 seconds or so, so the rdd would give me
> a nice instant picture of my power usage.
>
> Any more pointers, or should I have another read through the weather stuff &
> then ask again ?

I haven't looked at the rrd code in quite a while.  But, as I recall it
was not very generalized and may be difficult to just "clone" for other
purposes.  Creating usercode to log to a CSV should be pretty trivial;
it's doing the graphing support from RRD to expose them to mh's web
pages that is likely a lot more effort.  I would be tempted to consider
just logging the data via DBI to a mysql DB and then massaging it from
there; but, that's obviously a very different direction.  Unfortunately,
I don't have any easy pointers to suggest.

Gregg



-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365