0.5.14 • Published 9 years ago

sphero-websocket v0.5.14

Weekly downloads
28
License
MIT
Repository
github
Last release
9 years ago

sphero-websocket

使い方

サーバ

モジュールをインストール

$ npm install --save sphero-websocket

設定ファイルを作成

カレントディレクトリに、設定ファイルsphero-ws-config.jsを作成する。
例:

module.exports = {
    wsPort: 8080,
    allowedOrigin: "*",
    sphero: [
        {name: "Miku", port: "/dev/rfcomm0"},
        {name: "Rin", port: "/dev/rfcomm1"}
    ]
};
  • wsPort サーバのポート番号
  • allowedOrigin 接続を許可するoriginを指定する。*ならば全て許可。複数指定はArrayで与える。
  • Sphero サーバに接続するSpheroを列挙する。
    • name 識別名(省略可)
    • port 接続ポート

サーバーを起動する

sphero-ws-config.jsがあるディレクトリにて実行。

$ "./node-modules/.bin/sphero-websocket"

package.jsonのscriptsを次のようにすると、いい感じになる。

"scripts": {
  "server": "sphero-websocket",
  "server-test": "sphero-websocket --test"
}

次のようにできるようになる。

$ npm run server

もしくは、--test オプションをつけて実行
$ npm run server-test

--testオプションを付けると、実際にデバイスには接続せずログ出力のみとなる。

クライアント

ここから先、ポート番号は、8080を使っていることとする。
sphero-ws-config.js でポート番号を変更することができる。

example

http://localhost:8080/client/

(Client側ライブラリ)sphero-client.js

読み込みは、次のようにしてできる。

<script src="http://localhost:8080/client/sphero-client.js"></script>

以下のような感じで、Sphero.jsっぽく使える。

var orb = new sphero();
orb.connect("ws://127.0.0.1:8080", function() {
    orb.color("FF00FF");
    orb.roll(100, 0);
});

API

Spheroのコマンド(API)については、Sphero.js(JavaScript API Doc)を参照。

以下のコマンドが叩けるようになっている。Data Streaming系のコマンドとか、レスポンスを返すのは未実装。

  • sphero.js/lib/devices/sphero.js
  • sphero.js/lib/devices/custom.js
orb.connect(uri, successCallback, errorCallback)
  • uriは接続先WebSocketサーバのURI
  • successCallbackerrorCallbackは、それぞれ接続成功、接続失敗時に呼び出される。
orb.getList(callback)

サーバに接続されているSpheroの名前のリストを返す。callbackの引数にSpheroの名前のArrayが渡される。

orb.use(name)

使うSpheroを設定する。nameに使いたいSpheroの名前を指定する。

0.5.14

9 years ago

0.5.13

9 years ago

0.5.12

9 years ago

0.5.11

9 years ago

0.4.4

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.0

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago