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

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 bytes.decode() and str.edcode().

Edited to fix link tags

Statistics: Posted by thagrol — Sun Feb 09, 2025 11:02 pm



Viewing all articles
Browse latest Browse all 7742

Latest Images

Trending Articles



Latest Images