1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
| 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
|
|