[의식의 흐름] 라즈베리파이 3 Model B에서 구글 어시스턴트를 이용해보자 #1

Today I Learned를 이용해서 정리해볼까 했는데 성격상 깔끔하게 정리하는건 불가능하고, 그냥 의식의 흐름대로 휘갈겨보기로 했습니다.
이미 몇번 포스팅을 하긴 했지만 이번부터 #1로 시작하기로 했습니다.

라즈베리파이 Wifi와 Bluetooth를 동시에


Raspberry Pi 3 Model B 를 사용중인데 지난번 블루투스 설정을 잘 한것 같은데 금방 끊기는 현상이 발생해서 맨붕했었습니다. wifi를 끄니까 아주 잘 되더라구요! 이 문제를 해결하려합니다. 


Fix Raspberry Pi 3 Bluetooth Issues


검색하다보니 이런 문제가 있다고..

Now at this point, many guides I read stated that a quick reboot and then Bluetooth would be working and accessible through Bluetooth Manager in Menu -> Preferences -> Bluetooth Manager, but I found that whilst this was an option, selecting Bluetooth Manager did absolutely nothing.

After an hour or so of frustrated searches online, I stumbled across a page that stated “this happens because when Raspbian installs Blueman and the other Bluetooth software, it does not automatically add ordinary users to the “bluetooth” group. This group gives users permissions to access D-Bus, which Bluetooth uses for communication in Raspbian. This causes a “Permission Denied” error whenever a Bluetooth process initiated by the unprivileged user attempts to access Blueman.”

이런 문제가 있었나? 일단 적용


 $ sudo usermod -G bluetooth -a pi  
 $ cat /etc/group | grep bluetooth   
 bluetooth:x:113:pi  
 $ sudo reboot   


pulseaudio autostart


pulseaudio --start 를 따로 해줘야하는줄 알았더니 원래 되야하는거였네요. 그래서 해봤는데 안되네요? 뭐지....

https://raspberrypi.stackexchange.com/questions/50309/pulseaudio-not-autostarting-on-pi-3


Sleeping for a few seconds seems to be important!

ㅋㅋㅋㅋㅋ 진짜 웃기네요. 아래를 내려보니 위와 같은 코멘트가... 그래서 저도 다음과 같이 수정해줬습니다. 다른건 건드리지 말래요.

 $ sudo vi /etc/xdg/autostart/pulseaudio.desktop  
 Exec=/bin/sh -c "sleep 5; start-pulseaudio-x11"  

전 적당히 이렇게 넣어줬더니 잘 되네요!
오! 부팅 후 자동으로 블투 연결까지 되네요! 굿!



라즈베리파이 Wifi와 Bluetooth를 동시에

하지만 아직 이건 해결도 못했음...
그.러.나 wifi 신호가 좋지 않으면 발생하는 현상인듯하네요.
wifi 신호를 잘 받도록 위치를 조정했더니 잘 동작합니다.
대략 두가지로 추측이 가능한데

  1. wifi에 전력소모가 심해져 bluetooth 모듈의 전력 공급에 차질이 생김. 이건 H/W 적인 문제이므로 딱히 해결 방안이 없을테니 패스합니다.
  2. wifi측에 interrupt 발생이 심해져서 bluetooth 측 interrupt 처리 루틴에 문제가 생김. 이건 Kernel 레벨에서 맞는지 확인이 필요한데 그럼 꽤 난이도가 높아지겠죠. 어쨌든 wifi만 잘 잡아주면 문제가 안생기니 제품화할것도 아니고 넘어가기로 합니다.

PASS!


Next?

다음에 할일을 정리해봅시다.

  1. 구글 어시스턴트를 깔아서 테스트해본다.
  2. 라즈베리파이와 블투 스피커를 켜서 바로 구글 어시스턴트를 쓸수 있도록 정리한다.
  3. 구글 어시스턴트와 영어로 대화해본다.
  4. 텔레그램으로 현재 상태를 주고받을수 있도록 환경을 정리해준다.
    1. 블루투스 연결상태
    2. 와이파이 연결상태 : 이건 해놓은것 같은데
  5. 구글 어시스턴트와 아들이 영어로 대화하도록 해본다.
  6. 와이프한테 칭찬받는다.

구글 어시스턴트



감사한 블로그!
이 블로그에 나온대로 OAuth를 만들고
python3와 venv 설치

$ sudo apt install python3-dev python3-venv
$ sudo apt-get install portaudio19-dev libffi-dev libssl-dev  

에...그냥 저 블로그 주욱 따라하세요. 옮겨쓰기 귀찮음

물론 문제가 발생함

python: No module named googlesamples.assistant.auth_helpers

찾다보니 위 블로그는 아래를 해보고 블로깅을 해놓은 것이로군요. 감사합니다!
https://www.hackster.io/Salmanfarisvp/googlepi-google-assistant-on-raspberry-pi-9f3677


더 찾아보니 업데이트되어 위의 방식을 사용하지 않습니다.
https://github.com/warchildmd/google-assistant-hotword-raspi/issues/5

pip install --upgrade google-auth-oauthlib[tool]
google-oauthlib-tool --client-secrets path/to/client_secret_XXXXX.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless

그럼 아래와 같이 뜨는데 url을 복사해서 브라우저로 열면 인증 화면이 뜨고 거기에 나오는 authorization code: 를 입력하면 됩니다.

 $ google-oauthlib-tool --client-secrets ./client_secret_xxxx.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless  
 Please visit this URL to authorize this application: <여기에 뜨는 URL을 복사해서 웹브라우저에 붙여넣기 하세요>  
 Enter the authorization code: <거기서 나온 코드를 넣으세요>  
 credentials saved: /home/pi/.config/google-oauthlib-tool/credentials.json  


아오 힘드네요. 오늘은 여기까지 하겠습니다.




댓글

이 블로그의 인기 게시물

WSL2 Ubuntu 20.04 및 네트워크 설정

리눅스 멀티코어를 사용하는 tar 압축/해제

git pull 을 했더니 branch가 갈라지는 경우