Created
March 7, 2012 18:41
-
-
Save compbrain/1995038 to your computer and use it in GitHub Desktop.
power control utility for onkyo eiscp receivers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""Simple power on/off control for Onkyo receivers. | |
Derived from https://github.com/compbrain/Onkyo-TX-NR708-Control | |
""" | |
__author__ = 'Will Nowak <[email protected]>' | |
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