Skip to content

Commit 5c55b01

Browse files
author
brentru
committed
adding smaller, normative handling
1 parent bc99b3e commit 5c55b01

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

adafruit_minimqtt.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,16 @@ def connect(self, clean_session=True):
266266
remaining_length += 2 + len(self._lw_topic) + 2 + len(self._lw_msg)
267267
var_header[6] |= 0x4 | (self._lw_qos & 0x1) << 3 | (self._lw_qos & 0x2) << 3
268268
var_header[6] |= self._lw_retain << 5
269+
269270

270271
# Remaining length
271272
i = 1
273+
test_byte = 0
272274
if remaining_length > 0x7f:
273275
# Calculate Remaining Length [2.2.3]
274276
remaining_bytes = bytearray()
275277
while remaining_length > 0:
278+
test_byte = 1
276279
encoded_byte = remaining_length % 0x80
277280
remaining_length = remaining_length // 0x80
278281
# if there is more data to encode, set the top bit of the byte
@@ -285,22 +288,29 @@ def connect(self, clean_session=True):
285288
print('prl, rel.length: ', remaining_length)
286289
print('prl, byte: ', encoded_byte)
287290
i+=1
288-
#fixed_header[i] = 0x00
289-
fixed_header.append(0x00)
291+
if test_byte:
292+
fixed_header.append(0x00)
293+
else:
294+
print(fixed_header)
295+
print(remaining_length)
296+
fixed_header.append(remaining_length)
297+
fixed_header.append(0x00)
298+
290299

291300
"""
292301
# Old, non-working MMQT/UMQTT IMPL
293302
i = 1
303+
print(remaining_length)
294304
while remaining_length > 0x7f:
305+
print("with variable header...")
295306
fixed_header[i] = (remaining_length & 0x7f) | 0x80
296307
remaining_length >>= 7
297308
i += 1
298-
fixed_header[i] = remaining_length
299309
print("i: ", i)
310+
fixed_header[i] = remaining_length
300311
print(fixed_header)
301312
print(remaining_length)
302313
"""
303-
304314

305315
if self._logger is not None:
306316
self._logger.debug('Sending CONNECT packet to broker')

0 commit comments

Comments
 (0)