Use a Raspberry Pi Zero to expose an API to my Onkyo Receiver for an iOS app.
$ python -m venv env
$ source env/bin/activate
$ pip install -r requirements.txt
$ ./app.py
GET /onkyo/status
$ curl "http://localhost:8080/onkyo/status"
{
"status": {
"main": {
"source": "tv",
"status": "on",
"volume": 55
},
"zone2": {
"source": "appletv",
"status": "standby",
"volume": 0
}
}
}
PUT /onkyo/<zone>/power/<value>
$ curl -X "PUT" "http://localhost:8080/onkyo/main/power/on"
$ curl -X "PUT" "http://localhost:8080/onkyo/main/power/standby"
$ curl -X "PUT" "http://localhost:8080/onkyo/zone2/power/on"
$ curl -X "PUT" "http://localhost:8080/onkyo/zone2/power/standby"
PUT /onkyo/<zone>/volume/<level>
$ curl -X "PUT" "http://localhost:8080/onkyo/main/volume/55"
{
"volume": 55,
"zone": "main"
}
Run on startup on the Raspberry Pi as a task in crontab
$ crontab -e # edit cron table
@reboot /home/pi/.pyenv/shims/python3 /home/pi/bin/onkyo-server/app.py > /home/pi/logs/onkyo-server.log 2>&1 &
Daniel Bowden