Skip to content

revise generation of client ID #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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