# Parsing payload in Python to send from RPi based node

**URL:** <https://www.thethingsnetwork.org/forum/t/parsing-payload-in-python-to-send-from-rpi-based-node/41501>\
**Category:** End Devices (Nodes)\
**Created:** [November 17, 2020, 8:31pm UTC](https://www.thethingsnetwork.org/forum/t/parsing-payload-in-python-to-send-from-rpi-based-node/41501 "2020-11-17T20:31:18Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![cslorabox](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cslorabox/32/35697_2.png) [@cslorabox](https://www.thethingsnetwork.org/forum/u/cslorabox)\
**Post date:** [February 15, 2021, 3:35pm UTC](https://www.thethingsnetwork.org/forum/t/parsing-payload-in-python-to-send-from-rpi-based-node/41501/22 "2021-02-15T15:35:25Z")

</div>

Look at struct.pack() and .unpack() on the python end.

On the decoder end you’re going to need to spend some time to understand how multi-byte values are made of individual bytes. If you have signed values, getting the decoder right is particularly tricky, many people make coding mistakes there (and worse, for something like temperature or GPS it might be half a year or an overseas customer before the value passes through zero such that they discover the error)

---

<div class="post-metadata">

**Author:** ![edukavala](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/edukavala/32/35697_2.png) [@edukavala](https://www.thethingsnetwork.org/forum/u/edukavala)\
**Post date:** [February 15, 2021, 3:52pm UTC](https://www.thethingsnetwork.org/forum/t/parsing-payload-in-python-to-send-from-rpi-based-node/41501/23 "2021-02-15T15:52:08Z")

</div>

> [@cslorabox](#):
>
> and worse, for something like temperature or GPS it might be half a year or an overseas customer before the value passes through zero such that they discover the error)

I was having in mind the struct pack and unpack to arrange any bytes order, but i will look more on the TTN decoder as for now up until values 0-256 i wasn’t needing and i could pass my array as is. Thanks for this insight.

---

<div class="post-metadata">

**Author:** ![cslorabox](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cslorabox/32/35697_2.png) [@cslorabox](https://www.thethingsnetwork.org/forum/u/cslorabox)\
**Post date:** [February 15, 2021, 3:53pm UTC](https://www.thethingsnetwork.org/forum/t/parsing-payload-in-python-to-send-from-rpi-based-node/41501/24 "2021-02-15T15:53:32Z")

</div>

> [@edukavala](#):
>
> as for now up until values 0-256 i wasn’t needing

You mean 0-255.

And this is what I meant by understanding how larger values are represented as multiple bytes, 0-255 (or alternately -128 - 127) being the range of values that a byte can represent in the two most common interpretations.

---

<div class="post-metadata">

**Author:** ![edukavala](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/edukavala/32/35697_2.png) [@edukavala](https://www.thethingsnetwork.org/forum/u/edukavala)\
**Post date:** [February 15, 2021, 4:19pm UTC](https://www.thethingsnetwork.org/forum/t/parsing-payload-in-python-to-send-from-rpi-based-node/41501/25 "2021-02-15T16:19:36Z")

</div>

Yes i had the out of range error in python (0-256) before importing a numpy array. With numpy i didn’t had that error and i could display values \>255 only in the console. When i was attempting to send that equivalent bytes string a value eg of 326 i was displayed in my application the value of 70 in uint8.  
[(0, 326), (1, 42)]  
[0 70 1 42]  
b’\x00F\x01\*’  
In uint16 i assume 2 bytes per number i get the following result  
[0,0,70,1,1,0,42,0]

[Previous page](https://www.thethingsnetwork.org/forum/t/parsing-payload-in-python-to-send-from-rpi-based-node/41501.md?page=1)
