Reading/Writing .mpy Files with MQTT #11520
-
I have a project I am working on where I am able to send python files through mqtt to my pico and have it update those files inside its own file system. It is currently working with python files as plain text, but I cannot figure out how to get mpy to write to a file properly. I have it to the point where it matches exactly what you see from opening the mpy file, except it reads as plain text instead of binary/hex. I am using 'wb' to write to the file currently, but I have had no luck getting a compatible mpy file to work. Is this possible with mpy files? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
This should definitely be possible. I'm not sure what you mean by "except it reads as plain text instead of binary/hex" but sounds like something is going wrong with the encoding/decoding or the file mode (e.g. is it being encoded to base64 or hex for the mqtt message, but not decoded before writing?). You will need to post your code so we can provide more specific advice. |
Beta Was this translation helpful? Give feedback.
-
There is something odd going on here. I wrote the following and cross-compiled it to for x in range(10):
print(x) I then did the following
So it's possible to read an |
Beta Was this translation helpful? Give feedback.
-
@peterhinch @jimmo I solved this issue by concatenating all of the bytes into one long byte string then unhexlifying it. The issue was that I was copying the text version of the file which was bytes spaced out and having many lines, so I needed to get them into one line and in a byte array (like this: b'M\x06\x00\x1fE#\x16aducm355.py\x00\x0f\x08time\x00\x0emachine) |
Beta Was this translation helpful? Give feedback.
@peterhinch @jimmo I solved this issue by concatenating all of the bytes into one long byte string then unhexlifying it. The issue was that I was copying the text version of the file which was bytes spaced out and having many lines, so I needed to get them into one line and in a byte array (like this: b'M\x06\x00\x1fE#\x16aducm355.py\x00\x0f\x08time\x00\x0emachine)