|
|

楼主 |
发表于 2024-12-16 18:22:10
|
显示全部楼层
- # -*- coding: UTF-8 -*-
- # MindPlus
- # Python
- import siot
- from unihiker import GUI
- from cfg import *
- import json
- # 自定义函数
- def init():
- # siot.init(client_id="",server=iserver,port=iport,user=iuser,password=ipwd)
- siot.init(CLIENT_ID, SERVER, user=IOT_UserName, password=IOT_PassWord, port=IOT_PORT)
- siot.connect()
- siot.loop()
- siot.getsubscribe(IOT_TOPIC)
- siot.set_callback(on_message_callback)
-
- def siotpub(msg):
- # print("程序开始")
- siot.init(CLIENT_ID, SERVER, user=IOT_UserName, password=IOT_PassWord, port=IOT_PORT) # 初始化MQTT参数
- # 连接MQTT服务器
- siot.connect()
- print(msg)
- siot.getsubscribe(IOT_TOPIC)
- # print("连接完成connected")
- siot.publish(IOT_TOPIC, msg) # siot1.0发布信息
- return msg
- def MQTT(ZhuTi, ZuoPin):
- siot.getsubscribe(topic=ZhuTi)
- siot.publish(topic=ZhuTi, data=ZuoPin)
- def GP(msg):
- print(msg)
- return msg
- def FaSong(msg, topic):
- siot.publish(topic=topic, data=msg)
- return msg
- def fun_DongTai(msg):
- # 动态.config(text=msg)
- return msg
- def Rjson(FJson, K):
- fileObj = open(FJson, "r", encoding="UTF8")
- pyObj = json.loads(fileObj.read())
- fileObj.close()
- G_KEY = pyObj
- return (G_KEY[K])
-
- def RJD(Fjson):
- fileObj = open(Fjson, "r", encoding="UTF8")
- pyObj = json.loads(fileObj.read())
- fileObj.close()
- G_KEY = pyObj
- return G_KEY
- # 事件回调函数
- def on_message_callback(client, userdata, msg):
- fun_DongTai(GP((str(msg.payload.decode()))))
- # u_gui1=GUI()
- # 动态=u_gui1.draw_text(text="行空板",x=0,y=0,font_size=20, color="#0000FF")
- # init()
- # siotpub('代码导入调用 ')
- # init('i.37ck.cn',1883,'37ck','20200808')
- # MQTT('37ck/1215','37ck')
- # while True:
- # pass
复制代码
|
|