Skip to content

Instantly share code, notes, and snippets.

@pszafer
Created February 18, 2019 11: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 pszafer/6838d2232c00187f210b0b8314d298bf to your computer and use it in GitHub Desktop.
Save pszafer/6838d2232c00187f210b0b8314d298bf to your computer and use it in GitHub Desktop.
rolety_setup
#!/usr/bin/python3
import requests
import os
from multiprocessing import Process
def init_shutter_mode(host, openduration, closeduration):
import time
url="http://{0}/cm".format(host)
print("Starting shutter mode for {0}".format(host))
requests.get(url, { 'cmnd' : 'setoption80 1' })
requests.get(url, { 'cmnd' : 'setoption14 1' })
requests.get(url, { 'cmnd' : 'setoption81 1' })
requests.get(url, { 'cmnd' : 'PowerRetain 1' })
requests.get(url, { 'cmnd' : 'restart 1' })
print("Waiting for host to restart")
host_up = False
retries = 0
time.sleep(1)
while not host_up or retries < 10:
host_up = True if os.system("ping -c 1 " + host) is 0 else False
retries += 1
time.sleep(1)
setup_shutters(url, openduration, closeduration)
def setup_shutters(url, openduration, closeduration):
print("Setting up shutter time")
requests.get(url, { 'cmnd' : 'SHUTTEROPENDURATION {0}'.format(openduration) })
requests.get(url, { 'cmnd' : 'SHUTTERCLOSEDURATION {0}'.format(closeduration) })
requests.get(url, { 'cmnd' : 'switchmode1 0' })
requests.get(url, { 'cmnd' : 'switchmode1 0' })
print("Done")
if __name__=='__main__':
rolety = [
('192.168.4.145', 28, 27), ## IP, OPEN, CLOSE
('192.168.4.132', 28, 27),
]
for roleta in rolety:
p = Process(target=init_shutter_mode(roleta[0], roleta[1], roleta[2]))
p.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment