æè¡1課ã§OJTä¸ã®æ¿±å²¡ã§ãã ã¿ãããç¾å³ããå£ç¯ã«ãªãã¾ããã æè¿æ¯æ¥ã¿ãããé£ã¹ã¦ã¾ãã
ãã¦ãä»åã¯Raspberry Piã使ã£ã¦ä¼è°å®¤ã®æ®ãæéãéç¥ãã¦ããããã®ãä½ã£ã¦ã¿ã¾ããã
ãã£ãã
ä¼ç¤¾ã§ä¼è°ã¯ããããã¨æãã®ã§ãã ä¼è°ãæééãã«çµããã次ã®ä¼è°ãæ¼ãã¦ãã¾ã......ãªãã¦ãã¨ããã¾ãããã 5ååãããã«ã¯ä¼è°ãçµãã¦ä¼è°å®¤ã次ã®ä¼è°ã®äººãã¡ã«æã渡ãã®ãçæ³ã§ãã...ãªããªãé£ããã§ãããã
ãããªãä¸æ¹çã«ä¼è°å®¤ã®æ®ãã®æéãä¼ãããã®ãããã°ããã®ã§ã¯...ï¼ï¼ï¼ ã¨æãä½æãã¾ããã
ãã£ããã¨æ§æå³
ã¨ãã£ã¦ãåç´ã§Raspberry Piã«ã¹ãã¼ã«ã¼ãã¶ã£ããã¾ãã
ã¹ãã¼ã«ã¼ããé³å£°ãæµãã¦ä¼è°å®¤ã®æ®ãæéãä¼ãã¦ããã¾ãã ä»åã¯ã1åãã¨ã«ããã°ã©ã ãå®è¡ãã¦å®è¡ããæã®æéã¨éç¥ãããæéãä¸è´ããã°é³å£°ãåçããã¨ããããã«æ§æãã¦ããã¾ãã
ä»å使ç¨ãããã®
- Raspberry Pi 3
- ã¹ãã¼ã«ã¼(ã¹ãã¬ãªããã§æ¥ç¶ã§ãããã®) ä»å使ç¨ããã¹ãã¼ã«ã¼ã¯ãã¡ã
è¨èªã¯Python3ã使ç¨ãã¾ããã
ã¾ãã¯ä¼è°å®¤ã®äºå®ãåå¾
ãµã¼ãã¼ã¯ã¼ã¯ã¹ã§ã¯Googleã«ã¬ã³ãã¼ãå©ç¨ãã¦ä¼è°å®¤ã®äºç´ãè¡ãªã£ã¦ãã¾ãã ããã§Googleã«ã¬ã³ãã¼APIã使ç¨ãã¦ä¼è°å®¤ã®äºå®ãåå¾ãã¾ãã
åå¾ã®æ¹æ³ã¯ä»¥ä¸ãåèã«ãã¦ãã ããã ãåå¿è ã§ãã§ããï¼ãGoogle ã«ã¬ã³ãã¼ã®APIã§ãä»æ¥ã®æ®ãæébotããä½ã
ãã®ä¸ã§ã¯å人ã®IDããèªèº«ã®ã«ã¬ã³ãã¼ã®åå¾ãè¡ãªã£ã¦ãã¾ãã ä¼è°å®¤ã®ã«ã¬ã³ãã¼IDã使ç¨ããã°ä¼è°å®¤ã®äºå®ãåå¾ãããã¨ãå¯è½ã§ãã
確èªæ¹æ³ã¯
Googleã«ã¬ã³ãã¼ã®ã«ã¬ã³ãã¼ã追å
ããã«ã¬ã³ãã¼ã«ç»é²
ãé¸æãã¾ãã
ä¼è°å®¤ãæ¤ç´¢ãã¦è¿½å ãã¾ãã
ä¸ã¸ã¹ã¯ãã¼ã«ããã¨ã«ã¬ã³ãã¼IDãæ¸ãã¦ããã¾ãã
ãããã³ãã¼ãã¦ä½¿ç¨ãã¦ãã ããã
ããã§æ³¨æãã¦ããã ãããã®ãGoogleã«ã¬ã³ãã¼APIãæåã«ä½¿ç¨ããéã«
ãã©ã¦ã¶ä¸ã§èªè¨¼ãè¡ãå¿
è¦ããã ã¨ãããã¨ã§ãã
ä¸åº¦ãã¼ã«ã«ã§å®è¡ãèªè¨¼ãè¡ããããã§çæãããtoken.pickle
ã使ç¨ãã¦äºå®ãåå¾ãã¦ãã ããã
ä»åãRasberry Piã®æ§æã«é¢ãã¦ã¯/opt
é
ä¸ã«ä½æãã¦ãããã¨ãåæã¨ãã¦æ¸ãã¦ããã¾ãã®ã§å¿
è¦ãªãã¡ã¤ã«ã¯/opt
ã®ä¸ã«å
¥ãã¦ããã¦ãã ãããã
éç¥ãããæéãè¨ç®
å ã»ã©Googleã«ã¬ã³ãã¼ããäºå®ãåå¾ãããã¨ãã§ããã®ã§ ãã®äºå®ã®éå§æéã¨çµäºæéãè¨ç®ãã¦ããã¾ãã ä»åã¯å ¨ä½ã®æéã®ååã®æéã¨ä¼è°çµäºã5ååãéç¥ãããã¨ãèãã¾ãã
from datetime import datetime, timedelta
#ä¼è°ã®å
¨ä½ã®æéã®ååã®æéãè¨ç®
def get_half_time(start_time,end_time):
start_time_datetime = convert_datetime(start_time)
end_time_datetime = convert_datetime(end_time)
time_difference_sec = end_time_datetime - start_time_datetime
#ç§ããåã«å¤æ
time_difference_min = time_difference_sec.seconds // 60
half_time = start_time_str + timedelta(minutes=time_difference_min//2)
return half_time
#ä¼è°çµäºã®5ååãè¨ç®
def get_5min_ago(end_time):
end_time_datetime = convert_datetime(end_time)
time_5min_ago = end_time_datetime - timedelta(minutes=5)
return time_5min_ago
#åãåã£ã¦ããå¤ã¯Stringãªã®ã§datetimeã«å¤æ
def convert_datetime(time_str):
time_datetime = datetime.strptime(
time_datetime,
'%Y-%m-%dT%H:%M:%S+09:00'
)
return time_datetime
ä»åã¯datetimeã¢ã¸ã¥ã¼ã«ã使ã£ã¦æéã®è¨ç®ãè¡ãªã£ã¦ãã¾ãã
é³å£°ãä½æ
é³å£°ãã©ãç¨æããããã¨æ©ã¿ã¾ãã... ããããã°AWSã«é³å£°ãçæã§ãããã¤ãã£ããª!!! ã¨ãããã¨ã§ä»åã¯Amazon Pollyã使ã£ã¦é³å£°ãçæããã®é³å£°ãã¡ã¤ã«ã使ç¨ãã¾ããã AWSã®ããã¼ã¸ãã³ã³ã½ã¼ã«ç»é¢ããAmazon Pollyãé¸æãã¾ãã
赤æ ã«åããããè¨èãå ¥åãã¾ãã
ãã¦ã³ãã¼ãMP3
ããmp3ãã¡ã¤ã«ããã¦ã³ãã¼ããã¾ãã
ãã®ããã«ä¼è°å®¤ã®æ®ãæéã®ååç¨ã®é³å£°ã¨5ååç¨ã®é³å£°ãä½æãã¾ããã
é³å£°ã®åç
ã¾ã㯠Raspberry Piã®Audioã®è¨å®ãããã£ã¦ããã¾ãã
以ä¸ã®ã³ãã³ãããè¨å®ãéãã¾ãã
$ sudo raspi-config
7 Advanced Options ãé¸æ A4 Audio ãé¸æ 1 Force 3.5mm ãé¸æ Finish ãé¸æ
ããã§Raspberry Piã®è¨å®ã¯å®äºã§ãã
次ã¯ããã°ã©ã ã§ãã ä»åã¯é³å£°ã®åçã«Pygameã使ç¨ãã¾ããã ããã°ã©ã ãå®è¡ããæéã¨éç¥ãããæéãä¸è´ããã°é³å£°ãåçããã¨ããããã«æ¸ãã¦ããã¾ãã
import pygame.mixer
import time
import os.path
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
#eventsã¯Googleã«ã¬ã³ãã¼APIããåã£ã¦ããäºå®ã®æ
å ±,nowã¯ç¾å¨æå»(datetime)
def time_notification(events, now):
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
end = event['end'].get('dateTime', event['end'].get('date'))
half_time = get_half_time(start,end)
time_5min_ago = get_5min_ago(end)
ããããã#ä¼è°ã®å
¨ä½ã®æéã®ååã®éç¥
if (now.hour == half_time.hour
and now.minute == half_time.minute):
play_music(os.path.join(ROOT_PATH, 'é³å£°ãã¡ã¤ã«å'))
#ä¼è°çµäº5ååã®éç¥
elif (now.hour == time_5min_ago.hour
and now.minute == time_5min_ago.minute):
play_music(os.path.join(ROOT_PATH, 'é³å£°ãã¡ã¤ã«å'))
#é³ã®åç:ä»åã¯3åç¹°ãè¿ãã¦æµããããã«è¨å®
def play_music(file_name):
pygame.mixer.init()
pygame.mixer.music.load(file_name)
pygame.mixer.music.play(2)
time.sleep(8)
pygame.mixer.music.stop()
cronã®è¨å®
ä»åã¯1åãã¨ã«å®è¡ããã¦ããã¾ãã ãã®è¨å®ãcronã§è¡ãªã£ã¦ããã¾ãã
ã¨ãã®åã«Rasberry Piã ã¨ããã©ã«ãã§Python2ã§å®è¡ãã¦ãã¾ãã®ã§Python3ã§åãããã«è¨å®ãã¦ããã¾ã
$ cd /usr/bin
$ sudo unlink python
$ sudo ln -s python3 python
ããããcronã®è¨å®ã§ãã 以ä¸ã®ã³ãã³ãã§è¨å®ãã¡ã¤ã«ãéãã¾ãã
$ sudo cron -e
è¨å®ãã¡ã¤ã«ãéããã以ä¸ãè¨è¿°ãã¾ãã
*/1 10-19 * * 1-5 /usr/bin/python /opt/å®è¡ãããPythonãã¡ã¤ã«å
1åãã¨ã«æ-éææ¥10:00-19:00ã§å®è¡ããã¨ããããã«è¨å®ãã¾ããã
ããã§ãã¨ã¯ä¼è°å®¤ã«ã»ããã£ã³ã°ããã ãï¼
ã¾ã¨ã
ãããã§ããã§ããããï¼ Raspberry Piã£ã¦è²ã ã§ãããã ãªã¨æãã¾ãããã
ããããã°ä»åã®å®è£ ããã¦ããéã«ãããªãã®ãç»å ´ãã¾ããã Alexa for Business ã«ä¼è°çµäºãªãã¤ã³ãã¼ãã¤ã³ããªã¸ã§ã³ãã«ã¼ã ãªãªã¼ã¹ãããã³ä¼è°å®¤æ´»ç¨ã¡ããªã¯ã¹ã追å ããã¾ããã
( ï¾Ð´ï¾) ã»ã»ã»ã»ã»ã»ã»ã»ã»ã» ï¼Â´ã»Ïã»`ï¼.;:â¦ï¼Â´ã»Ï...:.;::..ï¼Â´ã»;::: .:.;: ï½»ï¾ï½»ï¾..
èå³ãããæ¹ã¯ãã¡ãã®è¨äºãã¿ã¦ã¿ã¦ãã ãããã
Alexa for Businessï¼11ï¼æ°æ©è½ï¼3ï¼ä¼è°çµäºãªãã¤ã³ãã¼
以ä¸ã濱岡ã§ããï¼