ブログ

Armadillo-IoTでrubyのwebsocket-client-simpleを利用するには

at_nakai
2015年1月8日 10時28分

Armadillo-IoTで簡易的に任意のRubyライブラリを追加するには、 /usr/lib/ruby/vendor_ruby/ディレクトリにライブラリファイルを配置する ことで利用できるようになります。

ここでは、WebSocketのシンプル実装である「websocket-client-simple」を 追加する例を記載してみます。 参照: https://rubygems.org/gems/websocket-client-simple

尚、本項では簡易的な手順を示すため、ユーザーランドイメージを作成することはありません。

■ 「websocket-client-simple」をダウンロード

Armadillo-IoTにログインして、下記のようにwgetコマンドなどでライブラリを配置します。

[root@armadillo-iotg (ttymxc1) ~]# cd /usr/lib/ruby/vendor_ruby/
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby]# wget https://github.com/shokai/websocket-client-simple/raw/master/lib/websocket-client-simple.rb
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby]# mkdir -p websocket-client-simple
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby]# cd websocket-client-simple/
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby/websocket-client-simple]# wget https://github.com/shokai/websocket-client-simple/raw/master/lib/websocket-client-simple/client.rb
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby/websocket-client-simple]# wget https://github.com/shokai/websocket-client-simple/raw/master/lib/websocket-client-simple/version.rb

「websocket-client-simple」は、「event_emitter」と「websocket」に依存しています。 「websocket」は標準イメージに含まれているので、「event_emitter」をダウンロードしておきます。

[root@armadillo-iotg (ttymxc1) ~]# cd /usr/lib/ruby/vendor_ruby/
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby]# wget https://github.com/shokai/event_emitter/raw/master/lib/event_emitter.rb
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby]# mkdir -p event_emitter
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby]# cd event_emitter/
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby/event_emitter]# wget https://github.com/shokai/event_emitter/raw/master/lib/event_emitter/emitter.rb
[root@armadillo-iotg (ttymxc1) /usr/lib/ruby/vendor_ruby/event_emitter]# wget https://github.com/shokai/event_emitter/raw/master/lib/event_emitter/version.rb

■ サンプル

websocket-client-simpleのサンプルコードは、下記URLにあります。 サンプルコード: https://github.com/shokai/websocket-client-simple/tree/master/sample

■ 【付録】 ATDE上で「websocket-client-simple」を利用できるようにするには

下記のようにgemでインストールします。

atmark@atde5:~$ gem install websocket-client-simple