そこで、今回は、Arduinoで計測した温度データを、Googleドライブ(Googleスプレッドシート)に記録する方法を説明します。

■IFTTTの準備
次の手順で、アカウントを作成し、レシピを作成します。
①IFTTTアカウントの作成
IFTTTのアカウントを作成します。
②IFTTTのレシピの作成
1.「My Recipes」をクリックし、 [Create a Recipe]をクリックします。

2.「this」をクリックします。

3.検索ボックスに「Maker」と入力し、「Maker」を選択します。

4.「Receive a web request」を選択します。

5.Event Name(イベント名)を入力し、[Create Trigger]をクリックします。

6.「that」をクリックします。

7.検索ボックスに「google」と入力し、「Google Drive」を選択します。

※初回のみ、[Connect]ボタンクリックし、Googleサービスへの接続を「許可」します。
8.「Add row to spreadsheet」を選択します。

9.[Create Action]をクリックします。

ここでは、 Spreadsheet name(シート名)、Formatted row(行の書式)、Drive folder path(保存先のパス)を設定します。今回はデフォルトの設定を使用することとします。
10.[Create recipe]をクリックします。

③Keyの確認
ブラウザでMaker Channelを開き、Keyを確認します。

■IoTデバイスの準備
①Arduinoのセットアップと回路の配線
1. 「ArduinoをJavaScriptで制御する」の手順でArduinoをセットアップし、Node.js、Johnny-Fiveをインストールします。
2.温度センサー(LM35)を次のように接続します。
②「request」モジュールのインストール
1.コマンドプロンプトを起動し、作業用フォルダに移動します。
2.「npm install request」と入力します。
③プログラムの作成
次のJavaScriptコードを入力し、「home_temperature.js」と名前を付けて作業用のフォルダに保存します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var event = '<Event Name>'; | |
var key = '<Your Key>'; | |
var url = 'https://maker.ifttt.com/trigger/' + event + '/with/key/' + key; | |
var options = { | |
uri: url, | |
form: {}, | |
json: true | |
}; | |
var five = require("johnny-five"); | |
five.Board().on("ready", function() { | |
var temperature = new five.Thermometer({ | |
controller: "LM35", | |
pin: "A0", | |
freq: 10000 // サンプリング間隔(ms) | |
}); | |
temperature.on("data", function() { | |
options.form.value1= this.celsius; | |
options.form.value2= this.fahrenheit; | |
console.log(this.celsius + "°C", this.fahrenheit + "°F"); | |
// データをPOSTメソッドで送信 | |
request.post(options, function(error, response, body){ | |
if (!error && response.statusCode == 200) { | |
console.log('success'); | |
} else { | |
console.log('error: '+ response.statusCode); | |
} | |
}); | |
}); | |
}); |
<your key>には、「IFTTTの準備」の「③Keyの確認」で確認したKeyを入力します。
④動作の確認
1.コマンドププロンプトを起動し、作業用フォルダに移動します。
2.「node home_temperature.js」と入力します。
3.Googleドライブに接続し、「IFTTT\Maker\<イベント名>」 フォルダの「IFTTT_Maker_Events」シートを開きます。
0 件のコメント:
コメントを投稿