Let's make the world a better place using digital technologies!

Category: Linux

Write your own Python Plugin for Dreambox Newnigma2 and Map to a QuickButton

I have a Samsung TV that is connected to the Dreambox 800SE. The audio output of the dreambox goes to a Sony Blu Ray player. I can turn on the Sony Blu Ray player through Samsung TV remote control but not through Dreambox remote. This always requires also having the Samsung remote handy. What I wanted was to simply map a long press of a quickbutton (e.g., color buttons on the dreambox remote) to a plugin that will send Samsung remote control commands to the Samsung TV. I have written a python script that shows how you can achieve this in another post. The following diagram will explain the setup that I just described.

So actually what I want is to send remote control commands to the Samsung TV through a plugin from the Dreambox which will in turn use my python script to send them to the TV. The TV will then execute them to connect over CEC to the Sony Blu Ray player.

To write the plugin for dreambox, I have used Python. The script development has been explained nicely in this guide which I also used as guideline. The main  component of the plugin is the plugin.py file which for my case is very simple as shown below.

# My own small Plugin
# Author: Asif Iqbal
# Date: 06 APR 2012

from Plugins.Plugin import PluginDescriptor
import os

def main(session, **kwargs):
        os.system('python /etc/samsungremote.py')

def Plugins(**kwargs):
        return PluginDescriptor(
                description="Samsung TV Remote",
                where = PluginDescriptor.WHERE_PLUGINMENU,

As you can see the plugin itself is very simple. It just calls your python script. The Python script as I have explained above can be found in one of my other posts. To use the plugin, follow these steps:

  • Create a folder according to the name of your plugin (in my case ExecuteMyScript)  /usr/lib/enigma2/python/Plugins/Extensions/
  • Put the above explained plugin script plugin.py under /usr/lib/enigma2/python/Plugins/Extensions/ExecuteMyScript or the folder name that you chose.
  • You also need to place an empty file named __init__.py in this folder.
  • Make sure that the link to your own script is correct in the plugin.py file.
  • Now you need to reboot the Dreambox (or restart GUI).
  • After reboot, use the QuickButton Plugin to choose your Plugin (ExecuteMyScript, in my case) to map to the long press of a color button of your choice.
  • That’s it. You have created your own Dreambox plugin and have successfully mapped to a quick button.

A zip file containing both the plugin files (__ini__.py and the plugin.py) can be found on my download page.

Continue Reading

Samsung TV Remote Control over LAN/WLAN using Python

For quite some time, I have been looking for a method to control my Samsung UE55C8000 TV using Linux scripts. Finally, I found this forum post on SamyGo that provides an example using Perl. As I like to do scripting in Python, so I have translated the script to Python with some minor changes. As you can see in the following Python code, the script contains Key names for all the remote control keys and even some extra. You should be able to easily modify the script to your needs. The script can also be downloaded on my download page.

#!  /usr/bin/python
#   Title: samsungremote.py
#   Author: Asif Iqbal
#   Date: 05APR2012
#   Info: To send remote control commands to the Samsung tv over LAN
#   TODO:

import socket
import base64
import time, datetime

#IP Address of TV
tvip = ""
#IP Address of TV
myip = ""
#Used for the access control/validation, but not after that AFAIK
mymac = "00-0c-29-3e-b1-4f"
#What the iPhone app reports
appstring = "iphone..iapp.samsung"
#Might need changing to match your TV type
tvappstring = "iphone.UE55C8000.iapp.samsung"
#What gets reported when it asks for permission
remotename = "Python Samsung Remote" 

# Function to send keys
def sendKey(skey, dataSock, appstring):
 messagepart3 = chr(0x00) + chr(0x00) + chr(0x00) + chr(len(
base64.b64encode(skey))) + chr(0x00) + base64.b64encode(skey);
 part3 = chr(0x00) + chr(len(appstring)) + chr(0x00) \
+ appstring + chr(len(messagepart3)) + chr(0x00) + messagepart3

# Open Socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((tvip, 55000))

# Key Reference
# Normal remote keys
 #KEY_W_LINK #Media P
 #KEY_RSS #Internet
 #KEY_MTS #Dual
# Bonus buttons not on the normal remote:
#Don't work/wrong codes:

# First configure the connection
ipencoded = base64.b64encode(myip)
macencoded = base64.b64encode(mymac)
messagepart1 = chr(0x64) + chr(0x00) + chr(len(ipencoded)) \
+ chr(0x00) + ipencoded + chr(len(macencoded)) + chr(0x00) \
+ macencoded + chr(len(base64.b64encode(remotename))) + chr(0x00) \
+ base64.b64encode(remotename)

part1 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart1)) + chr(0x00) + messagepart1

messagepart2 = chr(0xc8) + chr(0x00)
part2 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart2)) + chr(0x00) + messagepart2

# Now send the keys as you like, e.g.,

# Close the socket when done


Continue Reading

Remote Desktop to a Virtual Machine on VirtualBox running on a Headless Server

I have followed the excellent directions given by Falko Timme at howtoforge. I am copying his directions here with some changes to install a Windows 7 system.

First you need to add the VirtualBox repo to the Ubuntu resources.lst:
emacs /etc/apt/sources.list
Add the following line to it:
deb http://download.virtualbox.org/virtualbox/debian oneiric contrib

Then download and install the VirtualBox public key:
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
Update our package database:
apt-get update
Afterwards, install the VirtualBox 4.1 as follows:
apt-get install linux-headers-$(uname -r) build-essential virtualbox-4.1 dkms

Now install the VirtualBox extensions.

cd /tmp
wget http://download.virtualbox.org/virtualbox/4.1.10/Oracle_VM_VirtualBox_Extension_Pack-4.1.10-76795.vbox-extpack
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.1.8-75467.vbox-extpack

Now add the user who will run VirtualBox to the vboxusers group:
adduser root vboxusers

Now get a Windows 7 iso and do the following steps to install it to a virtual machine:

VBoxManage createvm --name "Windows 7" --register
VBoxManage modifyvm "Windows 7" --memory 2048 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0
VBoxManage createhd --filename windows7.vdi --size 50000
VBoxManage storagectl "Windows 7" --name "IDE Controller" --add ide
VBoxManage storageattach "Windows 7" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /mnt/Windows/windows7.vdi
VBoxManage storageattach "Windows 7" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /mnt/Windows/Windows7Ultimate.iso
VBoxHeadless --startvm "Windows 7"

You can now connect using Remote Desktop to this virtual machine.

Continue Reading

Useful tmux Commands

tmux is a powerful console window manager. The most valuable feature of tmux is the ability to detach from a running tmux session, exit the ssh session, relogin to ssh again and resume the tmux session. This is simply beautiful. Here I list some handy tmux commands.

  • tmux
    starts the tmux.
  • ^b d
    detaches from a running tmux session.
  • tmux attach
    attaches to a running tmux session.
  • ^b ?
    lists all the key-bindings. Great help.
  • ^b %
    splits the window into two vertical panes.
  • ^b c
    creates a new window.
    switches to right/left panes.
    scrolls the buffer up/down.
  • ^b d
    detaches the current session.
  • tmux attach -d
    attaches to a tmux session, detaching the other clients.

Thank you tmux-team for developing such a useful program.

Continue Reading

Useful rsync Commands

rsync -avn /pathtofolder/'Source Folder' /pathtofolder/'Destination Folder'
dry-runs a mirror of Source Folder to the Destination Folder.

rsync -av /pathtofolder/'Source Folder' /pathtofolder/'Destination Folder'
mirrors Source Folder to the Destination Folder.

rsync -avt --progress /pathtofolder/'Source Folder' /pathtofolder/'Destination Folder'
does the same as above, in addition maintaining time-stamps and printing progress.

Continue Reading

MTS/M2TS to MKV (Especially for Sony HDR-SR12)

After spending many frustrating hours, I finally found a solution to easily re-mux m2ts/mts files produced by Sony HDR-SR12 or other similar camcoders in order to stream them smoothly over DLNA to Samsung C-Series (55C8000) TV in full HD quality. But the solution is generic and can be used for any rendered.


First the problem: Above mentioned Sony camcoder produces 1920×1080, 60i video. However, the time-stamps on the frames in each interlaced field are wrong, both frames of a filed having same time-stamp. This is very problematic for almost all rendering devices.
My first approach was to re-encode these mts files using Handbrake to convert to m4v. This worked though at a heavy computing cost. The conversion is very intensive and for 50GB of videos could easily take more than 12 hours on a core-2 processor. One day, I was browsing Ubuntu forums, I came across this thread. This actually produced the re-muxed file in a fraction of a second as opposed to re-encoding with Handbrake that took very long time.
But there are two problems in the above solution:

  • It is using mencoder + lavf, a known broken combination in presence of B-frames.
  • It does not allow to copy the subtitle track (PGS) that Sony camcoder produces. This subtitle track is very important as it contains the recording date/time
    information which will be valuable when using these videos in future.


The following solution overcomes all the above-mentioned problems, is rock-stable and preserves the sub-title stream as well. I use ffmpeg to simply copy all the streams and output them in an mkv container. No information is lost/re-encoded. Here is the simple answer (as often observed in scientific research, the useful answer to a complex problem can often be stated very simply ):
ffmpeg -i input.mt2s -scodec copy -acodec copy -vcodec copy -f matroska input.mkv

I have written a script that converts all the m2ts files in a subfolder to mkv. The script is as below:
# m2tstomkv_subs (Fix the faulty fps (dual frames in the interlaced fields with same time-stamps) and repackage in matroska mkv container)
time {
# remux m2ts movies into mkv with ffmpeg
for i in *.m2ts; do
ffmpeg -i $i -scodec copy -acodec copy -vcodec copy -f matroska `basename $i .m2ts`.mkv;
echo "Conversion done";

The conversion is lightening fast. Finally I am able to watch the videos in their true quality. I will be glad if this information helps someone facing similar issues.

Continue Reading

Horde Keeps Rejecting the Login

If you unable to login to your horde (groupware webmail edition, or other versions as well) installation and receive messages like:

Login failed because your username or password was entered incorrectly.

or in /tmp/horde.log file you have something similar to:

Oct 29 12:18:42 HORDE [error] [imp] FAILED LOGIN for iqa [100.xx.xx.xx] to {localhost:143 [imap/notls]} [pid xxxxx on line 139 of “/var/www/horde/imp/lib/Auth/imp.php”]

then before digging deeper into horde internals, it is worthwhile to check whether your imap daemon (dovecot-imapd in my case) is running because if you have configured in many installations imap is the default authentication mechanism that horde uses. It can be checked quite easily by issuing:
telnet localhost 143
And if the response is like the following:
telnet: Unable to connect to remote host: Connection refused

then you do not have an imap daemon running. And that is preventing the horde to authenticate. In this case, you could install dovecot-imapd which will serve as the imap daemon and would provide the desired authentication mechanism for horde.

Continue Reading

Access Samba share over SSH Tunnel

  1. Add the Loopback Adapter to the Windows client machine.
  2. Configure this adapter as following:
    • Disable ‘File and Printer Sharing for Microsoft Networks’.
    • Choose appripriate IP address and netmask, such as: and
    • Under ‘Advanced’ settings, check ‘Enable LMHOSTS Lookup’ and ‘Disable NetBIOS over TCP/IP’
  3. Under Putty, configure the SSH Tunnel as:
    Source port:
    Destination: localhost:139
  4. Test the connection by entering \\ at Run prompt in Windows.
Continue Reading

Samba Print Server Problem

I tried connecting to my samba print server from my xp notebook. The printer was always visible, connectable and accepted documents for printing but never led to a physical print. I could solve it by visiting:
and adding the printer to CUPS. It worked immediately!

Continue Reading

Putting Hard Disks to Sleep

In Ubuntu server, you can put any disk that is not used for a give period of time to sleep using hdparm command. Simply do something like:
hdparm -S 20 /dev/sdb
hdparm -S 20 /dev/sda

to put the disks to sleep after 100 seconds (20 x 5)

To have it programmed automatically on bootup, write the same lines into /etc/rc.local.

Continue Reading