Thursday, October 11, 2012

Controlling an A/C unit using LIRC on centos

UPDATE 22/2/15: OK apparently the reason for the mess is that lirc_serial needs to be compiled/provided/supported by the kernel and is not included in recent lirc versions. ELREPO has kmod-lirc for Centos that seems to work out of the box (manually load it after "setserial /dev/ttyS? uart none" for el7 too). So you can install lirc using yum.

I needed to turn on the AC unit in a small server room. It would go off when a power failure occurred.

I purchased a serial transceiver from Iguana works.

Since Centos' (2.6.18-274.7.1.el5) lirc package did not include the default driver and lirc_serial modules, I downloaded lirc-0.8.7 (lirc-0.9.0 would not compile).

Compilation is pretty straight forward:

./setup.sh

make


make install

During setup I chose the serial port the transceiver was on.

Next steps are:

Copy the init script from contrib and adjust it to your requirements. Do not start lirc though.

Here is my init script:



#!/bin/sh
#
# lirc:        This is an init script for RedHat distribution.
#
# Author:      Denis V. Dmitrienko 
#
# chkconfig: 345 95 10
# description: lirc is a Linux Infrared Remote Control system.

# Source function library.
. /etc/rc.d/init.d/functions

[ -f /usr/local/sbin/lircd ] || exit 0
[ -f /usr/local/sbin/lircmd ] || exit 0

PATH=/usr/local/sbin:/usr/local/bin:$PATH

LIRC_CONFIG=/etc/lirc/lircd.conf
DRIVER=default
DEVICE=/dev/lirc
PORT=/dev/ttyS1
 
# Load LIRC config
[ -f /etc/sysconfig/lirc ] && . /etc/sysconfig/lirc

# See how we were called.
case "$1" in
  start)
        echo -n "Starting Infrared Remote Control: "
        setserial $PORT uart none

        if [ "$MODULES" != "" ]; then
                IFS=" "
                for MODULE in $MODULES
                do
                        modprobe $MODULE
                done
        fi

        daemon lircd --device=$DEVICE --driver=$DRIVER $LIRCD_ARGS $LIRC_CONFIG
        daemon lircmd $LIRC_CONFIG
        echo
        touch /var/lock/subsys/lirc
        ;;
  stop)
        echo -n "Shutting down Infrared Remote Control: "
        killproc lircmd
        killproc lircd
        echo
        rm -f /var/lock/subsys/lirc
        ;;
  status)
        status lircd
        status lircmd
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: lirc {start|stop|status|restart}"
        exit 1
esac

exit 0

Create /etc/sysconfig/lirc file:

# Arguments which will be used when launching lircd
LIRCD_ARGS=""

# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"
# Check which the name when lirc_serial is loaded
DEVICE="/dev/lirc0"

# lirc_dev will be loaded automatically
MODULES="lirc_serial"
 
#the serial port of your device 
PORT="/dev/ttyS1" 
Try to start lirc now.
Make sure that lirc_serial is loaded i.e. lsmod | grep lirc should produce something similar to:

lirc_serial            16980  1
lirc_dev               17176  3 lirc_serial

 


AC remote signals are more like complete status updates than state relative commands. irrecord will not work with that. Use mode2 -m and for each remote command capture the output in a file. Lircd must be stopped in order for mode2 to work  Remove any blank lines  and the first line if it only contains one number (leave any 6 columns of numbers). Repeat the process for any other states you wish. Capturing under fluorescent light can cause errors so turn off the lights for better results. When you use mode2 lirc should not be running.

Create the /etc/lirc/lircd.conf file and add the data from the previous step inside the raw_codes section. Precede each data block with a name line as shown below.




begin remote

  name  AC
  flags RAW_CODES
  frequency    38000
  gap 107326
    begin raw_codes

      name ON_24
     9115     4427      698     1594      585     1710
      661      460      688      455      585      536
      716      429      585     1708      691     1629
      617     1675      585     1708      688     1606
      689      457      663      455      691      455
      666      455      691     1629      592     1700
      585     1708      610     1681      719      430
      689      429      689      457      666      455
      691      455      689      457      689     1603
      692      429      716     1576      717      429
      589      532      716      430      584      562
      591      530      690      456      689      429
      691      458      688      430      689     1603
      717      432      582      563      590      529
      717      429      691      430      716      430
      691      430      686      460      688      430
      719      429      689      458      663      455
      607      514      716      430      585      535
      717     1601      690      431      690      455
      689      458      665      456      660      458
      691      455      608      512      691      455
      587      534      691      456      690      455
      585      536      691      455      587      531
      692      457      589      530      690      456
      607      538      591      530      691      455
      666      455      691      455      663      456
      690     1604      716      431      605      540
      590      528      694      453      665      456
      690      455      666      455      688      458
      665      453      694      455      691     1601
      691      455      615     1677      608      513
      691      455      589      530      693      455
      605      540      610      509      691      456
      665      455      691      455      666      455
      690      456      665     1627      606     1687
      692

      name ON_25
     9034     4483      663     1629      663     1629
      663      483      587      534      663      483
      587      534      661     1631      663     1657
      663     1629      663     1629      663     1657
      636     1656      635      486      661      485
      636      482      663     1657      668     1624
      587     1708      633     1659      689      457
      635      486      661      485      635      483
      663      483      663     1632      663     1629
      688      458      587      533      687      460
      642      476      663      483      587      559
      589      532      663      483      591      530
      662      484      635      483      663     1632
      662      484      607      538      615      506
      663      484      589      529      663      483
      637      484      688      458      636      484
      663      484      662      484      663      457
      661      485      636      482      608      513
      663     1657      663      455      689      458
      665      481      663      457      664      482
      638      483      608      510      691      455
      587      535      662      483      664      482
      585      536      663      483      585      536
      689      457      587      531      664      482
      608      538      587      534      663      483
      592      529      663      483      638      480
      666     1629      688      458      608      538
      587      534      663      483      589      529
      666      480      638      483      663      482
      639      483      662      484      663     1629
      691      455      614     1678      587      534
      663      483      589      531      664      482
      608      539      639     1653      608      512
      664      483      584      534      665      483
      587      532      690     1602      691     1629
      663

      name OFF
     9144     4425      642     1652      583     1710
      688      430      693      453      663      458
      692      454      607     1685      693     1627
      591     1701      584     1708      691     1603
      692     1601      693      453      638      482
      692      455      605     1687      693     1627
      665     1627      665     1627      591      530
      693      453      665      453      694      455
      605      541      665      453      693      453
      668      452      694      452      666      456
      691      455      665      453      693      455
      692      455      665      452      692      429
      694      453      633      487      691     1627
      668      452      693      453      691      455
      666      456      688      429      694      455
      658      461      692      453      608      513
      691      455      693      453      605      516
      691      455      589      529      693      453
      593     1702      606      512      694      452
      694      455      605      513      695      451
      610      511      693      453      665      455
      692      455      605      541      638      480
      693      456      665      453      693      453
      666      455      691      455      665      455
      691      455      691      456      665      453
      691      430      693      453      661      459
      691      455      606      513      693      455
      691      455      606      513      693      452
      611      510      694      453      637      483
      691      455      633      513      589     1703
      634      487      691     1629      665      453
      661      460      691      455      633      485
      694      453      693      455      606     1686
      689     1603      694     1599      693     1601
      691      455      605      513      694     1626
      666

    end raw_codes

end remote 

The gap value can be any number similar to what I've used, it does not matter since it doesn't apply for AC remotes. If it's too big it will block irsend for a significant amount of time though.

Next step is to try and start lirc. If all goes well you should be able to try sending commands using:

irsend DIRECTIVE REMOTE_NAME CODE_NAME

for instance:

irsend SEND_ONCE AC ON_24


Post a Comment