LoginSignup
2
2

More than 5 years have passed since last update.

RaspberryPi2からBluemix IoTFサービスへのデータ送信間隔を変更する方法

Last updated at Posted at 2015-08-31

概要

BluemixのRaspberryPi登録レシピに登場するデバイス用のsampleプログラムはデータの送信間隔が1回/秒である。
この送信間隔を変更するにはソースコード(iot.h)を修正してビルドする。

基本はこれ↓
https://github.com/ibm-messaging/iot-raspberrypi/tree/master/samples/c#note-for-users-who-want-to-change-the-code-compile-and-build-the-deb-file

前提

RaspberryPi2がBluemixのIoTFサービスに「レシピ」を使って接続済みであること。

手順

作業はRaspberryPi2にログインして行う。
実行時ユーザは次の通り
$ : pi
# : root

  1. 設定ファイルの退避
    # cd /etc/iotsample-raspberrypi/
    # cp -p device.cfg device.cfg.`date +%Y%m%d`_1
    ※これで、アンインストール(dpkg -P)してもフォルダとバックアップファイルが残るので安心。

  2. 必要パッケージのインストール
    # apt-get install dpkg-dev build-essential devscripts
    # apt-get install libssl-dev

  3. ソースコード一式を入手
    $ cd ~
    $ git clone https://github.com/ibm-messaging/iot-raspberrypi.git

  4. ソースコード修正(送信間隔を1秒から10秒に変更)
    $ cd ~/iot-raspberrypi/samples/c/
    $ vi iot.h
    39行目
    変更前)#define EVENTS_INTERVAL 1
    変更後)#define EVENTS_INTERVAL 10

  5. ビルド
    $ debuild -b
    署名のエラーは無視する。

  6. アンインストール(古いのを)
    # dpkg -P iot

  7. インストール
    # cd /home/pi/iot-raspberrypi/samples/
    # dpkg -i ./iot_1.0-1_armhf.deb

  8. サービスの確認
    # service iot status
    ※起動している(okが表示される)こと。

  9. 設定ファイル作成
    # cd /etc/iotsample-raspberrypi/
    # cp -p device.cfg.`date +%Y%m%d`_1 device.cfg
    ※6.でいったん削除されてしまうので、1.で退避したファイルで復元

  10. サービスの再起動
    # service iot restart
    ※起動している(okが表示される)こと。

  11. 起動モードの確認
    # service iot getdeviceid
    ※registerd mode で起動している(registerd modeが表示される)こと。

  12. 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/

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2