import http import ujson from modem import info import app_uart485 import kv isDevice=False #通过imei接口获取三元组信息 def getDeviceInfo(imei): global isDevice print('imei------------'+imei) htp = http.client() ret= htp.post('http://things.icoldchain.cn/device/info/getAliyunDeviceSecret?isAutoRegister=1&deviceName='+imei) if ret <0: print('http post return failed %d'%ret) return None cb_str= htp.get_response() print('---------------',cb_str) res=ujson.loads(cb_str) if res['code']==200: cb_data=ujson.loads(cb_str)["data"] iot_info={ 'region':cb_data['region'], 'productKey':cb_data["productKey"], 'deviceName':cb_data["deviceName"], 'deviceSecret':cb_data["deviceSecret"], 'keepaliveSec': 60 } isDevice=True return iot_info else: print('找不到设备三元组信息') isDevice=False return None #获取发送时间间隔 def getDefaultParameter(): imei=info.getDevImei() print('使用imei换取时间间隔'+imei) htp = http.client() ret= htp.post('http://things.icoldchain.cn/device/info/getDefaultParameter?imeiCode='+imei) if ret <0: print('http post return failed %d'%ret) return 180 cb_str= htp.get_response() print('---------------',cb_str) res=ujson.loads(cb_str) if res['code']==200: cb_data=ujson.loads(cb_str)["data"] return cb_data['interval'] else: return 180 def getDeviceKeyFlag(): global isDevice return isDevice #转成json格式 def toParams(strData): #获取485的数据 datas=app_uart485.getG_dian() print('------data-TO--Params-----------') jsonData={ "A":strData[6:11], "B":strData[12:17], "C":strData[18:23], "D":strData[24:29], "E":strData[30:35], "F": strData[36:41], "G": strData[42:47], "H": strData[48: 53], "I": strData[54: 59], "J": strData[60: 65], "K": strData[66: 71], "a": strData[72: 73], "b": strData[74: 75], "c": strData[76: 77], "d": strData[78: 79], "e": strData[80: 81], "f": strData[82: 83], "g": strData[84: 85], "h": strData[86: 87], "L": strData[88: 93], "M": strData[94: 99], "N": strData[100: 105], "O": strData[106: 111], "P": strData[112: 117], "Q": strData[118: 123], "R": strData[124: 129], "S": strData[130: 135], "T": strData[136: 141], "U": strData[142: 147], "V": strData[148: 153], "W": strData[154: 159], "X": strData[160: 165], "Y": strData[166: 171], "Z": strData[172: 177], "i": strData[178: 183], "j": strData[184: 185], "k": strData[186: 187], "l": strData[188: 189], "m": strData[190: 191], "n": strData[192: 200], "o": strData[201: 206], "p": strData[207: 208], "q": strData[209: 214], "r": strData[215: 220], "s": strData[221: 226], "t": strData[227: 232], "u": strData[233: 238], "v": strData[239: 244], "w": strData[245: 250], "x": strData[251: 252], "y": strData[253: 254], "z": strData[255: 256], "C53": strData[257: 258], "C54": strData[259: 264], "C55": strData[265: 266], "Dsos":datas[0], "Dv":datas[1], "Dalert":datas[2], "suedtime": '', "deviceType": '东丽' } return jsonData #是否有警报 def isObjectValueEqual(dictDa): if dictDa['a'] == '1': return False if dictDa['b'] == '1': return False if dictDa['c'] == '1': return False if dictDa['d'] == '1': return False if dictDa['e'] == '1': return False if dictDa['f'] == '1': return False if dictDa['g'] == '1': return False if dictDa['h'] == '1': return False if dictDa['p'] == '1': return False if dictDa['C55'] == '1': return False return True