I'm terrible at python and need your help with two questions
#46
i have the addon working when i hit it from the programs menu in xbmc but can't seem to make it come up automatically with a URL or similar...

When i go to: http://localhost:8081/xbmcCmds/xbmcHttp?....doorbell)

I get file not found page from my xbmc web interface...

Any ideas?

Just realised it's probably because im using Frodo and would have to use the JSON instead? Anyone managed to get this working and could point me in the right direction?
Reply
#47
if anyones bothered, managed to work it out after half hour or so....

http://localhost:8081/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.doorbell"}}
Reply
#48
Great script !

I see currently it gets jpeg snapshots and some cameras and motion programs only send mjpeg streams, It would be great to support that too Smile

So the script first would have to convert a mjpeg stream frame to jpeg.

It's my first time with python and I'm not being lucky trying it... :S

There are python projects doing that (like https://code.google.com/p/mjpeg-stream-c.../client.py ) but i'm unable to get it Big Grin
Reply
#49
(2013-05-24, 08:53)migmig Wrote: I see currently it gets jpeg snapshots and some cameras and motion programs only send mjpeg streams, It would be great to support that too Smile

Hey, that seems very useful! A friend of mine needs exactly that, she has a bunch of security cams (that all send mjpeg as you said) and is looking for a way to show events on top of XBMC... This seems to be almost there, just convert the mjpeg to a bunch of jpeg files and then display them as an animation to simulate PiP. Maybe some of the python wizards here could help us a little... unfortunately my python knowledge is pretty much nothing Undecided
Reply
#50
Looks like this is a fairly concise example: https://github.com/AmurSU/python-mjpeg-o..._client.py
Reply
#51
It's confirmed, python is not for me Smile

But by the moment if you want to use this xbmc script with mjpeg streams you can use this simple php script to split a single jpeg from the stream.

Use as url the php script:
url='http://serverip/mjpeg2jpg.php?stream=http://serveripmjpeg:port'

And install this php on your server:

PHP Code:
<?
$camurl = $_GET['stream'];
$boundary="\n--";
$f = @fopen($camurl,"r") ;
   if(!$f)
   {
        //**** cannot open
        echo "error";
   }
    else
  {
        //**** URL OK
         while (substr_count($r,"Content-Length") != 2) $r.=@fread($f,512);
    $start = strpos($r,"\xff"); 
         $end   = strpos($r,$boundary,$start)-1;
         $frame = substr("$r",$start,$end - $start);
         header("Content-type: image/jpeg");
         echo $frame;
   }
fclose($f);
?>
Reply
#52
Hello

Can anyone help me get this script working on openelec ?
The problem is that it's not updating the picture. It's working fine on the windows machines.
Is there anything missing on the openelec version that's needed to update the picture every 1 second ?

BR
Reply
#53
(2013-05-24, 08:53)migmig Wrote: Great script !

I see currently it gets jpeg snapshots and some cameras and motion programs only send mjpeg streams, It would be great to support that too Smile

So the script first would have to convert a mjpeg stream frame to jpeg.

It's my first time with python and I'm not being lucky trying it... :S

There are python projects doing that (like https://code.google.com/p/mjpeg-stream-c.../client.py ) but i'm unable to get it Big Grin

I'd rather add the mjeg stream as file. then have a script that tells xbmc to automatically play that file. xbmc can stream mjeg off the box Smile
Reply
#54
Hi

I'd like to give the script a try, I recently got my doorbell working with my Home Automation system (Vera - Micasaverde) which is Z-wave based.

Now when the doorbell is pressed I can trigger scenes in Vera to do stuff, I currently have it sending a popup notification to XBMC and it also pauses playback in XBMC which in turn brighten's up the lights to 100%.

I'd now like the IP camera image to be shown in XBMC as well.

However I am unsure which version of the script to use or how to even install it? Can anyone point me in the right direction.

Many Thanks.
Reply
#55
(2013-08-21, 23:19)cw-kid Wrote: Hi

I'd like to give the script a try, I recently got my doorbell working with my Home Automation system (Vera - Micasaverde) which is Z-wave based.

Now when the doorbell is pressed I can trigger scenes in Vera to do stuff, I currently have it sending a popup notification to XBMC and it also pauses playback in XBMC which in turn brighten's up the lights to 100%.

I'd now like the IP camera image to be shown in XBMC as well.

However I am unsure which version of the script to use or how to even install it? Can anyone point me in the right direction.

Many Thanks.

Ill post my script when i get home from work.
It works like this: grabs a image from the camera . Write it to disk, sendt it to xbmc using json API.
Reply
#56
I got this plugin working with my Vera Lite in a scene with the following code.

Code:
luup.inet.wget("http://192.168.0.5:81/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22Addons.ExecuteAddon%22,%22params%22:{%22addonid%22:%22script.doorbell%22}}")

SBS_announcement( '192.168.0.5'               ,
                  9090                           ,
                  '20:02:af:ac:78:22'            ,
                  'Text%20for%20Line1'           ,
                  'Text%20for%20Line2'           ,
                  3                              ,
                  '/D:/Misc/doorbell-2.wav',
                  5 )

But On Gotham alpha 7 the Bell icon does not show up and the image tends to flicker every few seconds bit ughh but still impresive nonetheless.

Where is the bell Icon supposed to go /media? I tried relabeling it as well. I used the github zip to install the plugin.
Reply
#57
Hey guys, I interfaced this with ZoneMinder and decided to add a way to see motion from multiple cameras, as well as display them on all XBMC installations simultaneously. Here are my changes/scripts:

(The changes here are at the beginning as well as down further, the xoptions definition)
doorbell.py_________________________________________
Code:
# Import the XBMC/XBMCGUI modules.
import xbmc, xbmcgui, time, urllib, xbmcvfs, xbmcaddon, os, sys
__addon__   = xbmcaddon.Addon()
__addonid__ = __addon__.getAddonInfo('id')

args = ['CamID','CamName']
dbvar = {'CamID': 1,
    'CamName': 'Default Camera'}

for item in sys.argv:
    arg = item.split('=')
    i = arg[0]
    if arg[0] in args:
        j = arg[1]
        dbvar.update({arg[0]:arg[1]})

url='http://zoneminderipaddr/cgi-bin/nph-zms?mode=single&monitor='+str(dbvar['CamID'])+'&scale=100&user=myZMuser&pass=myZMpass'

path = xbmc.translatePath('special://profile/addon_data/%s' % __addonid__)
if not xbmcvfs.exists(path):
    xbmcvfs.mkdir(path)
imagefile = os.path.join(path, 'bell.jpg')


class CamView(xbmcgui.WindowDialog):

    def __init__(self):
        #set the initial image before the window is shown
        urllib.urlretrieve(url, imagefile)
        self.image = xbmcgui.ControlImage(635, 160, 640, 480, "")
        self.addControl(self.image)

viewer = CamView()
viewer.show()
start_time = time.time()
firstimage = True
while(time.time() - start_time <= 14):
    urllib.urlretrieve(url, imagefile)
    viewer.image.setImage("")
    viewer.image.setImage(imagefile)
    curr_time = round(time.time() - start_time, 0)
    if firstimage:
        nowtime=time.strftime("%I:%M %p")
        xoptions="Notification(\"Motion on "+str(dbvar['CamName'])+" camera detected\",%s, 13800, special://masterprofile/media/bell1.png)" % (nowtime)
        xbmc.executebuiltin(xoptions)
        viewer.image.setAnimations([('conditional', 'effect=fade start=0 end=90 time=250 delay=125 condition=true',), ('conditional', 'effect=slide start=0,400 end=0,0 time=250 condition=true',)])
        firstimage = False
    elif curr_time == 14:
        viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',), ('conditional', 'effect=slide start=0,0 end=0,400 time=250 condition=true',)])
        print "catch"
    else:
        viewer.image.setAnimations([('conditional', 'effect=fade start=90 end=90 time=0 condition=true',)])
        print curr_time
    xbmc.sleep(500)


viewer.close()
del viewer


For anyone else attempting to do this, I used the trigger script found in the ZM wiki:
http://www.zoneminder.com/wiki/index.php...n_alarm.3F

Code:
#!/usr/bin/perl -w

use strict;

use ZoneMinder;

$| = 1;

zmDbgInit( "myscript", level=>0, to_log=>0, to_syslog=>0, to_term=>1 );

my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );

my $sql = "select M.*, max(E.Id) as LastEventId from Monitors as M left join Events as E on M.Id = E.MonitorId where M.Function != 'None' group by (M.Id)";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );

my $res = $sth->execute() or die( "Can't execute '$sql': ".$sth->errstr() );
my @monitors;
while ( my $monitor = $sth->fetchrow_hashref() )
{
    push( @monitors, $monitor );
}

while( 1 )
{
    foreach my $monitor ( @monitors )
    {
        next if ( !zmMemVerify( $monitor ) );

        if ( my $last_event_id = zmHasAlarmed( $monitor, $monitor->{LastEventId} ) )
        {
            $monitor->{LastEventId} = $last_event_id;
            print( "Monitor ".$monitor->{Name}." has alarmed\n" );
            #
            # Do your stuff here
            system(“/sbin/ZoneMinderTrigger CamID=”.$monitor->{Id}.” CamName=”.$monitor->{Name});
            sleep(12)
            #
        }
    }
    sleep( 1 );
}

I have this as an upstart job on my Ubuntu server named ZoneMinderAlarm. In the “Do Your Stuff Here” section, I had it call a python script with the specific camera ID and Name, then pause for a bit instead of continually retriggering during the event


I’m more familiar with Python, so that’s why it’s not all confined in the ZM perl script
ZoneMinderTrigger_________________________________________
Code:
#!/usr/bin/python

# This script is called by the ZoneMinderAlarm daemon/script and notifies
# all XBMC installations to overlay pictures on the screen
# It requires the doorbell xbmc plugin
# http://homeawesomation.wordpress.com/2013/02/18/doorbell-ipcam-xbmc-update/
# Credit for send_json_command to u/sffjunkie
# http://forum.xbmc.org/showthread.php?tid=92196

import json, httplib, base64, sys

xbmc_host=['myxbmcmachine','192.168.1.1','etcetcetc'] #List of XBMC HTPCs to send notification to
xbmc_port='8080'
username='myxbmcuser'
password='myxbmcpass'

args = ['CamID','CamName']
dbvar = {'CamID': 1,
    'CamName': 'Default'}
for item in sys.argv:
    arg = item.split('=')
    i = arg[0]
    if arg[0] in args:
        j = arg[1]
        dbvar.update({arg[0]:arg[1]})


def send_json_command(xbmc_host, xbmc_port, method, params=None, id=1, username=username, password=password):
    command = {'jsonrpc': '2.0', 'id': id, 'method': method}
    if params is not None: command['params'] = params
    payload = json.dumps(command, ensure_ascii=False, sort_keys=True)
    payload.encode('utf-8')
    headers = {'Content-Type': 'application/json'}
    if password != '':
        userpass = base64.encodestring('%s:%s' % (username, password))[:-1]
        headers['Authorization'] = 'Basic %s' % userpass
    conn = httplib.HTTPConnection(xbmc_host, xbmc_port)
    data = None
    try:
        conn.request('POST', '/jsonrpc', payload, headers)
        response = conn.getresponse()
        if response.status == 200: data = json.loads(response.read())['result']
        else: data = 'Response Error'
    except:
        data = 'Connection Error'
    conn.close()
    return data

def xbmc_doorbell(xbmc_host, xbmc_port=xbmc_port):
    for x in range(0, len(xbmc_host)):
        result = send_json_command(xbmc_host[x], xbmc_port, 'Addons.ExecuteAddon',{'addonid':'script.doorbell','params':{'CamID':str(dbvar['CamID']),'CamName':str(dbvar['CamName'])}})
        print xbmc_host[x]+": "+result

xbmc_doorbell(xbmc_host)
_________________________________________

There’s probably better ways to do this (I’m a shadetree programmer), but it seems to work well for me.
Reply
#58
Hi guys
i have a Axis P3367-VE camera

http://www.axis.com/en/products/cam_p3367ve/index.htm

and would like to configure the camera with an motion event notification over http to start the script

I have already put the script in the right directory and i can start it manualy with the command
http://xbmc:xbmc@localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.RunScript(script.doorbell)

but how can start the script directly from the cam

Does anyone have an Axis Camera?
Can someone help me to get things right?
Reply
#59
Hi Guys,

this doorbell plugin is a good pice oft software, but my doorcamera has a video stream. Is it possible to include the video stream (the stream plays with the strm Trick nice).

I think is not so easy to display a windowed video (only with playlist not with a direct url like http://x.y.c.d:8080/). Has somebody an idea how I could replace the image with an video stream?
Reply
#60
Hi panzaeron
i read that if a overlay video stream is display it would stop any kind of video of the main window which is already running when you are looking a movie or something like that. XBMC can only display one video at a time.

What i have found on the main homepage:
If you would like to increase the frames per second (makes it look more like a video) then decrease the amount of time the while loop sleeps by decreasing the value in the ‘xbmc.sleep(500)’ line. I decreased to 10, which leads to the popup box actually looking like a streaming video.
Reply

Logout Mark Read Team Forum Stats Members Help
I'm terrible at python and need your help with two questions0