Skip to content

Commit

Permalink
Merge pull request #26 from mchadwick-iqt/main
Browse files Browse the repository at this point in the history
Add in Fix for PTZ Lockup
  • Loading branch information
mchadwick-iqt committed Jun 28, 2022
2 parents 64e5084 + 8ccc2ef commit 96eb9ad
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions axis-ptz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
cameraDelay = None
cameraLead = 0
active = False
Active = True

object_topic = None
flight_topic = None
Expand Down Expand Up @@ -344,6 +345,13 @@ def on_message_impl(client, userdata, message):
else:
logging.info("Message: {} Object: {} Flight: {}".format(message.topic, object_topic, flight_topic))


def on_disconnect(client, userdata, rc):
global Active
Active = False
logging.error("Axis-PTZ MQTT Disconnect!")


def main():
global args
global logging
Expand All @@ -359,6 +367,7 @@ def main():
global cameraConfig
global flight_topic
global object_topic
global Active

parser = argparse.ArgumentParser(description='An MQTT based camera controller')
parser.add_argument('--lat', type=float, help="Latitude of camera")
Expand Down Expand Up @@ -407,7 +416,8 @@ def main():
camera_lead = args.camera_lead
#cameraConfig = vapix_config.CameraConfiguration(args.axis_ip, args.axis_username, args.axis_password)

threading.Thread(target=moveCamera, args=[args.axis_ip, args.axis_username, args.axis_password],daemon=True).start()
cameraMove = threading.Thread(target=moveCamera, args=[args.axis_ip, args.axis_username, args.axis_password],daemon=True)
cameraMove.start()
# Sleep for a bit so we're not hammering the HAT with updates
delay = 0.005
time.sleep(delay)
Expand All @@ -417,6 +427,7 @@ def main():
client = mqtt.Client("skyscan-axis-ptz-camera-" + ID) #create new instance

client.on_message=on_message #attach function to callback
client.on_disconnect = on_disconnect

client.connect(args.mqtt_host) #connect to broker
client.loop_start() #start the loop
Expand All @@ -430,10 +441,14 @@ def main():
## Main Loop ##
#############################################
timeHeartbeat = 0
while True:
while Active:
if timeHeartbeat < time.mktime(time.gmtime()):
timeHeartbeat = time.mktime(time.gmtime()) + 10
client.publish("skyscan/heartbeat", "skyscan-axis-ptz-camera-"+ID+" Heartbeat", 0, False)
if not cameraMove.is_alive():
logging.critical("Thread within Axis-PTZ has failed! Killing container.")
Active=False

delay = 0.1
time.sleep(delay)

Expand Down

0 comments on commit 96eb9ad

Please sign in to comment.