I'm terrible at python and need your help with two questions
#31
Hi

Just watched your youtube video looks very good. Just spent last 10 minutes looking in to how to add ip cam into xbmc, so probably not seen all possible options yet. Most talk about creating .strm files and streaming them. That sounds pretty easy.

I have one HD cam that streams rtsp and the other is a Foscam mjpeg.

Your solution looks / sounds much better, like picture in picture! Has anyone got this script working on v12 frodo?

How difficult is it to setup?

I am surprised no one hasnt written a IP Camera addon for XBMC.

XBMC seems to be lacking home automation addons. Was previously using mControl for Windows MCE, could control all z-wave devices in the house and view cams etc from the TV screens,[/i] lost all that now with XBMC.

Thanks
Reply
#32
The problem is each home automation system is "patch work" so everyone has different needs.

.strm files will only work if you have a url that is playable to xbmc, which depends on the camera
Reply
#33
Came across this script while looking for a PIP to show a video feed and seems like a great compromise. Any idea what the path would be when using XBMC on a mac? I've tried the following but it doesn't trigger the popup. Running it manually from within XBMC works so I know the script it setup properly and working.
Code:
http://localhost:8081/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.RunScript(/Macintosh%20HD/Applications/XBMC/Contents/Resources/XBMC/addons/script.doorbell/doorbell.py)
Reply
#34
Figured it out, I was missing the .app from the program name in the applications folder.

http://localhost:8081/xbmcCmds/xbmcHttp?...orbell.py)

But I'm getting an error popup now when run this way. Looking at the log..

Quote:16:00:17 T:2953850880 NOTICE: -->Python Interpreter Initialized<--
16:00:17 T:2953850880 ERROR: Error Type: <type 'exceptions.Exception'>
16:00:17 T:2953850880 ERROR: Error Contents: No valid addon id could be obtained. None was passed and the script wasn't executed in a normal xbmc manner.
16:00:17 T:2953850880 ERROR: Traceback (most recent call last):
File "/Applications/XBMC.app/Contents/Resources/XBMC/addons/script.doorbell/doorbell.py", line 3, in <module>
__addon__ = xbmcaddon.Addon()
Exception: No valid addon id could be obtained. None was passed and the script wasn't executed in a normal xbmc manner.
Reply
#35
Sorted it... No need to specify the full location any longer. Just run

http://localhost:8081/xbmcCmds/xbmcHttp?....doorbell)
Reply
#36
Would there by any way of passing a variable in the url or json call that the script could pick up and use to display a different message? Perhaps even taking a string and displaying this string in the popup.

I'm currently hacking this appart to use as a baby monitor system. IP cam will be on streaming video and audio. My server will monitor the feed, and based on different events such as volume triggers etc will call the xbmc url to trigger the popup and show the camera feed.

I'd love to be able to mute whatever I'm watching automatically and play the ip cam audio stream but one step at a time!
Reply
#37
Another update...

I've got it working using xbmc 12.1 frodo. Json was a little tricky to get sorted as it's rpc vesion 2 so it was giving me errors even it looked ok. The formatting is strict, so I resorted to building it up using arrays in PHP and json encoding it.

I have it working from a php script using curl. I've also worked out using the xbmc api that I can pass in variables over the json command, which I can then pick up in the xbmc app and show on the popup message.

Here's the code triggering the json command

PHP Code:
<?php

$blackBoxIP 
'10.0.7.12';
$XbmcPort '8081';

echo 
"Sending Notification...\n";

$data = array(    "jsonrpc" => "2.0"
                
"id" => "0"
                
"method" => "Addons.ExecuteAddon"
                
"params" => array(    "addonid"=> "script.doorbell",
                                    
"params" => array (    'image'  => 'notificationicon.jpg',
                                                        
'string1'=> 'Hello World',
                                                        
'string2'=> 'Showing this message using',
                                                        
'string3'=> 'Combination of XBMC python modules and',
                                                        
'string4'=> 'JSON-RPC API interface',
                                                        
'string5'=> 'Have fun coding'
                                                        
)
                                )
                );
                                                                          
$data_string json_encode($data);
 
$ch curl_init("http://$blackBoxIP:$XbmcPort/jsonrpc");                                                                      
curl_setopt($chCURLOPT_CUSTOMREQUEST"POST");                                                                     
curl_setopt($chCURLOPT_POSTFIELDS$data_string);                                                                  
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);                                                                      
curl_setopt($chCURLOPT_HTTPHEADER, array(                                                                          
    
'Content-Type: application/json',                                                                                
    
'Content-Length: ' strlen($data_string))                                                                       
);                                                                                                       
 
$result curl_exec($ch);


curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

if(
curl_exec($ch) === false)
{
    echo 
'Curl error: ' curl_error($ch);
}
else
{
    echo 
'Sent succesfully';
}

curl_close($ch); 

I'm still trying to figure out how I catch the strings in the script and display them on the popup. At the moment all I'm getting is erros but I have this to follow ( http://wiki.xbmc.org/index.php?title=HOW...orld_addon ) so I'll work out a little more tomorrow after work.
Reply
#38
I'd like to see the changes you've made to the python script. I used to fire the notification and invoke the script separately but you can see that I decided to make the python script itself make the call. I'm sure you could pass a string to it and then onto the notification.

(2013-03-23, 16:09)cw-kid Wrote: Has anyone got this script working on v12 frodo?

Thank you! For the record there is no real issue with this on frodo. Some animations wont work apparently. Never tried it.
Reply
#39
This is the first time I've dabbled with python so I'm still trying to figure it out at the moment. I can tell how I would do it in php quite easily so I just need to figure out the python equivalent of it all. I'll post it back as soon as its working.

also I think one of the main issues the json call to v12 wasn't working is it was being requested via get, rather than post so having a correctly formatted json array in the url would fail regardless. Perhaps somebody with more jsonrpc experience could confirm this? Safest bet is curl a application/json POST with the json array in the post fields
Reply
#40
sys.argv[2] contains a string of all the params passed to your addon, and you have to parse them into something useful like a dict. In your example,
Code:
import sys
import xbmc
import urlparse

params = urlparse.parse_qs(sys.argv[2])
img =     params['image']
title =     params['string1']
msg =    params['string2']
time = 2000  #in milliseconds
builtin = 'Notification(%s,%s,%s,%s)' %(title,msg,time,img)
xbmc.executebuiltin(builtin)

Notifications can only have one line of text, so the other strings are still passed, but you can't use them in the notification itself
Reply
#41
Good to know I was on the right track. I imported sys and urlparse I was just having some difficulty catching the message to put in the notification so I'm probably going wrong on the parsing. Ill take a look when I have my laptop to hand later
Reply
#42
I have it working...

Here's your modified script.

PHP Code:
# Import the XBMC/XBMCGUI modules.
import xbmcxbmcguitimeurllibxbmcvfsxbmcaddonossysurlparse
__addon__   
xbmcaddon.Addon()
__addonid__ __addon__.getAddonInfo('id')

params urlparse.parse_qs('&'.join(sys.argv[1:]))
title params['title'][0]
url params['url'][0]


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__(selfurltitle):
        
#set the initial image before the window is shown
        
urllib.urlretrieve(urlimagefile)
        
self.image xbmcgui.ControlImage(870383380253"")
        
self.addControl(self.image)

viewer CamView(urltitle)
viewer.show()
start_time time.time()
firstimage True
while(time.time() - start_time <= 14):
    
urllib.urlretrieve(urlimagefile)
    
viewer.image.setImage("")
    
viewer.image.setImage(imagefile)
    
curr_time round(time.time() - start_time0)
    if 
firstimage:
        
nowtime=time.strftime("%I:%M %p")
        
xoptions="Notification(%(x)s, %(y)s, 13800, special://masterprofile/media/bell1.png)" % {"x" title"y" : (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 
Reply
#43
I have this line appearing in the error log every time it's run.

What's the special:// doing?

Quote:ERROR: Texture manager unable to load file: special://masterprofile/media/bell1.png
Reply
#44
The special protocol is xbmc's way of making everything platform/location agnostic. See here for more info: http://wiki.xbmc.org/?title=Special_protocol
Reply
#45
(2013-04-02, 22:08)beardedgeek Wrote: I have this line appearing in the error log every time it's run.

What's the special:// doing?

Quote:ERROR: Texture manager unable to load file: special://masterprofile/media/bell1.png

Move bell1.png from the script's folder to .../media/ This is because I suck and I didn't know how to reference the bell1.png icon from within it's own directory.
Reply

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