物联网python996655

这里写自定义目录标题

物联网采集信息并显示

去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

javascript 复制代码
// An highlighted block



import json
import sys
import time,threading

from PyQt5 import QtGui

from un import Ui_MainWindow
import requests
from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

def th():                             #清空图片
    time.sleep(2)
    ui.label_6.setPixmap(QtGui.QPixmap())

class MyThread(QThread):
    xh=pyqtSignal(float)         #信号,前端后端交互
    def __init__(self):
        super().__init__()

    def run(self):
        while True:
            re = requests.get("http://api.nlecloud.com/devices/805914/datas?apitags=wendu",{"AccessToken":"13FC4C33875167C89DD1B351C0732B011BA5D85A4B799AA439F3895CCC46411307A75CCC63E68D9C18FD73C5778264B28556CDFCF7C44B7BABBAB978E76089CA6FE0B0F398BB1D46E878532B5D3C12AE43905256B79CEB95B9054D01FC721D7910D502C53917AAD93ECC6E1D62CFAB04E3A8B8BEA7C66E0B671FB4103C48FBFB43B368DBDB7FC6C79CB637DD5009C102D1475DC754BEB7F7075A6B646EF98639E132F523B3568D904E75C479597FF8365DE080F5F9D8F65D8232701C82C864351720C2CB899FEA1D49B4F03CE8105BA257A32F4E24D3830B9F5CC0741B48939A"})
            str1=json.loads(re.text)
            s1 = str1.get("ResultObj").get("DataPoints")[0].get("PointDTO")[0].get("Value")
            print(s1)
            if float(s1)<20 :
                ui.label_4.setPixmap(QtGui.QPixmap(".png"))
                ui.label_5.setText('危险')
            elif float(s1)>30:
                ui.label_4.setPixmap(QtGui.QPixmap(".png"))
                ui.label_5.setText('告警')
            else:
                ui.label_4.setPixmap(QtGui.QPixmap("开花.png"))
                ui.label_5.setText('正常')
            self.xh.emit(s1)                        #把信号发送出去
            time.sleep(10)

    def gx(self,date):
        s1=str(date)+'%RH'
        ui.label_3.setText(s1)

    def jh(self):                  #  显示图片
            ui.label_6.setPixmap(QtGui.QPixmap("浇水.png"))
            t=threading.Thread(target=th)          #延时
            t.start()

if __name__ == '__main__':
    app=QApplication(sys.argv)
    ma=QMainWindow()
    ui =Ui_MainWindow()
    ui.setupUi(ma)
    ma.show()
    m1=MyThread()
    m1.start()
    m1.xh.connect(m1.gx)                     #连接的gx函数,调用
    ui.pushButton.clicked.connect(m1.jh)
    sys.exit(app.exec())         #退出主程序
pyuic5 -o uu.py xx.ui

pip install --no-index --find-links=file:. -r modules.txt
五、ui转py文件 pyuic5 -o out.py out.ui

六、打包 pyinstaller -Fw test.py

import json

import sys

import time,threading

from PyQt5 import QtGui

from un import Ui_MainWindow

import requests

from PyQt5 import *

from PyQt5.QtGui import *

from PyQt5.QtWidgets import *

from PyQt5.QtCore import *

def th(): #清空图片

time.sleep(2)

ui.label_6.setPixmap(QtGui.QPixmap())

class MyThread(QThread):

xh=pyqtSignal(float) #信号,前端后端交互

def init (self):

super().init()

def run(self):

while True:

re = requests.get("http://api.nlecloud.com/devices/805914/datas?apitags=wendu",{"AccessToken":"13FC4C33875167C89DD1B351C0732B011BA5D85A4B799AA439F3895CCC46411307A75CCC63E68D9C18FD73C5778264B28556CDFCF7C44B7BABBAB978E76089CA6FE0B0F398BB1D46E878532B5D3C12AE43905256B79CEB95B9054D01FC721D7910D502C53917AAD93ECC6E1D62CFAB04E3A8B8BEA7C66E0B671FB4103C48FBFB43B368DBDB7FC6C79CB637DD5009C102D1475DC754BEB7F7075A6B646EF98639E132F523B3568D904E75C479597FF8365DE080F5F9D8F65D8232701C82C864351720C2CB899FEA1D49B4F03CE8105BA257A32F4E24D3830B9F5CC0741B48939A"})

str1=json.loads(re.text)

s1 = str1.get("ResultObj").get("DataPoints")0.get("PointDTO")0.get("Value")

print(s1)

if float(s1)<20 :

ui.label_4.setPixmap(QtGui.QPixmap(".png"))

ui.label_5.setText('危险')

elif float(s1)>30:

ui.label_4.setPixmap(QtGui.QPixmap(".png"))

ui.label_5.setText('告警')

else:

ui.label_4.setPixmap(QtGui.QPixmap("开花.png"))

ui.label_5.setText('正常')

self.xh.emit(s1) #把信号发送出去

time.sleep(10)

def gx(self,date):

s1=str(date)+'%RH'

ui.label_3.setText(s1)

def jh(self): # 显示图片

ui.label_6.setPixmap(QtGui.QPixmap("浇水.png"))

t=threading.Thread(target=th) #延时

t.start()

if name == 'main ':

app=QApplication(sys.argv)

ma=QMainWindow()

ui =Ui_MainWindow()

ui.setupUi(ma)

ma.show()

m1=MyThread()

m1.start()

m1.xh.connect(m1.gx) #连接的gx函数,调用

ui.pushButton.clicked.connect(m1.jh)

sys.exit(app.exec()) #退出主程序

pyuic5 -o uu.py xx.ui

pip install --no-index --find-links=file:. -r modules.txt

五、ui转py文件 pyuic5 -o out.py out.ui

六、打包 pyinstaller -Fw test.py

相关推荐
多加点辣也没关系2 小时前
JavaScript|第41章:性能优化实战
开发语言·javascript·性能优化
BD_Marathon3 小时前
安装Jupyter notebook
ide·python·jupyter
Zlzxzw3 小时前
End-to-End Autonomous Generation of Human Assembly Plans
python
Resean02233 小时前
架构设计系列(十六):DDD 与代码架构
java·开发语言·架构
Wellijohn3 小时前
2000 个请求、30% 失败率:我把 Python 批量并发的限流和重试参数算了一遍
后端·python·性能优化
码途行者4 小时前
每天10分钟学Go:第22课 自定义错误
开发语言·后端·golang
23图4 小时前
C 语言开散列表(拉链法)拆解:链挂得没错,key=-1 会去读 T[-1]
c语言·开发语言·散列表
feixing_fx5 小时前
解构与展开:可读性和性能的取舍
开发语言·前端·javascript·前端框架
小飞在努力5 小时前
【实现负载均匀在线判题③】从零散模块到统一,编译运行全链路封装
c语言·开发语言·c++·笔记
Logintern095 小时前
deep agents 多智能体模式——规划与委派
python·langchain