Skip to content

Instantly share code, notes, and snippets.

@compbrain
Created March 7, 2012 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save compbrain/1995038 to your computer and use it in GitHub Desktop.
Save compbrain/1995038 to your computer and use it in GitHub Desktop.
power control utility for onkyo eiscp receivers
#!/usr/bin/python
"""Simple power on/off control for Onkyo receivers.
Derived from https://github.com/compbrain/Onkyo-TX-NR708-Control
"""
__author__ = 'Will Nowak <wan@ccs.neu.edu>'
import socket
import sys
ISCP_CMDS = {'on': 'PWR01', 'off': 'PWR00'}
if len(sys.argv) != 3 or sys.argv[2] not in ISCP_CMDS:
sys.stderr.write('Usage: %s <ip> <on/off>\n' % sys.argv[0])
sys.exit(1)
_, target, mode = sys.argv
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((target, 60128))
command = ISCP_CMDS[mode]
if '!1' != command[:2]:
command = '!1%s' % command
command_length = len(command)
pad = chr(command_length + 1 + 16)
hex_command = ('ISCP\x00\x00\x00\x10\x00\x00\x00%s\x01\x00\x00\x00%s\x0D'
% (pad, command))
s.send(hex_command)
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment