@@ -224,11 +224,12 @@ def register_reading(self, target:bytes, data:bytes) -> None:
224
224
_log .debug ('register_reading(%s,%s)' ,target ,value )
225
225
if target == self .BOARD :
226
226
self ._board = value / 10.0
227
- elif target in { self .BT , self .OLD_BT } :
227
+ elif target in ( self .BT , self .OLD_BT ) :
228
228
BT = value / 10.0
229
229
self ._bt = (BT if self ._bt == - 1 else (2 * BT + self ._bt )/ 3 )
230
- _log .debug ('BT: %s' ,self ._bt )
231
- elif target in {self .ET , self .OLD_ET }:
230
+ if self ._logging :
231
+ _log .debug ('BT: %s' ,self ._bt )
232
+ elif target in (self .ET , self .OLD_ET ):
232
233
ET = value / 10.0
233
234
self ._et = (ET if self ._et == - 1 else (2 * ET + self ._et )/ 3 )
234
235
if self ._logging :
@@ -299,7 +300,9 @@ async def read_msg(self, stream: Union[asyncio.StreamReader, IteratorReader]) ->
299
300
# look for the first header byte
300
301
await stream .readuntil (self .HEADER [0 :1 ])
301
302
# check for the second header byte
302
- if await stream .readexactly (1 ) != self .HEADER [1 :2 ]:
303
+ # if await stream.readexactly(1) != self.HEADER[1:2]:
304
+ # return
305
+ if await stream .readexactly (1 ) not in (self .HEADER_BT [1 :2 ], self .HEADER_WIFI [1 :2 ]): # we always accept both headers, the one for WiFi and the one for BT
303
306
return
304
307
# read the data target (BT, ET,..)
305
308
target = await stream .readexactly (1 )
@@ -316,7 +319,8 @@ async def read_msg(self, stream: Union[asyncio.StreamReader, IteratorReader]) ->
316
319
crc = await stream .readexactly (2 )
317
320
calculated_crc = FramerRTU .compute_CRC (self .CODE_HEADER + data_len + data ).to_bytes (2 , 'big' )
318
321
# if self._verify_crc and crc != calculated_crc: # for whatever reason, the first byte of the received CRC is often wrongly just \x00
319
- if self ._verify_crc and crc != calculated_crc and crc [0 ] != 0 :
322
+ # if self._verify_crc and crc != calculated_crc and crc[0] != 0: # we accept a 0 as first CRC bit always!
323
+ if self ._verify_crc and crc [1 ] != calculated_crc [1 ]: # we only check the second CRC bit!
320
324
if self ._logging :
321
325
_log .debug ('CRC error' )
322
326
return
@@ -349,6 +353,7 @@ def send_msg(self, target:bytes, value: int) -> None:
349
353
350
354
def start (self , connect_timeout :float = 5 ) -> None :
351
355
if self ._connect_using_ble and hasattr (self , '_ble_client' ) and self ._ble_client is not None :
356
+ self ._ble_client .setLogging (self ._logging )
352
357
self ._ble_client .start (case_sensitive = False )
353
358
else :
354
359
super ().start (connect_timeout )
0 commit comments