Update
parent
af20c5f964
commit
7107c3a156
|
|
@ -15,12 +15,15 @@ class Camera:
|
||||||
|
|
||||||
def healthbeat(self):
|
def healthbeat(self):
|
||||||
try:
|
try:
|
||||||
|
# 摄像头状态: 1 在线, 2 离线
|
||||||
|
status = 2
|
||||||
|
|
||||||
cap = cv2.VideoCapture(self.rtsp)
|
cap = cv2.VideoCapture(self.rtsp)
|
||||||
|
if cap.isOpened():
|
||||||
ret, _ = cap.read()
|
ret, _ = cap.read()
|
||||||
cap.release()
|
cap.release()
|
||||||
|
if ret == True:
|
||||||
# 摄像头状态: 1 在线, 2 离线
|
status = 1
|
||||||
status = 1 if ret == True else 2
|
|
||||||
|
|
||||||
if status == 1:
|
if status == 1:
|
||||||
logging.info("摄像头ID: %s, 状态: 在线" % (self.id))
|
logging.info("摄像头ID: %s, 状态: 在线" % (self.id))
|
||||||
|
|
@ -32,7 +35,7 @@ class Camera:
|
||||||
|
|
||||||
with conn:
|
with conn:
|
||||||
with conn.cursor() as cursor:
|
with conn.cursor() as cursor:
|
||||||
cursor.execute("update devices set status = %s, updated_at = %s where id = %s", (status, self.id, datetime.datetime.now()))
|
cursor.execute("update devices set status = %s, updated_at = %s where id = %s", (status, datetime.datetime.now(), self.id))
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue