chenyc
2024-11-15 ce5e351b48a0a8bb666a579324586caeba8eba8a
合拼电压电量和透析机数据一起上传到阿里云
4个文件已修改
40 ■■■■ 已修改文件
src/app_aliyunIot.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/app_uart485.py 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tool.py 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
upgrade/pyamp.zip 补丁 | 查看 | 原始文档 | blame | 历史
src/app_aliyunIot.py
@@ -237,9 +237,9 @@
def get_mqtt_connect_flag():
    global iot_connected
    return iot_connected
def masgDefault_ver(id):
def masgDefault_ver(id):
    while True:
        print('当前App版本号:' + default_ver)
        print('等待Ota升级包.....')
        print('--------------------------------------------------------------------')
        time.sleep(5)
        time.sleep(30)
src/app_uart485.py
@@ -6,6 +6,13 @@
import utime   # 延时函数在utime库中
uart = UART()
#电量
g_dianlaing = 0
g_dianya=0
g_dianlaingbaojing=0
#打开串口通讯
def uart_init():
    uart.open("serial3")
@@ -41,6 +48,7 @@
    
#发送指令到串口
def sundSos(hex_data,type):
    global g_dianlaing,g_dianya,g_dianlaingbaojing
    # 将16进制数据列表转换为字节串
    byte_data = bytes(hex_data)
    uart.write(byte_data)
@@ -69,18 +77,28 @@
        print("CRC 校验正确")
        if type=='sos':
            print("输出计算得到的电量: {}".format(readBuf[4]))
            app_aliyunIot.sudDataPostProps({"Dsos":readBuf[4]})
            # app_aliyunIot.sudDataPostProps({"Dsos":readBuf[4]})
            g_dianlaing=readBuf[4]
        elif type=='alert':
            print("输出计算得到的电池报警: {}".format(readBuf[4]))
            app_aliyunIot.sudDataPostProps({"Dalert":readBuf[4]})
            g_dianlaingbaojing=readBuf[4]
            # app_aliyunIot.sudDataPostProps({"Dalert":readBuf[4]})
        elif type=='dianya':
            print(readBuf[3],readBuf[4])
            dianyasun=hex_to_decimal_divide(readBuf[3],readBuf[4])
            print("输出计算得到的电压: {}".format(dianyasun))
            app_aliyunIot.sudDataPostProps({"Dv":dianyasun})
            g_dianya=dianyasun
            # app_aliyunIot.sudDataPostProps({"Dv":dianyasun})
            
    else:
        print("CRC 校验不正确")
        if type=='sos':
            g_dianlaing=0
        elif type=='alert':
            g_dianlaingbaojing=0
        elif type=='dianya':
            g_dianya=0
            # app_aliyunIot.sudDataPostProps({"Dv":dianyasun})
def hex_to_decimal_divide(dec1, dec2):
    hex1 = '{:02X}'.format(dec1)
@@ -89,4 +107,7 @@
    decimal_value = int(hex1 + hex2, 16)
    # 除以 100 并保留一位小数
    result = round(decimal_value / 100, 1)
    return result
    return result
def getG_dian():
    global g_dianlaing,g_dianya,g_dianlaingbaojing
    return  [g_dianlaing,g_dianya,g_dianlaingbaojing]
src/tool.py
@@ -1,6 +1,7 @@
import http
import ujson
from modem import info 
import app_uart485
import kv
isDevice=False
#通过imei接口获取三元组信息
@@ -57,6 +58,8 @@
    return  isDevice 
#转成json格式
def toParams(strData):
    #获取485的数据
    datas=app_uart485.getG_dian()
    print('------data-TO--Params-----------')
    jsonData={
        "A":strData[6:11],
@@ -114,6 +117,10 @@
        "C53": strData[257: 258],
        "C54": strData[259: 264],
        "C55": strData[265: 266],
        "Dsos":datas[0],
        "Dv":datas[1],
        "Dalert":datas[2],
        "suedtime": '',
        "deviceType": '东丽'
upgrade/pyamp.zip
Binary files differ