# Dragino with ultrasonic sensor and TTN

**URL:** <https://www.thethingsnetwork.org/forum/t/dragino-with-ultrasonic-sensor-and-ttn/38423>\
**Category:** Dragino\
**Created:** [July 9, 2020, 1:14pm UTC](https://www.thethingsnetwork.org/forum/t/dragino-with-ultrasonic-sensor-and-ttn/38423 "2020-07-09T13:14:02Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [July 9, 2020, 9:58pm UTC](https://www.thethingsnetwork.org/forum/t/dragino-with-ultrasonic-sensor-and-ttn/38423/3 "2020-07-09T21:58:34Z")

</div>

> [@zielpuls](#):
>
> and send test text messages to the network

Good to see you changed that text into a 2 bytes binary encoded payload. But there’s still something left in your code:

> [@zielpuls](#):
>
> ```cpp
> byte payload[2];
> payload[0] = highByte(belegt);
> payload[1] = lowByte(belegt);
> 
> // Prepare upstream data transmission at the next possible time.
> LMIC_setTxData2(1, payload, sizeof(payload)-1, 0);
> 
> ```

Above, `sizeof(payload)-1` will make LMIC send 1 byte, not 2. Simply remove that `-1`.

The `-1` part is probably a leftover of the test that used text? Even a fixed-length char array has [a terminating null-character](https://en.wikipedia.org/wiki/Null-terminated_string). That does not need to be included in the LoRaWAN packet, as the receiver already knows how long a LoRaWAN packet it. So, for text you’ll often see `sizeof(...) - 1`.

LoRaWAN examples using text are just evil.

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/dragino-with-ultrasonic-sensor-and-ttn/38423)._
