怎麼做呢? 藉由 Temboo 這個雲端平台的整合功能, 萊恩大兵沒花太多工夫, 就取得了一段可檢查 Gmail 信箱的 Processing 程式碼. 再來就是藉由 serial port 傳遞資訊, 串連大眼仔做反應了.
做法如下:
Gmail 端
要讓 Temboo 的 API 能存取 Gmail 信箱, 得開啟 App passwords 的功能.
- 登入帳號密碼後, 切到 Security 頁面.

Gmail 帳戶的 Security 頁面 - 啟動 2-Step Verification 功能後, 會多了個 App passwords 的項目.

啟動 2-Step Verification 功能 - 授權給 Temboo API 一個 app password (名稱可隨意取, ex: Temboo Choreos for Google).

授權給 Temboo API 一個 app password - 這 app password 要保管好, 千萬別外洩了.

密碼千萬要保管好 - 若不放心這功能, 可隨時吊銷這筆授權.

這筆授權隨時可割可棄, 反觀..
Temboo 端
- 登入後, 切到 Library 頁面, 從左側欄找到 Google | Gmail 的 API (Temboo 的用詞是 Choreos) 頁面 .

支援一狗票的雲端服務 - 在 Gmail 的 API 頁面, 它有數種相關的 API (Choreos) 可以使用, 例如: GetUnreadImportantEmail, GetUnreadMail 等等.

光是 Gmail 就有數種服務 - 連到 GetUnreadMail 的頁面, 它需要填入 username 和 password. Username 就是 gmail 帳號 (gogoprivateryan@gmail.com), password 就是前面剛取得的 app passwords. 填入後, 按 “Run”.

帳密出手, 相信它.. - 等個幾秒鐘, 如果吐在 Output 欄位的是這串錯誤訊息, 請回去檢查 Gmail 的 app passwords 相關設定.

回去檢查 Gmail 的 app passwords 設定.. - 如果順利的話, 會看到 Output 的 FullCount 和 Response 欄位, 裡面有從 Gmail 信箱撈回來的資訊. 這個 FullCount 就是未讀信件的數字.

您有 5 封未讀信件.. - 再往下拉一點, Code 的欄位, 裡面就是相關的程式碼. 萊恩大兵選用 Processing, 其它支援的程式語言還有 Java, C#, Python, PHP, iOS, Ruby, Node.js 與 cURL. 如果 Arduino 有連網功能, Temboo 甚至可以直接產出 Arduino 的程式碼.

程式碼裡面有密碼明文, 已做塗銷處理..
再來就簡單了.
Processing
稍微改一下 Temboo 的程式碼, 加上一些功能:
- 每隔固定一段時間檢查 gmail 信箱一次.
- 如果有新信件, 就透過 serial port 傳給 arduino.
import com.temboo.core.*;
import com.temboo.Library.Google.Gmail.*;
import processing.serial.*;
// Create a session using your Temboo account application details
TembooSession session = new TembooSession("gogoprivateryan", "myFirstApp", "x-x-x-x-x-x-x-x-x-x-x-x-x-");
Serial myPort; // Create object from Serial class
int timeInterval = 30 * 60 * 1000; // half an hour
int lastUpdate;
String mailCount = "";
void setup()
{
myPort = new Serial(this, Serial.list()[5], 9600);
lastUpdate = millis() - timeInterval;
}
void draw()
{
if (millis()-lastUpdate >= timeInterval)
{
// Run the GetUnreadMail Choreo function
runGetUnreadMailChoreo();
myPort.write(mailCount "\n");
lastUpdate = millis();
}
}
void runGetUnreadMailChoreo()
{
// Create the Choreo object using your Temboo session
GetUnreadMail getUnreadMailChoreo = new GetUnreadMail(session);
// Set inputs
getUnreadMailChoreo.setUsername("gogoprivateryan@gmail.com");
getUnreadMailChoreo.setPassword("x-x-x-x-x-x-x-x-x-");
// Run the Choreo and store the results
GetUnreadMailResultSet getUnreadMailResults = getUnreadMailChoreo.run();
// Print results
//println(getUnreadMailResults.getResponse());
println(getUnreadMailResults.getFullCount());
mailCount = getUnreadMailResults.getFullCount();
}
Arduino + 大眼仔
這邊就完全聽命行事.
- 聽 serial port 傳來的數值, 再讓大眼仔依數值大小做適當的動作 (眨眼啦, 轉眼珠之類的).
#include <Servo.h>
#include <AniEyeball.h>
#define N_EYEBALL 1
AniEyeball eyeball;
// 眼皮_PIN # i
// 眼球_PIN # i + 1
const byte servoPin[N_EYEBALL*2] = {2,3};
char inData[10];
int index = 0;
int mailCount = 0;
void setup()
{
Serial.begin(9600);
eyeball.setPinP(servoPin[0]);
eyeball.setPinB(servoPin[1]);
}
void loop()
{
while (Serial.available() > 0)
{
char aChar = Serial.read();
if (aChar == '\n')
{
String str = inData;
mailCount = str.toInt();
index = 0;
inData[index] = NULL;
Serial.write(" done\n");
}
else
{
inData[index] = aChar;
index ;
inData[index] = '\0'; // Keep the string NULL terminated
}
}
if (mailCount >= 10)
{
eyeball.setBPos(1500);
delay(15);
for (int i=0; i<2; i )
{
eyeball.setPPos(2000);
delay(200);
eyeball.setPPos(1000);
delay(200);
}
}
else if (mailCount >= 3 && mailCount < 10)
{
eyeball.setPPos(1000);
delay(15);
for (int i=0; i<2; i )
{
eyeball.setBPos(2000);
delay(200);
eyeball.setBPos(1000);
delay(200);
}
}
else if (mailCount > 0 && mailCount < 3)
{
eyeball.sleepy();
}
mailCount = 0;
}
Okay, 準備就緒. 把它們全部串在一起, 大眼仔就扮起郵差來了. (說實在, 讓大眼仔來檢查 Gmail 信箱, 還真不實用. Anyway, 好玩就好.)
[萊恩大兵的其它文章]
自製大四軸
* 自製大四軸, (1) 零組件篇, 遙控器 (Drone, Quadcopter, Futaba, Maker, Arduino, Animatronic Eye)
* 自製大四軸, (2) 零組件篇, 飛控板 (Drone, Quadcopter, MultiWii, Arduino, Futaba, Maker)
* 自製大四軸, (3) 零組件篇, 自行雷切木質機架 (Drone, Quadcopter, Maker, Laser Cut)
* 自製大四軸, (4) 零組件篇, 馬達與電變調整 (Drone, Quadcopter, Maker, Electric Speed Control, Motor)
* 自製大四軸, (5) 組裝篇, 四軸飛行器成形 (Drone, Quadcopter, MultiWii, Arduino, Maker, Electric Speed Control, Motor)
* 自製大四軸, (6) 調整篇, 飛行前兩三事 (Drone, Quadcopter, Maker, Futaba, Arduino, MultiWii)
* 自製大四軸, (7) 充電篇, iMax B6 充電器操作記要 (Charger, Battery)
自動報球速的棒球
* 自動報球速的棒球, (1) 概念與雛形 (Arduino, MPU-6050, HC-06)
* 自動報球速的棒球, (2) 第一版試作品 (Arduino, NanoWii, microSD, MPU6050)
* 自動報球速的棒球, (3) 拋接實驗的數據分析 (Arduino, NanoWii, microSD, MPU6050)
* 自動報球速的棒球, (2) 第一版試作品 (Arduino, NanoWii, microSD, MPU6050)
* 自動報球速的棒球, (3) 拋接實驗的數據分析 (Arduino, NanoWii, microSD, MPU6050)
* 做實驗, 寫入 EEPROM 的速度能否跟得上 MPU6050 的數據產出? (Arduino, MPU-6050, EEPROM)
* 筆記, NanoWii, 一些經驗分享 (Arduino, NanoWii, MPU6050)
* Murmur, 很小很強大的穿戴式裝置模組 (Realtag, Bluetooth, CC2540, MPU6050, BMP180)
* 筆記, NanoWii, 一些經驗分享 (Arduino, NanoWii, MPU6050)
* Murmur, 很小很強大的穿戴式裝置模組 (Realtag, Bluetooth, CC2540, MPU6050, BMP180)
CC2540 Bluetooth Low Energy
* 筆記, CC2540 Bluetooth Low Energy, (1) 開發環境 架設 (Bluetooth, CC2540)
* 筆記, CC2540 Bluetooth Low Energy, (2) 跑第一個範例程式 (Bluetooth, CC2540)
* 筆記, CC2540 Bluetooth Low Energy, (3) SimpleBLEPeripheral 簡單介紹 (Bluetooth, CC2540)
* 筆記, CC2540 Bluetooth Low Energy, (4) 在智慧手機上執行範例程式 (Bluetooth, CC2540)
* 筆記, CC2540 Bluetooth Low Energy, (5) 偵測與發送 iBeacon 訊號 (Bluetooth, CC2540, iBeacon)
* 實作, iBeacon 發訊器 x 防丟器 (Bluetooth, CC2540, iBeacon)
* 實作, iBeacon 尋寶遊戲 (Bluetooth, CC2540, iBeacon, iOS app)
* 實作, BLE + iOS app, 遙控燈泡君 (Bluetooth, CC2540, iOS app)
* 做實驗, 用 iBeacon 做自動控制的可行性 (Bluetooth, iBeacon, CC2540, Automation, URL Scheme, iOS app)
* 筆記, CC2540 Bluetooth Low Energy, (2) 跑第一個範例程式 (Bluetooth, CC2540)
* 筆記, CC2540 Bluetooth Low Energy, (3) SimpleBLEPeripheral 簡單介紹 (Bluetooth, CC2540)
* 筆記, CC2540 Bluetooth Low Energy, (4) 在智慧手機上執行範例程式 (Bluetooth, CC2540)
* 筆記, CC2540 Bluetooth Low Energy, (5) 偵測與發送 iBeacon 訊號 (Bluetooth, CC2540, iBeacon)
* 實作, iBeacon 發訊器 x 防丟器 (Bluetooth, CC2540, iBeacon)
* 實作, iBeacon 尋寶遊戲 (Bluetooth, CC2540, iBeacon, iOS app)
* 實作, BLE + iOS app, 遙控燈泡君 (Bluetooth, CC2540, iOS app)
* 做實驗, 用 iBeacon 做自動控制的可行性 (Bluetooth, iBeacon, CC2540, Automation, URL Scheme, iOS app)
藍色小鋪一起來做
* 藍色小鋪一起來做, (1) 用 beacon 控制開關的枱燈
* 藍色小鋪一起來做, (2) 講解 BLE CC2540 UART 通訊範例程式 (Bluetooth, CC2540, UART)
* 藍色小鋪一起來做, (3) 藍牙枱燈專案實作 (上) (Bluetooth, CC2540)
* 藍色小鋪一起來做, (4) 藍牙枱燈專案實作 (下) (Bluetooth, CC2540)
* 藍色小鋪一起來做, (5) iBeacon scanner 專案示範與解說 (Bluetooth, CC2540, iBeacon)
* 藍色小鋪一起來做, (6) 完成, 用 iBeacon 控制開關的枱燈 (Bluetooth, CC2540, iBeacon)
小惡魔 無線溫度感測器
* 小惡魔, (1) 溫度感測 + 物聯網 (Electric Imp, Xively, LM35, Internet of Things)
* 小惡魔, (2) 溫度感測 + 物聯網 + 事件觸發 (Electric Imp, Xively, LM35, Internet of Things)
* 小惡魔, (2) 溫度感測 + 物聯網 + 事件觸發 (Electric Imp, Xively, LM35, Internet of Things)
108 大眼仔
Plot Clock
* 體驗, 蛋生音互動裝置@兒童美術館 (Arduino, 3D Printing, HC-SR04, Interactive)
* 實作, 電容感應音樂樹
* 修理, 樂高馬達 8883 (LEGO 8883 Power Functions M-Motor)
* 修理, (part 2) 樂高馬達 8883 (LEGO 8883 Power Functions M-Motor)
* 修理, 液晶螢幕 (LCD)
* 108 大眼仔, 初登場 (Arduino, SG-90, Maker Faire Taipei 2014, Animatronic Eye)
* 108 大眼仔, 進化, (1) 專屬程式庫 (Arduino, SG90, Animatronic Eye)
* 108 大眼仔, 進化, (2) 當我們串在一起 (Arduino, SG90, Animatronic Eye, I2C)
* 108 大眼仔, 進化, (3) 檢查 Gmail 信箱 (Arduino, SG90, Animatronic Eye, Temboo)
* 108 大眼仔, 進化, (4) 看著我的臉 (Arduino, SG90, Animatronic Eye, OpenCV, Processing, I2C)
* 108 大眼仔, 進化, (5) 迎著人來人往 (Arduino, SG90, Animatronic Eye, OpenCV, Processing, I2C)
* 108 大眼仔, 檢討筆記, 我要一個打十個 (Arduino, SG90, Animatronic Eye)
* 108 大眼仔, 進化, (1) 專屬程式庫 (Arduino, SG90, Animatronic Eye)
* 108 大眼仔, 進化, (2) 當我們串在一起 (Arduino, SG90, Animatronic Eye, I2C)
* 108 大眼仔, 進化, (3) 檢查 Gmail 信箱 (Arduino, SG90, Animatronic Eye, Temboo)
* 108 大眼仔, 進化, (4) 看著我的臉 (Arduino, SG90, Animatronic Eye, OpenCV, Processing, I2C)
* 108 大眼仔, 進化, (5) 迎著人來人往 (Arduino, SG90, Animatronic Eye, OpenCV, Processing, I2C)
* 108 大眼仔, 檢討筆記, 我要一個打十個 (Arduino, SG90, Animatronic Eye)
* Murmur, 有趣的零件售價
* Murmur, Arduino 保險桿 (Arduino, bumper, 3D printing)
* Murmur, 許一個 maker 分享網站
* Murmur, 物聯網新概念- The Physical Web (Internet of Things, The Physical Web)
* Murmur, 關於 HP Sprout 的一點想法
* Murmur, 說中文很難嗎? (Toy, Reed Switch, Voice Recorder Module)
* Murmur, 停車場自動繳費機的兩三事 (Kiosk)
* Murmur, 為什麼是 WiFi? 關於小米空氣清淨器的一點看法.. (Internet of Things)
* Murmur, 機器人是時尚元素? (Robot, Fashion)
* 體驗, 原住民互動故事書@宜蘭大同鄉泰雅生活館* Murmur, Arduino 保險桿 (Arduino, bumper, 3D printing)
* Murmur, 許一個 maker 分享網站
* Murmur, 物聯網新概念- The Physical Web (Internet of Things, The Physical Web)
* Murmur, 關於 HP Sprout 的一點想法
* Murmur, 說中文很難嗎? (Toy, Reed Switch, Voice Recorder Module)
* Murmur, 停車場自動繳費機的兩三事 (Kiosk)
* Murmur, 為什麼是 WiFi? 關於小米空氣清淨器的一點看法.. (Internet of Things)
* Murmur, 機器人是時尚元素? (Robot, Fashion)
* 體驗, 蛋生音互動裝置@兒童美術館 (Arduino, 3D Printing, HC-SR04, Interactive)
* 開箱, 鋼彈小劇場 (Pepper's Ghost, GUNDAM)
* 開箱, 偉力控二號機, 小四軸飛行器 (CG022, Quadcopter)
* 偉力控二號機, 修理防護罩與飛行心得 (CG022, Quadcopter)
* 偉力控二號機, 我想有個家 (CG022, Quadcopter)
* 偉控力二號機, 換馬達 (CG022, Quadcopter)
* 偉力控二號機, 盒子上的洞 (CG022, Quadcopter)
* 開箱, 偉力控二號機, 小四軸飛行器 (CG022, Quadcopter)
* 偉力控二號機, 修理防護罩與飛行心得 (CG022, Quadcopter)
* 偉力控二號機, 我想有個家 (CG022, Quadcopter)
* 偉控力二號機, 換馬達 (CG022, Quadcopter)
* 偉力控二號機, 盒子上的洞 (CG022, Quadcopter)
* 修理, 樂高馬達 8883 (LEGO 8883 Power Functions M-Motor)
* 修理, (part 2) 樂高馬達 8883 (LEGO 8883 Power Functions M-Motor)
* 修理, 液晶螢幕 (LCD)

沒有留言:
張貼留言