This repository is an updated project developed in JPHACKS.
Intercom control with servo motors and speaker using Raspi via lineAPI.
- RaspberryPi4
- Logicool HD720P
- HM05-5007
- HS-MC09UBK
- servo motor
- LINE Messaging API
- LINE Notify API
- FastAPI
- cloudflare(or ngrok)
-
First, you need to capture the intercom sound via the microphone connected to the Raspi and FFT analyze it. FFT procedure for intercom sound
-
Set Environment Variables
LINE_CHANNEL_SECRET_TOKEN=<Your_LINE_Channel_Secret_Token>
LINE_CHANNEL_ACCESS_TOKEN=<Your_LINE_Channel_Access_Token>
OPENAI_API_KEY=<Your_OpenAI_API_Key>
LINE_USER_ID=<Your_LINE_User_ID>
SWITCHBOT_AUTH_TOKEN=<Your_SwitchBot_Auth_Token>
LINE_NOTIFY_TOKEN=<Your_LINE_Notify_Token>
- The
Switch bot api
is optional. (It remotely controls electricity.)
- Run main.py and notify.py
# Update system and install dependencies
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install tmux portaudio19-dev libopenblas-dev python3-pandas fswebcam -y
# Setup virtual environment
python -m venv env
source env/bin/activate
pip install -r requirements.txt
# Start sessions in tmux for concurrent script execution
# Session 1: Run notify.py
tmux new-session -d -s mySession 'source env/bin/activate; python notify.py'
# Session 2: Run main.py
tmux new-window 'source env/bin/activate; sudo pigpiod; uvicorn main:app --host 0.0.0.0 --port 8000 --reload'
- Publish main.py on the Internet
There are two ways to publish localhost to the Internet: using ngrok and using cloudflare.
Using ngrok: Sign in to https://ngrok.com/ and get your Authtoken.
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
unzip ngrok-stable-linux-arm.zip
chmod +x ngrok
sudo mv ngrok /usr/local/bin/
ngrok authtoken YOUR_AUTHTOKEN
ngrok http 8000
With ngrok, you cannot specify a custom domain. Also note that the url will be changed each time you launch ngrok.
Using Cloudflare Tunnel: Get a domain name using a service such as Squarespace. This usually costs a fee. Configure the DNS servers to cloudflare for the domain that you have gained.
- Sets LINE bot webhook url
Set the webhookurl of the LINE bot to the url you obtained.
You must add
/callback
to the end of the url statement.