スマート農業日誌


 

題名: AT&T M2Xの使い方ついて 其の1

AT&T社M2Xは、IoT(Internet of Things)サービスで、接続デバイスがHTTP/HTTPSリクエストで通信している限り、データを格納するスペースを提供してくれる無料のサービスです。 Xivelyが有名ですが、新規の無料サービスは現在行われていないようです。
温度センサのデータを上げれば、自動でグラフを描いてくれます。
AT&T M2Xへは、https://m2x.att.com/devices?で アカウントを作成し、デバイスIDとAPIキーを作成します。Stremsと呼ばれる。

 

cURL(カール)で cURLのインストールについては、 他の方のブログが詳しいです!

 

$ curl -i "http://api-m2x.att.com/v2/devices/b1e8abbad65cb52b0d75eb2e63efa78(END POINT デバイスIDを入れる)/streams/(temperature 作成したStream名)" -H "X-M2X-KEY: API_KEY"

 

API_KEYは、取得したAPI KEYを入れて下さい。
上記の例では、デバイスID(b1e8abbad65cb52b0d75eb2e63efa78 )とそのデバイスストリームの1つの名前( temperature )URLで指定された。

 

GETリクエストの場合は、URLの一部として含まれていない任意のパラメータは、HTTPクエリ文字列パラメータとして渡すことができます:

 

at&t m2x001

 

 

ポストのため、PUT、およびDELETE要求は、URLに含まれていないパラメータがでJSONとしてエンコードする必要があるContent-Typeのapplication/json :

 

$ curl -i "http://api-m2x.att.com/v2/devices/0f5dad59dd0e5de1a21701bdaf402813(END POINT デバイスIDを入れる)/streams/(temperature 作成したStream名)/values" -d '[{"value": 30, "timestamp": "2014-07-16T02:55:12.345Z"}]' -H "Content-Type: application/json" -H "X-M2X-KEY: "

 

 

参照URL

 

AT&D M2X documentation

 

GitHub attm2x/m2x-arduino

 

$ curl -i "http://api-m2x.att.com/v2/devices/0f5dad59dd0e5de1a21701bdaf402813(END POINT デバイスIDを入れる)/streams/(temperature 作成したStream名)/values" -d '[{"value": 30, "timestamp": "2014-07-16T02:55:12.345Z"}]' -H "Content-Type: application/json" -H "X-M2X-KEY: API_KEY"

 

cURLでcurl で https の URL に接続することができない場合の対応

curl で https の URL にアクセスした際、アクセス先サーバ証明書の 検証ができないため、正常に接続できない場合があります。 その際、以下のエラーが出力される事があります。

 

例)curl で https の URL にアクセスした際のエラー

 

# curl https://www.example.com/file.txt -o file.txt
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). The default
bundle is named curl-ca-bundle.crt; you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.

 

回避策①
curl -k (kオプション)

 

特定のデバイスのストリームとその現在値のリストを取得

 

curl -i https://api-m2x.att.com/v2/devices/0f5dad59dd0e5de1a21701bdaf402813/streams?pretty -H "X-M2X-KEY: API_KEY"

 

curl_m2m_api_http1.1_Device
作成したストリームとデバイス情報を確認できる

 

データのプッシュ
特定のデバイス/ストリームに値をプッシュ、ストリームに値をプッシュする3つの方法があります。
ここでは、特定のストリームの現在の値を更新する、このコマンドは、対応するデバイス·ストリームに指定された値をプッシュします。

 

curl -i -X PUT https://api-m2x.att.com/v2/devices/0f5dad59dd0e5de1a21701bdaf402813/streams/temperature/value -H "X-M2X-KEY: API_KEY" -H "Content-Type: application/json" -d '{ "timestamp": "2014-10-03T12:00:00.789Z", "value": 40 }'

 

at&t m2x003

 

エラー番号: 6
メッセージ: Couldn't resolve host '....'
エラー内容:URLの名前解決ができていない

 

実際にM2Xに温度データをPUTすると 2015.7.6 Add.

温度計測

at&t m2x_IoT

水位を計測

at&t m2x_IoT

GPSをトラック

at&t m2x_IoT gps
at&t m2x003
こんな感じで簡単にデータを収集、蓄積、表示化できます!

 

 

*AT&T M2Xは、AT&T社のクラウドベースのデータストレージサービスとモノのインターネット(IoT)管理ツールセットです。

 

 

平成27年3月1日 株式会社 ジョイ・ワールド・パシフィック ソフト開発課
平成27年4月1日からITビジネス課に名称変更

 

 

 

 

 

 

 


記事一覧に戻る