Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in Fix for PTZ Lockup #26

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add in Fix for PTZ Lockup
Corrected for a condition where the thread would fail and not notify the container that it had failed.  Currently system is set to kill the container and reboot if the thread fails.
  • Loading branch information
mchadwick-iqt committed Jun 28, 2022
commit 8ccc2ef989182753c789524843202f0237746b3d
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