Raspberry Pi 備忘録 / Mbedもあるよ!

Raspberry Pi であれこれやった事の記録

USB GPSデバイス GLOBALSAT BU-353S4 を試す

USB GPSバイス GLOBALSAT BU-353S4 を試します。

ソフトの準備

cu

$ sudo apt-get install cu

差し込んで、デバイスが認識されていることを確認

 $ lsusb | grep Prolific 
Bus 001 Device 006: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
$ ls /dev/ttyUSB*
/dev/ttyUSB0

conf ファイルを設定した。

# cat /etc/default/gpsd 
START_DAEMON="true"
USBAUTO="true"
DEVICES="/dev/ttyUSB0"
GPSD_OPTIONS="-F /var/run/gpsd.sock -b -n"

動作確認

# gpsmon
# xgps

オプション確認

GPSD
usage: gpsd [-b] [-n] [-N] [-D n] [-F sockfile] [-G] [-P pidfile] [-S port] [-h] device...
  Options include: 
  -b                        = bluetooth-safe: open data sources read-only
  -n                        = don't wait for client connects to poll GPS
  -N                        = don't go into background
  -F sockfile               = specify control socket location
  -G                        = make gpsd listen on INADDR_ANY
  -P pidfile                = set file to record process ID 
  -D integer (default 0)    = set debug level 
  -S integer (default 2947) = set port for daemon 
  -h                        = help message 
  -V                        = emit version and exit.
A device may be a local serial device for GPS input, or a URL in one 
of the following forms:
     tcp://host[:port]
     udp://host[:port]
     {dgpsip|ntrip}://[user:passwd@]host[:port][/stream]
     gpsd://host[:port][/device][?protocol]
in which case it specifies an input source for device, DGPS or ntrip data.

The following driver types are compiled into this gpsd instance:
                                NMEA0183
                                Ashtech
                                Delorme TripMate
                                Pre-2003 Delorme EarthMate
                                Furuno Electric GH-79L4
n                               Garmin NMEA
                c               MTK-3301
                                OceanServer OS5000
                                San Jose Navigation FV18
        b                       True North
                c               Jackson Labs Fury
                        *       AIVDM
n       b       c       *       EverMore
n                       *       Garmin Serial binary
                        *       Garmin USB binary
n       b               *       GeoStar
                        *       iTalk
                        *       Motorola Oncore
        b               *       Navcom
n       b               *       SiRF
n       b               *       SuperStarII
n       b               *       Trimble TSIP
n       b       c       *       u-blox
        b               *       Zodiac
                        *       NMEA2000
                        *       RTCM104V2
                        *       RTCM104V3
                        *       Garmin Simple Text
                        *       JSON slave driver
# n: mode switch, b: speed switch, c: rate switch, *: non-NMEA packet type.
# Socket export enabled.
# Shared memory export enabled.
# DBUS export enabled
# Time service features enabled.
# PPS enabled.

Python コーディング

gps を使うので、 インストールしておく。

$ sudo pip install gps

最初から入ってたかも?

こちらを参考にする。

Setting Everything Up | Adafruit Ultimate GPS on the Raspberry Pi | Adafruit Learning System

import gps

# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:
    try:
        report = session.next()
                # Wait for a 'TPV' report and display the current time
                # To see all report data, uncomment the line below
        print report
        if report['class'] == 'TPV':
            if hasattr(report, 'time'):
                print "time:" + report.time
            if hasattr(report, 'speed'):
                print "speed:" + str(report.speed * gps.MPS_TO_KPH)
            if hasattr(report, 'lat'):
                print "lat:" + str(report.lat)
            if hasattr(report, 'lon'):
                print "lon:" + str(report.lon)
            if hasattr(report, 'alt'):
                print "alt:" + str(report.alt)
    except KeyError:
                pass
    except KeyboardInterrupt:
                quit()
    except StopIteration:
                session = None
                print "GPSD has terminated"

print report の箇所で、どんなデータが帰ってきているのか分かる。

こんな感じだ。(一部伏せました)

<dictwrapper: {u'epx': ***, u'epy': ***, u'epv': ***, u'ept': 0.005, u'lon': ***, u'eps': 63.47, u'epc': 187.7, u'lat': ***, u'tag': u'MID2', u'track': ***, u'mode': 3, u'time': u'2016-07-21T06:47:37.000Z', u'device': u'/dev/ttyUSB0', u'climb': -0.009, u'alt': 48.894, u'speed': 0.353, u'class': u'TPV'}>

ロギングの方針が決まっていませんが、とりあえず、緯度・経度・高度1セット出力したら修了するように改変する。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from datetime import datetime
import gps

# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

lat     = ''
lon     = ''
alt     = ''
tmie     = ''

while True:
        try:
                report = session.next()
                # print report # To see all report data, uncomment the line below
                if report['class'] == 'TPV':
                        if hasattr(report, 'lat'):
                                lat= str(report.lat)
                        if hasattr(report, 'lon'):
                                lon= str(report.lon)
                        if hasattr(report, 'alt'):
                                alt= str(report.alt)
                        if hasattr(report, 'time'):
                                alt= str(report.time)

                        if( lat!='' and lon!='' and alt!='' ):
                                print time
                                print "lat:" + lat
                                print "lon:" + lon
                                print "alt:" + alt
                                quit()
        except KeyError:
                pass
        except KeyboardInterrupt:
                quit()
        except StopIteration:
                session = None
                print "GPSD has terminated"

GPSログのフォーマットについて

どうやら、KML形式 と GPX形式 が、有名らしい。

gpxlogger という、そのまんまが有るので、利用する。

gpxlogger [-D debug-level] [-d] [-e export-method] [-f filename] [-l] [-m minmove] [-h] [-V]
                 [-i track timeout] [server [:port [:device]]]

   gpxlogger
       This program collects fixes from gpsd and logs them to standard output in GPX, an XML profile for track
       logging.

       The output may be composed of multiple tracks. A new track is created if there's no fix for an interval
       specified by the -i and defaulting to 5 seconds.

       The -d option tells gpxlogger to run as a daemon in background. It requires the -f option, which directs
       output to a specified logfile.

       The -m option sets a minimum move distance in meters (it may include a fractional decimal part). Motions
       shorter than this will not be logged.

       gpxlogger can use any of the export methods that gpsd supports. For a list of these methods, use the -l.
       To force the method, give the -e one of the colon-terminated method names from the -l table.

       If D-Bus support is available on the host, GPSD is configured to use it, and -e dbus is specified, this
       program listens to DBUS broadcasts from gpsd via org.gpsd.fix.

       With -e sockets, or if sockets is the method defaulted to, you may give a server-port-device
       specification as arguments.

どうやら、定期的にログを出すのではなく、設定した移動距離を超えたらログを出す仕様のようだ。

なるべく頻繁にロギングして欲しいので、、、

$ gpxlogger -d -i 30 -m 1 -f /usbmem/gps/`date +%Y%m%d%H%M%S`.gpx /dev/ttyUSB0

作成したファイルは、グーグルマイマップでインポート出来ます。

やってみたところ、起動直後のデータが 100m 程度ぶれており、あっちこっちにプロットされました。

NTP

Raspberry pi は、電池やバッテリが無く、OSが立ち上がっていない状態では時刻情報を更新しない。

そのため、起動すると、前回の時刻の続きに成る。

それでは困るので、GPSデータの時刻情報を元に、NTPで同期させる。

/etc/ntpd_conf

server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 refid GPS stratum 15

確認

$ ntpq -p
動作確認

数時間電源を落とした後に起動すると、同期してくれない。

man ntpd 抜粋

-g Normally, ntpd exits with a message to the system log if the offset exceeds the panic threshold,
which is 1000 s by default. This option allows the time to be set to any value without restric‐
tion; however, this can happen only once. If the threshold is exceeded after that, ntpd will exit
with a message to the system log. This option can be used with the -q and -x options.

1000秒以上のずれがあると、同期してくれない。

対応策としては、

$ sudo service ntp stop
$ sudo ntpd -qg
$ sudo service ntp start

となる。

が、足した所、1,2分待っても何も起こらなかった。

GPSDから読み取った値に対して、 date -s する方向で。

車載装置を作る その3

pongsuke.hatenablog.com

の続き。

ファイルサイズについて考える。

録画しっぱなしでいいのかを考える。

ロングドライブであれば、4時間つきっぱなしが想定される。

その際、4時間で1ファイルが良いのか、分割されているべきなのかを考え、分割しておくことにした。

とりあえず、定時( */10 = 毎 0,10,20,30,40,50分)に 5 秒止めて、録画を再度開始する。

動作の流れ

録画開始のタイミングが2つ有る。

  1. 電源ONのタイミング

  2. 定時 録画リスタート

実装

どっちも、crontab でやっちゃう。

起動

@reboot と、 */10 分 リスタート

動作テスト

0分で終了し、再起動する。

$ crontab -l
@reboot ./at_start.sh
*/10  *  *  *  * ./restart.sh
5-59/10  *  *  *  * ./convert.sh

各種スクリプト

AquesTalkPi は -g で音量を設定できる。

0-100 の範囲ということなのだが、100以上を設定すると、更に音が大きくなるので、使ってます。

録画開始スクリプト
$ cat record.sh 
#!/bin/bash

rec_milisec=`expr 60 \* 60 \* 1000 - 3000`
filename=`date +%Y%m%d%H%M`


function finish_recording(){
        /usr/local/etc/aquestalkpi/AquesTalkPi -g 200 -s 150 "録画が終了しました" | aplay -D plughw:0,0
}

trap 'finish_recording; exit 1' 1 2 3 15

/usr/local/etc/aquestalkpi/AquesTalkPi -g 200 -s 150 "録画を開始します" | aplay -D plughw:0,0

# 終了は、このプロセスを止める
/usr/bin/raspivid -w 640 -h 480 -fps 30 -t $rec_milisec -o ./video/$filename.h264 -a 4 -a "%Y-%m-%d %X" -p '460,220,320,240' -op 100 &

wait
finish_recording
起動スクリプト
$ cat at_start.sh 
#!/bin/bash

# ストレージ使用量を伝える
str1="ストレージ/使用量は"
str2=`df /usbmem/ | tail -1 | tr -s ' ' , | cut --delimiter , -f 5`
str3="です"

/usr/local/etc/aquestalkpi/AquesTalkPi -g 200 -s 150 $str1$str2$str3 | aplay -D plughw:0,0
sleep 1s

# 録画を開始する
./record.sh
コンバートスクリプト
$ cat convert.sh 
#!/bin/bash

/usr/local/etc/aquestalkpi/AquesTalkPi -g 200 -s 150 "変換を開始します" | aplay -D plughw:0,0
/usr/bin/find /usbmem/video/ -name "*.h264" -type f | xargs -I {} sh -c 'echo /usr/bin/MP4Box -fps 30 -add {} {} ; echo "/bin/rm {} "' | sed -e "s/h264$/mp4/" | sh
テスト結果

10秒は不要なので、5秒に修正した。

車載装置を作る その2

pongsuke.hatenablog.com

の続き。

動作環境を整えます。

タッチスクリーンで大苦戦!

まず、amazonで購入した LCD タッチパネルを模索したのですが、断念しました。

試したこと

  1. Noobs + LCD-show

カーネルパニック起こしました。

  1. raspbian-jessie + LCD-show-160520

ディスプレイは正常の動くのですが、アナログサウンドデバイス /dev/snd が消えた。

  1. 配布ドライバ

テックシェアストア(TechShareStore)

やはり、 /dev/snd が消えている。

表示もカクカクするし、、、。

そこで、せっかくなので、公式タッチスクリーンを使用する。

公式カメラモジュールも使用するので、消費電力が心配ではある。

NOOBS をインストールする

  1. SDカードのフォマット

  2. ファイルをコピー、起動、インストール

  3. 画面反転を修正

learn.pimoroni.com

/boot/config.txt に1行追加。

lcd_rotate=2

  1. ファームウェアをアップデート rpi-update

  2. IP固定 /etc/dhcpcd.conf

interface eth0
static ip_address=192.168.100.92/24
static routers=192.168.100.1
static domain_name_servers=192.168.100.1
# ./LCD-hdmi
  1. 日本語環境の整備

raspi-config から、ロケールなどを設定し、フォントを入れる

# apt-get install -y fonts-takao ibus-mozc jfbterm

カメラ

モジュールのテスト

先に、feh 入れておく。 sudo apt-get install feh

また、failed to open vchiq instance 出るので、 # gpasswd -a _user_name_video

しておく。

# sudo raspistill -o test.jpg
# feh test.jpg

続いて動画。

# sudo raspivid -w 640 -h 480 -fps 30 -t 10000 -o test.h264 -d

-t 0 で、録画しっぱなし

-a でアノテーション -d でテストモード(ディスプレイしながら)

#!/bin/sh
/usr/bin/raspivid -w 640 -h 480 -fps 30 -t 0 -o ./video/`date +%Y%m%d%H%M`.h264 -a 4 -a "%Y-%m-%d %X" -d

など。

-d の位置を前にしたら、正常に録画できなくなったりした。

MP4にしてみる
$ sudo apt-get install -y gpac

$ rm video/test.mp4; MP4Box -fps 30 -add video/test.h264 video/test.mp4
$ omxplayer video/test.mp4 

音楽再生環境

まずは動作テスト。
# amixer cset numid=3 1
# aplay -D hw:0,0 /usr/share/sounds/alsa/Front_Center.wav
aquestalkpi インストール & テスト
# tar zxvf aquestalkpi-20130827.tgz
# mv aquestalkpi /usr/local/etc/

$ /usr/local/etc/aquestalkpi/AquesTalkPi -g 20 こんにちは | aplay -D plughw:0,0

USBメモリを使用する

/var/log/messages から、デバイスを確認して、

 tail /var/log/messages 
Jul 19 14:42:22 raspberrypi kernel: [ 1218.356963] scsi 1:0:0:0: Direct-Access     SanDisk  Cruzer Fit       1.27 PQ: 0 ANSI: 6
Jul 19 14:42:22 raspberrypi kernel: [ 1218.358576] sd 1:0:0:0: Attached scsi generic sg0 type 0
Jul 19 14:42:22 raspberrypi kernel: [ 1218.359563] sd 1:0:0:0: [sda] 122107136 512-byte logical blocks: (62.5 GB/58.2 GiB)
Jul 19 14:42:22 raspberrypi kernel: [ 1218.361227] sd 1:0:0:0: [sda] Write Protect is off
Jul 19 14:42:22 raspberrypi kernel: [ 1218.361888] sd 1:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Jul 19 14:42:22 raspberrypi kernel: [ 1218.382595]  sda: sda1

exfat を使えるようにして、マウントする。

# apt-get install exfat-fuse
# mkdir /usbmem
# mount /dev/sda1 /usbmem/
FUSE exfat 1.1.0
# ls /usbmem/
起動時に、自動マウント
# cat /etc/fstab 
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p6  /boot           vfat    defaults          0       2
/dev/mmcblk0p7  /               ext4    defaults,noatime  0       1
/dev/sda1       /usbmem         exfat   defaults          0       0
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

車載装置を作る その1

現在自動車に、トヨタの純正カーナビが付いているが、ドライブレコーダーは付いていない。

そこで、ドライブレコーダーと自作する。

せっかくなので、GPSロギングも行い、走行ルートを自動的に記録させる。

ハードウェアの選定

RPI

RPI3は、2.5A求められるので、回避して、2ModelBにする。

カメラ

  1. USB接続のWEBカメラ
  2. カメラモジュール

せっかくなので、購入済みのカメラモジュールを使いたい。

RASPBERRY PI CAMERA MODULE V2.1

Raspberry Pi Camera v2.1 with mount - Pimoroni

消費電力を計算していないので、不足するかも?!

モニタ

  1. HDMIのポータブルディスプレイ

  2. LCDタッチパネル

  3. 公式タッチスクリーン

その2で結論になるが、公式タッチスクリーンを採用した。

GPSバイ

  1. USB GPS
  2. GPSモジュール

USB GPS なら、

GLOBALSAT BU-353S4 SiRFstarIV搭載 GPSレシーバUSB 東京通商正規販売

https://www.amazon.co.jp/gp/product/B00HZCQYLU/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1

モジュールなら、

Ultimate GPS Breakout + GPSアンテナ などが候補に上がる。

消費電力が読めないけど、動作までが早そうな、USBタイプにしてみる。

ストレージ

動画の記録デバイス。相当な量になると思われる。

たまに、抜き差しして、Windowsマシンで眺めることを想定する。

  1. USB フラッシュメモリ
  2. USB HDD

消費電力が小さいほうがいいと思う。

とりあえず、USBフラッシュメモリ 64 BG でテストする。

SanDisk Cruzer Fit USBフラッシュメモリー 64GB (5年間保証)[国内正規品] SDCZ33-064G-J57

https://www.amazon.co.jp/gp/product/B00IUF56T2/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1

金魚に餌をあげる装置を作る(成功)

pongsuke.hatenablog.com

から。

軌道修正

USBモデムを使えるまで頑張るのが面倒になったのと、そもそも、USBモデムでインターネットに接続できた際に、外部から接続できるように設定可能なのかも、不明なので、軌道修正する。

  1. 動画ストリーミングは、FFmpeg & FFserver(別の固定IPを持っているサーバーを使用) にする
  2. 操作コマンドは、サーバーにSSHトンネルを張りっぱなしにして、実現する

SSHポートフォワーディング

今回は、root での ssh は、さすがに避けて、一般ユーザーでの ssh ポートフォワーディングをします。

RPIマシンから、接続する。

-L -R で、逆向きなので注意する。

サーバーにログインして、トンネルを作る。

ssh -f -N -R 10022:localhost:22 _USER_@_SERVER_IP_

サーバー側で、トンネルを試す

/usr/bin/ssh _USER_@localhost -p 10022 

ログインできる。はず。

公開鍵認証にしておく

鍵を作って、その鍵情報を、ログイン先の .ssh/authorized_keys に足す。

$ ssh-keygen

$ cat .ssh/id_rsa.pub
(中身を、ログイン先の .ssh/authorized_keys に追記する)

常時SSHトンネル@クライアント側(RPI)

SSHトンネル、SSHポートフォワーディング

「常時」は、autossh -N を活用する。

autossh -f -N -R 10022:localhost:22 _USER_@_SERVER_IP_

autossh の自動起動は、

ユーザー の crontab で、@reboot を使用する。

自動でログインできるように、公開鍵認証にしておく。

これで、お互いに公開鍵認証になった。

※補足

環境によっては? sshトンネル越しにログインし、そのまま(ログインしたまま) OS を reboot かけたりすると、SSHが正常に切断されず?、OS立ち上がり後にログインできなくなります。

回避策として

#!/bin/sh

sleep 5s
killall autossh
sleep 3s
sudo reboot

を実行して速やかに切断(ログアウト)してます。

ssh でコマンドを投げるテスト

# /usr/bin/sudo -u _user_ /usr/bin/ssh _user_@localhost -p 10022 "ls"

などをテストする。

最終的には、RIP側でも、user から sudo で GIPO の操作を行う。

sudoの環境整備@サーバー側

まず、流れは、

(ざっくり)
スマホのブラウザ > WEBサーバー > RPI


(細かく)
スマホのブラウザ > WEBサーバー:wwwrun > sudo -u _user_ ssh ===ssh接続(ポートフォワーディング)=== _user_@RPI > sudo GPIO操作

WEBサーバーから、RPIにコマンドを投げるに辺り、sudoを使用するので、WEBサーバーから sudo できるように、sudo の使用環境を整える。

WEBサーバーが立っている opensuse の apache2 は、ユーザー wwwrun に成っていた(デフォルトのまま)。

なので、wwwrun から、```sudo できるようにする。

visudo

visudo で、使用するプログラムに許可を与える。実行するスクリプトではない。

wwwrun ALL=(_USERNAME_) NOPASSWD: /usr/bin/ssh

sudoの環境整備@RPI側

GPIOを触るので、 user で、sudo できるようにしておく。

スクリプトにしておく

手順が多く、頭がこんがらがるので、触るファイルを少なくするため、スクリプトにしておく。

サーバー側

> cat kingyo.sh 
#!/usr/bin/sh

if [ "$1" = "TEMPERATURE" ]; then
        /usr/bin/sudo -u _user_ /usr/bin/ssh _user_@localhost -p 10022 "/usr/bin/sudo /root/temperature.sh"
elif [ "$1" = "AC_LED" -a "$2" = "ON" ]; then
        /usr/bin/sudo -u _user_ /usr/bin/ssh _user_@localhost -p 10022 "/usr/bin/sudo /root/ac_led__on.sh"
elif [ "$1" = "AC_LED" -a "$2" = "OFF" ]; then
        /usr/bin/sudo -u _user_ /usr/bin/ssh _user_@localhost -p 10022 "/usr/bin/sudo /root/ac_led__off.sh"
elif [ "$1" = "FEED" ]; then
        /usr/bin/sudo -u _user_ /usr/bin/ssh _user_@localhost -p 10022 "/usr/bin/sudo /root/feeding.py"
fi

RPI側

# cat ac_led__on.sh 

#!/bin/sh
/usr/bin/irsend SEND_ONCE ac_led on


root@raspberrypi:~# cat ac_led__off.sh 

#!/bin/sh
/usr/bin/irsend SEND_ONCE ac_led off

# cat temperature.sh 

#!/bin/sh
/bin/cat /sys/bus/w1/devices/w1_bus_master1/28-00000724377c/w1_slave | grep t= | /usr/bin/tr -s ' ' , | /usr/bin/cut --delimiter , -f 10 | sed -e "s/t=\(..\)\(...\)/\1.\2/"


# cat feeding.py 

#!/usr/bin/python
# coding: utf-8 

import RPi.GPIO as GPIO
import time
import signal
import sys 

def exit_handler(signal, frame):
        # Ctrl+Cが押されたときにデバイスを初期状態に戻して終了する。
        print("\nExit")
        servo.ChangeDutyCycle(2.5)
        time.sleep(0.5)
        servo.stop()
        GPIO.cleanup()
        sys.exit(0)

# 終了処理用のシグナルハンドラを準備
signal.signal(signal.SIGINT, exit_handler)

GPIO.setmode(GPIO.BCM)

# GPIO 21番を使用
gp_out = 21

GPIO.setup(gp_out, GPIO.OUT)
# pwm = GPIO.PWM([チャンネル], [周波数(Hz)])
servo = GPIO.PWM(gp_out, 50) 


# 初期化
servo.start(0.0)

val = [2.5, 3.6875, 4.875, 6.0625, 7.25, 8.4375, 9.625, 10.8125, 12]

# 初期位置
servo.ChangeDutyCycle(val[0])
time.sleep(1.0)

# 餌を落とす
servo.ChangeDutyCycle(val[8])
time.sleep(1.0)

# 初期位置
servo.ChangeDutyCycle(val[0])
time.sleep(0.5)

# 終了
servo.stop()
GPIO.cleanup()

sys.exit(0)

固定IPをDHCPに直してテストする

/etc/dhcpcd.conf の、固定IPに設定した部分をコメントアウトする。

リブートして、動作確認する。

ffmpeg による動画 feeding が、reboot した際に上手く動いていない。

DHCPに変えたからなのか、エラーログを確認できず、確証は無いが、DHCPで、IPが確定する前に、コマンドが実行されてしまっているのではないかと考える。

そこで、しかたがないので、ffmpeg を起動する前に、 sleep 10s して、10秒またせて対処しました。

仕上げ

  1. FFserver の ACLの変更

  2. FFserver の Feed URL などを、推定されずらいようにハッシュ文字列を使用する。

赤外線受信モジュール PL-IRM0101-3 動作テスト

赤外線受信モジュール PL-IRM0101-3 の動作テスト

目的:既存の赤外線デバイスの信号を解析/記録する。

lirc をインストール

# apt-get install lirc

/boot/config.txt に追記。

dtoverlay=lirc-rpi, gpio_in_pin=23, gpio_out_pin=24

再起動して確認する。

# ls /dev/lirc*
/dev/lirc0

# lsmod | grep lirc
lirc_rpi                6478  0 
lirc_dev                8310  1 lirc_rpi
rc_core                16468  1 lirc_dev

# /etc/init.d/lirc stop
[ ok ] Stopping lirc (via systemctl): lirc.service.

受信させてみる

コマンド実行後に、センサーにリモコンを当てる。

# mode2 -d /dev/lirc0 
space 6065810
pulse 2537
space 2711
pulse 832
space 856
pulse 834
space 856
pulse 834
space 1897
pulse 833
space 1896
pulse 835
space 1896
pulse 833
space 1897
pulse 834
space 858
pulse 832
space 857
pulse 834
space 54197
pulse 2567
space 2687
pulse 836
space 853
pulse 834
space 860
pulse 831
space 1896
pulse 835
space 1896
pulse 833
space 1906
pulse 827
space 1899
pulse 831
space 853
pulse 835
space 855
pulse 833
space 54074
pulse 2562

xmode2 で、波形をプロットさせる、、、はずが、エラーを吐く。

could't load font

フォントに絡んだバグ?らしく、パッチも出ているが、ソースコードからコンパイルし直す気にはなれない。

portage/lirc-0.9.0-fixed-font.patch at master · portage/portage · GitHub

ちなみに、エラーコードも、修正対象になってる・・・。 couldn't !!

データの保存とスクリプトファイルへの登録

confファイルの作成

# irsend  LIST ac_led.conf ''

(ボタンを1秒押して、離してを繰り返したり、連打したり?)
Successfully written config file.
# cat ac.conf > /etc/lirc/lircd.conf

ちなみに、

  toggle_bit_mask 0x0

      begin codes
          on                       0x3C
          off                      0x4B
      end codes

でした。

修正

name ac_ledなど。

確認

# irsend LIST "" ""
irsend: ac_led

# irsend LIST ac_led ""
irsend: 000000000000003c on
irsend: 000000000000004b offf

動作チェック

# for i in {0..100}; do irsend SEND_ONCE ac_led on; echo $i; done;

実機でテスト

わたし場合、ON / OFF できなかったのですが、

irsend をやり直した所、正常に動きました。

自動起動のためのメモ

# update-rc.d lirc defaults で、ON
# update-rc.d lirc remove で、OFF

もしくは

# systemctl enable lirc
# systemctl disable lirc

ではないかと予測して、メモをしておく。

ffserver メモ

FFServer を、別のマシンで建てるまでのメモ

Opensuse にて。

フォーマットは、 x264 がオススメらしい。

Yast から GIT, yasm, 入れる。

# git clone git://git.videolan.org/x264
# cd x264/
# ./configure -–disable-opencl --enable-static
# make 
# make instal
# git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
# cd ffmpeg
# ./configure --enable-libx264 --enable-gpl
# make
# make install

# cp doc/ffserver.conf /etc/

/etc/ffserver.conf の編集

ACL allow 192.168.100.1 192.168.100.255

など。

FFMpegで動画を投げる

ffmpeg http://localhost:8090/feed1.ffm