Hopefully this helps. I had a similar issue a while ago and Erik helped me with similar advice. This is what I did.
needtoreinitialize starts as 'True'.
I catch the exceptions from my overarching loop and set the needtoreinitialize variable back to True. Then at the top of that loop I check to make sure I don't need to re-initialize the camera (PoE).
` found, device_info = dai.Device.getDeviceByMxId(self.OakID)
needtoreinitialize = True
device = qPreview = None
recoveryattempts = 0
while needtoreinitialize:
try:
device = dai.Device(pipeline, device_info)
preview = device.getOutputQueue(name=rgb_str, maxSize=2, blocking=False)
qDet = device.getOutputQueue(name=nns_str, maxSize=2, blocking=False)
needtoreinitialize = False
recoveryattempts = 0
except Exception as exception:
exc_type, exc_obj, exc_tb = sys.exc_info()
print(str(exc_type)+" "+str(exc_tb.tb_lineno))
self.oaklogging.error("<b>"+self.camlogident+"_Oakcam has encountered an error, reconnection attempt: "+str(recoveryattempts)+"</b>")
recoveryattempts += 1`