Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Numeric Feedback (and textual) for kodi

I'm trying to get feedback working from kodi over IP/JSON, specifically some things like title and a numeric for percent played and I'm really having a hard time. I have verified with a sniffer that the json calls are sucessfull and I'm getting the responses back to irule but I have no idea how irule is processing the response. I feel like I'm struggling because there appears to be no real documentation on how to write a feedback. For example can you use regexp? looks like you can use globs (at least *). How greedy is the matching? If you do a call that generates multiple response (I.E. json with multiple parameters in the response) does irule attempt to match all feedbacks to the response or is it terminate on first match etc..

For the record I have the feedback tied to the device. The device works perfectly from a control perspective. I have then tried several of the "canned" feedbacks. None of these are working for me. I am running Kodi "Isengard" which I think is 15.1 which may be part of the problem.

Anyway, I have the feedback configured for say the numeric for volume. This is what kodi returns to the ipad (as my sniffer sees it):

{"id":14,"jsonrpc":"2.0","result": {"percentage":41.353317260742188}}

I created a numeric feedback like so:

Code:

prefix percentage":
suffix }}

Value:

format ascii
notation decimal
point position floating
formula
min 0
max 100
value units percent
set variable $kp$

I then created a label on a page with the text pointing to $kp$ and made a button to send the json call to produce the above reply.. I don't see my label ever get updated with the numerical value... I've tried many permutations of how to do the prefix match and the suffix including things like *percentage": and the whole string. Unfortunately the id number in the response seems to change so I can't specify all the way to the start of the string or it would surely break when the id changed...

I know this should work as I do the exact same thing with my onkyo feedback (volume written into a label). Of course someone else wrote that and it works so this is telling me I just don't have the feedback configured correctly.

Help please!
2 people have
this problem
+1
Reply
  • Change your prefix to *"percentage":

    Unlike you Onkyo Receiver, you have to constantly send the command to Kodi in order to get values to update.

    Depending on your vs of iPad you should be be able to send the command from 1 to 5 second interval. To give an example, on my iPad Mini I can send it every 3 seconds, and it works OK. I'm my new Galaxy S6, I can send it every second and with out any problems.

    So every time you press the button, you should get and updated value.

    Question, are you trying to get a seek slider working for KODI?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I do have the query string in my panel entrance to update. I do the same thing with the onkyo so that the value paints before I adjust it or if I change the knob on the preamp. Even without that you should be able to send a single query and get a single update of the variable.

    I actually got it to work a little just now. The change that made me start getting data was adding the asterisk to the suffix.... the issue I have is that the value that it reads is crazy. What I mean is that I have a sniffer running on the machine with kodi so I can see exactly what is being returned to irule per query. For the last query kodi sent the percentage as 38.207695007324219 and irule is displaying 14.5. A few seconds later and we have 55.30572509765625 being displayed as 16.6.

    The number doesn't change up or down when I fast forward up or down in kodi. The sniffer is still showing a sane percentage progress but irule is showing a bizzare unrelated number. It's almost like there is an integer getting overrun here or something.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Nevermind, restarted irule and the number is working properly.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • If you want to give me your email, I will gladly send you my backup if you want to see, I pretty much have Kodi all working now.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Isidoros,

    I've seen your youtube and that's all really excellent. Frankly it's what has shown me that it can be done. I'm trying to get a small portion of that going. I'm using what I believe is your Kodi chrome device, but this is not all completely documented other than some odd forum posts and some youtube.

    This is for my main theater and I'm not interested in browsing the titles on screen, but specifically the progress bar with runtimes and I would like to have the title, large thumbnail and "plot" information.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • 1
    get all time

    jsonrpc?request=%7B%22jsonrpc%22:%222.0%22,%22method%22%3A%22Player.GetProperties%22%2C%22params%22%3A%7B%22playerid%22%3A1%2C%22properties%22%3A%5B%22time%22%5D%7D%2C%22id%22%3A9%7D

    kodi hours

    starts with : {"id":9,"jsonrpc":"2.0","result":{"time":{"hours":

    'Numeric' Properties

    Value' Properties
    min :0
    max :24

    kodi minutes

    starts with : {"id":9,"jsonrpc":"2.0","result":{"time":{"hours":*,"milliseconds":*,"minutes":

    'Numeric' Properties

    Value' Properties
    min :0
    max :600

    kodi seconds

    starts with : {"id":9,"jsonrpc":"2.0","result":{"time":{"hours":*,"milliseconds":*,"minutes":*,"seconds":

    'Numeric' Properties

    Value' Properties
    min :0
    max :600

    works perfectly
    (isikape)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I agree that feedback is a big black area of iRule, with no usable documentation.

    I find that feedback either works, doesn't work, or works, but badly, especially with regard to speed.

    Why iRule doesn't have a json or xml decoder beats me, as many items return this format.

    I have the same questions as you, what regex can we use (just *, what about ? How do you escape things), how does parsing work?

    I believe there are some default time outs in iRule, that kills feedback performance. For example, if I decode some json as *"item":" "* then feedback is grindingly slow. If I add starts with { and ends with } then it is lightning fast.

    Also the * seems to be required, but I don't know why. If I say prefix with "item" why does it need a * surely that's implied. Also suffix needs 2 characters, I can put another character say , but one character doesn't work -it has to end with two. Bizarre.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • This is why I am doing all the work in EventGhost and have EG update iRule. You can do so much more in EG and not tie up iRule. I have an iPad mini vs 1 and feedback was very slow. Now that I am doing this in EG and just sending small amount of info over to iRule, it works very well and very fast. Seems like iRule has a much harder time sending requests out and waiting for a return, then just receiving the data.
    I can now update time and seek slider every second with out any problems. Plus I can set the seek slider back to 0% when nothing is playing. Can't do that through iRule. I can also add a leading 0 to seconds, if it is under 10 second. For an example doing this in iRule, the only way you can display time for a file playing that has a time index of 5 minutes and 5 seconds would be 5:5. When doing this in EG I can display 5:05 in iRule.
    There are a few other things I am working on. Will post a video soon.
    Mike
    mpg732@gmail.com
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I actually wrote my own server in Python, just to feed feedback to iRule. Gives me total control of what's happening, and that's how I figured out the feedback/time issue.

    I was updating about 15 items (using json) and my iPads were taking 30 seconds or more (the older iPads were slower). I wanted to increase the number of items, but it was taking too long for the initial load (after that one item at a time was no problem).

    So the start up time for loading all the initial values for everything was the problem.

    Once I figured out the starts with and ends with {} for json, I'm now loading about 60 items on start up in less than 1second. Even my oldest iPad tales 4 seconds total.

    This is why feedback needs better documentation, how many people have slow feedback and think that's "just the way it is" because it's configured wrong. I was astounded when the time went from 30 seconds to load (you could watch them popping up one at a time), to essentially instantaneous, by adding one } in the right place.
    • view 3 more comments
    • Many thanks. I'll have a look and see if I can cut down the long list of fields that I have. I expect that it'll need a few different queries to run it successfully. I've started running my media servers on Raspberry Pis (Volumio for music - with a web interface that's OK iniRule) and OSMC for "videos". I'm trying to avoid having to launch the Kodi app from iRule to do the media searching and information (that's *so* much faster than iRule feedbacks).
      I've done some UNIX ksh scripting in the past but never used python and al this new-fangled web stuff! If you have any pointers as to where to start with python that would be really helpful. I'm really pretty impressed with iRule - my old Control4 system controller died I took the plunge to work things out myself. I just love having control of the system now.
    • Depending on what info you all want returned, you probably need to send out two commands, One, is for time, and % and the other is for title, show title and so on. You also need two difference sets of commands depending if you are doing video and music. As for python, I am running it in EventGhost which requires a PC to be on at all times
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • If you have some RPi's, you can leave them on all the time, and they come with Python built in.

    I would start with Python 2.7 (3 is the latest, but it's not all there yet, and almost everything out there is written for 2.7) - this is the RPi default.

    It's way easier than shell scripting. Try some text based stuff first (don't try graphics), remember all the "web stuff" is text under the surface. All the GET and POST and json and headers etc. Is all just text.

    In Python you import pre-existing modules, there are a bunch for web based stuff, "requests" and "json" are the main two (although requests has a built in json encoder/decoder, but the json module lets you change the separators and spacing). There are several http server modules "simplehttpserver" is the obvious one. You can write an http server in about 10 lines of Python. I use raw sockets, as it's more flexible, but http server is easier. Google Python simplehttpserver, you'll see what I mean.

    Once you have your server sitting in the middle, receiving the GET/POST from iRule, and sending them on via requests, you can do whatever you want to the data in the middle. Strip out extraneous json, convert numeric to text. Don't want an entrance polling every 10 seconds? Easy, your Python script polls for you, if the data returned is the same as last time -don't send it!

    No queries, no polling, the data just floods in to iRule in real time. That's why you have to get the feedback formatting right, or it will bog iRule down.

    I have taken all the "delays" out of iRule now, so I can send and receive as fast as the real world allows.

    Best of luck!
    • view 10 more comments
    • Well I started at https://www.python.org/ and then went to to try and work out how to do things on a Raspberry Pi (https://www.raspberrypi.org) for various reasons:
      1) I wanted to know what all of that Pi stuff was about anyway.
      2) I thought I could use the Pi for some control and feedback (and I can!)
      3) There's a Minecraft Tutorial on the Pi (so my son was keen...)
      4) I could install stuff and then just start again by re-flashing the SD card if I made a complete mess of it.
      You could install python on Windows or a Mac - that works just as well.
      However I have to admit it took a lot longer than I thought, and it was quite a steep learning curve. Part of my trouble was that I was impatient and wanted to do a feedback to iRule quickly - and there are LOTS of steps and concepts to learn first. So I'd definitely break it down into a long term plan:
      1) Get Python installed and get familiar with a text editor and navigating around 2) Get some simple programs done: variables, input, calculations and outputting results to a screen.
      3) Understand the data types (sets, arrays, lists, tuples)
      4) Try to get the hang of using and interpreting json values
      5) Then try getting loading in data from an external site
      6) Only then start looking at the http server and socket servers.
      It took me a good few weeks/months and a fair few frustrated hours but I've got there in the end. But if you start out very ambitious and try to 'run before you walk' it'll make it that bit harder. Start with Python by all means, but be realistic that getting a feedback in iRule working is a good way down the line if you have no prior programming experience. Well, that's what I think... no doubt someone will disagree!
    • John, I wrote a long comment replying to you about a month ago about how to get started. See a few posts down.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Try this simple example https://gist.github.com/bradmontgomer...

    When a GET is received, do_GET is executed, when a POST is received, do_POST is executed. The wfile.write sends text back to the client (ie iRule) that sent the GET/POST.

    Don't worry about the "self" it's just pythonese for being in a "class" ie "I belong to this class".

    The odd __main stuff is just pythons way of saying where the main program starts, you don't actually need it. In Python indenting is important, as that is how blocks of code are defined. 4 space indenting is the standard, but you can use what you like.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Thank you! I'll make a start tonight. I've just tried simplehttpserver and it did exactly what it said it should do... I could get a directory listing. Now it looks like it's a matter of getting the different features working one by (receive a kodi response, manipulate it, send it back out to iRule) and then it should just be down to programming the python bit. Easier said than done but I can see now how it's all possible.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I’m thankful.
    After a few false starts (mainly to do with decoding the json strings and deciding whether I was looking at sets, dictionaries or lists... and the power supply to my kramer switch blowing up just to distract me) I've managed to get something up and running using simplehttpserver. The feedback really is remarkably quick compared to what I had before. Next challenge: getting some images displayed. I think that might take a little while. Many thanks for the help and pointers in the right direction.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • If you have any success with images, let me know. The new apple TV module does a nice job of displaying the "currently playing" album art, but I haven't figured out how to send images yet (without using the URL device).

    Glad to hear you had some success with python. I'm connecting to openHAB (a home automation server), via it's rest interface. it supports websockets (which are blindingly fast), so using python "websockets-client" I'm opening a websocket for each "item" in openhab (an "item" in openhab is a switch, or dimmer, or volume control, or number, or text - you get the idea).

    So right now there are 343 items feeding real time info to iRule. I load the initial state on page entry, then just stream updates via websockets. the initial load (343 items) takes about 2 seconds on my iPad mini 3. I am adding to the load somewhat as I have added a "last updated" field, which updates with the time once per second (when data is received), so that I can see the connection is updating. With some clever iRule macros, this goes white, yellow, then orange if updates are not received after preset periods of time.

    I also have some feedback from LED lights (RGBW) which produces truly vast amounts of feedback (R, G, B and W levels 0-100 changing many times per second). My iPad mini 3 copes with no problem, but my iPad mini 1 starts to fall behind. With a little more ingenuity, I get iRule to send the "last updated" field back to my server. By comparing this time with the current time, I can tell if iRule is too slow processing all the feedback. If the lag goes over a threshold (currently 3 seconds) I start selectively dropping data - the RGBW feedback specifically - until the lag is below 3 seconds again. Because there is so much RGBW feedback, dropping some values has literally no effect on the display.

    By running each connection from iRule in it's own thread, each device gets it's own connection which is then managed to it's processing speed.

    Just works!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Hi,

    Im finally starting to understand some of the feedback principles (im not a coder and a home user of irule). I came across this thread a few weeks ago and it was double dutch but after some playing around and some help from Dave Bowdler via this forum ive got some variable images working (sometimes... but this is a different story) and have started building a Kodi remote panel to replace XBMC Constellation.

    "Now playing" is working fine using a repeatable entrance :

    jsonrpc?request={%22jsonrpc%22:%222.0%22,%22params%22:%7B%22playerid%22:1%7D,%22method%22:%22Player.GetItem%22,%22id%22:%22libGetItem%22%7D

    However 2 other entrance querys, playing time and volume level, seem to return "Result:OK" rather than the actual query I am making. Both of these return the correct respnses when the query is made in HTML though. At first I could not understand why the return was not displaying in irule so I changed the prefix and suffix to * to show the full string and this is when I realised the feedback was not the same as displayed in HTML.

    HTML resposnse in Safari : {"id":9,"jsonrpc":"2.0","result":{"time":{"hours":1,"milliseconds":227,"minutes":57,"seconds":45}}}"

    Irule Displays : {"id":9,"jsonrpc":"2.0","result:OK"} .... (or something similar)

    Anyone have an idea what is going on?

    John
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • %7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22Player.GetProperties%22%2C%22params%22%3A%7B%22playerid%22%3A1%2C%22properties%22%3A%5B%22time%22%5D%7D%2C%22id%22%3A14%7D

    I believe this should get you the time of a video playing
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Anyone else using iRule to control openhab?  I'm trying to get openhab integrated into my irule setup and using the rest API to control lighting seems like it would be straightforward, but am struggling with how to start with feedback/device status.  Can anyone point me in the right direction as to how to get the python wrapper set up?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Here’s what I’ve done - anyone else feel free to jump in with a better suggestion. I’m old school so web services really aren’t my thing... I have a feeling that there may be a better way than continually sending back all of the information, every time I run a query - maybe I could get iRule to only look at the information that has changed?

    1. I set up a web server on a Raspberry Pi. It receives a query from the iRule device and then sends back a string of text on the socket. Image 1.

    2. The Pi runs a ‘simple’ HTTP Server (I put it in quotes because it isn’t simple to me...) Images 2 and 3 show the snippets of code. search for Simple HTTPServer on the web and you should find something suitable.

    3. The Python server is set up as a Device in iRule. I have a series of queries that pass parameters to the Python script - such as ?osmc=query. The python script reads the data sent (osmc query) and works out what to do. Image 4.

    4. The Python server is connected in iRule as an HTTP Gateway. In my case 192.168.1.126, port 9091 HTTP method: GET

    5. Depending upon the query sent, the Python script sends back a string of text to the socket. I’ve separated the data with tags like an xml document. So when I run an osmc query it sends back things like:
    The name of the TV Show01:15:3656
    If it was a query for, say, the weather it would send back 26 February 2016Sunny

    6. A feedback is then created for the Python server and is connected to the iRule Python Server device. Image 5.

    7. The feedback "starts with" and "ends with" tokens are then set to the tags in the file e.g. Starts with: Ends with Image 6.
    In the example shown the actual title would be set to the iRule variable $ShowTitle$. That can then be used to display the feedback on a panel or used in a macro.

    8. On the iRule panel that you need to use the feedback, set the query to be run on the entrance - and then re-run at whatever period you want to re-query things. Image 7.

    Hope that helps. It's a bit cryptic, I know. And iRule feedback isn’t the clearest topic in the world...
    • view 4 more comments
    • could you guys share a working script and help a non-coder get this running when you finish? - John
    • You are looking at a non-coder here. I'm just a copy-paster basically. Unfortunately I couldn't get this to work using delamr's example above, but he was a tremendous amount of help in making me understand along the way. I ended up getting this to work by using python and flask. First, read this entire page and do these examples, it will make you understand how it all works:

      https://help.parsehub.com/hc/en-us/ar...

      Here's my python script:

      from flask import Flask, render_template
      import requests
      import json

      app = Flask(__name__, template_folder='.')
      @app.route('/')
      def homepage():

      r = requests.get("http://api.wunderground.com/api/MY-AP...")
      data = r.json()
      x = 1
      f = open('c:\users\kinne\desktop\work - to do\data.txt', 'w')
      for period in data['forecast']['txt_forecast']['forecastday']:

      f.write( "(D" + str(x) + ")" + period['title'] + "{D" + str(x) + "}"
      "(F" + str(x) + ")" + period['fcttext'] + "{F" + str(x) + "}"
      "(P" + str(x) + ")" + period['pop'] + "%" + "{P" + str(x) + "}" )

      x += 1

      f.close()

      with open('data.txt', 'r') as g:
      return render_template('weather.html', weather=g.read())

      if __name__ == '__main__':
      app.run(host='0.0.0.0', debug=True)

      -------------------------------------------------------

      So this is taking json from a weather api and storing it in a file called "data.txt" on my computer. Then it takes that data and parses it how I have asked it to. What it returns is something like this:

      (D1)Friday{D1}(F1)Abundant sunshine. High 51F. Winds NW at 10 to 20 mph.{F1}(P1)0%{P1}(D2)Friday Night{D2}(F2)Clear skies. Low 26F. Winds N at 10 to 15 mph.{F2}(P2)0%{P2}(D3)Saturday{D3}(F3)Sunny skies. High 51F. Winds WNW at 5 to 10 mph.{F3}(P3)0%{P3}

      Then it opens that text file and sends the contents to weather.html which is located in the same folder as the python script. Here's what my weather.html looks like:

      html
      body

      {{weather}}

      /body
      /html

      (add the <> to the lines above except {{weather}} - I had to take them off to get the code to post here)
      ---------------------------------

      Now if I go to my browser and type in the ip address of the computer where my python script runs, and pull up the weather page http://192.168.0.45:5000/weather.html it will update the results each time I go there. So in iRule, I set up my gateway http://192.168.0.45, port 5000. Then I create a device with network code weather.html and in my feedback I create each one prefix (D1) suffix {D1}. I put the network code in the entrance and results are returned. Now I can use the data to change the background image to reflect the current weather.

      I haven't gotten to kodi yet, but hopefully that's enough info, and using the notes from the rest of this discussion from these nice gentlemen, you can apply it to kodi.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • What are you running KODI on? If you are running it on a PC, you don't need to use a Pi to run the scripts. I did this in EventGhost, which can run Python scripts. Running a Python script, you should be able to write it so only update when info when it changes.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I'm running OSMC - which is effectively Kodi on the Pi. What I haven't figured out is how to only send an update back to iRule only when something changes. I think I'm missing some knowledge about how the sockets are supposed to work? I'm basically running a process that goes:
    1. Send a request to the http server from iRule. (the feedback query)
    2. When the query is received, run a script to generate all of the data (one big long string...) e.g. "The name of the show01:00:02..."
    3. Send the string of text back to the socket so that it gets picked up by teh iRule feedback.

    What that means is that even if the data doesn't change (like the title of the show) I'm sending it back anyway... which doesn't sound too efficient.

    Should I be ignoring the query part and just running the script on a scheduled basis, and sending back only data that has changed ? So to start with I might send "The name of the show01:00:02..." and then later on *(say 10 seconds later) I'd just send "01:00:12" ?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • So in the simplest way would be to add more "IF" Statements in the script comparing variables. So you could use "title", when title changes send to iRule the new data. Obviously you will want to keep things like "time" outside that loop.

    I would spend so time Googling and see if there is a better way in Python the to use "IF" Statements.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Thanks.
    I think the bit that's confusing me is that I have an http server running. I send a GET command from iRule to trigger the http server to run a script to run a query and then the http server returns the data to iRule. But is it possible to tell the http server to send the data to the port without that initial GET command?
    At the moment I think I'll need to store the values each time the query is called and only send back any changes. I've used "cpickle" to store the values in a file but it seems a bit slow (although that may be how I've coded it...) I can't help think I'm missing something obvious.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I would think you could do a few things, you could set up iRule with a repeatable entrance command that can send out the "get" command on a regular basis. This can slow down iRule a bit depending on how often you want the info updated.

    What I would do, is in iRule, is on the page load send a command to start the script and have a loop in it. I would set the loop on a delay interval, say every few seconds. Then when you leave the page, you stop the script from running. This way iRule only have to send the command once to start and the the web server can do all the work. I found that iRule has an easier time receiving data then it does sending out the request and wait for the returned data.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Thanks for the pointers. I tried a repeating entrance a while ago but found it a bit sluggish. I'll have a go with with the GET command triggering a repeating script and see what I can find...
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Hi,

    Has anyone set any queries up for openelec? (similar to OSMC). I am assuming I can run the http server from the shell in openelec but im not sure on what the query and feedback settings are?

    John
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • This reply was removed on 2016-05-11.
    see the change log
  • Openelec communicates with the exact same url encoded json strings as any Kody distro. So yes there is an amazing Collection of commands that you can import into your project directly in the builder. Go to browse and import devices then Search community for "JTM Kodi Chromebox" you can get the associated feedback as well by using the same method.

    Reguarding Query: when you're going down his list of commands you will see some that say query and some say get (both of these are query items that you can run as a repeatable on non repeatable entrance.)

    And also no need to run via shell see attached pic
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Hi,

    I understand and use the kodi feedbacks via irule. What i would like to learn is step by step process for using a webserver to communicate with irule and have the webserver handle the feedback and talk to irule which is said to be quicker and more effective. Note the webserver on your screengrab is one used for kodi itself.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • can you give me an example of the query you need to send to kodi via the webserver? JTM chromebox is no longer showing in the devices list... I have saw it in the past
    • ===== Get Current Title========
      yourkodip:yourwebserverport/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22,%22method%22:%22Player.GetItem%22,%22params%22:%7B%22playerid%22:1,%22properties%22:%5B%22title%22%5D%7D,%22id%22:3%7D
    • That is how you test in the browser however the command you would use for on controls/Irule is as follows --------jsonrpc?request=%7B%22jsonrpc%22:%222.0%22,%22method%22:%22Player.GetItem%22,%22params%22:%7B%22playerid%22:1,%22properties%22:%5B%22title%22%5D%7D,%22id%22:3%7D
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Posted my comment above but I'm not sure if it will be seen...

    Can someone re-upload a copy of the "JTM Kodi Chromebox" device and related feedback? I can't seem to find it no matter what I search for or how I search.

    I'm just starting to set this up and it would be really helpful! Thanks!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I have a fully functional iRule handset setup with feedbacks working. iRule is connecting to the RPI that is acting as a serial to IP gateway (i.e. Global Caché device on the cheap). I'd now like to offload some of the overhead (delays and polling) from iRule to the RPI like some of you are doing here.

    I've set up a python server and can successfully output XML to a web page which I'll pick up on iRule (through feedbacks). What I don't have a view on, though, is the connection architecture.

    Does iRule poll the web page to get the data and then close the connection? Does it keep the connection open the entire time? Or can the RPI push the updates to iRule if the connection is closed.

    Cheers!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I am the guy who shared the kodi device codes temporarily for a friend.
    Was not aware that other people were using it until I saw this.
    Ah well. It is in no way complete or bugfree and I am currently using it with an alpha version on Libre Elec but it should work with any version of Kodi from Jarvis and onwards. I have cleaned it up a little and shared it up again under the name:
    Kodi JTM share 2016 11

    Search community devices: vendor: kodi, model: jsonjtm and it should show.

    I have a convoluted set of feedbacks too that I could share with the same
    work in progress reservations. YMMV etc. Good luck.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I've got things running two ways (as I learn more about sockets and web pages...!) It's tricky to write it down simply, but here's an outline.
    Option 1.
    Python as an http server. I have the Pi set up as an http gateway on the handset, and as a device within iRule. I can send a send a request to the Pi (such as ?LoungeTVPower=On). The Pi can then return an xml page which iRule can then parse as feedback. This works fine, albeit the feedback parsing is a bit slow. The data is sent to iRule in response to a specific request (command)received.
    Option 2.
    Python as a socket server.
    i) I started this with TCP sockets which guarantee delivery of the data but needs a bound/permanent connection. Every time I reconnected by handset it spawned a new connection and eventually the Pi fell over. I've abandoned this approach.
    ii) UDP sockets seemed to be the way to go. The Pi is set up as a Device in iRule builder and it's linked to a feedback. The Pi broadcasts the data to the socket with a command like : sock.sendto(KODIoutput, (host,port))
    The Pi socket server is set up to broadcast to x.x.x.255, and the iRule Network gateway is set to receive from this address. The Pi sends the data when it wants to - and iRule processes the feedback straight away. It's pretty quick. I think iRule just picks it up as and when it see any data on the port.

    I always send the in an xml format with delimiters because it makes the feedback syntax (begins with/ends with) easier for me to work out.
    • view 2 more comments
    • Thanks. I stripped out some code above; what you have is almost identical to mine. What isn't working for me is when I 'ncat' from my computer to the UDP server...I am expecting to see the output on both the computer and the iRule. But that's not happening.
    • (in your case, the command I think you would use is)

      ncat 192.168.1.255 9094 -u
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I would love to know how to set a python script working on the rpi... unfortunately ive got zero coding ability, my limit is he feedback process on irule.

    If anyone ever creates a step by step guide for all the coding scripts etc it would be fab!

    John
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Does anyone have a walkthrough on how to set this up on a raspberry pi 3 running raspbian Jessie? I have tried to figure this out, but I apparently suck.
    • view 8 more comments
    • I think you have UDP_IP = "127.0.0.1"
      I have (effectively) UDP_IP='192.168.1.255'
      Does that make a difference?

      To expand on it in a bit more detail, actually I have a python script caled socket_server_udp.py

      where my socket server is set up as:

      #!/usr/bin/env python
      import daemon
      import time
      import os
      import socket
      import sys

      def serve(host,port,delay):
      #Set socket options - UDP and BROADCAST
      sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
      try:
      sock.bind((host,port))
      except socket.error, msg :
      print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
      sys.exit()
      print 'Using host:socket ', host,':',port
      while 1 :
      ' Call a routine to get the data for irule and store it in MESSAGE
      try:
      sock.sendto(MESSAGE, (host,port))
      except:
      pass
      # Delay for a few seconds
      time.sleep(delay)

      if __name__ == "__main__":
      host='192.168.1.255'
      port=9094
      delay=3
      x=serve(host,port,delay)

      And then I run
      ./socket_server_udp.py &
      so it runs continually in the background as a unix daemon
    • I got it to work. I needed to give the sender the IP Address of the iRule Device.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned



  • So Im trying to follow the various tips on this thread and now implement a UDP socket as others have managed.

    Following Delamrs steps :

    1) Get any simple feedback working with iRule (using XMBC/Kodi web service is a good way). Get some understanding of feedbacks and setting up the "begins with/ends with" statements.

    I can get various feedbacks working in irule including kodi and variable expressions so Ive mastered general feedback in irule.

    2) Build the simple socket server (like you have above). Make sure you can send and receive a message on one device.

    I can set this up and send to the same device.

    3) Then pick up the message on another computer on your network (in my case I have a Pi and a Pi Zero so I can test it that way).

    I cant get the message from one pi to another. See pic... Ive tried adding the ip addresses on the pi's in the UDP / port sections. Which parts of the send/receive scripts do I need to adjust to get the script working on my setup?

    4) Finally try to get iRule to parse the message you send.
    It is a frustrating process (well it was for me) but once it's up and running it's usually fine.

    Havent tired this yet...
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I'm away from home at the moment, but the old backup of my code that I have access to has 192.168.1.255 as the broadcast address on the UDP sender.
    Give it your code a try with 192.168.0.255 (assuming your subnet is 192.168.0.xxx) as the UDP_IP address and see if that works....
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I get a permission denied, some googling says its to do with SO_broadcast being used?





    UPDATE, I added : sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) from the example above... now I see the reply on the other machine... 1 more step closer :-)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Alright, let's take this one small step at a time. I'm no expert on this, I'm just going to show you what I'm doing which is working, so I apologize if some of my instructions might be wrong or unnecessary.
    1) Add the sock.setsockopt line to both of your scripts.
    2) Make your UDP_IP 192.168.0.255 on both of your scripts.
    3) Make your message "(test)55{test}"
    4) In iRule, add a new device and call it Socket Server. That's it. No other code.
    5) In iRule, create a new feedback. Add code under numeric (easier to parse). Do begins with (test) and ends with {test}. Under device for the feedback, choose Socket Server. That's it, no other changes. Drag and drop it on one of your iRule pages.
    6) Start your socket server (receive.py)
    7) Get out your iRule device and navigate to the page where you dragged your feedback and leave it out and on.
    8) Run your send.py script and you should see the message pop up on your iRule page as well as your socket server.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Ok so I just tested it and you don't have to run your socket server script (receive.py). I guess that makes sense that iRule is receiving the message.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • mmm... strange it doesnt appear in irule but still appears on my other pi as a received message... Ive got the network device setup as 192.168.0.255, the UDP device selected and UDP (auto selected)



  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Yeah it's just an iRule parsing thing at this point. For starts with, use something different. I use parentheses ( ) for my starts with and brackets { } for my ends with. And get rid of the asterisks. You don't need them since that's all it's sending.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Hi Greg,

    Strangely I had to delete the numeric a couple of times and then kill irule and reload it... and it appeared. Thanks for your help.

    The million dollar question how do I now use this method to pull things like kodi feedbacks in now? im assuming I pull that somehow into the "message"?

    John
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Yeah, that's iRule feedback for you.

    I was afraid you were going to ask that next haha. Ok, there are 100 ways to skin a cat. I still haven't dug into kodi yet, so delamr might be able to address that, I'm using web sockets for Sonos, but I think it's the same basics. I use a Python plugin called Flask. Flask is a web server that will allow you to send an http request that can do a python script. So I have an entrance in my irule page for sonos and that sends a command to my RPi 192.168.0.50/start and that will start the Flask server which will poll Sonos for it's json information that I will then have my python program parse and broadcast to iRule. Parsing json through python is the most difficult part of this process for me - I still don't quite understand the difference between a dict, an object, and a list, but oh well.

    If you choose to go the Flask route, I strongly recommend starting with this tutorial. It will make you understand Flask https://help.parsehub.com/hc/en-us/ar... . If you do decide to use Flask, it's great for other feedback. I use it to get the weather, the time, sunrise/sunset, moon phases, a quote of the day, even my and my wife's google calendar for the week.

    Here's my code:----------------------------------------------------------
    import requests
    import os
    import time
    import datetime
    from flask import Flask, render_template
    import socket

    app = Flask(__name__, template_folder='.')
    @app.route('/start')
    def homepage():
    time.sleep(2)
    counter = 1
    while data['playbackState'] != "PAUSED_PLAYBACK":
    r = requests.get("http://192.168.0.50:5005/kitchen/state")
    data = r.json()
    d = data['currentTrack']
    dd = d.get('absoluteAlbumArtUri','http://192.168.0.50:5000/sonosArt')
    MESSAGE = ("(vol)" + str(data['volume']) + "{vol}\n"
    "(curArtist)" + data['currentTrack']['artist'] + "{curArtist}\n"
    + "(curTitle)" + data['currentTrack']['title'] + "{curTitle}\n"
    + "(curArt)" + dd + "{curArt}\n"
    + "(nextArtist)" + data['nextTrack']['artist'] + "{nextArtist}\n"
    + "(nextTitle)" + data['nextTrack']['title'] + "{nextTitle}\n")

    UDP_IP = "192.168.0.255"
    UDP_PORT = 9094
    sock = socket.socket(socket.AF_INET, # Internet
    socket.SOCK_DGRAM) # UDP
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
    time.sleep(1)

    if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5001, debug=True)
    -----------------------------------------------------------------------------------------------

    Don't copy and paste this - it will not work for you. You can use the first 3 lines and the last 2 lines out of the box(where I put /start, you can put whatever you want to initiate your script). Then you would have a get request for the json data (r=request.get....) then you would have your message. If iRule parses the json data as it is, lucky you! Just put message=data and do your parsing in your irule feedback. Then you will see the familiar web socket send message lines.

    So, whatever this script is called, start it and leave it running. It's an http server. It will wait and listen until you send it code to start it (/start). Then it will poll for that json data to pass through to irule. As long as my sonos is playing, it will not say paused, so I have the line "while data != paused". Then I have time.sleep(1) at the end which will poll and send the data to irule once every second. It's nice and feels about like real time. If I left that line off, the responsiveness was everything I always hoped irule would be but was pretty taxing on my RPi.

    Good luck!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • Thanks Greg. I will try to decifer the code and start with Flask
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned