Page 1 of 2

xPL-PERL - Communication between xPL processess

Posted: Tue Mar 18, 2008 9:04 pm
by Jfn
Just today I got my RFXCOM USB receiver. Hooked it up to my laptop first (Windows), to check whether the unit was working.

Well, it did. I have a BWR102 wireless weightscale and it showed my weight perfectly.

After having programmed the RFXCOM for 32-bits I hooked it up to my linux server, did an 'export XPL_RFXCOM_TTY' and ran xpl-perl-setup. So far so good.

The xpl-rfxcom logfile shows the packet being decoded:

2008-03-18_18:54:15.03204 Processed: 385c16ec<i><b>3093</b></i>5016

From this I can decode that my weight is 93,3 KG.

However, then I started xpl-logger expecting it to show the same messages there, but I only see this:

debian:/# xpl-logger -v
Listening on 192.168.1.12:33274
Sending on 192.168.1.255
192.168.1.12:32773 [xpl-stat/hbeat.app: bnz-listener.debian -> *]
192.168.1.12:32773 [xpl-stat/hbeat.app: bnz-rrdgraph.debian -> *]
192.168.1.12:32773 [xpl-stat/hbeat.app: bnz-dawndusk.debian -> *]
192.168.1.12:32773 [xpl-stat/hbeat.app: bnz-rfxcom.debian -> *]

Where is my data? Should it not appear on xpl-logger? If not, where can I find it. xpl-rfxcom does decode the message, but it it does not show up on xpl-logger, so where is it?



Als het niet kapot is, niet repareren!

xPL-PERL - Communication between xPL processess

Posted: Tue Mar 18, 2008 9:07 pm
by Snelvuur
the oregon scale is not supported in xpl yet.. http://www.xpl-perl.org.uk/ticket/21 i've asked to support this. Unless you know howto, you can submit a fix/update.

Its not rocket scienve if i'am correct for beanz, but he needs to sit down for a bit.

// Erik (binkey.nl)

xPL-PERL - Communication between xPL processess

Posted: Tue Mar 18, 2008 9:45 pm
by Jfn
Whether or not it is supported, I had at least expected that any data that is received by the xpl-rfxcom module is found back in the xpl-logger output.

Is it not that all xpl modules send their data to xpl-hub which again retransmits all messages to all modules currently active?

When looking at the xpl-logger code (or the code of any other xpl-perl module) there is this line:

Code: Select all

# Add a callback to receive all incoming xPL messages
$xpl->add_xpl_callback(id => "logger",
                       self_skip => 0, targetted => 0,
                       callback => \&log);
If I am not mistaken, this code suggests that any data detected/decoded by any xpl-perl module is received by xpl-logger. Is this correct, or should I buy new glasses and have a new look at the xpl code?




Als het niet kapot is, niet repareren!

xPL-PERL - Communication between xPL processess

Posted: Tue Mar 18, 2008 9:49 pm
by Snelvuur
The logger only shows what the other xpl tools send. in the case of the xpl-rfxcom it does see somethiing coming in, but since it is not known as a valid package it does not send it to the hub. Why would you want to send incorrect data through anyway, so if you would set xpl-rfxcom in verbose mode (check with -h) i think you should be able to see it coming by. (that is the raw data then) let me know if it doesn't, then i'll test it too.

// Erik (binkey.nl)

xPL-PERL - Communication between xPL processess

Posted: Tue Mar 18, 2008 11:21 pm
by beanz
I've added support for the scales in xpl-perl to svn revision 465.
-Mark.

xPL-PERL - Communication between xPL processess

Posted: Wed Mar 19, 2008 8:19 am
by Jfn
Updated the SVN tree and it is working now:

Code: Select all

debian:/etc/xplperl/service/xpl-rfxcom/log/main# tail -f current
2008-03-19_06:10:54.32892 Listening on 192.168.1.12:33338
2008-03-19_06:10:54.32934 Sending on 192.168.1.255
2008-03-19_06:10:54.56996 Sending 'F020' to rfxcom receiver
2008-03-19_06:10:54.57550 Not a variable length message: 4d23
2008-03-19_06:10:55.57147 Sending 'F02A' to rfxcom receiver
2008-03-19_06:10:56.57575 Sending 'F041' to rfxcom receiver
2008-03-19_06:10:56.59171 Discarding: 41
2008-03-19_06:11:30.41618 Discarding: 41
2008-03-19_06:11:30.41623 Processed: 38ec14fc5091e014
2008-03-19_06:11:30.41624 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0915
And the xpl-logger script is now also showing output:

Code: Select all

debian:/home/jann/tmp/xpl-perl# /usr/local/bin/xpl-logger -v
Listening on 192.168.1.12:33343
Sending on 192.168.1.255
192.168.1.12:33340 [xpl-stat/hbeat.app: bnz-listener.debian -> *]
192.168.1.12:33340 [xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0915]
@beanz: Thanks for the latest versions supporting the BWR scale. Btw, you should update the 'xpl-perl-setup' script too. The 'make install' installs everything in '/usr/local/bin', but the xpl-perl-setup script still thinks everything is located in '/usr/bin' (You will probably already have considered not to use hard-coded directories in your scripts)

Keep up the good work!



Als het niet kapot is, niet repareren!

xPL-PERL - Communication between xPL processess

Posted: Wed Mar 19, 2008 9:14 am
by beanz
Oops. I meant to divide by 10. Fixing in revision 467.

xPL-PERL - Communication between xPL processess

Posted: Wed Mar 19, 2008 11:33 am
by Jfn
What you mean by 'I meant to divide by 10'? Is it because of the leading '0' in the measured weight?

Another issue concerning the BWR102 scale is that it outputs the same information about 11 times in a row.

Code: Select all


2008-03-19_09:27:29.24432 Processed: 38dd1ecc2294d01e
2008-03-19_09:27:29.24437 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:35.32035 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:35.32039 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:38.31264 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:38.31268 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:41.31980 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:41.31984 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:44.31115 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:44.31119 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:47.31922 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:47.31927 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:50.31051 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:50.31054 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:53.30273 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:53.30277 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:56.31305 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:56.31308 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:27:59.30529 Processed: 38dc1ecc2294d01e
2008-03-19_09:27:59.30533 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
2008-03-19_09:28:02.31249 Processed: 38dc1ecc2294d01e
2008-03-19_09:28:02.31253 xpl-trig/sensor.basic: bnz-rfxcom.debian -> * - bwr102.01[weight]=0942
Is this something that should be dealt with on the serverside (by Zenah), or do you think it should be implemented on the client-side?


<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by beanz</i>
<br />Oops. I meant to divide by 10. Fixing in revision 467.
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

Als het niet kapot is, niet repareren!

xPL-PERL - Communication between xPL processess

Posted: Wed Mar 19, 2008 1:01 pm
by Jfn
I did some further testing with xPL(-perl) and Zenah, but still feel that it is too complex for what I want.

I have a very simple basic demand: If there is an event, log an entry in a MySQL database: If I stand on the scale, add an entry to the database stating time-of-day and the measured weight. If a door opens, log an entry with time-of-day and with status 'Door open'.

What I want is a module per interface connected to the PC:
Module 1: RFXCOM interface
<ul>
<li>Device A: Weightscale; If event --> Add timestamp + weight to database</li>
<li>Device B: Doorsensor livingroom; If event --> Add timestamp + status to database</li>
<li>Device C: Tempsensor attic; If event --> Add timestamp + temp to database</li></ul>

Module 2: X10 computerinterface
<ul>
<li>Device A: Lightswitch livingroom; If event --> Add timestamp + X10 status (on/off) to database</li>
<li>Device B: etc ...</li></ul>

Based on info I gather from the database I can, for example, make lighting-arrangements for when I am not at home.

Is it possible to implement what I want using xPL? Is xPL too complex for what I want, or do I make it look too complex?


Als het niet kapot is, niet repareren!

xPL-PERL - Communication between xPL processess

Posted: Wed Mar 19, 2008 1:54 pm
by Snelvuur
Zenah rules engine can allow you to do matches on certain devices/events and put it in the database. This is allready done for temperature sensors for instance.

For the x10, zenah rules also puts that in the database but as far as i know it keeps only the current state (i mean, why would you want to remember when you turned on the light in the toilet 2 years ago) wishes can be different.

To change the rules you can use zenah admin part, although it might be difficult the gui is only (as far as i know) made to interact with the rules engine and give basic function parts via the web.

Also why i started with a php gui is to make things like that easier, create rules extra based on type of sensor weither you want to keep it or not and create graphs. You can make it as big as you want yourself too. I've started but it takes a lot of time ofcourse. I want my approach to work, since it will be the foundation of the php gui which needs some carefull thinking (like having template layouts so others can change it and having language option storing the "text" seperate) after the bones are layed someone with photoshop knowledge can give it some extra flavour and since its templated it should be easy for that person to do without a lot of knowledge for php needed.

Perhaps there are easier ways to add rules or do something what you want with it but i've not really jumped onto that wagon yet.

// Erik (binkey.nl)

xPL-PERL - Communication between xPL processess

Posted: Wed Mar 19, 2008 7:46 pm
by Jfn
I found this URL: http://illx.org/digitemp/index.jsp

What it does for 1-wire devices is what I am looking for to do with my RFXCOM interface.

When I get a measurement from the scale, I want it to add an entry to the MySQL database. When a door-sensor signals a change, I want the status of this doorsensor updated in the database.

The same goes for a Xanura CTX35 that I will be installing in the future. If I hit a lightswitch, update the status of the lamp in the database.

So you see, my whole approach to home-automation is more that of home-control. I want to know what is going on and I want to be able to remotely control lights, heating, etc ... I do not need the complex approach that xPL/Zenah offers. I will initiate any action, not the software.

Besides that, I just started programming in perl, so reading the full xPL sources to understand how things are happening is not that easy. I have decided to not actively use xPL-Perl/zenah for now, but to follow its development and wait for a more user-friendly environment before I step back on the wagon.

Als het niet kapot is, niet repareren!

xPL-PERL - Communication between xPL processess

Posted: Wed Mar 19, 2008 7:50 pm
by Snelvuur
you can still use xpl-perl and write your own tool based on incoming messages. Just make a xpl-something, then match the device which you want to measure and to a sql insert in perl. At least you have your basic functionality what you want then aswell.

// Erik (binkey.nl)

xPL-PERL - Communication between xPL processess

Posted: Sun Mar 23, 2008 9:20 am
by Jfn
I am trying to get info from the weightscale, but run into some problems. The two code samples are based on the code from the 'xpl-sql-logger' script.

The first example gives an error: <i>Can't locate object method "device" via package "xPL::Message::hbeat::app::xplstat" at ./t1.pl line 83.</i>

The second example works fine. I cannot figure out why. Anyone? Both scripts should yield the same output:

<i><b>*** device = bwr102.01 ***
*** type = weight ***
*** current = 92.3 ***</b></i>

(Fields 4 to 6 are undefined, so no output there.).

The parts that are different between both examples are written in bold/italic.

Code: Select all

Code example 1: Gives an error

# The callback to log the incoming messages
sub log {
  my %p = @_;
  my $msg = $p{message};
  my $peeraddr = $p{peeraddr};
  my $peerport = $p{peerport};

<i><b>  my @fields = ('device', 'type', 'current', 'lowest', 'highest', 'units');
  foreach my $field (@fields)
  {
    print "*** $field = ".$msg->$field." ***\n";
  }</b></i>};

Code: Select all

Code example 2:
# The callback to log the incoming messages
sub log {
  my %p = @_;
  my $msg = $p{message};
  my $peeraddr = $p{peeraddr};
  my $peerport = $p{peerport};

<i><b>  foreach my $field ($msg->body_fields)
  {
   print "*** $field = ".$msg->$field." ***\n";
  }</b></i>};
I just want to check for '$msg->device' being equal to 'bwr102.01' (Meaning the scale is transmitting info) and then grab '$msg->current' as the measured weight and put it in an SQL database. However, simply entering 'my $weight=$msg->current' gives an error and I cannot figure out why.



Als het niet kapot is, niet repareren!

xPL-PERL - Communication between xPL processess

Posted: Sun Mar 23, 2008 1:26 pm
by Jfn
Got it working. The script is now only outputting data when it gets a message from the scale:

Code: Select all

sub log {
  my %p = @_;
  my $msg=$p{message};
  my %info;

  # Put field<->value relation in hash-table. Do not put fields with empty value in hash
  foreach my $field ($msg->body_fields)
  {
   $info{$field} = $msg->$field if (defined $msg->$field);
  }

  # Make sure that the device field is available in this message
  if (defined $info{'device'})
  {
    # It is, so check whether the message originates from the scale
    if ($info{'device'} eq "bwr102.01")
    {
      print "Your current weight is ".$info{'current'}." KG\n";
    }
  }

};
Next step is making sure that the script only sees one measurement. I found out that for every time I step on the scale it outputs my weight 11 times in a row, meaning I get 11 measurements when I only need one.

@snelvuur: What do you think of this code? Remarks are welcome!

Als het niet kapot is, niet repareren!

xPL-PERL - Communication between xPL processess

Posted: Sun Mar 23, 2008 2:18 pm
by Snelvuur
i assume changes are pretty slim that you weigh the same each time exactly. So just put in, if eq to last value then dont print. my php projet is going slow, lots to think off, my scale is not yet supported (has bmi and such) most tricky part is how to use the rules and current mysql stuff. I can read out all oregon stuff easy and make graphs for it. I think scale will be my nr 2 project. Just as a proof of concept to get more people to look into it :)

Code is nice jfn, dont think that i'am a expert in it, i grab from google too.

You could do a extra check if its a "sensor.basic" message. That way you dont have to parse every incoming message.

If you have "completed" scripts, place them here too. I could also place them then on the wiki as reference for other people.

// Erik (binkey.nl)