python-aidot 0.3.46__tar.gz → 0.3.48__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_aidot-0.3.46 → python_aidot-0.3.48}/PKG-INFO +1 -1
- {python_aidot-0.3.46 → python_aidot-0.3.48}/aidot/client.py +1 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/aidot/device_client.py +30 -44
- {python_aidot-0.3.46 → python_aidot-0.3.48}/aidot/discover.py +2 -2
- {python_aidot-0.3.46 → python_aidot-0.3.48}/python_aidot.egg-info/PKG-INFO +1 -1
- {python_aidot-0.3.46 → python_aidot-0.3.48}/setup.py +1 -1
- {python_aidot-0.3.46 → python_aidot-0.3.48}/LICENSE +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/README.md +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/aidot/__init__.py +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/aidot/aes_utils.py +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/aidot/const.py +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/aidot/exceptions.py +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/aidot/login_const.py +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/python_aidot.egg-info/SOURCES.txt +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/python_aidot.egg-info/dependency_links.txt +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/python_aidot.egg-info/requires.txt +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/python_aidot.egg-info/top_level.txt +0 -0
- {python_aidot-0.3.46 → python_aidot-0.3.48}/setup.cfg +0 -0
|
@@ -114,6 +114,7 @@ class DeviceClient(object):
|
|
|
114
114
|
_ping_timer: Any = None
|
|
115
115
|
writer: Any = None
|
|
116
116
|
reader: Any = None
|
|
117
|
+
_TAG: str = "DeviceClient"
|
|
117
118
|
@property
|
|
118
119
|
def connect_and_login(self) -> bool:
|
|
119
120
|
return self._connect_and_login
|
|
@@ -138,9 +139,11 @@ class DeviceClient(object):
|
|
|
138
139
|
self.password = device.get(CONF_PASSWORD)
|
|
139
140
|
self.device_id = device.get(CONF_ID)
|
|
140
141
|
self._simpleVersion = device.get("simpleVersion")
|
|
142
|
+
self._TAG = f"{self.device_id}";
|
|
143
|
+
_LOGGER.warning(f"{self._TAG}:{device}")
|
|
141
144
|
|
|
142
145
|
async def connect(self, ip_address) -> None:
|
|
143
|
-
_LOGGER.
|
|
146
|
+
_LOGGER.warning(f"{self._TAG}:connect device: {ip_address}")
|
|
144
147
|
self.reader = self.writer = None
|
|
145
148
|
self._connecting = True
|
|
146
149
|
try:
|
|
@@ -208,34 +211,20 @@ class DeviceClient(object):
|
|
|
208
211
|
try:
|
|
209
212
|
self.writer.write(self.get_send_packet(json.dumps(message).encode(), 1))
|
|
210
213
|
await self.writer.drain()
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
_LOGGER.error(f"recv data error {e}")
|
|
216
|
-
|
|
217
|
-
data_len = len(data)
|
|
218
|
-
if data_len <= 0:
|
|
219
|
-
return
|
|
220
|
-
|
|
221
|
-
try:
|
|
222
|
-
magic, msgtype, bodysize = struct.unpack(">HHI", data[:8])
|
|
223
|
-
encrypted_data = data[8:]
|
|
224
|
-
if self.aes_key is not None:
|
|
225
|
-
decrypted_data = aes_decrypt(encrypted_data, self.aes_key)
|
|
226
|
-
else:
|
|
227
|
-
decrypted_data = encrypted_data
|
|
228
|
-
|
|
214
|
+
header = await self.reader.readexactly(8)
|
|
215
|
+
magic, msgtype, bodysize = struct.unpack(">HHI", header)
|
|
216
|
+
body = await self.reader.readexactly(bodysize)
|
|
217
|
+
decrypted_data = aes_decrypt(body, self.aes_key) if self.aes_key else body
|
|
229
218
|
json_data = json.loads(decrypted_data)
|
|
230
219
|
code = json_data[CONF_ACK][CONF_CODE]
|
|
220
|
+
|
|
231
221
|
if code != 200:
|
|
232
222
|
# 登录失败
|
|
233
|
-
_LOGGER.error(f"{self.
|
|
223
|
+
_LOGGER.error(f"{self._TAG}:login error, code: {code}")
|
|
234
224
|
await self.reset()
|
|
235
225
|
return
|
|
236
226
|
|
|
237
|
-
self.ascNumber = json_data[CONF_PAYLOAD][CONF_ASCNUMBER]
|
|
238
|
-
self.ascNumber += 1
|
|
227
|
+
self.ascNumber = json_data[CONF_PAYLOAD][CONF_ASCNUMBER] + 1
|
|
239
228
|
self.status.online = True
|
|
240
229
|
self._receive_task = asyncio.create_task(
|
|
241
230
|
self.receive_data(),
|
|
@@ -247,38 +236,35 @@ class DeviceClient(object):
|
|
|
247
236
|
self._reconnect_handle.cancel()
|
|
248
237
|
self._reconnect_handle = None
|
|
249
238
|
self._schedule_ping()
|
|
250
|
-
_LOGGER.
|
|
239
|
+
_LOGGER.warning(f"{self._TAG}:connect success: {self._ip_address}")
|
|
251
240
|
await self.send_action({}, "getDevAttrReq")
|
|
252
|
-
except Exception as e:
|
|
253
|
-
_LOGGER.error(f"
|
|
254
|
-
return
|
|
241
|
+
except (BrokenPipeError, ConnectionResetError, Exception) as e:
|
|
242
|
+
_LOGGER.error(f"{self.device_id} login read status error {e}")
|
|
255
243
|
|
|
256
244
|
# TCP容易拼包,需要谨慎处理
|
|
257
245
|
async def receive_data(self) -> None:
|
|
258
246
|
while True:
|
|
259
247
|
try:
|
|
260
|
-
# 先读取 8 字节头
|
|
261
248
|
header = await self.reader.readexactly(8)
|
|
262
249
|
magic, msgtype, bodysize = struct.unpack(">HHI", header)
|
|
263
|
-
|
|
264
|
-
# 再读取 body
|
|
250
|
+
self.ping_count = 0 #有读到数据就把ping清零
|
|
265
251
|
body = await self.reader.readexactly(bodysize)
|
|
266
|
-
|
|
267
|
-
# 解密
|
|
268
252
|
decrypted_data = aes_decrypt(body, self.aes_key)
|
|
269
253
|
json_data = json.loads(decrypted_data)
|
|
270
|
-
|
|
254
|
+
_LOGGER.warning(f"{self._TAG}:reveive_data : {json_data}")
|
|
271
255
|
except asyncio.CancelledError:
|
|
272
|
-
_LOGGER.debug("Receive task cancelled")
|
|
256
|
+
_LOGGER.debug(f"{self._TAG}:Receive task cancelled")
|
|
273
257
|
raise
|
|
274
258
|
except (BrokenPipeError, ConnectionResetError, asyncio.IncompleteReadError) as e:
|
|
275
|
-
_LOGGER.error(f"{self.
|
|
276
|
-
await self.reset()
|
|
277
|
-
|
|
278
|
-
|
|
259
|
+
_LOGGER.error(f"{self._TAG}:read status error {e}")
|
|
260
|
+
# await self.reset()
|
|
261
|
+
syncio.get_running_loop().call_soon(
|
|
262
|
+
lambda: asyncio.create_task(self.reset())
|
|
263
|
+
)
|
|
279
264
|
return
|
|
280
265
|
except Exception as e:
|
|
281
|
-
_LOGGER.error(f"recv error: {e}")
|
|
266
|
+
_LOGGER.error(f"{self._TAG}:recv error: {e}")
|
|
267
|
+
self.ping_count = 0
|
|
282
268
|
continue
|
|
283
269
|
|
|
284
270
|
if "service" in json_data:
|
|
@@ -295,7 +281,7 @@ class DeviceClient(object):
|
|
|
295
281
|
def _schedule_ping(self):
|
|
296
282
|
loop = asyncio.get_running_loop()
|
|
297
283
|
loop.create_task(self.send_ping_action())
|
|
298
|
-
self._ping_timer = loop.call_later(
|
|
284
|
+
self._ping_timer = loop.call_later(30, self._schedule_ping)
|
|
299
285
|
|
|
300
286
|
async def send_dev_attr(self, dev_attr) -> None:
|
|
301
287
|
if not self._connect_and_login:
|
|
@@ -364,10 +350,10 @@ class DeviceClient(object):
|
|
|
364
350
|
self.writer.write(self.get_send_packet(json.dumps(action).encode(), 1))
|
|
365
351
|
await self.writer.drain()
|
|
366
352
|
except (BrokenPipeError, ConnectionResetError) as e:
|
|
367
|
-
_LOGGER.error(f"{self.
|
|
353
|
+
_LOGGER.error(f"{self._TAG}:send action error {e}")
|
|
368
354
|
await self.reset()
|
|
369
355
|
except Exception as e:
|
|
370
|
-
_LOGGER.error(f"{self.
|
|
356
|
+
_LOGGER.error(f"{self._TAG}:send action error {e}")
|
|
371
357
|
|
|
372
358
|
async def send_ping_action(self) -> int:
|
|
373
359
|
if self._is_close:
|
|
@@ -379,11 +365,11 @@ class DeviceClient(object):
|
|
|
379
365
|
"srcAddr": "x.xxxxxxx",
|
|
380
366
|
CONF_PAYLOAD: {},
|
|
381
367
|
}
|
|
382
|
-
_LOGGER.info(f"{self.device_id} send_ping_action {ping}")
|
|
368
|
+
# _LOGGER.info(f"{self.device_id} send_ping_action {ping}")
|
|
383
369
|
try:
|
|
384
|
-
if self.ping_count >=
|
|
370
|
+
if self.ping_count >= 3:
|
|
385
371
|
_LOGGER.error(
|
|
386
|
-
f"
|
|
372
|
+
f"{self._TAG}:Device unresponsive within 90 seconds, disconnecting."
|
|
387
373
|
)
|
|
388
374
|
await self.reset()
|
|
389
375
|
return -1
|
|
@@ -12,7 +12,7 @@ from .exceptions import AidotOSError
|
|
|
12
12
|
_LOGGER = logging.getLogger(__name__)
|
|
13
13
|
# _DISCOVER_TIME = 15
|
|
14
14
|
|
|
15
|
-
_DISCOVER_FAST =
|
|
15
|
+
_DISCOVER_FAST = 10 # 启动时快速发现
|
|
16
16
|
_DISCOVER_SLOW = 120 # 稳定后慢速维持
|
|
17
17
|
|
|
18
18
|
class BroadcastProtocol:
|
|
@@ -111,7 +111,7 @@ class Discover:
|
|
|
111
111
|
|
|
112
112
|
def start_repeat_broadcast(self) -> None:
|
|
113
113
|
self._is_close = False
|
|
114
|
-
self._fast_discover_count =
|
|
114
|
+
self._fast_discover_count = 3 # 前三次快速
|
|
115
115
|
self._schedule_broadcast()
|
|
116
116
|
|
|
117
117
|
def _schedule_broadcast(self) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|