Can't Get Output in Python Program

General Discussion

Can't Get Output in Python Program

Postby Rene » Mon Jan 09, 2017 12:42 am

I am trying to intercept arm/disarm messages from my A2PI so I can execute http post to enable/disable my cameras. I ready that I should use Ser2Sock calls because the /dev/ttyAMA0 port is already used by the web app but can use whatever method works. I have used python sample code to try and connect to the SocketDevice and read the output messages. I am running python right on the A2Pi and also am using SSL. The program runs but not I don't get any output. I tried telnet {IP} 10000 from a remote computer on the same network and it does not receive any messages either. Is the SSL cert preventing output? Not sure what I am doing wrong. However, the web app picks up all alarm panel messages.

Thanks!

import time
from alarmdecoder import AlarmDecoder
from alarmdecoder.devices import SocketDevice

#default AD2Pi device on Raspberry Pi
SERIAL_DEVICE='/dev/ttyAMA0'
BAUDRATE = 115200
SER2SOCK_HOST = 'localhost'
SER2SOCK_PORT = 10000

def main():
"""
Example application that prints messages from the panel to the terminal.
"""
try:
# Retrieved an AD2 device that has been exposed with ser2sock on localhost:10000
device = AlarmDecoder(SocketDevice(interface=(SER2SOCK_HOST,SER2SOCK_PORT)))

# Retrieve the first Serial device
#device = AlarmDecoder(SerialDevice(interface=SERIAL_DEVICE))

# Set up an event handler and open the device
device.on_message += handle_message
print 'Running...'

with device.open(baudrate=BAUDRATE):
while True:
time.sleep(1)

except Exception, ex:
print 'Exception:', ex

def handle_message(sender, message):
"""
Handles message events from the AlarmDecoder.
"""
print sender, message.raw

if __name__ == '__main__':
main()
Rene
newt
newt
 
Posts: 8
Joined: Mon Jan 09, 2017 12:26 am

Re: Can't Get Output in Python Program

Postby kevin » Mon Jan 09, 2017 12:37 pm

encrypting the ser2sock stream will definitely do this - you have to setup your cert chains to deal with it properly.

That said, if you're using the webapp, it has built-in custom GET/POST based off events in the notifications.
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

Re: Can't Get Output in Python Program

Postby jeffwu » Wed Sep 06, 2017 7:56 pm

Hi,

I plan to use "Custom" notification in web app to send events info to a REST API server where it compiles the data to determine zone occupancy state. what system variable(s) is available in Custom Notification setting ? (I guess they can be referenced in custom key/value field?) with other built-in notification methods, like pushover, the notification message contains zone id and zone status. how can I construct a custom notification to send similar zone info to my own REST web server.

I use "nc -lv 8080" to print output sent by web app. I didn't see any event info contained in HTTP header or data.

your help is much appreciated.

Jeff
jeffwu
Senior Nut
Senior Nut
 
Posts: 40
Joined: Fri Mar 17, 2017 6:24 pm

Re: Can't Get Output in Python Program

Postby kevin » Wed Sep 06, 2017 8:01 pm

All you need to do to achieve that is customize your messages for the events and use the message replacer - these are replaced in different places and different ways - this way you only have to replace it in your message and it will work across all notifications. The custom notification replacers listed are the ones available.

You can add {arm_mode} to the armed event message to get instant/stay/away status

The key/value pairs are represented via GET or POST and accessible in the request via those methods

example php using GET:
Code: Select all
<?php
    echo $_GET['message'];
?>


You will have to parse the message to get the data you want if you want to get that granular.
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

Re: Can't Get Output in Python Program

Postby jeffwu » Thu Sep 07, 2017 6:47 am

Where should have the list of message replacers? Is it within WebApp setting page? I didn't see them or I could overlook.

Thanks
jeffwu
Senior Nut
Senior Nut
 
Posts: 40
Joined: Fri Mar 17, 2017 6:24 pm

Re: Can't Get Output in Python Program

Postby kevin » Thu Sep 07, 2017 7:41 am

When you create a custom notification and add a key/value pair, a helpful tooltip will appear at the bottom of the notification screen with a list.

If you are looking to customize your notification messages - there is a button on the main notifications page at the bottom for editing your messages. Replacers here aren't listed - the only one missing is {arm_mode} by default installations.
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

Re: Can't Get Output in Python Program

Postby jeffwu » Thu Sep 07, 2017 4:03 pm

thanks Kevin. I didn't notice the tips. now I created a new custom notification and after adding key/value fields, the tips were shown.

I followed the tips and added these key/value pairs
1)key: time, value: {{time}}
2)key: msg, value: {{message}}

with GET method and urlencoded.

however, I could see {{time}} was replaced by actual time values. {{message}} was not replaced. why was that?

below were HTTP headers

GET /ad2pi?msg=%7B%7Bmessage%7D%7D+&time=2017-09-07+19%3A53%3A50+EDT HTTP/1.1
Host: 10.10.0.5:1500
Accept-Encoding: identity
Content-type: application/x-www-form-urlencoded
User-Agent: AlarmDecoder/v1.0
jeffwu
Senior Nut
Senior Nut
 
Posts: 40
Joined: Fri Mar 17, 2017 6:24 pm

Re: Can't Get Output in Python Program

Postby jeffwu » Thu Sep 07, 2017 4:08 pm

nvm. my bad. extra tailing space after {{message}}. it is working now. thanks again.
jeffwu
Senior Nut
Senior Nut
 
Posts: 40
Joined: Fri Mar 17, 2017 6:24 pm

Re: Can't Get Output in Python Program

Postby jeffwu » Sun Sep 10, 2017 6:26 am

Hi Kevin,

you mentioned {arm_mode} missing in default installation, thus I tried to add it in message notification. I amended "Arm" message as below, however, after doing that, I didn't receive "Arm" notification any more. after reverting back to the default, it was working again.

"The alarm system has been armed {arm_mode}." ------ this one didn't work
"The alarm system has been armed." ------ this one worked

Did I miss anything?

thanks

Jeff
jeffwu
Senior Nut
Senior Nut
 
Posts: 40
Joined: Fri Mar 17, 2017 6:24 pm

Re: Can't Get Output in Python Program

Postby kevin » Sun Sep 10, 2017 10:49 am

Ahh sorry it's {arm_type} - as long as you have the latest alarmdecoder library and webapp, arm_type should work
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

Next

Return to General

Who is online

Users browsing this forum: No registered users and 5 guests

cron