peposearchIRKit

peposearchIRKitとはrasberry_piで学習型赤外線リモコンIRKitのIPアドレスを見つける為のスクリプトです。

o 2014.9.14 ファーストリリース

o 2014.11.20 Lockfile処理追加

o 2015.1.15 日本語環境で発生するバグ修正

  1. #!/bin/sh
  2. # licence GPLv3 ; this scripts designed by Isamu.Yamauchi 2014.9.14 update 2015.1.5
  3. # peposearchIRKit is a tool to find the IRKit in rasberry_pi
  4. WORKFILE=/www/remote-hand/tmp/irkit_out_document
  5. prog=peposearchIRKit
  6. pidfile=/var/run/$prog.pid
  7. error(){
  8. [ -e $pidfile ] && rm -f $pidfile
  9. exit 0
  10. }
  11. trap error SIGTERM SIGHUP SIGKILL SIGINT
  12. while [ -e ${pidfile} ]
  13. do
  14. msleep 1000
  15. kill -HUP `cat ${pidfile}`
  16. done
  17. echo -en $$ > ${pidfile}
  18. LAN=`/sbin/ip addr |awk '/192.168./{gsub("addr:","");split($2,I,".");printf("%s.%s.%s",I[1],I[2],I[3])}'`
  19. if [ -z $LAN ];then
  20. echo -n 0
  21. exit
  22. else
  23. CT=2
  24. while [ $CT -lt 255 ]
  25. do
  26. # echo ${LAN}.${CT}
  27. wget http://${LAN}.${CT}/messages --save-headers --output-document=${WORKFILE} --tries=1 --connect-timeout=0.2 >/dev/null 2>&1
  28. if [ `cat ${WORKFILE} | grep "IRKit"| wc -c` != 0 ];then
  29. break
  30. fi
  31. CT="$(($CT + 1))"
  32. done
  33. fi
  34. if [ $CT != 255 ];then
  35. echo -n $LAN.${CT}
  36. else
  37. echo -n 0
  38. fi
  39. [ -e ${pidfile} ] && rm ${pidfile}