HOW-TO:Create a resume script

This guide assumes that you have installed XBMC Live or have at least performed all steps outlined in one of the articles listed here Installing XBMC for Linux and here HOW-TO setup Lirc to talk to XBMC. This guide assumes that your remote works well upon startup. If it does not, then do not proceed with this article.

You will also need a SFTP client and a terminal emulator like WinSCP and Putty.

To enable resume from your remote see the following article Enable Wake-On-Device

You will need root access for the following commands.

Setting up the basics
This section discusses installation and use of curl

Installing curl
apt-get install curl
 * Log into a terminal as root
 * Execute the following command to get a program which will allow you to turn on and off XBMC's remote monitoring function

Using Curl
The following command will disable XBMC's ability to turn your remote's commands into usable input. curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Stop" The following command will enable XBMC's ability to turn your remote's commands into usable input. curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Start" The following command will stop and then restart XBMC's ability to turn your remote's commands into usable input. curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.restart"
 * Ensure XBMC's event server is enabled. XBMC-Settings-Network-Event Server-Enable event server

Designing your resume script
This section discusses creating a basic lirc resume script. You will now go through each one of the sections and design your custom restart script. It is recommended that you create a wiki article like this one, Snapstream Firefly when you are finished. When you add to the wiki, it is documented so people who are not as good with scripting may follow behind your work.

Create your basic script outline
case "$1" in 	resume) 		curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Stop" 		/etc/init.d/lirc restart  		curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Start"  		echo "lirc resume script completed!!!" >>/tmp/script.log 	;; esac This is the basic resume script outline. The two blank lines under curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Stop" will be for restarting your drivers.
 * Open a notepad so that you can keep notes for your resume script
 * Copy the following into your notepad
 * 1) !/bin/sh
 * 1) This script uses curl. Install curl using the following command from your terminal apt-get install curl
 * 2) This script will restart (ADD YOUR DEVICE NAME HERE WHEN FINISHED), Lirc, and XBMC upon resume.

checking remote output
curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Stop" /etc/init.d/lirc restart curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Start irw If your remote works, then skip to the creating a resume file section.
 * put the computer in standby
 * resume from standby
 * From your terminal copy and paste the following to verify if your remote is working.
 * Press a few buttons on your remote
 * press ctrl + C to exit irw

Finding the offending device
This section will cover locating the driver and restarting. The computer should be in a resumed state after completion of standby.

Ensuring physical device connectivity after standby
lsusb EG. (T: XBMCLive)root@XBMCLive:~# lsusb Bus 001 Device 003: ID 0bda:0151 Realtek Semiconductor Corp. Mass Stroage Device Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 002: ID 0bc7:0008 X10 Wireless Technology, Inc. Wireless Transceiver (ACPI-compliant) Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub (T: XBMCLive)root@XBMCLive:~# 08 X10 Wireless Technology, Inc. Wireless Transceiver (ACPI-compliant) is the remote device. You can verify this by unplugging the device and running lsusb again /etc/init.d/udev restart
 * From your terminal type the following to verify your system is recognizing your remote's receiver
 * Search for your remote's physical device
 * If you cannot find your device, add the following to your notepad under the xbmc.stop command
 * If you unplugged your remote receiver, you will need to put the computer back into suspend mode and resume again to recreate the fault condition

Locating and restarting drivers
sudo modprobe -l |grep lirc
 * List all lirc devices
 * Search for the driver which controls the physical device

EG. (T: XBMCLive)root@XBMCLive:~# sudo modprobe -l |grep lirc kernel/ubuntu/lirc/lirc_dev/lirc_dev.ko kernel/ubuntu/lirc/lirc_atiusb/lirc_atiusb.ko kernel/ubuntu/lirc/lirc_bt829/lirc_bt829.ko kernel/ubuntu/lirc/lirc_cmdir/lirc_cmdir.ko kernel/ubuntu/lirc/lirc_cmdir/commandir.ko kernel/ubuntu/lirc/lirc_i2c/lirc_i2c.ko kernel/ubuntu/lirc/lirc_igorplugusb/lirc_igorplugusb.ko kernel/ubuntu/lirc/lirc_imon/lirc_imon.ko kernel/ubuntu/lirc/lirc_it87/lirc_it87.ko kernel/ubuntu/lirc/lirc_mceusb/lirc_mceusb.ko kernel/ubuntu/lirc/lirc_mceusb2/lirc_mceusb2.ko kernel/ubuntu/lirc/lirc_pvr150/lirc_pvr150.ko kernel/ubuntu/lirc/lirc_sasem/lirc_sasem.ko kernel/ubuntu/lirc/lirc_serial/lirc_serial.ko kernel/ubuntu/lirc/lirc_serial_igor/lirc_serial_igor.ko kernel/ubuntu/lirc/lirc_sir/lirc_sir.ko kernel/ubuntu/lirc/lirc_streamzap/lirc_streamzap.ko kernel/ubuntu/lirc/lirc_ttusbir/lirc_ttusbir.ko kernel/ubuntu/lirc/lirc_gpio/lirc_gpio.ko in this case lirc_atiusb happens to be the driver

curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Stop" rmmod lirc_atiusb modprobe lirc_atiusb /etc/init.d/lirc restart irw
 * remove the binding of lirc to xbmc
 * systematically restart drivers until your remote works in irw
 * press buttons on the remote to verify proper operation
 * stop irw with ctrl + C and try the next driver in the grep lirc list

eg. (T: XBMCLive)root@XBMCLive:~# curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=LIRC.Stop" html li OK /html (T: XBMCLive)root@XBMCLive:~# rmmod lirc_atiusb (T: XBMCLive)root@XBMCLive:~# modprobe lirc_atiusb (T: XBMCLive)root@XBMCLive:~# /etc/init.d/lirc restart * Stopping remote control daemon(s): LIRC                              [ OK ] * Loading LIRC modules                                                 [ OK ] * Starting remote control daemon(s) : LIRC                             [ OK ] (T: XBMCLive)root@XBMCLive:~# irw 000000146f9a0000 00 up Snapstream 000000146f9a0000 01 up Snapstream


 * Once you have determined which driver works, add that driver to your notepad
 * Change your notepad to reflect the proper driver in the notes at the top.

EG. case "$1" in  	resume)  		curl "http://127.0.0.1:8080/xbmcCmds /xbmcHttp?command=ExecBuilt&Inparameter=LIRC.Stop" 		rmmod lirc_atiusb 		modprobe lirc_atiusb 		/etc/init.d/lirc restart  		irw & sleep 1; killall irw 		curl "http://127.0.0.1:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn& parameter=LIRC.Start"  		echo "lirc resume script completed!!!" >>/tmp/script.log 	;; esac
 * 1) !/bin/sh
 * 1) This script uses curl. Install curl using the following command from your terminal apt-get install curl
 * 2) This script will restart ATIUSB, Lirc, and XBMC upon resume.

Creating a resume file
This section discusses creating your resume script after you have collected the required data.

Add your script to sleep.d
chmod +x /etc/pm/sleep.d/99lirc-resume.sh
 * Using your SFTP client, create a file called /etc/pm/sleep.d/99lirc-resume.sh
 * add the contents of your notepad into /etc/pm/sleep.d/99lirc-resume.sh
 * make it executable

You are now done.