Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8041

MicroPython • Re: Pico 2 mqtt quick question on sending binary

$
0
0

Code:

import secretswifi_ssid = secrets.SSIDwifi_password = secrets.PASSWORDmqtt_server = b'secrets.MQTTSERVER'#mqtt_server = b'MQTT_BROKER_URL'mqtt_username = b'BROKER_USERNAME'mqtt_password = b'BROKER_PASSWORD'
Will the mqtt_server = b'secrets.MQTTSERVER' work? Using secrets.py for my internet/pass connection but sending in binary will that work as b'secrets.MQTTSERVER'?

No. That will return the literal string b'secrets.MQTTSERVER'. You can see that by running the following:

Code:

foo = b'baz'bar = b'foo'print(foo, bar)
If the module you're importing defines that as a byte string it will remain a byte string unless you convert it to a "normal" (unicode) string. Either explicitly via bytes.decode() or implicitly depending on how you use it and manipulate it.

You may want to look at the python docs for url=https://docs.python.org/3.9/library/std ... tes.decode]bytes.decode()[/url] and [url=https://docs.python.org/3.9/library/std ... str.encode]str.edcode()[/url.
Thank you so much. Wasn't sure how to call the variable needed. This answered more than a few questions.

Statistics: Posted by eflwi — Sun Feb 09, 2025 11:24 pm



Viewing all articles
Browse latest Browse all 8041

Trending Articles