You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.4 KiB

3 years ago
import time
import zmq
import json
context = zmq.Context()
pubSocket = context.socket(zmq.PUB)
pubSocket.connect('tcp://127.0.0.1:5001')
# pubSocket.SendMoreFrame("Topic").SendFrame("Pub from python")
#pubSocket.send_multipart(['Topic', 'Pub from python'])
# while True:
# msg = input("请输入要发布的信息:").strip()
# if msg == 'b':
# sys.exit()
# #socket.send(msg.encode('utf-8'))
# # socket.send_multipart('Topic'.encode('utf-8')) # 接收所有消息
# #socket.send( 'Topic Pub from python'.encode('utf-8'))
# pubSocket.send_multipart(['Show_Single_Video001'.encode('utf-8'), '192.168.1.65'.encode('utf-8')])
# time.sleep(1)
def sendcount(detectionmodel):
detectionmodel["datetime"]=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
resultjson= json.dumps(detectionmodel, ensure_ascii=False)#listToJson(tolist)
print("发送消息:",resultjson)
# topic='ai_detect_warning_data'
topic='ai_detect_count'
pubSocket.send_multipart([topic.encode('utf-8'), resultjson.encode('utf-8')])
def sendcwarning(detectionmodel):
detectionmodel["datetime"]=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
resultjson= json.dumps(detectionmodel, ensure_ascii=False)#listToJson(tolist)
print("发送消息:",resultjson)
# topic='ai_detect_warning_data'
topic='ai_detect_warning'
pubSocket.send_multipart([topic.encode('utf-8'), resultjson.encode('utf-8')])