AD2PI REST API

General Discussion

Re: AD2PI REST API

Postby miragejb » Wed Jan 24, 2018 4:23 am

Now I understand what you are referring to. I didn't see the "Custom Notification" value in that section of the doc. Thanks for pointing me to it. It may come in handy some day.

Unfortunately, since my requirements have a client connecting to the PI, this can't be used. The device that is communicating with the PI doesn't have a web server embedded on it to process the incoming HTTP requests.

I'll play around with web app on the device and see if I can't add push notifications that will notify a registered device when an event occurs. There are many implementation APIs for them. I've used several of them in PC/Server world, but I don't know if there is one that will work on the PI's web app (or micro-devices in general). I'll have to pull it apart a bit to see how it works internally. For the meantime, I don't mind polling the server to see when states change.

Thanks for clarifying everything.

Regards.
miragejb
Junior Nut
Junior Nut
 
Posts: 29
Joined: Wed Jan 17, 2018 7:32 am

Re: AD2PI REST API

Postby kevin » Wed Jan 24, 2018 5:58 am

Maybe your device can connect to the exposed raw stream and deal with it there ... it's just a socket

Or, for example, the SmartThings notification type... this will wait until there is an event, then tell smartthings to fetch the endpoint to get data, so it's not polling, it's told to go look

I guess with all the vagueness of what you're describing your process and what you want to do with the device, I don't understand your end goal
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: AD2PI REST API

Postby miragejb » Tue Feb 06, 2018 9:21 am

Hi, Kevin:

I'm sorry I haven't gotten back sooner, but I've been playing around with the webapp for a few days to see how it works and how custom notifications work. I want to explain in more detail on what I need to accomplish by using the Pi, ask you some questions on the current ways to accomplish it (without doing much/any coding on the Pi), and, if there aren't current capabilities to satisfy the requirements, what your recommendations would through custom development.

Please note that I am not a Linux person nor am I a Python person (I hate snakes). I'm sure Python is great, but I really want to avoid it if possible. I don't have room left in my head for another development language. Having said that, I have over 30 years of experience in software architecture and development -- primarily in C++, Java and C#.

At a high level, I have custom "software" that runs on a Raspberry Pi 3 using Windows 10 IoT Core as its OS. The location of the Pi is not near the alarm panel. It would be impossible to use the AD2USB standalone to get the job done, which is why i need the AD2PI.

This "software" does various things. What I want to do is add functionality to it that will act as a client to your AD2PI (server) using the webapp. I do not care about the UI on the webapp -- just the ability to send commands and/or receive alarm events. If the webapp isn't the approach to take, then I don't mind coding at a lower network level bypassing the webapp all together .

I have played around with the custom notification functionality on the webapp. I'm not sure if it can provide all of the data I need. Preferably, I would like for it to send me a notification (from the selected choices) and include the raw data stream that was interpreted (webapp interfacing with AD2USB). For example, the data that is documented on http://www.alarmdecoder.com/wiki/index.php/Protocol. If I can get all of the information needed from the event without having to send an http message to the REST API, then this could work by me opening an HttpListener on the my application and pointing the webapp's notifications to it.

Here are some questions regarding this scenario:

1. Can the custom notifications provide this level of information?
2. If not, what are all of the "substitution variables (i.e. {{message}}) that it can provide?
3. Can it provide Partition information in the message?

If this isn't the approach to take, then here are two other alternatives that would be considered:

  • My ideal approach would be to use a publish/subscribe design (or something like a publish/subscribe pattern), where I subscribe to the events that are occurring on the AD2PI via the network and the AD2PI publishes them to me immediately -- again providing as much information as necessary. I am afraid if the software polled the AD2PI using the REST API continuously and indefinitely, I might miss some events and/or degrade the performance of both devices and the network. Can the AD2PI broadcast the data read from the AD2USB to other listeners on the network?
  • OK. If not, then I don't mind getting my hands dirty in the webapp's Python code, but would need some help from you. Could you point me in the exact direction of where I could modify the "Notification logic" to add a substitution variable for the entire data stream"? Which source file would it be in? Where would I get the data stream to add? As much information as you could give me regarding this would help me out tremendously.

If none of these options sound good to you, how would you advise me to accomplish this?

I think I can use the REST API to send commands (i.e. keys) to the panel. The only thing I am unsure about is how to specify the partition (or keypad) that I want the keys sent to. I don't necessarily see how to do this. Is it possible?

Your input is greatly appreciated.

Also, I wanted to let you know that I got the webapp up and running on my Raspberry Pi 3 using the latest version of Raspbian Stretch Lite (9.1 - <2017-11-29>). The current pull.sh wasn't working -- primarily because of the version of "docker" that was being used. I replaced it with the latest "docker-ce" and it installed with no problems. If you like, here is the modified pull.sh (nothing fancy). Again, please note that I am not a Linux person:

Code: Select all
#!/bin/bash
echo "Reading config...." >&2
source config.cfg
echo "******************************************" >&2
echo "********* Configuring Pi Hardware ********" >&2
echo "******************************************" >&2
echo "enable_uart=1" | sudo tee -a /boot/config.txt

echo "disabling serial console..." >&2
sudo sed -i 's/console=serial0,115200/ /g' /boot/cmdline.txt
sudo sed -i 's/kgdbog=ttyAMA0,115200/ /g' /boot/cmdline.txt
sudo systemctl disable serial-getty@ttyAMA0.service

echo "******************************************" >&2
echo "********* Installing Dependencies ********" >&2
echo "******************************************" >&2

sudo sed -i 's/frontend=pager/frontend=text/g' /etc/apt/listchanges.conf
sudo apt remove docker docker-engine docker.io
sudo apt update
sudo apt -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common rpi-update

if [ $? != 0 ]; then
    echo "******************************************" >&2
   echo *"*************** ERROR!!!! ***************" >&2
   echo "********* Installing Dependencies ********" >&2
   echo "******************************************" >&2
    exit 1
fi

echo "******************************************" >&2
echo "************ Installing Docker ***********" >&2
echo "******************************************" >&2
echo "deb [arch=armhf] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
sudo apt -y install docker-ce

if [ $? != 0 ]; then
    echo "******************************************" >&2
   echo *"*************** ERROR!!!! ***************" >&2
   echo "************ Installing Docker ***********" >&2
   echo "******************************************" >&2
    exit 1
fi

echo "******************************************" >&2
echo "************* Enabling Docker ************" >&2
echo "******************************************" >&2

sudo systemctl enable docker
sudo service docker start

if [ $? != 0 ]; then
    echo "******************************************" >&2
   echo *"*************** ERROR!!!! ***************" >&2
   echo "************* Enabling Docker ************" >&2
   echo "******************************************" >&2
    exit 1
fi

echo "******************************************" >&2
echo "*********** Show Docker Version **********" >&2
echo "******************************************" >&2
sudo docker version

echo "******************************************" >&2
echo "*** Getting Latest Alarm Decoder Image ***" >&2
echo "******************************************" >&2

echo "alarmdecoder" | sudo tee /etc/hostname
sudo docker pull alarmdecoder/alarmdecoder:latest

if [ $? != 0 ]; then
    echo "******************************************" >&2
   echo *"*************** ERROR!!!! ***************" >&2
   echo "******* Getting alarmdecoder Image *******" >&2
   echo "******************************************" >&2
    exit 1
fi

sudo hostname alarmdecoder
sudo sed -i 's/raspberrypi/alarmdecoder/g' /etc/hosts
sudo /etc/init.d/hostname.sh start

echo "******************************************" >&2
echo "************ Fetching nsenter ************" >&2
echo "******************************************" >&2
sudo docker run --restart $RESTART_PARAM -v /usr/local/bin:/target jpetazzo/nsenter

echo "******************************************" >&2
echo "**** Starting alarmdecoder Container *****" >&2
echo "******************************************" >&2
sudo docker run --restart $RESTART_PARAM --net="host" --device=$DEVICE --privileged -d -ti -e "container=docker" -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p $EXTERNAL_HTTP_PORT:$INTERNAL_HTTP_PORT -p $EXTERNAL_HTTPS_PORT:$INTERNAL_HTTPS_PORT -p $EXTERNAL_WORKER_PORT:$INTERNAL_WORKER_PORT -p $EXTERNAL_SER2SOCK_PORT:$INTERNAL_SER2SOCK_PORT alarmdecoder/alarmdecoder

if [ $? != 0 ]; then
    if [ $? != 0 ]; then
    echo "******************************************" >&2
   echo *"*************** ERROR!!!! ***************" >&2
   echo "** alarmdecoder Container Start Failed ***" >&2
   echo "******************************************" >&2
    exit 1
fi
    exit 1
else
    echo "******************************************" >&2
   echo "******************************************" >&2
   echo "********** INSTALL SUCCESSFUL!!! *********" >&2
   echo "******************************************" >&2
   echo "******************************************" >&2
    exit 0
fi
miragejb
Junior Nut
Junior Nut
 
Posts: 29
Joined: Wed Jan 17, 2018 7:32 am

Re: AD2PI REST API

Postby kevin » Tue Feb 06, 2018 7:36 pm

The easiest way to get what you want out of the system would be to utilize the raw socket itself at port 10000 by default (ser2sock)

The python library is open source and has examples of connecting to the socket and consuming/handling messages in github

Should be fairly trivial to adapt to c# for your purposes
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: AD2PI REST API

Postby miragejb » Mon Feb 12, 2018 9:27 am

Thanks, Kevin:

Before I dig deep in the "Python", I want to make sure we are talking about the same thing. I have an AD2PI (Raspberry Pi) connected to an AD2USB to connect to the alarm panel. Via TCP/IP, my Raspberry Pi is going to connect to the AD2PI via Sockets (IP address/Port 10000). My Pi will also listen for data streams coming from the AD2PI and send data commands (again via TCP/IP). I have attached a quick diagram to make sure we are talking apples-to-apples.

Is this what I am understanding?

AD2PI Sockets.jpg
AD2PI Sockets.jpg (26.92 KiB) Viewed 4836 times
miragejb
Junior Nut
Junior Nut
 
Posts: 29
Joined: Wed Jan 17, 2018 7:32 am

Re: AD2PI REST API

Postby kevin » Sat Feb 17, 2018 12:17 pm

The alarmdecoder python library can connect to the exposed socket and you can wire up the events you want to listen to and do with them what you want

You can also use the library to send keys, which will go over the socket you connect to via the python library and control the alarm
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

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 5 guests

cron