def camtrigger(monitor, ip, monid, moncodes):
    global host, port, username, password, tz
    if moncodes != 'VideoMotion':
        print(f" - Subscribing to event codes: {moncodes}")
    moncodes = urllib.parse.quote_plus(moncodes)
    cam = Http(ip,
               80,
               username,
               password,
               retries_connection=3,
               timeout_protocol=3.05)
    try:
        ret = cam.command('eventManager.cgi?action=attach&codes=[' + moncodes +
                          ']',
                          timeout_cmd=(3.05, None),
                          stream=True)
        ret.encoding = 'utf-8'
    except:
        print(f" - ERROR - There was an error starting {monitor}.\n")
        # time.sleep(30)
        return

    print(str(datetime.now(tz)) + f" - Firing up: {monitor}")

    try:
        for line in lines(ret, monitor):
            timenow = datetime.now(tz)
            if line.lower().startswith('content-length:'):
                chunk_size = int(line.split(':')[1])
                action = repr(
                    next(
                        ret.iter_content(chunk_size=chunk_size,
                                         decode_unicode=True)))
                if "Start" in action:
                    startrec(monid)
                    print(str(timenow) + f" - {monitor} - Start")
                elif "Stop" in action:
                    stoprec(monid)
                    print(str(timenow) + f" - {monitor} - Stop")
                else:
                    continue
    except KeyboardInterrupt:
        ret.close()
Exemple #2
0
def main():
    if len(sys.argv) != 5:
        print(f'{sys.argv[0]} host port user password')
        sys.exit(1)

    host = sys.argv[1]
    port = sys.argv[2]
    user = sys.argv[3]
    pswd = sys.argv[4]

    cam = Http(host,
               port,
               user,
               pswd,
               retries_connection=1,
               timeout_protocol=3.05)

    print(cam.device_type)
    print(*cam.software_information)
    print(cam.version_http_api)

    ret = cam.command('eventManager.cgi?action=attach&codes=[VideoMotion]',
                      timeout_cmd=(3.05, None),
                      stream=True)
    ret.encoding = 'utf-8'

    try:
        for line in lines(ret):
            if line.lower().startswith('content-length:'):
                chunk_size = int(line.split(':')[1])
                print(
                    datetime.now().replace(microsecond=0),
                    repr(
                        next(
                            ret.iter_content(chunk_size=chunk_size,
                                             decode_unicode=True))),
                )
    except KeyboardInterrupt:
        ret.close()
        print(' Done!')
Exemple #3
0
def main():
    global config, camera, user, pswd, host, port, ad110, biurl, bicred

    cam = Http(host,
               port,
               user,
               pswd,
               retries_connection=1,
               timeout_protocol=3.05)
    ret = cam.command(
        'eventManager.cgi?action=attach&codes=[VideoMotion, CrossLineDetection, CrossRegionDetection, _DoTalkAction_]',
        timeout_cmd=(3.05, None),
        stream=True)  # Will pull just these events
    #	ret = cam.command('eventManager.cgi?action=attach&codes=[All]', timeout_cmd=(3.05, None), stream=True)
    ret.encoding = 'utf-8'

    for line in lines(ret):
        code = ''
        action = ''
        index = ''
        QOS = 2
        m = re.search('Code=(.*?);', line)
        if m:
            line = line.replace('\n', '')
            print("-----")
            print(line)
            print("-----")
            code = m.group(1)

        m2 = re.search('action=(.*?);', line)
        if m2:
            action = m2.group(1)
        m3 = re.search('index=(.*?);', line)
        if m3:
            index = m3.group(1)
        m4 = re.search(';data={(.*)}', line, flags=re.S)
        if m4:
            data = m4.group(1).replace('\n', '')
            data = f'{{ {data} }}'
            obj = json.loads(data)

        if code == '_DoTalkAction_':
            print("-----")
            print(line)
            print("-----")
            print(obj['Action'])
            if obj['Action'] == 'Invite':
                print("Button Pressed")
                client.publish(basetopic + '/' + camera + '/button', 'on', QOS,
                               False)
            elif obj['Action'] == 'Hangup':
                print("Button Cancelled")
                client.publish(basetopic + '/' + camera + '/button', 'off',
                               QOS, False)

        elif code == 'AlarmLocal':
            ##			global recording
            if action == 'Start':
                print(datetime.now().replace(microsecond=0),
                      ' - Doorbell Motion Start')
            elif action == 'Stop':
                print(datetime.now().replace(microsecond=0),
                      ' - Doorbell Motion Stop')

        elif code == 'VideoMotion' and not ad110:
            if action == 'Start':
                print(datetime.now().replace(microsecond=0), ' - Motion Start')
            elif action == 'Stop':
                print(datetime.now().replace(microsecond=0), ' - Motion Stop')

        elif code == 'CrossLineDetection':
            if action == 'Start':
                print(datetime.now().replace(microsecond=0),
                      ' - Intrusion Start (' + obj['Name'] + ')')
                #				response = requests.get(biurl+"/admin?camera="+camera+"&trigger&flagalert=1&"+bicred)#memo=IVS&"+bicred)
                client.publish(
                    basetopic + '/' + camera + '/ivs/' + obj['Name'], 'on',
                    QOS, False)
            elif action == 'Stop':
                print(datetime.now().replace(microsecond=0),
                      ' - Intrusion Stop (' + obj['Name'] + ')')
                client.publish(
                    basetopic + '/' + camera + '/ivs/' + obj['Name'], 'off',
                    QOS, False)

        elif code == 'CrossRegionDetection':
            if action == 'Start':
                print(datetime.now().replace(microsecond=0),
                      ' - Region Start (' + obj['Name'] + ')')
                #				response = requests.get(biurl+"/admin?camera="+camera+"&trigger&flagalert=1&"+bicred)#memo=IVS&"+bicred)
                client.publish(
                    basetopic + '/' + camera + '/ivs/' + obj['Name'], 'on',
                    QOS, False)
            elif action == 'Stop':
                print(datetime.now().replace(microsecond=0),
                      ' - Region Stop (' + obj['Name'] + ')')
                client.publish(
                    basetopic + '/' + camera + '/ivs/' + obj['Name'], 'off',
                    QOS, False)
Exemple #4
0
basetopic = ""  #whatever first trunk topic you want to use (homeassistant) with NO "/"
biurl = "http://192.168.10.201:81"
bicred = "user=george&pw=Yellow1997"
broker_address = "192.168.10.201"

client.connected_flag = False
client.on_connect = on_connect
client.connect(broker_address)
client.loop_start()
while not client.connected_flag:
    time.sleep(1)

if ad110:
    cam = Http(host,
               port,
               user,
               pswd,
               retries_connection=1,
               timeout_protocol=3.05)
    ret = cam.command(
        'configManager.cgi?action=setConfig&Lighting[0] [0].Mode=Off',
        timeout_cmd=(3.05, None),
        stream=False)
    if ret.status_code == requests.codes.ok:
        print("Night Vision Disabled...")


def main():
    global config, camera, user, pswd, host, port, ad110, biurl, bicred

    cam = Http(host,
               port,
def main():
    global config, camera, user, pswd, host, port, ad110, biurl, bicred

    cam = Http(host,
               port,
               user,
               pswd,
               retries_connection=1,
               timeout_protocol=3.05)
    # 	ret = cam.command('eventManager.cgi?action=attach&codes=[VideoMotion,CrossLineDetection,CrossRegionDetection,_DoTalkAction_]', timeout_cmd=(3.05, None), stream=True) # Will pull just these events
    ret = cam.command(
        "eventManager.cgi?action=attach&codes=[All]",
        timeout_cmd=(3.05, None),
        stream=True,
    )
    ret.encoding = "utf-8"

    for line in lines(ret):
        code = ""
        action = ""
        index = ""
        QOS = 2
        m = re.search("Code=(.*?);", line)
        if m:
            line = line.replace("\n", "")
            ##			print("-----")
            ##			print(line)
            ##			print("-----")
            code = m.group(1)

        m2 = re.search("action=(.*?);", line)
        if m2:
            action = m2.group(1)
        m3 = re.search("index=(.*?);", line)
        if m3:
            index = m3.group(1)
        m4 = re.search(";data={(.*)}", line, flags=re.S)
        if m4:
            data = m4.group(1).replace("\n", "")
            data = f"{{ {data} }}"
            obj = json.loads(data)

        if code == "_DoTalkAction_":
            # 			print("-----")
            # 			print(line)
            # 			print("-----")
            # 			print(obj['Action'])
            if obj["Action"] == "Invite":
                print(datetime.now().replace(microsecond=0), "Button Pressed")
                client.publish(basetopic + "/" + camera + "/button", "on", QOS,
                               False)
            elif obj["Action"] == "Hangup":
                print(datetime.now().replace(microsecond=0),
                      "Button Cancelled")
                client.publish(basetopic + "/" + camera + "/button", "off",
                               QOS, False)

        elif code == "AlarmLocal":
            # 			global recording (in case I decide to manually control recording)
            if action == "Start":
                print(datetime.now().replace(microsecond=0),
                      " - Doorbell Motion Start")
            elif action == "Stop":
                print(datetime.now().replace(microsecond=0),
                      " - Doorbell Motion Stop")

        elif code == "VideoMotion" and not ad110:
            if action == "Start":
                print(datetime.now().replace(microsecond=0), " - Motion Start")
            elif action == "Stop":
                print(datetime.now().replace(microsecond=0), " - Motion Stop")

        elif code == "CrossLineDetection":
            if action == "Start":
                print(
                    datetime.now().replace(microsecond=0),
                    " - Intrusion Start (" + obj["Name"] + ")",
                )
                # 				response = requests.get(biurl+"/admin?camera="+camera+"&trigger&flagalert=1&"+bicred)#memo=IVS&"+bicred)
                client.publish(
                    basetopic + "/" + camera + "/ivs/" + obj["Name"], "on",
                    QOS, False)
            elif action == "Stop":
                print(
                    datetime.now().replace(microsecond=0),
                    " - Intrusion Stop (" + obj["Name"] + ")",
                )
                client.publish(
                    basetopic + "/" + camera + "/ivs/" + obj["Name"], "off",
                    QOS, False)

        elif code == "CrossRegionDetection":
            if action == "Start":
                print(
                    datetime.now().replace(microsecond=0),
                    " - Region Start (" + obj["Name"] + ")",
                )
                # 				response = requests.get(biurl+"/admin?camera="+camera+"&trigger&flagalert=1&"+bicred)#memo=IVS&"+bicred)
                client.publish(
                    basetopic + "/" + camera + "/ivs/" + obj["Name"], "on",
                    QOS, False)
            elif action == "Stop":
                print(
                    datetime.now().replace(microsecond=0),
                    " - Region Stop (" + obj["Name"] + ")",
                )
                client.publish(
                    basetopic + "/" + camera + "/ivs/" + obj["Name"], "off",
                    QOS, False)
Exemple #6
0
def main():
    if len(sys.argv) not in (5, 6):
        print(f'{sys.argv[0]} host port user password [log]')
        sys.exit(1)

    host = sys.argv[1]
    port = sys.argv[2]
    user = sys.argv[3]
    pswd = sys.argv[4]
    log = len(sys.argv) == 6
    if log:
        logging.basicConfig(
            level=logging.DEBUG,
            format="%(asctime)s %(levelname)s: %(name)s: %(message)s",
        )
        urllib3_logger = logging.getLogger("urllib3.connectionpool")
        if not any(
                isinstance(x, NoHeaderErrorFilter)
                for x in urllib3_logger.filters):
            urllib3_logger.addFilter(NoHeaderErrorFilter())

    cam = Http(host,
               port,
               user,
               pswd,
               retries_connection=1,
               timeout_protocol=3.05)

    dev_type = cam.device_type
    if log:
        print()
    print(dev_type.strip())
    if log:
        print()

    sw_info = cam.software_information
    if log:
        print()
    for info in sw_info:
        print(info.strip())
    if log:
        print()

    ver_http = cam.version_http_api
    if log:
        print()
    print(ver_http.strip())
    if log:
        print()

    ret = cam.command('eventManager.cgi?action=attach&codes=[VideoMotion]',
                      timeout_cmd=(3.05, None),
                      stream=True)
    ret.encoding = 'utf-8'
    print()

    try:
        for line in lines(ret):
            if line.lower().startswith('content-length:'):
                chunk_size = int(line.split(':')[1])
                print(
                    datetime.now().replace(microsecond=0),
                    repr(
                        next(
                            ret.iter_content(chunk_size=chunk_size,
                                             decode_unicode=True))),
                )
    except KeyboardInterrupt:
        ret.close()
        print(' Done!')