Skip to content

Conversation

@llamafilm
Copy link

fixes #17

Length should be encoded without the object ID, according to https://bthome.io/format/

@llamafilm
Copy link
Author

I'm not sure what impact this will have on the 'complete name' since I'm not using that piece of the code. (adafruit_ble creates the name separately).

@DavesCodeMusings
Copy link
Owner

This should do the job in one line:

return pack("B", object_id) + bytes([len(value.encode())]) + value.encode()

I need to check into the effect on pack_advertisement() for the complete name, as you pointed out, before committing. Appreciate the bug report though!

@llamafilm
Copy link
Author

The one-liner reduces the file size but uses more CPU and RAM to encode twice. I'm not sure which is more important on a tiny microcontroller but my gut says my version is better. I could shorten the variable name to encoded?

@DavesCodeMusings
Copy link
Owner

I was assuming some sort of compiler optimization would kick in and say, "I've seen value.encode() twice on the same line, I'll just calculate it once and use the same value both places." I think this is a fairly common optimization, but I'm not a microcode compiler expert. I might ask on the MicroPython discussion board just to make sure I have it straight in my brain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raw text encoded with wrong length

2 participants