# Maximize LoPy message size

**URL:** <https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272>\
**Category:** Pycom\
**Created:** [August 28, 2018, 10:37pm UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272 "2018-08-28T22:37:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brady\_aiello](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/brady_aiello/32/27724_2.png) [@brady\_aiello](https://www.thethingsnetwork.org/forum/u/brady_aiello)\
**Post date:** [August 28, 2018, 10:37pm UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272/1 "2018-08-28T22:37:51Z")

</div>

I want to make the LoPy to be able to reliably send a large payload, the max of 242 bytes. Right now, I just want to get to sending 150 bytes, which I did multiple times this morning. However, after a reboot, it stopped letting me send messages \> 100 bytes.

```
from network import LoRa
import socket
import binascii

lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.US915, bandwidth=LoRa.BW_125KHZ, sf=7, adr=True)

dev_addr = 0x00000000
nwk_skey = binascii.unhexlify("0000000000000000000000000000000000")
app_skey = binascii.unhexlify("0000000000000000000000000000000000")

for i in range(8, 72):
    lora.remove_channel(i)

start = 903900000
f_inc = 200000
curr = start

for i in range(8):
    print(curr)
    lora.add_channel(index=i, frequency=curr, dr_min=0, dr_max=4)
    curr += f_inc

lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_skey, app_skey))
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
big_buffer = bytes([0xFF] * 150)
s.send(big_buffer)

```

What should the `coding_rate`, `dr_min`, and `sf` be to achiever this? And should `adr` be enabled? I’ve tried many combinations and can’t quite it right. Thanks.

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [August 29, 2018, 4:16am UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272/2 "2018-08-29T04:16:20Z")

</div>

The maximum depends on the data rate. So I assume the data rate dropped to a rate too low to allow for the 150 bytes:

> [@Fair Use Policy explained](https://www.thethingsnetwork.org/forum/t/fair-use-policy-explained/1300/1):
>
> Like for the European 863-870MHz band, the _application_ packet size varies between 51 bytes for the slowest data rate, and 222 bytes for faster rates. Note that the LoRaWAN protocol [adds at least 13 bytes](https://www.thethingsnetwork.org/forum/t/spreadsheet-for-lora-airtime-calculation/1190/4) to the application payload. And beware:
> 
> - Some libraries, [such as LMiC](https://www.thethingsnetwork.org/forum/t/what-is-the-maximum-number-of-characters-i-can-send-with-lmic/9537), only support 51 bytes for all SF.
> - Some providers, [such as the Dutch KPN](https://zakelijkforum.kpn.com/lora-forum-16/lora-frequently-asked-questions-faq-8329), only support 51 bytes for all SF.

As for why the data rate changed: maybe the node did a new OTAA Join and only succeeded at some low rate (high SF), or maybe it used confirmed uplinks and failed to receive the confirmation, hence also lowered its data rate and tried again.

In short: change your application to not need the maximum.

---

<div class="post-metadata">

**Author:** ![brady\_aiello](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/brady_aiello/32/27724_2.png) [@brady\_aiello](https://www.thethingsnetwork.org/forum/u/brady_aiello)\
**Post date:** [August 29, 2018, 5:16am UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272/3 "2018-08-29T05:16:10Z")

</div>

Thank you, input is always appreciated. I would respond exactly as you, but the maximum payload is non-negotiable. I’m using LoRaWAN for a non-IoT research project that requires large payloads. It is a very atypical use case.

On line 1215 of the LoPy’s LoRa module, it only allows data rates 0 - 4 of 7 for the US bands. Do you know why? I’m trying to understand which rates they are, and which spreading factors they correspond with.

[https://github.com/pycom/pycom-micropython-sigfox/blob/master/esp32/mods/modlora.c](https://github.com/pycom/pycom-micropython-sigfox/blob/master/esp32/mods/modlora.c)

Removing this line sometimes lets me send large messages (up to 242!), but the behavior is inconsistent. I would greatly appreciate any more input. Thanks.

---

<div class="post-metadata">

**Author:** ![brady\_aiello](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/brady_aiello/32/27724_2.png) [@brady\_aiello](https://www.thethingsnetwork.org/forum/u/brady_aiello)\
**Post date:** [August 29, 2018, 5:40am UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272/4 "2018-08-29T05:40:10Z")

</div>

I’m reading this header file with spreading factor and data rate definitions. [https://github.com/pycom/pycom-micropython-sigfox/blob/4481a1c283be97640592ea2a0440830e336064de/lib/lora/mac/region/Region.h](https://github.com/pycom/pycom-micropython-sigfox/blob/4481a1c283be97640592ea2a0440830e336064de/lib/lora/mac/region/Region.h)

To me it looks like sf=7 and dr=3 would be the right choice for US915. What do you think?

---

<div class="post-metadata">

**Author:** ![kersing](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/kersing/32/44777_2.png) [@kersing](https://www.thethingsnetwork.org/forum/u/kersing)\
**Post date:** [August 29, 2018, 6:06am UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272/5 "2018-08-29T06:06:00Z")

</div>

> [@brady\_aiello](#):
>
> it only allows data rates 0 - 4 of 7 for the US bands. Do you know why?

Read the LoRaWAN specification and regional parameters document, that will clear things up.

---

<div class="post-metadata">

**Author:** ![brady\_aiello](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/brady_aiello/32/27724_2.png) [@brady\_aiello](https://www.thethingsnetwork.org/forum/u/brady_aiello)\
**Post date:** [August 29, 2018, 8:05pm UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272/6 "2018-08-29T20:05:48Z")

</div>

Thanks. I checked out the spec. To get the largest message, it looks like SF7 at DR\_3 and bw of 125 kHz is what I want.

But the LoPy device is not being set to either. No matter how I initialize the LoRa object, or set the data rate in the socket, it won’t actually transmit with those settings. Using `lora.sf()` gives me 7, but it only transmits at DR\_0 (SF10, bw=125kHz) with cr=4/5. Has anyone been able to get the LoPy to actually transmit at different data rates?

![max-payloads](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/9/2/92769c98a546689c8923537b6032b4253df52551.png) ![sf-data-rates](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/a/d/ad4fb3d02a0d82b4ae5adf70a07ad02b509d996e.png)

---

<div class="post-metadata">

**Author:** ![kersing](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/kersing/32/44777_2.png) [@kersing](https://www.thethingsnetwork.org/forum/u/kersing)\
**Post date:** [August 29, 2018, 10:20pm UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272/7 "2018-08-29T22:20:01Z")

</div>

Time to visit the Pycom forum?

---

<div class="post-metadata">

**Author:** ![brady\_aiello](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/brady_aiello/32/27724_2.png) [@brady\_aiello](https://www.thethingsnetwork.org/forum/u/brady_aiello)\
**Post date:** [September 1, 2018, 10:37pm UTC](https://www.thethingsnetwork.org/forum/t/maximize-lopy-message-size/17272/8 "2018-09-01T22:37:39Z")

</div>

I ended up having to edit the PyCom firmware to allow data rates other than DR\_0. It doesn’t actually support other data rates in LoRaWAN mode, even though it says it does.
