Google Home이 도난당하면 스스로 비명을 지르게 합니다.
11900 단어 TWELiteGoogleHomeIoT
회사에서도 조사 용도로 1대 사고 있어, 주위의 사람에게 놀아 주도록(듯이) 두고 있습니다만 「도난 대책 어떻게 하자・・・」라고 고민하고 있었습니다. 거기서, 정확히 ↓의 기사로 Google Home에 말해달라고 하는 것이 있었으므로, 그쪽을 참고로, 도난당하게 되면 Google Home 자신에게 비명을 들도록 해 보았습니다!
집에 돌아오면 Google Home에서 좋아하는 음성으로 '어서 오세요'라고 말합니다.
환경
결과
이런 느낌이 들었습니다.
YouTube
"助けてーー!!盗まれるーーーーーーー!!"
구성
라즈파이는 아직 사용한 적이 없었기 때문에 다음과 같은 구성으로 만들었습니다.

Google Home Mini의 무게만으로는 압력 센서가 충분히 반응하지 않았기 때문에, MacBook의 AC 어댑터(와 500엔 구슬)를 사이에 두지 않고 있습니다. 뭔가 다른 센서로 하면 좋았을지도・・・

친기(mac)측은 이러한 느낌으로 USB 시리얼 변환 어댑터(AE-UM232R)를 경유하고 있습니다

코드
index.js
const googlehome = require('google-home-notifier');
const SerialPort = require('serialport');
// setup seiarl port
const port = new SerialPort(process.env.TWELITE_PORT, {
baudRate: 115200,
})
// setup google home
googlehome.device(process.env.GOOGLE_HOME_NAME, 'ja')
googlehome.ip(process.env.GOOGLE_HOME_IP)
port.on('open', () => {
console.log('port opened')
})
port.on('error', err => {
console.log('Error: ', err.message);
})
let buffer = ""
port.on('data', data => {
for (const k of data.keys()) {
const s = data.toString('utf8', k, k + 1)
if (s == '\r' || s == '\n') {
if (buffer !== "") {
handleTweliteLine(buffer)
buffer = ""
}
} else {
buffer = buffer + s
}
}
})
let lastState // 0: Google Home is on the sensor, 1: not
function handleTweliteLine(line) {
if (line.length != 49 || line.indexOf(':') != 0) {
console.error(`invalid line: ${line}`)
return
}
const state = line.charAt(34) == '1' ? 1 : 0
if (lastState != state) {
console.log('state changed', state)
}
if (lastState == 0 && state == 1) {
console.log('盗まれた!')
googlehome.notify('助けてーー!!盗まれるーーーーーーー!!', (res) => {
console.log(res)
})
}
lastState = state
}
port.on('data', data => {})
에서 TWELITE의 직렬 데이터를 처리하고 있습니다.handleTweliteLine()
실행하여 (YouTube 동영상처럼) Google Home을 압력 센서에 올리거나 제외하면 다음과 같은 출력이 됩니다.
$ export GOOGLE_HOME_NAME="<Google Homeの名前>"
$ export GOOGLE_HOME_IP="<Google HomeのIP>"
$ export TWELITE_PORT="/dev/<TWELITEのTTYデバイス名>"
$ node index.js
port opened
state changed 1
state changed 0
state changed 1
盗まれた!
Device notified
Fritzing에서 작성한 회로도를 포함하여 아래에 코드 등을 두고 있습니다.
ottijp/google-home-shout
해봐
도난 당하면 전원을 뽑을 수 있기 때문에 의미가 없습니다 ... 😝
Reference
이 문제에 관하여(Google Home이 도난당하면 스스로 비명을 지르게 합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ottijp/items/c22a47292354d6670e4f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)