37创客科创中心

 找回密码
 立即注册
查看: 1204|回复: 1

241215 外调程序

[复制链接]

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
发表于 2024-12-15 11:40:18 | 显示全部楼层 |阅读模式

py程序文件

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
 楼主| 发表于 2024-12-16 18:22:10 | 显示全部楼层
  1. #  -*- coding: UTF-8 -*-

  2. # MindPlus
  3. # Python
  4. import siot
  5. from unihiker import GUI
  6. from cfg import *
  7. import json


  8. # 自定义函数
  9. def init():
  10.     # siot.init(client_id="",server=iserver,port=iport,user=iuser,password=ipwd)
  11.     siot.init(CLIENT_ID, SERVER, user=IOT_UserName, password=IOT_PassWord, port=IOT_PORT)
  12.     siot.connect()
  13.     siot.loop()
  14.     siot.getsubscribe(IOT_TOPIC)
  15.     siot.set_callback(on_message_callback)
  16.    
  17. def siotpub(msg):
  18.     # print("程序开始")
  19.     siot.init(CLIENT_ID, SERVER, user=IOT_UserName, password=IOT_PassWord, port=IOT_PORT)  # 初始化MQTT参数
  20.     # 连接MQTT服务器
  21.     siot.connect()
  22.     print(msg)
  23.     siot.getsubscribe(IOT_TOPIC)
  24.     # print("连接完成connected")
  25.     siot.publish(IOT_TOPIC, msg)  # siot1.0发布信息
  26.     return msg

  27. def MQTT(ZhuTi, ZuoPin):   
  28.     siot.getsubscribe(topic=ZhuTi)
  29.     siot.publish(topic=ZhuTi, data=ZuoPin)
  30. def GP(msg):
  31.     print(msg)
  32.     return msg
  33. def FaSong(msg, topic):
  34.     siot.publish(topic=topic, data=msg)
  35.     return msg
  36. def fun_DongTai(msg):
  37.     # 动态.config(text=msg)
  38.     return msg

  39. def Rjson(FJson, K):
  40.     fileObj = open(FJson, "r", encoding="UTF8")
  41.     pyObj = json.loads(fileObj.read())
  42.     fileObj.close()
  43.     G_KEY = pyObj
  44.     return (G_KEY[K])
  45.    
  46. def RJD(Fjson):
  47.     fileObj = open(Fjson, "r", encoding="UTF8")
  48.     pyObj = json.loads(fileObj.read())
  49.     fileObj.close()
  50.     G_KEY = pyObj
  51.     return G_KEY

  52. # 事件回调函数
  53. def on_message_callback(client, userdata, msg):
  54.     fun_DongTai(GP((str(msg.payload.decode()))))



  55. # u_gui1=GUI()
  56. # 动态=u_gui1.draw_text(text="行空板",x=0,y=0,font_size=20, color="#0000FF")
  57. # init()
  58. # siotpub('代码导入调用 ')
  59. # init('i.37ck.cn',1883,'37ck','20200808')
  60. # MQTT('37ck/1215','37ck')
  61. # while True:
  62. #     pass
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|37创客科创中心

GMT+8, 2025-12-10 05:10 , Processed in 0.153436 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表