物联网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

相关推荐
belldeep2 小时前
python:genesis-world, Genesis-Embodied-AI
人工智能·python·ai·genesis
布莱克6052 小时前
C/C++ 中变量的声明与定义:区别、联系与常见误区
c语言·开发语言·c++·声明·定义
LabVIEW开发3 小时前
LabVIEW 局部变量为何引发竞争条件?四种同步机制
开发语言·labview
benchmark_cc3 小时前
A 股、港股、美股如何建立统一的标的主数据格式?
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
维克兜率天4 小时前
【维克】趋势型CTA:期货市场的“追涨杀跌“
人工智能·python
Zenova EdgeOS4 小时前
Go 工业边缘错误处理实战:用 errors 构建可追溯错误链
开发语言·数据库·golang
取名真是5 小时前
Python 算法知识点从基础到进阶
开发语言·python·算法
梦想不只是梦与想5 小时前
PyTorch、CPU、GPU、CUDA
人工智能·pytorch·python·深度学习·机器学习·cuda
数字融合5 小时前
透明化视频孪生危化安全管控解决方案
人工智能·python·安全
FRing035 小时前
vue2干货总结3(computed计算属性、watch监听器)
开发语言·前端·vue.js·vue2