国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

15、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(11)

這篇具有很好參考價值的文章主要介紹了15、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(11)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

源碼將于最后一遍文章給出下載

  1. 監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(10)

程序自動更新開發(fā)

前面章節(jié)寫了部分功能模塊開發(fā):

  1. 日志或文本文件讀寫開發(fā);
  2. Sqlite3數(shù)據(jù)庫讀寫操作開發(fā);
  3. 定時器插件化開發(fā);
  4. 串口(COM)通訊開發(fā);
  5. TCP/IP Client開發(fā);
  6. TCP/IP Server 開發(fā);
  7. modbus協(xié)議開發(fā);

本章節(jié)啰嗦些,該解決方案最終業(yè)務(wù)成品有些需要部署在不同工控機(jī)或設(shè)備上,在實(shí)際應(yīng)用過程中隨時間推移有些需要升級迭代或修改bug,一旦安裝部署設(shè)備點(diǎn)位達(dá)到一定數(shù)量,系統(tǒng)自動更新升級就是一個必要的步驟了。筆者開發(fā)的業(yè)務(wù)應(yīng)用在相應(yīng)的設(shè)備上安裝已近千臺設(shè)備,鑒于此增加了程序自動更新功能模塊。

com.zxy.common.Com_Para.py中添加如下內(nèi)容

#自動更新服務(wù)端文件夾地址
urlPath = ""
#程序版本號
version = ""

新建程序版本自動更新類com.zxy.autoUpdate.GetVersion.py
?

#! python3
# -*- coding: utf-8 -
'''
Created on 2017年05月10日
@author: zxyong 13738196011
'''

import urllib.request,datetime
from com.zxy.adminlog.UsAdmin_Log import UsAdmin_Log
from com.zxy.common import Com_Para
from com.zxy.common.Com_Fun import Com_Fun
from com.zxy.interfaceReflect.A01_A1B2C3 import A01_A1B2C3
from com.zxy.z_debug import z_debug
from urllib.parse import urlparse

#監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用--程序版本自動更新類
class GetVersion(z_debug):

? ? def __init__(self):
? ? ? ? pass
? ??
? ? #下載文件
? ? def SaveRemoteFile(self,inputFileName,inputLocalFileName):
? ? ? ? try:
? ? ? ? ? ? temResult = urllib.request.urlretrieve(Com_Para.urlPath+"/"+inputFileName,Com_Para.ApplicationPath+Com_Para.zxyPath+inputLocalFileName)
? ? ? ? except Exception as e:
? ? ? ? ? ? if str(type(self)) == "<class 'type'>":
? ? ? ? ? ? ? ? self.debug_in(self,repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
? ? ? ? return temResult
? ??
? ? #保存版本號文件
? ? def SaveVersionFile(self,version_no,inputLocalFileName):
? ? ? ? temStrTFileName = Com_Para.ApplicationPath+Com_Para.zxyPath+inputLocalFileName
? ? ? ? temFile = None
? ? ? ? try:?
? ? ? ? ? ? temFile = open(temStrTFileName, 'w',encoding=Com_Para.U_CODE)
? ? ? ? ? ? temFile.write(version_no)
? ? ? ? ? ? temFile.close()
? ? ? ? except Exception as e:
? ? ? ? ? ? if str(type(self)) == "<class 'type'>":
? ? ? ? ? ? ? ? self.debug_in(self,repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
? ? ? ? finally:
? ? ? ? ? ? if temFile != None:
? ? ? ? ? ? ? ? temFile.close()
? ? ? ? ? ??
? ? #檢測最新版本
? ? def CheckVersion(self):
? ? ? ? try:
? ? ? ? ? ? print("check new version..."+Com_Fun.GetTimeDef())
? ? ? ? ? ? #讀取服務(wù)器端version.txt信息
? ? ? ? ? ? temResult = self.GetRequestWeb()
? ? ? ? ? ? if temResult == "":
? ? ? ? ? ? ? ? return 0
? ? ? ? ? ? temUL = UsAdmin_Log(Com_Para.ApplicationPath,temResult,0)
? ? ? ? ? ? #文件形式版本號管理
? ? ? ? ? ? temVersion = temUL.ReadFile(Com_Para.ApplicationPath+Com_Para.zxyPath + "version.txt")
? ? ? ? ? ? Com_Para.version = temVersion
? ? ? ? ? ? #數(shù)據(jù)庫形式版本號管理
? ? ? ? ? ? temVersion = Com_Para.version
? ? ? ? ? ? temAryTem = []
? ? ? ? ? ? temVersion_No = ""
? ? ? ? ? ? temLastFile = ""
? ? ? ? ? ? #判斷文件是否存在
? ? ? ? ? ? if temVersion == "" and temResult != "":
? ? ? ? ? ? ? ? print("local version none,downloading new version")
? ? ? ? ? ? ? ? temAryTem = temResult.split("\n")
? ? ? ? ? ? ? ? for temLine in temAryTem:
? ? ? ? ? ? ? ? ? ? temLine = temLine.replace("\r","").replace("\n","")
? ? ? ? ? ? ? ? ? ? temLastFile = temLine
? ? ? ? ? ? ? ? ? ? if temLine.find("version=") != -1:
? ? ? ? ? ? ? ? ? ? ? ? temVersion_No = temLine
? ? ? ? ? ? ? ? ? ? elif temLine != "":
? ? ? ? ? ? ? ? ? ? ? ? print("new version file download:"+temLine)
? ? ? ? ? ? ? ? ? ? ? ? self.SaveRemoteFile(temLine,"back/"+temLine)
? ? ? ? ? ? ? ? ? ? ? ? self.CopyFile(temLine)
? ? ? ? ? ? ? ? ? ? ? ? if temVersion_No != "":
? ? ? ? ? ? ? ? ? ? ? ? ? ? #文件形式版本管理 ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.SaveVersionFile(temVersion_No,"version.txt")
? ? ? ? ? ? ? ? ? ? ? ? ? ? #數(shù)據(jù)庫形式版本文件管理
? ? ? ? ? ? ? ? ? ? ? ? ? ? #將版本號insert入庫 該處代碼省略....
? ? ? ? ? ? ? ? ? ? ? ? ? ? Com_Para.version = temVersion_No ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? print("new version updated over:")
? ? ? ? ? ? ? ? ? ? ? ? #如果讀到reboot.txt則需要重啟設(shè)備
? ? ? ? ? ? ? ? ? ? ? ? if temLastFile.strip() == "reboot.txt":
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.RebootProgram()
? ? ? ? ? ? ? ? ? ? ? ? ? ? return 0
? ? ? ? ? ? ? ? if temVersion_No != "":
? ? ? ? ? ? ? ? ? ? #文件形式版本管理 ? ??
? ? ? ? ? ? ? ? ? ? print("new version updated over:")
? ? ? ? ? ? ? ? ? ? self.SaveVersionFile(temVersion_No,"version.txt")
? ? ? ? ? ? ? ? ? ? #數(shù)據(jù)庫形式版本文件管理
? ? ? ? ? ? ? ? ? ? #將版本號insert入庫 ?該處代碼省略....
? ? ? ? ? ? ? ? ? ? Com_Para.version = temVersion_No
? ? ? ? ? ? elif temResult != "":
? ? ? ? ? ? ? ? #數(shù)據(jù)庫形式版本號管理
# ? ? ? ? ? ? ? ? localVersion = Com_Para.version
? ? ? ? ? ? ? ? #文件形式版本號管理
? ? ? ? ? ? ? ? temAryTem = temVersion.split("\n")
? ? ? ? ? ? ? ? for temLine in temAryTem:
? ? ? ? ? ? ? ? ? ? temArySub = temLine.split("=")
? ? ? ? ? ? ? ? ? ? if len(temArySub) > 1 and temArySub[0] == "version":
? ? ? ? ? ? ? ? ? ? ? ? localVersion = temArySub[1]
? ? ? ? ? ? ? ? ? ? ? ? break?
? ? ? ? ? ? ? ? bFlag = False
? ? ? ? ? ? ? ? temAryTem = temResult.split("\n")
? ? ? ? ? ? ? ? for temLine in temAryTem:
? ? ? ? ? ? ? ? ? ? temLine = temLine.replace("\r","").replace("\n","")
? ? ? ? ? ? ? ? ? ? temLastFile = temLine
? ? ? ? ? ? ? ? ? ? temArySub = temLine.split("=")
? ? ? ? ? ? ? ? ? ? if len(temArySub) > 1 and temArySub[0] == "version":
? ? ? ? ? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? ? ? ? ? if localVersion.find("=") != -1:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? iLV = int(localVersion.split("=")[1])
? ? ? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? iLV = int(localVersion)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? if localVersion != "" and iLV >= int(temArySub[1]):
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bFlag = False
? ? ? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? temVersion_No = temLine
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bFlag = True
? ? ? ? ? ? ? ? ? ? ? ? except:
? ? ? ? ? ? ? ? ? ? ? ? ? ? bFlag = False
? ? ? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? if bFlag:
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.SaveRemoteFile(temLine,"back/"+temLine)
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.CopyFile(temLine)
? ? ? ? ? ? ? ? ? ? ? ? ? ? if temVersion_No != "":
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #文件形式版本管理 ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? self.SaveVersionFile(temVersion_No,"version.txt")?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #數(shù)據(jù)庫形式版本文件管理 ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #將版本號insert入庫 ?該處代碼省略....
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Com_Para.version = temVersion_No
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? print("new version updated over:"+temVersion_No)
? ? ? ? ? ? ? ? ? ? ? ? ? ? if temLastFile.strip() == "reboot.txt":
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? self.RebootProgram()
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return 0
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? if (bFlag and temVersion_No != ""):
? ? ? ? ? ? ? ? ? ? #文件形式版本管理 ? ??
? ? ? ? ? ? ? ? ? ? self.SaveVersionFile(temVersion_No,"version.txt")
? ? ? ? ? ? ? ? ? ? #數(shù)據(jù)庫形式版本文件管理 ?
? ? ? ? ? ? ? ? ? ? #將版本號insert入庫 ?該處代碼省略....
? ? ? ? ? ? ? ? ? ? Com_Para.version = temVersion_No
? ? ? ? ? ? ? ? ? ? print("new version updated over:")
? ? ? ? ? ? ? ? if bFlag and temLastFile.strip() == "reboot.txt":
? ? ? ? ? ? ? ? ? ? self.RebootProgram()
? ? ? ? ? ? ? ? ? ? return 0
? ? ? ? except Exception as e:
? ? ? ? ? ? if str(type(self)) == "<class 'type'>":
? ? ? ? ? ? ? ? self.debug_in(self,repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
? ? ? ? return 1
? ??
? ? #重啟設(shè)備
? ? def RebootProgram(self): ? ? ? ?
? ? ? ? aa = A01_A1B2C3()
? ? ? ? if Com_Para.devsys.lower() == "linux":?
? ? ? ? ? ? aa.param_value2 = "reboot -f"
? ? ? ? ? ? aa.CmdExecLinux()
? ? ? ? else:
? ? ? ? ? ? aa.param_value2 = "shutdown -r"
? ? ? ? ? ? aa.CmdExecWin()
? ? ? ??
? ? #文件更新
? ? def CopyFile(self,inputWebFile):
? ? ? ? temAryTem = inputWebFile.split("\n")
? ? ? ? for temLine in temAryTem:
? ? ? ? ? ? if temLine.find("=") == -1:
? ? ? ? ? ? ? ? aa = A01_A1B2C3()
? ? ? ? ? ? ? ? temFileName = temLine[0:temLine.find(".")]
? ? ? ? ? ? ? ? temFileAtt = temLine[temLine.find("."):len(temLine)].upper()
? ? ? ? ? ? ? ? if temFileAtt.upper() == ".ZIP":
? ? ? ? ? ? ? ? ? ? aa.param_value2 = "unzip -o "+Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temLine+" -d "+Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temFileName+Com_Para.zxyPath
? ? ? ? ? ? ? ? ? ? aa.param_value3 = Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temLine
? ? ? ? ? ? ? ? ? ? aa.param_value4 = Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temFileName+Com_Para.zxyPath
? ? ? ? ? ? ? ? ? ? #利用命令進(jìn)行解壓縮
? ? ? ? ? ? ? ? ? ? #aa.CmdExecLinux()
? ? ? ? ? ? ? ? ? ? #利用python自帶解壓縮模塊
? ? ? ? ? ? ? ? ? ? aa.unzip_file() ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? if Com_Para.devsys.lower() == "linux": ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? aa.param_value2 = "cp -rf "+Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temFileName+Com_Para.zxyPath+"* "+Com_Para.ApplicationPath+Com_Para.zxyPath
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? aa.param_value2 = "xcopy "+Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temFileName+Com_Para.zxyPath+"*.* "+Com_Para.ApplicationPath+" /E /Y"
? ? ? ? ? ? ? ? ? ? aa.CmdExecLinux()
? ? ? ? ? ? ? ? #執(zhí)行sql語句
? ? ? ? ? ? ? ? elif temFileAtt.upper() == ".SQL":
? ? ? ? ? ? ? ? ? ? aa.RunSqlFile(Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temLine)
? ? ? ? ? ? ? ? #執(zhí)行更新數(shù)據(jù)接口
? ? ? ? ? ? ? ? elif temFileAtt.upper() == ".JSON":
? ? ? ? ? ? ? ? ? ? #JSON業(yè)務(wù)數(shù)據(jù)進(jìn)行數(shù)據(jù)庫結(jié)構(gòu)更改或升級
? ? ? ? ? ? ? ? ? ? pass
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? if Com_Para.devsys.lower() == "linux": ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? aa.param_value2 = "cp -rf "+Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temLine+" "+Com_Para.ApplicationPath+Com_Para.zxyPath
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? aa.param_value2 = "copy "+Com_Para.ApplicationPath+Com_Para.zxyPath+"back"+Com_Para.zxyPath+temLine+" "+Com_Para.ApplicationPath+Com_Para.zxyPath+" /Y"
? ? ? ? ? ? ? ? ? ? aa.CmdExecLinux()
? ??
? ? #inputFlag網(wǎng)絡(luò)鏈接是否正常
? ? def set_dSockList(self,inputFlag):
? ? ? ? urlp = urlparse(Com_Para.urlPath)
? ? ? ? if Com_Para.urlPath == "":
? ? ? ? ? ? return None ? ? ? ? ? ? ? ?
? ? ? ? key = str(urlp.netloc.replace(":","|"))?
? ? ? ? #存在
? ? ? ? if key not in list(Com_Para.dSockList.keys()):
? ? ? ? ? ? Com_Para.dSockList[key] = [0,datetime.datetime.now()]
? ? ? ? if inputFlag == False:
? ? ? ? ? ? objAry = Com_Para.dSockList[key]
? ? ? ? ? ? if objAry[0] <= 10:
? ? ? ? ? ? ? ? objAry[0] = objAry[0] + 1
? ? ? ? ? ? objAry[1] = datetime.datetime.now()
? ? ? ? ? ? Com_Para.dSockList[key] = objAry
? ? ? ? else:
? ? ? ? ? ? Com_Para.dSockList[key] = [0,datetime.datetime.now()] ? ?
? ??
? ? #判斷上次鏈接時間頻率是否合規(guī)
? ? def judge_dSock(self):
? ? ? ? urlp = urlparse(Com_Para.urlPath)
? ? ? ? if Com_Para.urlPath == "":
? ? ? ? ? ? return False ? ? ? ? ? ? ? ?
? ? ? ? key = str(urlp.netloc.replace(":","|"))?
? ? ? ? if key not in list(Com_Para.dSockList.keys()):
? ? ? ? ? ? Com_Para.dSockList[key] = [0,datetime.datetime.now()]
? ? ? ? objAry = Com_Para.dSockList[key]
? ? ? ? starttime = datetime.datetime.now()
? ? ? ? if objAry[0] <= 3:
? ? ? ? ? ? return True
? ? ? ? elif objAry[0] > 4 and starttime >= objAry[1] + datetime.timedelta(hours=12):
? ? ? ? ? ? return True
? ? ? ? else:
? ? ? ? ? ? return False
? ? ? ? ? ??
? ? def GetRequestWeb(self):
? ? ? ? temResult = ""
? ? ? ? try:
? ? ? ? ? ? #判斷上次鏈接時間頻率是否合規(guī)
? ? ? ? ? ? if not self.judge_dSock():
? ? ? ? ? ? ? ? return ""
? ? ? ? ? ? resp = urllib.request.urlopen(Com_Para.urlPath+"/version.txt",timeout=5)
? ? ? ? ? ? temResult = resp.read().decode(Com_Para.U_CODE) ? ? ? ?
? ? ? ? except Exception as e:
? ? ? ? ? ? temLog = ""
? ? ? ? ? ? if str(type(self)) == "<class 'type'>":
? ? ? ? ? ? ? ? temLog = self.debug_info(self)+repr(e)
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? temLog = self.debug_info()+repr(e)
? ? ? ? ? ? uL = UsAdmin_Log(Com_Para.ApplicationPath, temLog+"=>"+str(e.__traceback__.tb_lineno))
? ? ? ? ? ? uL.WriteLog()
? ? ? ? ? ? temResult = ""
? ? ? ? ? ? self.set_dSockList(False)
? ? ? ? return temResult

新建操作系統(tǒng)執(zhí)行指令接口類com.zxy.interfaceReflect.A01_A1B2C3.py

#! python3
# -*- coding: utf-8 -
'''
Created on 2017年05月10日
@author: zxyong 13738196011
'''

import os, sys,zipfile,subprocess,tempfile
from urllib.parse import unquote
from com.zxy.common import Com_Para
from com.zxy.common.Com_Fun import Com_Fun
from com.zxy.z_debug import z_debug

#監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用--操作系統(tǒng)執(zhí)行指令接口類
class A01_A1B2C3(z_debug):
    strResult        = ""
    session_id       = ""
    param_name       = ""
    param_value1     = None  #1:同步更新設(shè)備時間
    param_value2     = None  #當(dāng)前時間
    param_value3     = None
    param_value4     = None
    param_value5     = None
    param_value6     = None
    param_value7     = None
    param_value8     = None
    param_value9     = None
    param_value10    = None
    #是否繼續(xù)執(zhí)行 1:繼續(xù)執(zhí)行 0:中斷執(zhí)行
    strContinue      = "0"
    strCmdValue     = ""
    
    def __init__(self):
        pass
        
    def init_start(self):       
#         /**************************************************/
#         //示例: 此處寫業(yè)務(wù)邏輯,最后給 param_name,param_value1....重新賦值 
#         // param_name += Com_Fun.Get_New_GUID()
#         // param_value1 += Com_Fun.Get_New_GUID()
#         // param_value2 += Com_Fun.Get_New_GUID()
#         // ......
        
#         /**************************************************/
#         //示例:若業(yè)務(wù)邏輯判斷失敗,不發(fā)送數(shù)據(jù)庫接口請求并返回失敗信息
        #strContinue      = "0" 表示攔截器判斷接口執(zhí)行結(jié)束,不需要入庫操作,直接返回信息
        temValue = ""
        self.strContinue = "0"
        if self.param_value1 == "100" and Com_Para.devsys == "linux":
            temValue = self.CmdExecLinux(self)
            self.strResult = "命令結(jié)果:\r\n"
            for temR in temValue:
                self.strResult = self.strResult+temR.decode(Com_Para.U_CODE)+"\r\n"
        #100執(zhí)行命令
        elif self.param_value1 == "100" and Com_Para.devsys == "windows":
            temValue = self.CmdExecWin(self)
            self.strResult = "{\""+self.param_name+"\":[{\"s_result\":\"1\",\"error_desc\":\"命令執(zhí)行成功"+temValue+"\"}]}"
       
    #利用python自帶解壓縮
    def unzip_file(self):
        temzipfile = zipfile.ZipFile(self.param_value3, 'r')
        temzipfile.extractall(self.param_value4)        
    
    #重啟程序
    def RestartPro(self):
        python = sys.executable
        os.execl(python,python,* sys.argv)
        
    #執(zhí)行命令(Linux)
    def CmdExecLinux(self):
        out_temp = None
        try:       
            temCommand = unquote(unquote(self.param_value2,Com_Para.U_CODE))
            out_temp = tempfile.SpooledTemporaryFile(max_size=10*1000)
            fileno = out_temp.fileno()
            obj = subprocess.Popen(temCommand,stdout=fileno,stderr=fileno,shell=True)
            obj.wait()            
            out_temp.seek(0)
            temResult = out_temp.readlines()              
        except Exception as e:
            temResult = repr(e)
        finally:
            if out_temp is not None:
                out_temp.close()
        return temResult
    
    #執(zhí)行命令(Windows)
    def CmdExecWin(self):
        try:
            temCommand = unquote(unquote(self.param_value2,Com_Para.U_CODE))
            temResult = os.popen(temCommand).read()
        except Exception as e:
            temResult = repr(e)
        return temResult
    
    #更新設(shè)備時間(Windows)
    def ChangeDateWin(self):
        try:
            temDate = Com_Fun.GetDateInput('%Y-%m-%d', '%Y-%m-%d %H:%M:%S', unquote(unquote(self.param_value2.replace("+"," "),Com_Para.U_CODE)))
            temTime = Com_Fun.GetDateInput('%H:%M:%S', '%Y-%m-%d %H:%M:%S', unquote(unquote(self.param_value2.replace("+"," "),Com_Para.U_CODE)))
            temResult = os.system('date {} && time {}'.format(temDate,temTime))
        except:
            temResult = -1
        return temResult
    
    #更新設(shè)備時間(Linux)
    def ChangeDateLinux(self):
        try:            
            #將硬件時間寫入到系統(tǒng)時間:
            #hwclock -s
            #將系統(tǒng)時間寫入到硬件時間
            #hwclock -w
            temCommand = unquote(unquote("date -s \""+self.param_value2.replace("+"," ").split(" ")[0]+"\"",Com_Para.U_CODE))
            temCommand = unquote(unquote("date -s \""+self.param_value2.replace("+"," ").split(" ")[1]+"\"",Com_Para.U_CODE))
            out_temp = tempfile.SpooledTemporaryFile(max_size=10*1000)
            fileno = out_temp.fileno()
            obj = subprocess.Popen(temCommand,stdout=fileno,stderr=fileno,shell=True)
            obj.wait()
            temCommand = unquote(unquote("hwclock -w",Com_Para.U_CODE))
            obj = subprocess.Popen(temCommand,stdout=fileno,stderr=fileno,shell=True)
            obj.wait()         
            out_temp.seek(0)
            temByt = out_temp.readlines()
            temResult = temByt[0].decode(Com_Para.U_CODE)
            if temResult == "" :
                temResult = "1"
        except Exception as e:
            temResult = "-1"        
        finally:
            if out_temp is not None:
                out_temp.close()
        return temResult

版本更新測試案例MonitorDataCmd.py主文件中編寫:

from com.zxy.autoUpdate.GetVersion import GetVersion

在????if?__name__ == '__main__':下添加

????????#版本更新測試

????????Com_Para.urlPath = "http://localhost:8080/testweb/updtest/"

????????gv = GetVersion() ???

????????gv.CheckVersion()

????????print("=>版本更新完成")

程序文件新建15、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(11),python,物聯(lián)網(wǎng)back文件夾臨時存放下載更新包的zip文件;

版本更新服務(wù)端文件信息15、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(11),python,物聯(lián)網(wǎng)

版本更新服務(wù)端版本號信息

15、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(11),python,物聯(lián)網(wǎng)

運(yùn)行結(jié)果設(shè)備端更新之后新增文件

15、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(11),python,物聯(lián)網(wǎng)

更新文件已下載并自動解壓縮成功。

print打印出的內(nèi)容

15、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(11),python,物聯(lián)網(wǎng)文章來源地址http://www.zghlxwxcb.cn/news/detail-686843.html

  1. 監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(12.1)

到了這里,關(guān)于15、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(11)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 7、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(5.3)

    7、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(5.3)

    監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(5.2) 靜態(tài)配置庫數(shù)據(jù)庫調(diào)用,新建全局變量初始化類 com.zxy.main.Init_Page.py 數(shù)據(jù)庫操作測試 MonitorDataCmd.py 主文件中編寫: if __name__ == \\\'__main__\\\' : 下編寫 程序執(zhí)行成功結(jié)果:自動生成center_data.db 打印出數(shù)據(jù)庫數(shù)據(jù) 小測試:把上文的sql語句故意語法

    2024年02月10日
    瀏覽(25)
  • 11、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(8.2)

    11、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(8.2)

    監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(8.1) 新建TCP/IP Client線程類 com.zxy.tcp.ClientThread.py 新建tcp client數(shù)據(jù)接收插件類1 com.plugins.Usereflect.testClientReflectClass1.py 新建tcp client數(shù)據(jù)接收插件類2 com.plugins.Usereflect.testClientReflectClass2.py 在 com.zxy.main.Init_Page.py 中添加代碼 TCP Client測試案例 Monit

    2024年02月10日
    瀏覽(25)
  • 13、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(9.2)

    13、監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(9.2)

    監(jiān)測數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開發(fā)步驟(9.1) TCP/IP Server開發(fā) 新建TCP/IP Server線程類 com.zxy.tcp.ServerThread.py 新建作為TCP Server接收數(shù)據(jù)攔截器插件類 com.plugins.usereflect.testServerReflectInClass1.py 新建作為TCP Server接收數(shù)據(jù)攔截器插件類 com.plugins.usereflect.testServerReflectInClass2.py 在 com.zxy.main.Init_

    2024年02月10日
    瀏覽(52)
  • 物聯(lián)網(wǎng)數(shù)據(jù)采集網(wǎng)關(guān)在工廠數(shù)字化轉(zhuǎn)型中的應(yīng)用

    物聯(lián)網(wǎng)數(shù)據(jù)采集網(wǎng)關(guān)能將各種傳感器、執(zhí)行器等設(shè)備連接在一起,通過收集、處理和傳輸來自各種物理設(shè)備的信息,實(shí)現(xiàn)數(shù)據(jù)的集成和分析,同時可通過云平臺進(jìn)行數(shù)據(jù)交互。它具有數(shù)據(jù)轉(zhuǎn)換、數(shù)據(jù)處理、數(shù)據(jù)傳輸?shù)裙δ埽枪S數(shù)字化轉(zhuǎn)型的核心組件。隨著科技的飛速發(fā)展

    2024年02月22日
    瀏覽(20)
  • iNeuOS工業(yè)互聯(lián)網(wǎng)操作系統(tǒng),高效采集數(shù)據(jù)配置與應(yīng)用

    iNeuOS工業(yè)互聯(lián)網(wǎng)操作系統(tǒng),高效采集數(shù)據(jù)配置與應(yīng)用

    1. 概述 2. 通訊原理 3. 參數(shù)配置 ?1.?? 概述 某生產(chǎn)企業(yè)世界500強(qiáng)的集團(tuán)能源管控平臺項(xiàng)目建設(shè),通過專線網(wǎng)絡(luò)實(shí)現(xiàn)異地廠區(qū)數(shù)據(jù)集成, 每個終端能源儀表都有 IP 地址,總共有1000 多臺能源表計(jì),總共有將近10000 個數(shù)據(jù)點(diǎn) 。在集團(tuán)端部署iNeuOS工業(yè)互聯(lián)網(wǎng)操作系統(tǒng),終端能源表

    2024年02月05日
    瀏覽(25)
  • 【雕爺學(xué)編程】MicroPython手冊之 ESP32-CAM 物聯(lián)網(wǎng)圖像數(shù)據(jù)采集應(yīng)用

    【雕爺學(xué)編程】MicroPython手冊之 ESP32-CAM 物聯(lián)網(wǎng)圖像數(shù)據(jù)采集應(yīng)用

    MicroPython是為了在嵌入式系統(tǒng)中運(yùn)行Python 3編程語言而設(shè)計(jì)的輕量級版本解釋器。與常規(guī)Python相比,MicroPython解釋器體積小(僅100KB左右),通過編譯成二進(jìn)制Executable文件運(yùn)行,執(zhí)行效率較高。它使用了輕量級的垃圾回收機(jī)制并移除了大部分Python標(biāo)準(zhǔn)庫,以適應(yīng)資源限制的微控制

    2024年02月20日
    瀏覽(29)
  • 【IoT物聯(lián)網(wǎng)】IoT小程序在展示中央空調(diào)采集數(shù)據(jù)和實(shí)時運(yùn)行狀態(tài)上的應(yīng)用

    【IoT物聯(lián)網(wǎng)】IoT小程序在展示中央空調(diào)采集數(shù)據(jù)和實(shí)時運(yùn)行狀態(tài)上的應(yīng)用

    ??利用前端語言實(shí)現(xiàn)跨平臺應(yīng)用開發(fā)似乎是大勢所趨,跨平臺并不是一個新的概念,“一次編譯、到處運(yùn)行”是老牌服務(wù)端跨平臺語言Java的一個基本特性。隨著時代的發(fā)展,無論是后端開發(fā)語言還是前端開發(fā)語言,一切都在朝著減少工作量,降低工作成本的方向發(fā)展。 ?

    2024年02月16日
    瀏覽(20)
  • 水庫安全監(jiān)測方案(實(shí)時數(shù)據(jù)采集、高速數(shù)據(jù)傳輸)

    水庫安全監(jiān)測方案(實(shí)時數(shù)據(jù)采集、高速數(shù)據(jù)傳輸)

    ? 一、引言 水庫的安全監(jiān)測對于防止水災(zāi)和保障人民生命財(cái)產(chǎn)安全至關(guān)重要。為了提高水庫安全監(jiān)測的效率和準(zhǔn)確性,本文將介紹一種使用星創(chuàng)易聯(lián)DTU200和SG800 5g工業(yè)路由器部署的水庫安全監(jiān)測方案。 二、方案概述 本方案主要通過使用星創(chuàng)易聯(lián)DTU200和SG800 5g工業(yè)路由器實(shí)現(xiàn)

    2024年02月08日
    瀏覽(27)
  • 橋梁安全監(jiān)測系統(tǒng)中數(shù)據(jù)采集上傳用 什么?

    橋梁安全監(jiān)測系統(tǒng)中數(shù)據(jù)采集上傳用 什么?

    背景 2023年7月6日凌晨時分,G5012恩廣高速達(dá)萬段230公里加80米處6號大橋部分橋面發(fā)生垮塌,導(dǎo)致造成2車受損后自燃,3人受輕傷。目前,四川省公安廳交通警察總隊(duì)高速公路五支隊(duì)十四大隊(duì)民警已對現(xiàn)場進(jìn)行雙向管制。 作為世界第一橋梁大國,目前我國公路橋梁數(shù)量超過100萬

    2024年02月12日
    瀏覽(35)
  • 工程監(jiān)測振弦采集儀采集到的數(shù)據(jù)如何進(jìn)行分析和處理

    工程監(jiān)測振弦采集儀采集到的數(shù)據(jù)如何進(jìn)行分析和處理

    工程監(jiān)測振弦采集儀采集到的數(shù)據(jù)如何進(jìn)行分析和處理 振弦采集儀是一個用于測量和記錄物體振動的設(shè)備。它通過測量物體表面的振動來提取振動信號數(shù)據(jù),然后將其轉(zhuǎn)換為數(shù)字信號,以便進(jìn)行分析和處理。在實(shí)際應(yīng)用中,振弦采集儀是廣泛應(yīng)用于機(jī)械、建筑、航空航天和汽

    2024年02月12日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包