IFTTT = IF This (happens) Then (teigger) That
IFTTT (IF This Then That) is a free web-based service that people use to create chains of simple conditional statements, called applets, which will coordinate small tasks between Internet and web services
開瀏覽器,連結 https://ifttt.com/,以 google 帳號登入
IFTTT,IF This Than That,要建立 This 事件觸發 That 服務的 Applets
選 Create,建立 This 事件觸發
新增 This 事件
搜尋 web,選 Webhooks 類的事件
服務選項與數目、排列,隨時會有改變,可能與截圖不同。
這兒選 Receive a web request,這是最常使用的觸發事件,此事件,當接收到 HTTP 請求時,會觸發 That 服務
給 Webhooks Receive a web request 事件命名,完成建立。複製記錄下來,後面會用到
新增 That 事件
搜尋 google,選 Google Sheet 服務
服務選項與數目、排列,隨時會有改變,可能與截圖不同。
這兒要選 Add row to spreadsheet,每次觸發,會於指定的 google 試算表中新增一列資料
取得 google 帳戶授權
設定 Add row to spreadsheet That 服務
選連結Gmail 帳號(付費版可同時記錄在多個Gmail 帳號)
自行命名:要建立的 google 試算表檔名
送出資料有 時間(OccurredAt), 名稱(EventName) 及最多3個Value值。這裡設定光敏電阻感測之類比值(Value1)與數位值(Value2)、送出之控制板hostname(Value3)三筆資料
Google 試算表會儲存在雲端硬碟中的路徑:我的雲端硬碟/IOT/名稱(EventName) 下
選 Continue
要修改 If This 的設定,選 If 右上角 Edit 後更改設定;要更改成其他服務,選 Delete 後重新設定
要修改 Than That 的設定,選 Then 右上角 Edit 後更改設定;要更改成其他服務,選 Delete 後重新設定
選 Finish
Applet 啟動,要 email 通知,把開關打開
Applets 建立完成,且已作用中。
可以按 Edit title 可自行修改長長的 Applets 標題
View activity,可看 Applets 運作資訊
Check now,可確認 Applets 是否運作中
Archive 可刪除(這裡請勿選)。
選 My Applets,可查看所有建立的 Applets 列表。
Free 帳號的使用者,最多只能建立 2 個 Applets(112/02)。最多只能建立 5 個 Applets。最多只能建立 3 個 Applets。
選 My Applets
選要測試的 Applet
選 webhooks
選 Documentation
於測試頁下,複製 Applet key,此 key 在 ESP8266 程式會使用。
cirex1fv_DCPqBT3-V2tG0
1 給定 自己剛剛設定的 EventName(espDataToGsheet),注意:大小寫不同
2,3 任意模擬光敏電阻的類比值與數位值
4 任意給控制板 hostname
完成按 Test It
成功觸發 Applets
登入個人 Google 雲端硬碟。依上面的設定, IFTTT 會在雲端硬碟 我的雲端硬碟下建立 IOT/espDataToGsheet(EventName) 資料夾
建立了 Applet 中設定的試算表檔
資料進來了
開瀏覽器。網址列輸入 https://maker.ifttt.com/trigger/espDataToGsheet/with/key/cirex1fv_DCPqBT3-V2tG0?value1=128&value2=0&value3=ESP-123456
紅色部分改成自己的資料
回到試算表,資料進來了
My Applet > 選要更改的 Applet > Setting
要更改 This 或 That,選 This 或 That 上的 Edit
也可刪除 This 或 That 重新建立,選 This 或 That 上的 Delete
例 1 更改/查看 eventname
例 2 更改 that 中的試算表檔名
IOT > Web Services > IFTTT
WiFiClient client;
String MakerIFTTT_Key ;
;String MakerIFTTT_Event;
char *append_str(char *here, String s) { int i=0; while (*here++ = s[i]){i++;};return here-1;}
char *append_ul(char *here, unsigned long u) { char buf[20]; return append_str(here, ultoa(u, buf, 10));}
char post_rqst[256];char *p;char *content_length_here;char *json_start;int compi;
void loop()
{
if (client.connect("maker.ifttt.com",80)) {
MakerIFTTT_Key ="";
MakerIFTTT_Event ="facebook";
p = post_rqst;
p = append_str(p, "POST /trigger/");
p = append_str(p, MakerIFTTT_Event);
p = append_str(p, "/with/key/");
p = append_str(p, MakerIFTTT_Key);
p = append_str(p, " HTTP/1.1\r\n");
p = append_str(p, "Host: maker.ifttt.com\r\n");
p = append_str(p, "Content-Type: application/json\r\n");
p = append_str(p, "Content-Length: ");
content_length_here = p;
p = append_str(p, "NN\r\n");
p = append_str(p, "\r\n");
json_start = p;
p = append_str(p, "{\"value1\":\"");
p = append_str(p, "");
p = append_str(p, "\",\"value2\":\"");
p = append_str(p, "");
p = append_str(p, "\",\"value3\":\"");
p = append_str(p, "");
p = append_str(p, "\"}");
compi= strlen(json_start);
content_length_here[0] = '0' + (compi/10);
content_length_here[1] = '0' + (compi%10);
client.print(post_rqst);
}
}
完成之積木程式
randomSeed(analogRead(0));
key: x44q-yN5DPxkYrTkKN7wP
EventName: espLdrDataByIfttt110A
請參考EXP2,自行修改實作