Skip to content
Discussion options

You must be logged in to vote

The length check is checking the number of bytes written up until comma+length. Assuming you are using Python (MicroPython) and standard (utf-8) encoding for stdout, you can try:

def len_ck(message):
    bytes = len(message.encode('utf-8'))
    return "," + str(bytes)

loadText_A = "55"
message = "Knobs,0.1,A201,,,LoadA:" + loadText_A
sys.stdout.write(message + len_ck(message) + "\n")

It outputs for me:

Knobs,0.1,A201,,,LoadA:55,25

If you know that your string contains "standard" 1-byte chars (e.g. ASCII), you can just do len(message) instead of len(message.encode('utf-8')) to save cycles. Let me know if this is on a very hot path - would be interesting to figure out optimal solution :).

W…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@thewiseguyshivam
Comment options

@alexteaa
Comment options

Answer selected by thewiseguyshivam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants