Skip to content

Commit

Permalink
Merge pull request #19 from jerryneedell/jerryn_clientid
Browse files Browse the repository at this point in the history
 revise generation of client ID
  • Loading branch information
brentru authored Jan 6, 2020
2 parents 4e6b6fa + e58e907 commit 4ef5c3e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import struct
import time
from random import randint
import microcontroller
from micropython import const
import adafruit_logging as logging

Expand Down Expand Up @@ -126,8 +125,8 @@ def __init__(self, socket, broker, port=None, username=None,
self.client_id = client_id
else:
# assign a unique client_id
self.client_id = 'cpy{0}{1}'.format(microcontroller.cpu.uid[randint(0, 15)],
randint(0, 9))
self.client_id = 'cpy{0}{1}'.format(randint(0, int(time.monotonic()*100)%1000),
randint(0, 99))
# generated client_id's enforce spec.'s length rules
if len(self.client_id) > 23 or not self.client_id:
raise ValueError('MQTT Client ID must be between 1 and 23 bytes')
Expand Down

0 comments on commit 4ef5c3e

Please sign in to comment.