手を動かすことの大事さ

d.hatena.ne.jp


ディープラーニングも興味深いけど、清水さんのコメントが刺さったのでメモ。

でも人がやってるのをただ見てるのと、自分で手を動かしてやってみるのとではだいぶ理解の程度が違う。昨日も会社で若い技術者にいろいろ仕組みや原理を聞いたりしながらいろいろ考えた。

手を動かしてみないと実際にどのような流れになっているか理解できない。

理解してないからぼんやりしたことを言ってしまう。
だから完全には理解できないまでもある程度のところまでは手を動かして試してみないことにはどうにもならない。


アタリマエのことだが年をとるとついサボっちゃうんだよなあ。
本読めばわかるというものでもなし。

結局泥臭くコードを読み書きするしかないのよなあ

IoT的なデバイス

pc.watch.impress.co.jp

pc.watch.impress.co.jp


それぞれ応用して何ができるか考えてみる。

HBaseマイグレーション

hbaseコマンドでエクスポート/インポート

注意: エクスポート/インポートの処理はMapReduceを使うため、Hadoop環境にMapReduceをインストールしておく必要がある。

FRP: Functional reactive programming

  • プログラミング・パラダイムのひとつ。
  • ネットワークのI/Oやユーザ・インタラクションの処理に向いている。
  • FRPには、behaviorとeventという二つの重要な概念がある。
    • behavior: 例) 時間の経過にともなう状態の変化。振る舞い。
    • event: 例) ある時間の状態
  • behaviorとeventを組み合わせて計算することで、逐次的に書くと記述が煩雑になる処理を簡潔に書ける(場合がある)。

参考:

BLEでペリフェラルを操作する

とりあえずAndroid DeveloperにあるBLEのサンプル(BluetoothLeGatt | Android Developers)をいじって、ペリフェラルのスキャン => 接続 => Characteristic の取得 => HRPで心拍数を取得する処理の流れはひととおりわかった(気がする)。

HRPは心拍数が変わったら通知するだけの単純なプロファイルらしく、あんまり応用がない。


というわけで Characteristic で read/writeしたいのだが、下記のサイトが参考になった。


BLEの拡張プロファイルについては下記が参考になりそう。


【BLEを使う】GATT(Generic Attribute Profile)概要 - 叶鋼は午前1時に計算をする



Android と BLESerial をつなげた例。サンプルコードあり。


浅草ギ研 ArduinoとAndroid端末をBLEでつないでみる

任意のcharacteristicのnotificationをenable/disableする疑似コード

    BluetoothGattCharacteristic characteristic; // 任意のcharacteristic
    boolean enable;
    
    int charaProp = characteristic.getProperties();
    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
        // このcharacteristicは read に対応している
        enable = false;

        mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

        mBluetoothGatt.readCharacteristic(characteristic);
        // このcharacteristicに対してreadのリクエストを送る
        // 非同期に BluetoothGattCallback#onCharacteristicRead(BluetoothGatt, BluetoothGattCharacteristic, int) がコールバックされる
    }

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
        // このcharacteristicは notification に対応している
        enable = true;

        mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
            UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        // characteristicの設定を行うときに指定するUUIDは "00002902-0000-1000-8000-00805f9b34fb" の固定値
        // 対向の BLE peripheral の notification 機能を有効化するため、この characteristic の descriptor に対して BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE を設定する

        mBluetoothGatt.writeDescriptor(descriptor);
        // 設定した descriptor を書き込む
        // 非同期に BluetoothGattCallback#onCharacteristicChanged(BluetoothGatt, BluetoothGattCharacteristic) がコールバックされる
    }

使っているAPI:

  • boolean BluetoothGatt#setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enable)
  • BluetoothGattDescriptor BluetoothGattCharacteristic#getDescriptor(UUID uuid)
    • characteristicの設定を行うときに指定するUUIDは "00002902-0000-1000-8000-00805f9b34fb" の固定値
  • BluetoothGattDescriptor#setValue(byte[] bytes)
    • BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE を設定
  • BluetoothGatt#writeDescriptor(BluetoothGattDescriptor descriptor)

BLE peripheral へバイト列を書き込む模擬コード

    byte[] bytes = { … }; // 書き込むバイト列
    
    BluetoothGattService myService = mBluetoothGatt.getService(UUID.fromString("<Service UUID>"));
    BluetoothGattCharacteristic characteristic = myService.getCharacteristic(UUID.fromString("<Characteristic UUID>"));
    characteristic.setValue(bytes);
    mBluetoothGatt.writeCharacteristic(characteristic);

使っているAPI:

  • BluetoothGattService BluetoothGatt#getService(UUID uuid)
    • 引数は対向 BLE peripheral の Service UUID
  • BluetoothGattCharacteristic BluetoothGattService#getCharacteristic(UUID uuid)
    • 引数は対向 BLE peripheral の Service の Characteristic UUID
  • BluetoothGattCharacteristic#setValue(byte[] bytes);
    • 引数は書き込むバイト列
  • boolean BluetoothGatt#writeCharacteristic(BluetoothGattCharacteristic characteristic)
    • 引数は対向 BLE peripheral へ送信する Characteristic

アイコンとか

creative commons

非商用利用にかぎる

Fez, gear, preferences, settings icon | Icon search engine