原文の下に日本語訳をおいておきます。
日本語が訳解らない場合は、上の英語をみてください。


========================
Processing/Arduino application step-by-step
プロセッシング/アルディノ アプリケーション ステップバイ ステップ チュートリアル

Here you will learn to build your own Pachube/Arduino/Processing application step-by-step, connecting Arduino to Processing to Pachube. This tutorial consists of two basic steps.
ここでは、Pachube(パッチベイ)、アルディノ、プロセッシングを使ったアプリケーションを一歩一歩勉強して行きます。

このチュートリアルでは2つの基本的な事をして行きます。

Use Arduino to create an input to Pachube (i.e. provide Arduino's realtime sensor readings for others to connect to).

Use an output from Pachube to control Arduino (i.e. to have your Arduino respond to realtime sensor readings from remote devices).

1、アルディノ側からパッチベイへ、インプットをする。(例:アルディノからのセンサー情報をリアルタイムでパッチベイに送る。)

2、パッチベイからのアウトプットで、アルディノをコントロールする。(例:パッチベイからどこか離れたところに設置されているデバイスのセンサー情報をリアルタイムで受け取り、アルディノに反応させる)

Quickstart: All source files are available here. Inside this zipped folder are 5 Processing programmes. The first four are used in the explanations below; the fifth, arduinoInputOutput_Pachube_05 can be used as a quick start to create an applet that uses both inputs from and outputs to Pachube.
クイックスタート:すべてのソースファイルはここにあります。このZIPフォルダーのなかには5つ、プロセッシングのプログラムが入っています。

最初の4つは以下に説明があります;5つ目の、arduinoInputOutput_Pachube_05を使うと、パッチベイに関わるインプットとアウトプットのアプレットを手っ取り早く作れます。

Please note that Pachube.com will be live and open to the public in Summer 2008; until then, it will not be possible to add a feed to the repository or receive data from Pachube feeds unless you are a beta-tester. Thank you!
(この Pachube.comは2008年夏に正規オープンいたします;それまでは貴方が”ベータテスターユーザー”になるまで、レポジトリやフィードを自由に加える、若しくはパッチベイのフィードデータを受け取る事はできません。 )


-----------------------------------------------------
A. Using Arduino to create a Pachube input
A. アルディノを使ってパッチベイ・インプットを作る

This would enable your local sensor readings to be accessible to others in realtime.
自分の手元にあるセンサーのデータに他者がリアルタイムでアクセスできるようにします。

Part 1. Getting Arduino, Processing and Firmata up and running
パート1、アルディノの準備、プロセッシングとフィルマーターをインストールする。

upload Firmata to your Arduino. 
1、Firmata(フィルマータ)を手元のアルディノにアップロードする。(フィルマータは、ardinoのファームウェアーソフトです。このファイルはardinoから開いてください)

make a simple light sensor circuit attached to analog pin 0 (something like this circuit would do fine).
2、シンプルな光センサー(CDSと抵抗で作られている)回路を作り、”アナログ・ピン0”に接続する(こんな感じの回路で大丈夫です)

download and install the Arduino library for Processing.
3、アルディノについてのプロセッシング・ライブラリー(Arduino library for Processing.)をダウンロードして、インストールする。(ダウンロードしたフォルダを、アルディノの”library”のフォルダにドラッグアンドドロップ(コピー&ペースト))

Use the following code as your initial Processing programme
:以下のコードをプロセッシングのプログラムのページにコピーする。
--------------------------------------------


import processing.serial.*;
import cc.arduino.*;



Arduino arduino;
float myValue;

void setup()
{
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
}

void draw()
{
myValue = arduino.analogRead(0);
println(myValue);
}

------------------------------------------
[Note: You can download the source files here and use arduinoInput_Firmata_01 for this exercise].
[注:このソースファイルをダウンロードできます。この場面で使っているのは”arduinoInput_Firmata_01”のフォルダの中のファイルです。]

Depending on which particular USB port is connected you'll have to change the '0' in the following line to the correct number
: 使用している正しいUSBポートの数字を”0”の所に書き入れる。

-----------------------------------------------------------------
arduino = new Arduino(this, Arduino.list()[0], 57600);
-----------------------------------------------------------------
You can find out what number to use there because when you run your Processing programme, the first thing it does ("println(Arduino.list());") is display a list of serial ports in your Processing console. Look for the one that says something like "/dev/tty.usbserial-A4001cKk".
ここで、それがどの数字かを知るには、貴方のプロセッシングのプログラムを走らせると判ります。
まず最初にする事は ("println(Arduino.list());") で、プロセッシングのコンソールに”シリアルポートのリスト”の表示をさせる事ができます。
そこで"/dev/tty.usbserial-A4001cKk"の様な記述を探してください。

If this is working correctly, you should see a value printed to your console several times a second that changes as you change the light level (or cover up the light sensor with your hand).
もしそれが上手くいった場合、コンソールに時々変化する数値が表示されます。ライトセンサーに手をかざし、その数値がかわるようであるならば、正解です。

Part 2. Adding the Arduino's realtime sensor reading to a Pachube feed
パート2、アルディノのセンサーのリアルタイム情報をパッチベイのfeedに加える。

Using the code above, you just need a few extra lines to get it ready for serving to the Pachube website. The procedure is:
上記にあるコードを使い、ほんの数行をパッチベイのサイトの為に準備します。

Install the EEML library for Processing. 
EEML library for Processingをインストールします。

Edit your previous code so that it looks like: 
今あるコードを以下のように改訂します。

ーーーーーーーーーーーーーーーーー

import processing.serial.*;
import cc.arduino.*; import eeml.*;

Arduino arduino;
float myValue;

DataOut dOut;

void setup()
{
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);

dOut = new DataOut(this, 5210);

dOut.addData(0,"light sensor, LDR, light level");

}

void draw()
{
myValue = arduino.analogRead(0);
println(myValue);
}

void onReceiveRequest(DataOut d){
d.update(0, myValue);
}


ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
[Note: You can download the source files here and use arduinoInput_Pachube_02 for this exercise].
[注:このソースファイルをダウンロードできます。この場面で使っているのは”arduinoInput_Pachube_02”のフォルダの中のファイルです。]

Looking at this additional code line by line:
以下のコードを見つけてください。
ーーーーーーーーーーー
import eeml.*;
ーーーーーーーーーーー

... imports the EEML library. (EEML is the data format used by Pachube. To see the full range of methods available, see the complete EEML documentation here).
EEMLライブラリーを読み込んでいます。( EEMLはパッチベイで使用されているデータフォーマットです。すべてのメソッドがあるかを見る為にはここを見てください、 EEMLドキュメント完全版はここです。 )
ーーーーーーーーーーーーーーー
DataOut dOut;
ーーーーーーーーーーーーーーー
... initiates "dOut" which is a "DataOut" object. Basically this is an object that will handle all the information about data we want to send "outwards", i.e. that will be available for others to connect to via Pachube, and handles serving that data every time it's requested. 
"dOut" を始める、"dOut"とは"DataOut"オブジェクトです。これはオブジェクトで、送りたいデータについてのすべての情報を処理します。例:パッチベイを通じて接続する他者の為、リクエストが来た時にデータ提供の処理もします。

ーーーーーーーーーーーーーーーーーー
dOut = new DataOut(this, 5210);
ーーーーーーーーーーーーーーーーーー
... creates the object dOut, specifying that it will serve on port 5210. (As an all-too-brief intro to 'ports' you should understand that, while your computer might have a single IP address, it has many different 'ports' each assigned to different types of network activity; e.g. 80 for serving web pages, 110 for POP mail activity, etc.). If for some reason 5210 is already in use by another application then you can choose any number, but try something higher in value rather than lower where they're more likely to be in use. By doing this, you computer will know that every time it gets a request on port 5210 it should forward that request to this Processing applet.
オブジェクト"dOut"を作ります。それが、ポート5210に情報を転送する事を指示しています。(自分のコンピュータが多分シングルIPアドレスを持っている事、それがいくつかの別のタイプのネットワークアクティビティを割り当てられた”ポート”を持つ(例えば80がウェブページ、110がPOPメールアクティビティを提供している等)事を理解してください。

もし、他のアプリケーションに使われている等の理由で5210という数字が既に使われている場合、他のどの数字を選ぶ事ができます。しかし、高い数値の方が小さい数値よりも使われていない可能性があるので、そちらを選ぶ方がよいでしょう。

この時、ポート5210はプロセッシングのアプレットにリクエストを毎回転送するのを貴方のコンピュータは感知します。

ーーーーーーーーーーーーーーーーーーーーーーーーー
dOut.addData(0,"light sensor, LDR, light level");
ーーーーーーーーーーーーーーーーーーーーーーーーー
... adds a new data stream to the feed. Its ID number is '0', and it is tagged by a comma-delimited list of descriptions. You can use whatever you like here to describe how this value should be listed on Pachube.
新しいデータをフィードにストリーミングします。IDナンバーが’0’、そしてカンマで区切られた後に、説明やタグを入力します。自分の好きな様にその変数に説明をつける事ができます。この説明のタグは自動的にパッチベイのサイト側にも反映されます。

ーーーーーーーーーーーーーーーーーーーー
void onReceiveRequest(DataOut d){
d.update(0, myValue);
}
ーーーーーーーーーーーーーーーーーーーー
... is the final chunk. When using the EEML library, you always need this as a callback function: basically this is the method that is called every time your Processing programme receives a request for data. (In case you have a number of different DataOut objects, operating on different ports, it also knows which particular one is being requested). The line "d.update(0,myValue);" is just saying something like "for DataOut object 'd', update stream '0' with the value of 'myValue'".
最後のコードですが、EEMLライブラリを使う時に、コールバックファンクションとして、いつも必要になります。これは毎回プロセッシングのプログラムがデータの為のリクエストを受け取った時に呼びだされるものです。(もし、複数のデータアウトオブジェクトや、オペレーティングポートを持っている場合、どれがリクエストを送ったのか解ります。)"d.update(0,myValue);"、この行が"データアウトオブジェクト’d’の為に、’0’と’myValuse’をストリミーングでアップデートします、という様な事を言っているだけです。

That's all there is to it! Of course you can add other pin readings, assigned to different float values and tag those each with their own descriptive tags. (They'll also each need their own new dOut.addData() and d.update(), but all sensor readings can be handled by the single dOut object).
以上です。もちろん、自分で他のセンサー入力のピン読み込みや、他の小数点の数値や、説明タグの割当も加える事ができます。(その時には、それらの為に各々dOut.addData() と d.update()が新しく必要になります。しかし全てのセンサー入力は一つのdOut objectで処理できます。)

Test locally first, to make sure it's serving correctly; the simplest way to do this is open up your browser and type in http://localhost:5210/ as the address. Most browsers should show the XML returned, looking something like this:
上手く送信されているか確かめる為に、ローカルでのテストをします。一番簡単なのはブラウザでhttp://localhost:5210/を開きます。ほとんどのブラウザでなら、以下のようなXMLが表示されるはずです。

ーーーーーーーーーーーーーーーーーーーーーーーーーーー

<?xml version="1.0" encoding="UTF-8"?>
<eeml xmlns="http://www.eeml.org/xsd/005"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eeml.org/xsd/005
http://www.eeml.org/xsd/005/005.xsd" version="5">
<environment>
<data id="0">
<tag>light sensor</tag>
<tag>LDR</tag>
<tag>light level</tag>
<tag>light dependent resistor</tag>
<value>238.0</value>
<unit> </unit>
</data>
</environment>
</eeml>

ーーーーーーーーーーーーーーーーーーーーーーーーーーー
... though some (like Safari) only return the non-XML portion, which might look something like this: "light sensor LDR light level light dependent resistor 247.0".
サファリ等の一部のブラウザではnon-XML portionしか見れません。たぶん"light sensor LDR light level light dependent resistor 247.0"こんな感じの見た目です。

Don't worry about what any of this XML means -- it's only important to Pachube and you don't need to be able to read it yourself. The important thing is that it's working.
心配しなくても、これはPachube(パッチベイ)で読めるので大丈夫です。
重要なのはちゃんと動いているのかどうかなので。

If you get an error message, make sure that your Processing applet is actually running, and without errors.
もしエラーメッセージが来た場合、プロセッシングアプレットがちゃんと起動しているか、エラーが出ていないか確認してください。

The next step, once you're sure it's running locally is to make sure it's visible externally; i.e. outside of your computer. In order to do this, you need to know what your IP address is and to make sure that external traffic will reach your computer.
次のステップでは、ローカルで起動した時に、ちゃんと外部から見えるか確認します。
例えば、この為には自分のIPアドレスが何か、そして 自分のコンピューターの外からちゃんと自分コンピューターが見えるか確認します。

If your computer is directly connected to the internet (e.g. it's actually attached to the DSL modem) then chances are your external IP address is easy to find (as you can determine from System Preferences > Network (Mac OS X) or using Start > Run > cmd.exe > ipconfig /all (Windows); see http://www.simplehelp.net/2006/ 07/06/ how-to-determine- your-ip-or-mac- address-in-windows/ for more info).

もし自分のコンピュータが直接DSLモデム等で接続されている場合は話は簡単で、
(Mac OS Xの場合、システムプレファレンス>ネットワーク、Windowsの場合、スタート>ラン>cmd.exe > ipconfig /allから探し出せます。( 詳しくはここを参照http://www.simplehelp.net/2006/ 07/06/ how-to-determine- your-ip-or-mac- address-in-windows/ )

If you think you now have the correct IP address, you can double check by going to http://whatismyip.com/ which should tell you automatically what your externally-visible IP address is.
もし正しいIPアドレスを知っているなら、http://whatismyip.com/でもう一度確認ができます。ここにアクセスするだけで自動的に外部から見た貴方のIPアドレスを教えてくれます。

If they correspond then all is good; if not it probably means you're on a local network.
もし以上の事で上手くいかない場合は、ローカルネットワークを使用している可能性があります。

If your IP address, as determined on your computer, looks anything like 192.168.xx.xx then that's definitely on a local network (i.e. it's not visible externally).
もしIPアドレスが 192.168.xx.xxの様な感じならば、それはローカルネットワーク(外部から見れません)です。

If you're on a local network, then you need to ensure that external traffic that requests port 5210 (or whichever port you used) is forwarded to your computer. This might require talking to your System Administrator or if you have access to your own router then basically you need to enable "port forwarding" for 5210 to your local IP address (e.g. 192.168.0.10). This procedure will vary from router to router and is not generally complex. For example to configure a Netgear router, see http://kbserver.netgear.com/kb_web_files/N101145.asp.
もしローカルネットワークならば、ポート5210(もしくは自分の必要とするいかなるポート)から外部通信を確保しなければなりません。
自分のシステム管理者に訊くか、ルーターを使用しているのならば、ポート5210からローカルIPアドレス(例:192.168.0.10)に "port forwarding(ポートの転送)"をしなければなりません。この手順はルーターの種類によって違ってきます。

例えば、ネットギアのルーターを使用している場合は、http://kbserver.netgear.com/kb_web_files/N101145.aspを参照してください。
その他の人は、各々ルーターの設定をいじって、そのポートのアクセスを出来る様に、(例えばファイヤーウォールだったり)そのポート番号を例外的に認めるような設定をします。

If your external IP address changes frequently (i.e. it's "dynamic") you can also use a free service like DynDNS to create static hostname.
もし自分のIPアドレスが頻繁に変わる場合、 DynDNSの無料サービスを使って、通信ホストネームを作る事ができます。これを使った場合、そのもらったURLでパッチベイフィードに登録できます。

Once you know your IP address, and port forwarding is enabled you are ready to add your feed to the Pachube repository!
既にIPアドレスが解って居る人、もしくはポートの転送ができている人は、パッチベイ レポジトリー(Pachube repository!)にフィード(データをリアルタイムでアップロード)する事ができます。

To add your feed to Pachube, you need to:
パッチベイにフィードするには、
first, login to Pachube or sign up.
まず、パッチベイにログインかサインアップします。

then select "Add an input" or go here.
その次に"Add an input" を選ぶ。

find your location on the map and double-click to add a new location.
ロケーションマップから、自分の居る場所を探し、ダブルクリックして新しくマーカを作ります。

type in your feed IP address and port, which might look something like 123.45.67.89:5210.
自分のIPアドレスとポート(こんな感じの123.45.67.89:5210)を入力する。(DynDNS等を使っている人はそこでもらったURLのようなものを入力)

fill in any other meta data about this feed (e.g. a description, a contact email address about it (if you wish it to be publicly available)).
その他の情報を入力する。(例:自分のセンサーの説明、光センサーとか、部屋の明るさ等、やメールアドレス、その他必要だと思う情報等)

click "Preview feed".
"Preview feed"をクリック。

verify that your light sensor reading is being read correctly by Pachube.
センサーの情報がちゃんとパッチベイに読み取られているか確認する。

once you're happy that the data is being read correctly, that it is tagged as desired, click "Submit feed". 
以上問題なければ "Submit feed"をクリックします。


You have now added your feed to the repository! Pachube will now give your feed a unique ID and a URL through which this feed may be accessed (so that you don't need to make your own IP address public). It will also log your sensor data whenever it is connected to the internet (so long as your IP address doesn't change!). You can now doing any of a number of things including:
これでレポジトリにフィードが追加されました。パッチベイからランダムなIDとURLが与えられます。(なので自分でIPアドレスを作る必要もありません) あなたのネット接続されているセンサーのログデータも(IPアドレスが変わらない限り)取ります。これから貴方は以下の事ができるようになりました。

build further devices on other remote computers that connect to this feed.
別のコンピュータで今のフィードに接続する、更なるデバイスを作る事ができます。

distribute the feed URL to others so that they can make devices that remotely connect to it.
このフィードのURLを色々な人に教えて、彼らが貴方のフィードとつながるデバイスを作ることができます。

enable the background colour of your webpage to change with the realtime sensor reading.
リアルタイムにウェブの背景の色等、デザインに変化を与える事ができます。

embed a graph of historical data from the sensor readings in your blog.
ブログ等にログやグラフを埋め込む事も出来ます。

be sure to check out the complete documentation for the EEML library to see other methods that can be applied to your DataOut object, including the ability to set geographical location data; add "units" information for sensor values; and provide maximum and minimum values expected for a particular stream.

0 コメント:

Subscribe