Cannot transmit full byte value

(Morrison) #1

Hi guys!

I’m using a lopy4 attached to a pysense and I’m trying to send a temperature value to the ttn via lorawan on a node - nano-gateway connection. I want the temperature value with a decimal case so i’m multiplying it by 10 and for a value, let’s say 288 (28,8 ºC) I pass the value to bytes and append it to a bytearray a proceed to send it to the ttn.

Now, the problem is to trasnmit 288d i need 2 bytes and 288d = 120h = 0000 0001 0010 0000
but when i transmit it with s.send(bytearray) in the ttn I only get a Payload of 20H so… I’m only sending the 1st byte of information. Why’s that??

I’ve previously sent strings with many more bytes and decoded them successfully and i can’t do this with a simple value? Why the different behaviour? Can you help me troubleshoot this?

Thank you!

(Jreiss) #2

(Mark Wills) #3

Post your source code.

(Tim Everitt) #4

Hi @Morrison, to send multibyte integer data from a Lopy4 I use python code like:

databytes = struct.pack('>Bh', status, value)

status is a 1 byte integer (python struct “B”), value is a short 2 byte integer (python struct “h”).
The databytes variable will have a length of 3.
I then send the uplink data using python code like:


I get 3 bytes turning up no problem via TTN.

(Morrison) #5

That did it i have to rearrange the values but i can send it now…

Thank you guys, for the fast and detailed responses!

(Morrison) #6

Hey guys i hope everything goes well!

I’m working on 2 lopy4/pysense one as a node and other as gateway…
My objective for now is to send the most efficient payloads possible so i can reduce airtime as much as possible. i want to send every value read by the sensors in pysense and some more but for now i’m only testing with temperature and humidity…

So my node I have (among other stuff) these functions:

  • readsensor() wich is a function for reading the values
  • then i run atrbCode() wich is a function that starts building a header for each sensor, by first atributing the code of the sensor to a byte
  • then i calculate the size and format (for the struct pack function) of the value read by the sensor

So… In practical terms what i send is (469, 21, 3011, 25) which in hex is 01 D5 15 0B C3 19
and what i get in ttn is D5 01 15 00 C3 0B 19. My problem concerns with that extra 00 in the middle
i’ve read that “Padding is only automatically added between successive structure members.” (in struct pack)

The thing is i have around 15 sensors reading information, is ther any other way to encode/pack data where i don’t have to lose 13 bytes of padding?

Thank you in advance!