Length Check #1
-
|
Tried using this library with Raspberry Pi Pico, and I am sending serial data over USB. No matter how I format the text, it does not detect variables to show in the readings tab. I have a question about the length check - is that the issue? I don't understand how to use the length check part: what number should I write? I added a line like this: Here: loadText_A is a variable that can range from 0 to 65535. In that case the length of the variable itself changes. How do I decide the length check number? Please help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
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: If you know that your string contains "standard" 1-byte chars (e.g. ASCII), you can just do We should probably add device-side MicroPython lib (in addition to Arduino that is included already) to make this nicer. If at all helpful, here's (outputs Let us know if this works! |
Beta Was this translation helpful? Give feedback.
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:
It outputs for me:
If you know that your string contains "standard" 1-byte chars (e.g. ASCII), you can just do
len(message)instead oflen(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…