diff --git a/server/power.py b/server/power.py new file mode 100644 index 0000000..8ed7a69 --- /dev/null +++ b/server/power.py @@ -0,0 +1,34 @@ +import requests +import settings +import logging +import time + +def np_02B_api(ip, username, password, is_on): + if is_on: + endpoint = '/cmd.cgi?grp=0' + else: + endpoint = '/cmd.cgi?grp=30' + + url = 'http://' + ip + endpoint + r = requests.get(url, auth=(username, password), timeout=4) + r.raise_for_status() + +def lights_on(): + np_02B_api(settings.LIGHT_IP, settings.LIGHT_USER, settings.LIGHT_PASS, True) + +def lights_off(): + np_02B_api(settings.LIGHT_IP, settings.LIGHT_USER, settings.LIGHT_PASS, False) + + +if __name__ == '__main__': + try: + print('Turning lights on...') + lights_on() + + print('Waiting three seconds...') + time.sleep(3) + + print('Turning lights off...') + lights_off() + except BaseException as e: + logging.error('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e))) diff --git a/server/settings.py b/server/settings.py new file mode 100644 index 0000000..d180801 --- /dev/null +++ b/server/settings.py @@ -0,0 +1,7 @@ +LIGHT_IP = '192.168.99.25' +LIGHT_USER = 'admin' +LIGHT_PASS = 'admin' + +GRID_IP = '192.168.99.20' +GRID_USER = 'admin' +GRID_PASS = 'admin'