Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 58 additions & 45 deletions ultrasonic-sensor/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ https://gist.github.com/j3tm0t0/65367f971c3d770557f3
pi@raspberrypi:~ $ curl -O http://soracom-files.s3.amazonaws.com/connect_air.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1420 100 1420 0 0 2416 0 --:--:-- --:--:-- --:--:-- 2414<br>
pi@raspberrypi ~ $ chmod +x connect_air.sh<br>
100 1420 100 1420 0 0 2416 0 --:--:-- --:--:-- --:--:-- 2414
pi@raspberrypi ~ $ chmod +x connect_air.sh
pi@raspberrypi ~ $ sudo mv connect_air.sh /usr/local/sbin/

```
Expand All @@ -240,20 +240,21 @@ pi@raspberrypi ~ $ sudo mv connect_air.sh /usr/local/sbin/

接続の準備ができましたので、接続スクリプトを実行します。接続スクリプトは root 権限で実行する必要があるため、sudoで実行します。

****
pi@raspberrypi:~ $ sudo /usr/local/sbin/connect_air.sh<br>
Bus 001 Device 004: ID 1c9e:98ff OMEGA TECHNOLOGY<br>
Look for target devices ...<br>
No devices in target mode or class found<br>
Look for default devices ...<br>
product ID matched<br>
Found devices in default mode (1)<br>
Access device 004 on bus 001<br>
Current configuration number is 1<br>
Use interface number 0<br>
Use endpoints 0x01 (out) and 0x81 (in)<br>
****
```
pi@raspberrypi:~ $ sudo /usr/local/sbin/connect_air.sh
Bus 001 Device 004: ID 1c9e:98ff OMEGA TECHNOLOGY
Look for target devices ...
No devices in target mode or class found
Look for default devices ...
product ID matched
Found devices in default mode (1)
Access device 004 on bus 001
Current configuration number is 1
Use interface number 0
Use endpoints 0x01 (out) and 0x81 (in)
```

```
USB description data (for identification)

-------------------------
Expand Down Expand Up @@ -314,16 +315,19 @@ CONNECT 14400000
--> secondary DNS address 100.127.1.53
--> pppd: ���v�r[01]�r[01]

```

上記のように表示されると接続完了です。

AWS を経由してインターネット接続できていることを確認します。
別のターミナルを立ち上げ、以下のコマンドを実行します。

```
pi@raspberrypi ~ $ curl ifconfig.io
54.65.XXX.XXX (IPアドレスが表示されます)
pi@raspberrypi ~ $ host 54.65.xxx.xxx
xxx.xxx.65.54.in-addr.arpa domain name pointer ec2-54-65-xx-xxx.ap-northeast-1.compute.amazonaws.com.
```

CurlコマンドによるIPアドレスとhostコマンドにより、EC2からインターネットに接続されていることがわかりました。

Expand Down Expand Up @@ -367,14 +371,14 @@ CurlコマンドによるIPアドレスとhostコマンドにより、EC2から
また、画面下部にある [データ使用量実績データを CSV 形式でダウンロード] から、期間を選択して [ダウンロード] ボタンをクリックすることで、基本料金、転送データ量などの詳細を確認することができます。



```
請求額詳細のCSVには、IMSIごとに以下の項目が記載されています。
✓ date (日付)
✓ billItemName (basicCharge は基本料金、upload/downloadDataChargeは転送データ量に対する課金)
✓ quantity (数量: upload/downloadDataChargeの場合の単位はバイト)
✓ amount (金額: 日ごとの料金。この項目の総合計が、月額請求額となります)
✓ タグ、グループ

```

#### <a name = "section4-4">監視機能の確認
通信量にしきい値を設定し、超えた場合にメールでの通知と通信帯域制限をすることができます。監視できる項目は以下のとおりです。
Expand All @@ -397,13 +401,19 @@ Air SIMに監視の設定をしましょう。当ハンズオンの間に通知

ここでの設定は、対象のAir SIMごとに有効になります。

```
監視の設定は、以下の3つを対象することができます。
✓ Air SIM<br>
✓ (Air SIMの所属する)グループ<br>
✓ (登録した)全てのSIM
```


すぐに、メール通知を確認したい場合は、Raspberry Piから以下のコマンドを実行して、1MiBのダウンロードを実施してみてください。

```
pi@raspberrypi ~ $ wget http://soracom-files.s3.amazonaws.com/1MB
```

以下のような通知が届きます。(通知は最大で5分程度かかります。)

Expand Down Expand Up @@ -460,24 +470,25 @@ pi@raspberrypi ~ $ wget http://soracom-files.s3.amazonaws.com/1MB
#### <a name = "section5-3">3.センサーをテストしてみる
以下のコマンドで、プログラムをダウンロード・実行し、正しくセンサー値が読み出せるか試しましょう

****
```
pi@raspberrypi ~ $ wget http://soracom-files.s3.amazonaws.com/sensor_test.py
--2016-03-23 18:07:17-- http://soracom-files.s3.amazonaws.com/sensor_test.py<br>
Resolving soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com)... 54.231.225.133<br>
Connecting to soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com)|54.231.225.133|:80... connected.<br>
HTTP request sent, awaiting response... 200 OK<br>
Length: 870 [text/plain]<br>
Saving to: ‘sensor_test.py’<br>
--2016-03-23 18:07:17-- http://soracom-files.s3.amazonaws.com/sensor_test.py
Resolving soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com)... 54.231.225.133
Connecting to soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com)|54.231.225.133|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 870 [text/plain]
Saving to: ‘sensor_test.py’

sensor_test.py 100%[===================>] 870 3.72KB/s in 0.2s

2016-03-23 18:07:19 (3.72 KB/s) - ‘sensor_test.py’ saved [870/870]

pi@raspberrypi ~ $ python sensor_test.py<br>
distance: 38.6 cm<br>
distance: 38.9 cm<br>
pi@raspberrypi ~ $ python sensor_test.py
distance: 38.6 cm
distance: 38.9 cm
distance: 2.3 cm ← センサーの前に手をかざして変化を確認しましょう
:
```

#### <a name = "section5-4">4.トラブルシュート

Expand Down Expand Up @@ -551,9 +562,12 @@ ESへのデータ転送は[Webエントリポイント]を使用します。[SOR

表示された画面で以下のように設定してください。

● 設定名:ES(別の名前でも構いません)<br>
● 転送先のプロトコル:HTTPS<br>
```
● 設定名:ES(別の名前でも構いません)
● 転送先のプロトコル:HTTPS
● ホスト名: search-handson-z3uroa6oh3aky2j3juhpot5evq.ap-northeast-1.es.amazonaws.com
```


![](image/6-9.png)

Expand Down Expand Up @@ -587,16 +601,16 @@ ESへのデータ転送は[Webエントリポイント]を使用します。[SOR

Beamを使用する(「send_to_cloud.py」の実行時)には、SORACOM Airで通信している必要があります。

****
pi@raspberrypi:~ $ sudo apt-get install -y python-pip<br>
:<br>
pi@raspberrypi ~ $ sudo pip install elasticsearch<br>
:<br>
```
pi@raspberrypi:~ $ sudo apt-get install -y python-pip
:
pi@raspberrypi ~ $ sudo pip install elasticsearch
:
pi@raspberrypi ~ $ wget http://soracom-files.s3.amazonaws.com/send_to_cloud.py
--2016-03-24 02:40:12-- http://soracom-files.s3.amazonaws.com/send_to_cloud.py<br>
soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com) をDNSに問いあわせています... 54.231.224.18<br>
soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com)|54.231.224.18|:80 に接続しています... 接続しました。<br>
HTTP による接続要求を送信しました、応答を待っています... 200 OK<br>
--2016-03-24 02:40:12-- http://soracom-files.s3.amazonaws.com/send_to_cloud.py
soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com) をDNSに問いあわせています... 54.231.224.18
soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com)|54.231.224.18|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 2678 (2.6K) [text/plain]
`send_to_cloud.py' に保存中

Expand All @@ -617,7 +631,6 @@ pi@raspberrypi ~ $ python send_to_cloud.py
- ステータスが 'in'(何か物体がある) に変化しました
- Beam 経由でデータを送信します

****
{u'_type': u'event', u'_id': u'AVRRGrS4IfRhQRmTbOsN', u'created': True, u'_version': 1, u'_index': u'sensor'} ← 正常にデータが送信されたら created: True になります


Expand All @@ -629,13 +642,13 @@ pi@raspberrypi ~ $ python send_to_cloud.py

- Beam 経由でデータを送信します
{u'_type': u'event', u'_id': u'AVRRGsWEIfRhQRmTbOsO', u'created': True, u'_version': 1, u'_index': u'sensor'} ← 正常にデータが送信されたら created: True になります
****

```



#### <a name = "section6-8">4. クラウド上でデータを確認する
Elasticsearch Service 上にインストールされている Kibana にアクセスします。

https://search-handson-z3uroa6oh3aky2j3juhpot5evq.ap-northeast-1.es.amazonaws.com/_plugin/kibana/

![](image/6-11.png)
Expand Down Expand Up @@ -722,10 +735,10 @@ IFTTTへのデータ転送を設定します。IFTTTへのデータ転送は[HTT
[保存]をクリックします。
以上でBeamの設定は完了です。


```
ここで設定した通り、IFTTTへのアクセスURLは、{maker_key}を含んでいますが、Beamを使用することで、デバイスに認証情報をもたせる必要がなくなります。
これにより、認証情報が盗まれるリスクを回避できます。また、変更になった場合もたくさんのデバイスに手を入れることなく、変更を適用することができます。

```



Expand All @@ -738,7 +751,7 @@ IFTTTへの送信をおこないます。

ESの場合と同様に、Beamを使用する(「send_to_ifttt.py」の実行時)には、SORACOM Airで通信している必要があります。


```
pi@raspberrypi ~ $ wget http://soracom-files.s3.amazonaws.com/send_to_ifttt.py
--2016-03-24 03:24:30-- http://soracom-files.s3.amazonaws.com/send_to_ifttt.py
soracom-files.s3.amazonaws.com (soracom-files.s3.amazonaws.com) をDNSに問いあわせています...<br>
Expand Down Expand Up @@ -771,7 +784,7 @@ status changed to 'in' : {"value3": "", "value2": "5", "value1": "in"}
- Beam 経由でデータを送信します
status changed to 'out' : {"value3": "", "value2": "9", "value1": "out"}
<Response [200]> ← 正常にデータが送信されたら 200 になります

```

すると、下記のようなツイートが行われます。
![](image/7-10.png)
Expand Down