Skip to content

.encode not available on STM32F05 build -- potential workaround #16

Closed
@jerryneedell

Description

@jerryneedell

The STM32F405 build does not have .encode available.
see this discussion adafruit/circuitpython#2433 (comment)

I have a fix for this -- so it works without .encode
do you want a PR for it?

here are the diffs

jerryneedell@Ubuntu-Macmini:~/projects/stm32f405/airlift$ diff adafruit_minimqtt.py ~/projects/adafruit_github/Adafruit_CircuitPython_MiniMQTT/
121c121
<         if self.password is not None and len(bytes(password,"utf-8")) > MQTT_TOPIC_LENGTH_LIMIT:
---
>         if self.password is not None and len(password.encode('utf-8')) > MQTT_TOPIC_LENGTH_LIMIT:
129c129
<             self.client_id = 'cpy{0}{1}'.format(microcontroller.cpu.uid[randint(0, len(microcontroller.cpu.uid)-1)],
---
>             self.client_id = 'cpy{0}{1}'.format(microcontroller.cpu.uid[randint(0, 15)],
355c355
<             msg = bytes(str(msg),"ascii")
---
>             msg = str(msg).encode('ascii')
357c357
<             msg = bytes(str(msg),"utf-8")
---
>             msg = str(msg).encode('utf-8')
690c690
<             self._sock.send(bytes(string, "utf-8"))
---
>             self._sock.send(str.encode(string, 'utf-8'))
705c705
<         elif len(bytes(topic,'utf-8')) > MQTT_TOPIC_LENGTH_LIMIT:
---
>         elif len(topic.encode('utf-8')) > MQTT_TOPIC_LENGTH_LIMIT:

note the change at line 129 -- the STM build microcontroller.cpu.uid is only 12 bytes so this was failing -- I set it to len() to avoid the error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions