Issue with reading after writing(arm etc) to the alarm panel

General Discussion

Issue with reading after writing(arm etc) to the alarm panel

Postby duachirag » Fri Apr 11, 2014 9:35 am

First of all, thanks a lot to Kevin and Scott for your prompt responses in the past, really helped me, I have almost setup the system I wanted with AD2PI and Vista 10SE. Currently I am using WEBIOPI with AlarmDecoder libraries. In the main script, I am trying to open the SerialDevice, setup some events/event handlers like on_arm etc and expose some WEBIOPI macros in the same script to remotely arm/disarm the system. Event handlers are just sending out the notifications via email. What is happening is, I am able to read from the panel via on_message before I arm/disarm the panel via send method. Once I use send, no more events are getting called. As if reading, writing and then reading from the panel, some issue going on, which I am trying to diagnose. Question for you guys is, is the setup correct? Anything wrong with the approach? Here is the short snippet of code:

Code: Select all
import webiopi
from alarmdecoder import AlarmDecoder
from alarmdecoder.devices import SerialDevice

# Configuration values
ARM_STAY = <STAY_CODE>
ARM_AWAY = <AWAY_CODE>
DISARM = <DISARM_CODE>
SERIAL_DEVICE = '/dev/ttyAMA0'
BAUDRATE='115200'
SUBJECT = "Home Security Alarm Notification"
FROM_ADDRESS = "chiragdua1977@gmail.com"
TO_ADDRESS = "chiragdua1977@gmail.com"
SMTP_SERVER = "smtp.gmail.com:587"
SMTP_USERNAME = <USERNAME>
SMTP_PASSWORD = <PASSWORD>
device = AlarmDecoder(SerialDevice(interface=SERIAL_DEVICE))

def setup():
    global device
    device.on_arm += handle_arm
    device.on_disarm += handle_disarm
    device.on_power_changed += handle_power_changed
    device.on_alarm += handle_alarm
    device.on_low_battery += handle_low_battery
    device.open(BAUDRATE)

def destroy():
    global device
    device.close()

@webiopi.macro
def armInStayMode():
    global device
    device.send(ARM_STAY)
    return 'System successfully armed in stay mode.'

@webiopi.macro
def armInAwayMode():
    global device
    device.send(ARM_AWAY)
    return 'System successfully armed in away mode.'

@webiopi.macro
def disarm():
    global device
    device.send(DISARM)
    return 'System successfully disarmed.'

def handle_message(sender, message):
    print message

def handle_arm(sender):
    content = 'System Armed'
    send_notification(content)

---------------------------Rest of the methods--------------------

duachirag
newt
newt
 
Posts: 9
Joined: Tue Apr 08, 2014 6:18 am

Re: Issue with reading after writing(arm etc) to the alarm p

Postby Scott » Fri Apr 11, 2014 9:58 am

I'm not familiar with webiopi, but your code seems okay to me.

Sounds like perhaps the read thread is dying and I believe I fixed an issue involving that in the dev branch a while back. You can switch to using that branch on your Pi by doing:

Code: Select all
sudo pip uninstall alarmdecoder
cd /opt/alarmdecoder
git pull
git checkout dev
sudo python setup.py develop
Scott
Expert Nut
Expert Nut
 
Posts: 118
Joined: Thu Dec 12, 2013 11:17 am

Re: Issue with reading after writing(arm etc) to the alarm p

Postby duachirag » Fri Apr 11, 2014 10:03 am

I can try that but I installed AlarmDecoder after getting it from GIT and running the setup script, will uninstall work? Then I can get the dev branch from GIT I suppose.
duachirag
newt
newt
 
Posts: 9
Joined: Tue Apr 08, 2014 6:18 am

Re: Issue with reading after writing(arm etc) to the alarm p

Postby Scott » Fri Apr 11, 2014 10:18 am

Oh! In that case you can skip the pip step and the rest should do the job.

At that point you'll be running out of that source directory, so any changes you make or pull in the future, will automatically be used by python.
Scott
Expert Nut
Expert Nut
 
Posts: 118
Joined: Thu Dec 12, 2013 11:17 am

Re: Issue with reading after writing(arm etc) to the alarm p

Postby duachirag » Fri Apr 11, 2014 11:50 am

One more question, when I call open on AlarmDecoder, I assume reader thread will be started, right? Default no_reader_thread should be false, if I send true, then read won't start.
duachirag
newt
newt
 
Posts: 9
Joined: Tue Apr 08, 2014 6:18 am

Re: Issue with reading after writing(arm etc) to the alarm p

Postby Scott » Fri Apr 11, 2014 12:02 pm

Yup, that's correct.
Scott
Expert Nut
Expert Nut
 
Posts: 118
Joined: Thu Dec 12, 2013 11:17 am

Re: Issue with reading after writing(arm etc) to the alarm p

Postby duachirag » Fri Apr 11, 2014 6:41 pm

Thanks again, everything working now! But I will end up throwing my stuff once
your shiny keypad for PI is released.
duachirag
newt
newt
 
Posts: 9
Joined: Tue Apr 08, 2014 6:18 am


Return to General

Who is online

Users browsing this forum: No registered users and 42 guests

cron