Curl to sent JSON notification help
#1
Hello

I am trying to sent a popup notification to XBMC using curl in a Python script.

This is my notification code that works OK in a web browser.

Code:
http://192.168.1.100:8080/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"Home","message":"Turning Lounge Lights On"},"id":1}

Once I have ran it in the browser it changes to this:

Code:
http://192.168.1.100:8080/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22GUI.ShowNotification%22,%22params%22:{%22title%22:%22Home%22,%22message%22:%22Turning%20Lounge%20Lights%20On%22},%22id%22:1}

This is my python script

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "http://192.168.1.100:8080/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22GUI.ShowNotification%22,%22params%22:{%22title%22:%22Home%22,%22message%22:%22Turning%20Lounge%20Lights%20On%22},%22id%22:1}"])

I get this error when running the python in terminal

curl: (3) [globbing] nested brace in column 122

It doesn't seem to like the nested brackets { }

Ideally I would like the final python script to send two different http commands via curl if possible? One to send a http request to my home automation controller to turn on my lights and the second http request to send a popup notification in XBMC.

This is the working python script that sends a http request to the home automation controller to turn on the lights:

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "http://192.168.1.101:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=1"])

Can any developers / programmers please help me?


Many thanks
Reply
#2
Try
Code:
http://192.168.1.100:8080/jsonrpc?request=%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22GUI.ShowNotification%22%2C%22params%22%3A%7B%22title%22%3A%22Home%22%2C%22message%22%3A%22Turning%20Lounge%20Lights%20On%22%7D%2C%22id%22%3A1%7D
i.e. you need to URL encode the whole request including the curly braces.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#3
Hi Montellese

Thank you very much for your reply!

I just installed Notepad++ after a quick Google search for unicode text editor.

I have edited my python script using Notepad++ and pasted in the http command you suggested.

Code:
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "http://192.168.1.100:8080/jsonrpc?request=%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22GUI.ShowNotific​ation%22%2C%22params%22%3A%7B%22title%22%3A%22Home%22%2C%22message%22%3A%22Turning%20Lounge%20Lights%20On%22%7D%2C%22id%22%3A1%7D"])

When I run the python script in terminal it now says:


XBMC01:~/.xbmc/userdata/vera # python lounge-on.py
{"error":{"code":-32601,"message":"Method not found."},"id":1,"jsonrpc":"2.0"}XBMC01:~/.xbmc/userdata/vera #

If I just run that http string in the browser it says the same thing as well.

I just got it working using this website:

http://www.url-encode-decode.com/

I wasn't sure but selected UTF-8

Image

Thanks
Reply
#4
Hey Montellese

Thanks for your help pointing me in the right direction, I gave you a mention on my blog post here I've been writing about integrating Logitech Harmony remotes with XBMC and home automation controllers.

Cheers
Reply
#5
I set $msg="message"

I'm doing something similar and trying to send $msg as a notification. When I run Echo $msg, it comes up fine, but in the JSON call it is displaying in Kodi as $msg rather than "message". Any ideas?
Reply

Logout Mark Read Team Forum Stats Members Help
Curl to sent JSON notification help0