from hub import methods, Global import threading import time import json class PotDataMessageListener(object): @staticmethod def decorate_method(client, userdata, message): """消息处理方法""" try: # --- update --- """ PotData: 渣罐数据 PotData.pot_name: 渣罐别称(例: M.24) PotData.pot_x: 坐标值 PotData.pot_y: 坐标值 PotData.mark_pot_pose: 渣罐姿态 """ message = json.loads(message.payload) unique_dict = {'pot_name': message.get('pot_name')} update_dict = { 'pot_x': message.get('pot_x'), 'pot_y': message.get('pot_y'), 'mark_pot_pose': message.get('mark_pot_pose'), } Global.mdb.update_one('PotData', unique_dict, update_dict) methods.debug_log(f"PotDataMessageListener.30", f"#message: {message}") except Exception as exception: methods.debug_log('PotDataMessageListener.33', f"#exception: {exception}") methods.debug_log('PotDataMessageListener.33', f"#traceback: {methods.trace_log()}") @classmethod def start_check_loop(cls): """启动循环""" """ topic: hs/pot/data message.name: 渣罐名称 message.pot_x: 坐标值 message.pot_y: 坐标值 message.mark_pot_pose: 渣罐姿态 """ Global.mq02.start_subscribe_loop( decorate_method=PotDataMessageListener.decorate_method, subscribe_topic='hs/pot/data' ) @classmethod def run_background(cls, background_is=True): """启动现成""" p1 = threading.Thread(target=cls.start_check_loop) p1.start() if __name__ == '__main__': # --- test --- MessageListener.run_background()