Skip to content

How to enable logging for non-Python programmers? #15

Description

@jcwren

I'm using the script below, and while it connects to the Camect and get the name, I'm not seeing any events when the cameras are triggered. The Camect is sending email and telegram notices, so it's definitely seeing the camera events, they just don't seem to be getting through the Python interface. I'd like to set the logging level to DEBUG, but I have no idea how this works in Python.

import camect
import time
import paho.mqtt.client as mqtt

camect_host="camect.local:443"
camect_passwd="xxx"
camect_user="admin"

mqtt_host="localhost"
mqtt_port=1883
mqtt_user=None
mqtt_passwd=None
mqtt_topic="camect"

def post_event_to_mqtt(client, evt):
    if evt["type"] == "alert":
        client.publish(mqtt_topic+"/motion", evt["cam_name"])
    else:
        print(evt)

# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected to MQTT server with result code "+str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("$SYS/#")


def on_log(mqttc, obj, level, string):
    print(string)

# Connect to mqtt
client = mqtt.Client()
client.on_connect = on_connect
#client.on_log = on_log

client.connect(mqtt_host, mqtt_port, 60)

home = camect.Home(camect_host, camect_user, camect_passwd)
home.add_event_listener(lambda evt: post_event_to_mqtt(client,evt))
print("Camect name is '%s'" % home.get_name())
client.loop_forever()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions