概要
BluemixのRaspberryPi登録レシピに登場するデバイス用のsampleプログラムはデータの送信間隔が1回/秒である。
この送信間隔を変更するにはソースコード(iot.h)を修正してビルドする。
前提
RaspberryPi2がBluemixのIoTFサービスに「レシピ」を使って接続済みであること。
手順
作業はRaspberryPi2にログインして行う。
実行時ユーザは次の通り
$ : pi
# : root
設定ファイルの退避
# cd /etc/iotsample-raspberrypi/
# cp -p device.cfg device.cfg.`date +%Y%m%d`_1
※これで、アンインストール(dpkg -P)してもフォルダとバックアップファイルが残るので安心。必要パッケージのインストール
# apt-get install dpkg-dev build-essential devscripts
# apt-get install libssl-dev
ソースコード一式を入手
$ cd ~
$ git clone https://github.com/ibm-messaging/iot-raspberrypi.git
ソースコード修正(送信間隔を1秒から10秒に変更)
$ cd ~/iot-raspberrypi/samples/c/
$ vi iot.h
39行目
変更前)#define EVENTS_INTERVAL 1
変更後)#define EVENTS_INTERVAL 10ビルド
$ debuild -b
署名のエラーは無視する。アンインストール(古いのを)
# dpkg -P iot
インストール
# cd /home/pi/iot-raspberrypi/samples/
# dpkg -i ./iot_1.0-1_armhf.deb
サービスの確認
# service iot status
※起動している(okが表示される)こと。設定ファイル作成
# cd /etc/iotsample-raspberrypi/
# cp -p device.cfg.`date +%Y%m%d`_1 device.cfg
※6.でいったん削除されてしまうので、1.で退避したファイルで復元サービスの再起動
# service iot restart
※起動している(okが表示される)こと。起動モードの確認
# service iot getdeviceid
※registerd mode で起動している(registerd modeが表示される)こと。IoTFで確認
Bluemix IoTFダッシュボード→デバイス→参照→登録済みのデバイスを選択
ライブ・イベント欄にて1回/10秒の間隔でデータ受信していること。
環境
Raspberry Pi 2
Bluemix IoT Foundation
参考
https://github.com/ibm-messaging/iot-raspberrypi/blob/master/samples/c/README.md
https://developer.ibm.com/recipes/tutorials/raspberry-pi-4/