Using an Apple TV remote with kodi on Raspberry Pi (using Flirc)

I have become a big fan of both kodi and Raspberry Pi.

On of the advantages with Kodi is that it works with HDMI cec, wich basically means that You can use Your regular tv remote since all button input signals will be transfered using Your HDMI cable – nice. On most of the tv manufacturers remote controls, the arrow and media buttons are in the bottom region of the remote. For just navigating kodi I started to search for a more simple remote. I wanted a remote of good qaility, nice design and not too expensive. And somehow that lead me into wanting to use an apple tv remote along with kodi. The apple tv remote (3rd gen.) has a simple and very nice aluminum design with just a few simple buttons used to navigate. The price is also very attractive compared to other remotes like Logitech Harmony




I will not go into details of how to use flirc or kodi – but will focus on the procedure you need to go through. If You need any information about how to configure flirc, please visit their website. If You need to know more about kodi, please visit their wiki.

First step – configure the remote to work with flirc – pairing buttons

One important thing to know about flirc is that it just records keybord commands. Below is how I mapped the Apple tv remote buttons.

Button on apple tv remote Keyboard signal
Left button Left arrow
Right button Right arrow
Up button Up arrow
Down button Down arrow
Center button Enter
Menu button Backspace
Play/Pause button Space


Here is a complete list of Kodi keyboard commands

Second step – create kodi keymap

One of the features that makes kodi extremely flexible is that you can create keymaps. This basically means, that You can have a button work one way if you are in one menu and have the same button act in another way in some other menu. Put in another way – one button can act in different ways based on the context in the user interface. Having only seven buttons to configure this is very useful.

So the basic features that I would want to have the apple remote to support?:

  • Navigate left
  • Navigate right
  • Navigate down
  • navigate up
  • Select
  • Play/pause
  • Context menu
  • Navigate back (escaping a menu)

As you migh notice, this is eight commands for seven buttons.

I decided to have the play/pause button work in two different ways.

  1. When wathching movies etc. I want it to play/pause when pressed
  2. When items are highlighted in playlists and in the video submenu I want it to display the context menu for instance for being able to see movie information)

To make a long story short what You basically need to do is to map a keyboard command with a kodi command – and that is what You use the keymap for.

  • Create a remote.xml file
  • Paste this xml snippet

<?xml version="1.0" encoding="UTF-8"?>
<!– This file contains the mapping of keys (gamepad, remote, and keyboard) to actions within XBMC –>
<!– The <global> section is a fall through – they will only be used if the button is not          –>
<!– used in the current window’s section.  Note that there is only handling                       –>
<!– for a single action per button at this stage.                                                 –>
<!– For joystick/gamepad configuration under linux/win32, see below as it differs from xbox       –>
<!– gamepads.                                                                                     –>

<!– The format is:                      –>
<!–    <device>                         –>
<!–      <button>action</button>        –>
<!–    </device>                        –>

<!– To map keys from other remotes using the RCA protocol, you may add <universalremote> blocks –>
<!– In this case, the tags used are <obc#> where # is the original button code (OBC) of the key –>
<!– You set it up by adding a <universalremote> block to the window or <global> section:       –>
<!–    <universalremote>             –>
<!–       <obc45>Stop</obc45>         –>
<!–    </universalremote>            –>

<!– Note that the action can be a built-in function.                 –>
<!–  eg <B>ActivateWindow(MyMusic)</B>                         –>
<!– would automatically go to My Music on the press of the B button. –>

<!– Joysticks / Gamepads:                                                                    –>
<!–   See the sample PS3 controller configuration below for the format.                      –>
<!–                                                                                          –>
<!–  Joystick Name:                                                                          –>
<!–   Do ‘cat /proc/bus/input/devices’ or see your xbmc log file  to find the names of       –>
<!–   detected joysticks. The name used in the configuration should match the detected name. –>
<!–                                                                                          –>
<!–  Button Ids:                                                                             –>
<!–   ‘id’ is the button ID used by SDL. Joystick button ids of connected joysticks appear   –>
<!–   in xbmc.log when they are pressed. Use your log to map custom buttons to actions.      –>
<!–                                                                                          –>
<!–  Axis Ids / Analog Controls                                                              –>
<!–   Coming soon.                                                                           –>
            <key id="VK_SPACE">ContextMenu</key>
            <key id="VK_SPACE">ContextMenu</key>

VK_space is the keyboard command that kodi receives. See List of keynames that can be used in keymap for more information

  • upload the remote.xml file to your Raspberry Pi/Kodi – path: /storage/.kodi/userdata/keymaps/
  • Put flirc usb device in usb port on Raspberry Pi
  • Reboot kodi

That’s it.



Insufficient memory to run script

Today I met a boundary when creeating a routine that produces a pricelist in AX 4.0 for a webshop. When creating the required xml I was receiving the error:

Error executing code: Insufficient memory to run script.

It turns out that AX4.0 per default has a 4mb buffersize. And as the resulting xml would contain about 16 mb of data I kept getting the exception. I found good help to increase the buffersize in this post from Martin Dráb.

How to diagnose .net memory issues

Recently I had the quite interesting task to debug some memory issues in a windows service.

I was quite surprised how good the various tools have become and after some reading I was quite quickly able to pinpoint where the probmelm, in this case a memory leak, was to be found.

I found to articles to be very helpful:

In my case I had to upgrade to VS 2015 enterprise to being able to debug the managed memory.


In combination the two articles describe how to get started and I recommend reading especially the first one. But if You are in a hurry this list of things to do might be helpful.

  1. First of all we need to create the actual memory dump
  2. Download ProcDump from and save/unzip it to a folder on the machine where your application is installed.
  3. Open a command prompt and switch to the folder where you saved/unzipped ProcDump.exe
  4. Run the command “ProcDump.exe –ma NameOfYourService.exe NameOfDumpFile
  5. This will create a memorydump in the same folder as where ProcDump is located.
  6. As described in the article on msdn, it could be a good idea to create a baseline/initial dump and afterwards create another dump to see how memory consumption evolves.
  7. Having created the dump file, we need to switch to Visual studio – in my case VS 2015 Enterprise
  8. From the files menu select “open file” and browse to select your dump file. You will see something like this
  9. If you do not see the “Debug Managed Memory” action, then your version of VS doesn’t support this and You will need to upgrade to a “bigger” version.
  10. In my scenario it was quite obvious in which area the problem were to be found – please note the “Size (Bytes)” column.
  11. Having the information above I could go back to my code at analyze where the objects were used and ensure proper release of the memory used by these objects.
    If you know what to look for, things get a hole lot easier:-)

How to export configuration settings for AIF inbound/outbound ports

A very tedious task of mine has often been to deploy AIF services accross environments. I am used to do this the old school way = manually.

Today I had something that might be compared to as an epiphany – I stumbled upon this great technet artichle descripting how to export the configuration settings using the data import/export framework. Tried it out for the first time today and it’s working just great. The only downside so far, is that I haven’t been aware of this feature before…:-)

Unable to render content due to an error. Please contact your system administrator.

Recently I experienced a strange error in an usercontrol. The error would cause the classic “Unable to render content due to an error. Please contact your system administrator.” message on EP and in the eventviewer I saw this:




The strange thjing turned out to be that the code for the usercontrol was an exact match with the one from a reference environment where everything worked just fine.

Trying to narrow things down I ended up finding that it was the AllowPaging property on the grid that was set to false that caused the error. Setting this property to true, would make the control work just fine. However my customer didn’t want paging – and it woked just fine in the reference environment. Giving this thought I concluded that the error was related to data. In my environment the dataset would return 55 records and in the reference environment I would have just 12 records. I started to play around with the PageSize property of the grid and found the the magic limit was 45 records. A limit of 44 in the PageSize property would make the control work just fine, whereas a limit of 45 would make the control crash with the above eventlog entries to follow.

I don’t think that the error is related to 45 records but more likely the size of the entire dataset. In my case the dataset contains information about expences and in that context some image/binary bitmap data. I therefore expect the data to be quite big.



If you begin to experience strange errors like the ones above – maybe it would be a good idea to look into the size of data.

Assembly containing type is not referenced

When developing VS studio components in AX2012 You might experience the following error trying to run the code:


When You build your vs project You will have to decide whether to publish to either client or server or maybe even both. This is where You need to keep in mind, that the server is quite certain to run as a 64 bit application where the client runs in 32 bit mode. So when building your dll for either server or client, You need specifically target the right cpu architecture. If You are deploying to both client and server You need to build using the “AnyCPU” option.

Using the AnyCPU option will cause a warning when compilling – just ignore it…

If You need to test your component on both server and client an easy way could be to:

  1. create a class with a new method and instantiate your dll in that method.
  2. Set the class to run on client
  3. Create a job and run the method.
  4. Switch the class properties to run on server and perform the same test again.
  5. If no errors occur You are good to go…