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

相关推荐
麦兜*4 小时前
Spring Boot集成方案 + Elasticsearch向量检索,语义搜索核弹
java·spring boot·python·spring·elasticsearch·spring cloud·系统架构
仪器科学与传感技术博士4 小时前
python:讲懂决策树,为理解随机森林算法做准备,以示例带学习,通俗易懂,容易理解和掌握
python·算法·决策树
歪歪1004 小时前
HTML 如何转 Markdown
开发语言·chrome·python·程序人生·html
小坏坏的大世界4 小时前
C++中多线程和互斥锁的基本使用
开发语言·c++
路由侠内网穿透5 小时前
本地部署 SQLite 数据库管理工具 SQLite Browser ( Web ) 并实现外部访问
运维·服务器·开发语言·前端·数据库·sqlite
王者鳜錸5 小时前
PYTHON从入门到实践-18Django模版渲染
开发语言·python·django
Hard but lovely5 小时前
C++ STL--> vector的模拟实现!
开发语言·c++
hweiyu005 小时前
IDEA搭建GO环境
开发语言·后端·golang·intellij-idea·idea·intellij idea
归辞...6 小时前
「iOS」————单例与代理
开发语言·javascript·ios
l1t6 小时前
利用DeepSeek改写并增强测试Duckdb和sqlite的不同插入方法性能
python·sql·sqlite·duckdb