[Solved] Python Event Problems

General Discussion

[Solved] Python Event Problems

Postby n5qm » Tue Jan 28, 2014 3:44 pm

All,

I have been working on getting a python script working with my new AD2USB. I am able to extract and parse RFX messages using the python module, however I am not able to get any zone tracking events or events such as on_arm or on_disarm.

Here is the script I am using to test with, it outputs nothing at all to the referenced log file.

Code: Select all
import time, logging
from alarmdecoder import AlarmDecoder
from alarmdecoder.devices import USBDevice

# Global Variables
LOG_FILE = 'alarm_state.log'

def main():

    try:

        # Setup and begin logging
        logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S')
        logging.info('---------- Starting log ----------')

        # Retrieve the first USB device
        device = AlarmDecoder(USBDevice.find())

        # Set up an event handler and open the device
        device.on_zone_fault += handle_zone_fault
        device.on_zone_restore += handle_zone_restore
        device.on_arm += handle_arm
        device.on_disarm += handle_disarm
        with device.open():
            while True:
                time.sleep(1)

    except Exception, ex:
        logging.error('Exception:'+str(ex))

def handle_zone_fault(sender, zone):
    logging.info('Zone Fault:'+str(zone))

def handle_zone_restore(sender, zone):
    logging.info('Zone Restored:'+str(zone))

def handle_arm(sender):

    logging.info('System Armed')

def handle_disarm(sender):

    logging.info('System Disarmed')

if __name__ == '__main__':
    main()


Here is the output from the AD2USB device directly, while faulting a zone and restoring it. Curiously, I get a series of keypad messages, one stating everything is in the ready state and another telling me the zone is faulted, both while the zone is in the faulted state.

Code: Select all
!Ademco Keypad Emulator V2.2a.6
!Copyright (C) 2008-2010 Nu Tech Software Solutions, Inc.
!Reproduction without permission is prohibited
!By Sean Mathews <drwho at f34r.com>
!For support email general@support.nutech.com
!www.NuTech.com
!Reading configuration.
!UART init.
!Ready. Press ! for configuration.
[1000000110000000----],008,[f70000031008001c28020000000000]," DISARMED CHIME   Ready to Arm  "
[1000000110000000----],008,[f70000040008001c28020000000000]," DISARMED CHIME   Ready to Arm  "
!RFX:0206723,80
[0000030110000000----],010,[f70000011010030028020000000000],"FAULT 10 BACK   DOOR            "
[0000000110000000----],010,[f70000020010000028020000000000],"FAULT 10 BACK   DOOR            "
[0000000110000000----],008,[f70000031008000c28020000000000]," DISARMED CHIME Hit * for faults"
[1000000110000000----],008,[f70000040008001c28020000000000]," DISARMED CHIME   Ready to Arm  "
[0000000110000000----],008,[f70000031008000c28020000000000]," DISARMED CHIME Hit * for faults"
[1000000110000000----],008,[f70000040008001c28020000000000]," DISARMED CHIME   Ready to Arm  "
[0000000110000000----],008,[f70000031008000c28020000000000]," DISARMED CHIME Hit * for faults"
[1000000110000000----],008,[f70000040008001c28020000000000]," DISARMED CHIME   Ready to Arm  "
[0000000110000000----],008,[f70000031008000c28020000000000]," DISARMED CHIME Hit * for faults"
[1000000110000000----],008,[f70000040008001c28020000000000]," DISARMED CHIME   Ready to Arm  "


The AD2USB is has the default configuration and I am using a Vista 20P. Can someone provide guidance on where I may be going wrong?

Robert
n5qm
newt
newt
 
Posts: 6
Joined: Tue Jan 28, 2014 3:36 pm

Re: Python Event Problems

Postby Scott » Tue Jan 28, 2014 4:11 pm

Hey Robert,

Your test code worked fine here, so I suspect it's likely an issue with the address mask that's configured on the AD2USB.

Terminal to your AD2USB, send '!' and then hit enter. It should spit back a configuration string at you.. checking that out should be our next step.
Scott
Expert Nut
Expert Nut
 
Posts: 118
Joined: Thu Dec 12, 2013 11:17 am

Re: Python Event Problems

Postby n5qm » Tue Jan 28, 2014 4:37 pm

Scott,

Thanks for the help. Here is the output of the configuration.

Code: Select all
!>Keypad Address       (18) :>
!>Config Bits        (ff00) :>
!WARNING. Do not enable a module if the physical module exists on the system.
!Zone Expanders Y/N Max allowed: 02
!>expander module #01 ZN 09-16 (N) :>
!>expander module #02 ZN 17-24 (N) :>
!>expander module #03 ZN 25-32 (N) :>
!>expander module #04 ZN 33-40 (N) :>
!>expander module #05 ZN 41-48 (N) :>
!Relay Modules Y/N Max allowed: 04
!>relay module #01 (N) :>
!>relay module #02 (N) :>
!>relay module #03 (N) :>
!>relay module #04 (N) :>
!>Emulate Long Range Radio Y/N: (N) :>
!>Address Filter Mask  (ffffffff) :>
!>Deduplicate          (N) :>
!Reading configuration.


The panel is configured with only a single partition, two keypads, and nothing "special". I don't understand how to appropriately configure the mask. Can you provide some guidance?

Robert
n5qm
newt
newt
 
Posts: 6
Joined: Tue Jan 28, 2014 3:36 pm

Re: Python Event Problems

Postby Scott » Tue Jan 28, 2014 5:04 pm

All of those messages are destined for a particular keypad mask which indicate who the message is destined for. By default the AlarmDecoder comes configured with a mask of 0xFFFFFFFF so that it sees all messages. The library ANDs this against the message mask (bytes 3-11 of the 3rd section, zero-indexed and accounting for the bracket) and if it matches, takes action on it.

The library sends a request for the configuration in the background when it's first opened. If you bind an event handler to on_config_received that should tell you whether or not this is happening or not. If we don't get the configuration back the address mask in the library defaults to 0x00000000 (should probably change this default to 0xFFFFFFFF...) and wouldn't recognize any messages to generate events. You could also try forcing a call to get_config() after it's opened, in case it's a timing issue or something.

Been talking with Sean and he and I agree that your masks look strange, but I want to make sure that the configuration string is being read by the library first before we open that can of worms.

Hopefully that makes sense. Let us know what you find.
Scott
Expert Nut
Expert Nut
 
Posts: 118
Joined: Thu Dec 12, 2013 11:17 am

Re: Python Event Problems

Postby n5qm » Tue Jan 28, 2014 5:09 pm

Scott,

I think I figured it out and my initial testing looks good. I misread the keypad programming instructions for the 20P and programmed address 18 to be in the "common" partition. I reviewed the programming for the other keypad and realized my error. I changed the programming for keypad address 18 to be in partition 1 and now it appears to be functioning as expected.

Thanks for helping me out!

Robert
n5qm
newt
newt
 
Posts: 6
Joined: Tue Jan 28, 2014 3:36 pm

Re: Python Event Problems

Postby Scott » Tue Jan 28, 2014 5:53 pm

Glad to hear it, Robert! And I take back the strange mask comment.. totally misinterpreted those, so I think you're good to go all the way around.
Scott
Expert Nut
Expert Nut
 
Posts: 118
Joined: Thu Dec 12, 2013 11:17 am

Re: Python Event Problems

Postby n5qm » Wed Jan 29, 2014 6:56 am

Scott,

I did continue to have issues, but it was not consistent. I modified the default mask, so it was all Fs and things seem to be working properly on a regular basis now.

I am using the AD2USB connected to a BBB which is also running OpenHAB and submitting contact closure information and system status to OpenHab via the REST API. I will post a sample script once I clean it up a bit.

Thanks again for your help.

Robert
n5qm
newt
newt
 
Posts: 6
Joined: Tue Jan 28, 2014 3:36 pm

Re: Python Event Problems

Postby danimal1228 » Wed Jan 29, 2014 11:42 am

Make sure that whoever starts this script has write permissions for your log file. You may need to 'touch' the file first and verify the owner, group and permissions.

I had a similar issue because I was writing my log file to /var/log and the process that was starting the python script didnt have write permission. It gave no error, it just didnt write the file.
danimal1228
Junior Nut
Junior Nut
 
Posts: 20
Joined: Sat Jan 11, 2014 9:35 am

Re: Python Event Problems

Postby magudelo58 » Thu Jul 03, 2014 8:38 pm

n5qm wrote:Scott,

I did continue to have issues, but it was not consistent. I modified the default mask, so it was all Fs and things seem to be working properly on a regular basis now.

I am using the AD2USB connected to a BBB which is also running OpenHAB and submitting contact closure information and system status to OpenHab via the REST API. I will post a sample script once I clean it up a bit.

Thanks again for your help.

Robert


Hi Robert, have you been able to clear up that script, I started playing with OpenHAB today and would like to have it integrated with my AD2PI.

Thank you.

Marco
magudelo58
newt
newt
 
Posts: 4
Joined: Sat Jun 14, 2014 7:30 pm

Re: [Solved] Python Event Problems

Postby kevin » Thu Jul 03, 2014 8:55 pm

In case he doesn't reply, viewtopic.php?f=6&t=38 is where he posted his OpenHAB code, in the Code Contributions section
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am


Return to General

Who is online

Users browsing this forum: No registered users and 23 guests

cron