Cannot transmit full byte value

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!

https://docs.pycom.io/firmwareapi/pycom/network/lora.html

Post your source code.

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:

s.send(databytes)

I get 3 bytes turning up no problem via TTN.

1 Like

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

Thank you guys, for the fast and detailed responses!

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 main.py 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!

Hey guys,

I’m running a node which is a pycom lopy4 + pysense and i’m joining a lora session and saving that sessions sending values and restoring the lora session what i want to ask is:

  • does the session expires? if yes when (at what time)?
  • how can i update the frame counter? because i’m always reading the frame 0 despite the information being correct…
  • i have the tag “retry” in the application traffic; what’s the consequence of this?

Thank you guys!

I don’t understand that.

You are joining TTN 1e time with device… how ? OTAA or ABP ?

Sorry i’m joining to ttn first time and then restoring after that
and i’m doing that in OTAA

Hi @Morrison, pseudo-code of the high-level logic should be something like:

Wake up
Set up lora object
Restore lora object from nvram
Loop: check lora object is-joined? if not then join lora object
Setup and configure socket object
Send data via socket object
Check socket object for downlink data
Save lora object to nvram
Sleep

1 Like

Hi @Morrison, did you fix this? I never see any padding when I use struct.pack. If necessary please post the one line of python code for the struct.pack call with the format being used.