more G-Labs products

Author Topic: Send Http to Kodi  (Read 919 times)

November 28, 2016, 10:48:05 PM
Read 919 times

IanR

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hello
I have been trying to find out how to send an http string from HG so fare no luck (please help point me in the correct direction).
I have a Kodi box and am looking to send this to it:
Code: [Select]
http://192.168.***.***:80/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam"},"id":"1"}}This string is so when the door bell is pressed the app on Kodi will pop up the IP camera in the area of the door on the screen and I can see how is there (and If want to answer it).
Please see the discussion on the kodi forum http://forum.kodi.tv/showthread.php?tid=182540&page=5 for more about the kodi app.
Is there an easy way (and forgive me if I have missed something I am new at HG ) to send this string from HG?
Thank you
IanR

November 29, 2016, 11:10:19 AM
Reply #1

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
Looking on the net I've knocked this up (untested) and looks like it should do what you want.. from the example below
http://stackoverflow.com/questions/22392362/making-a-json-rpc-http-call-using-c-sharp

Code: [Select]

var server = "192.168.***.***";
var port = "80";

using (System.Net.WebClient wc = new System.Net.WebClient())
{
  // Might be required to prevent HTTP 401: Unauthorized messages
  wc.Credentials = new NetworkCredential("username", "password");
  var json = "{\"jsonrpc\":\"2.0\",\"method\":\"Addons.ExecuteAddon\",\"params\":{\"addonid\":\"script.securitycam\"},\"id\":\"1\"}}"
  response = wc.UploadString($"http://{server}:{port}/jsonrpc", "POST", json);
}

David

November 29, 2016, 11:11:41 AM
Reply #2

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
.. you will need the namespace for the network credential actually.

So System.Net.NetworkCredential

November 29, 2016, 11:42:45 PM
Reply #3

IanR

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hello
Thank you for your reply.
I tried the code but I had a separate problem with the kodi app so changed the json to put a message on to the screen. So I could still test the HG code.
Code: [Select]
http://192.168.***.***:80/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22GUI.ShowNotification%22,%22params%22:{%22title%22:%22Front%20Doorbell%22,%22message%22:%22Someone%20at%20the%20door!%22},%22id%22:1}%22
I could not get your code to work but I looked at the link you suggested and used the other code on the site. That gave me this:
Code: [Select]
using (var webClient = new WebClient())
{
  var json = "{\"jsonrpc\":\"2.0\",\"method\":\"GUI.ShowNotification\",\"params\":{\"title here\":\"Title\",\"message\":\"Door\"},\"id\":1}";
  var response = webClient.UploadString("http://192.168.***.***:8080/jsonrpc", "POST", json);
}
And it worked. It put a 2 line Text popup onto the TV screen with line 1 being “title here” and on the second line “Door”.
When I have the Kodi app working I hope to test it with code above adjusted with the required json = command as in my first post of this thread above and will report back but this could take some time sorry,
Thank you for your help.
IanR