# Arduino Pro Mini + Lmic+OTAA with Multi Channel Gateway

**URL:** <https://www.thethingsnetwork.org/forum/t/arduino-pro-mini-lmic-otaa-with-multi-channel-gateway/9400>\
**Category:** LMIC\
**Created:** [September 9, 2017, 4:15am UTC](https://www.thethingsnetwork.org/forum/t/arduino-pro-mini-lmic-otaa-with-multi-channel-gateway/9400 "2017-09-09T04:15:27Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [September 9, 2017, 4:35pm UTC](https://www.thethingsnetwork.org/forum/t/arduino-pro-mini-lmic-otaa-with-multi-channel-gateway/9400/8 "2017-09-09T16:35:02Z")

</div>

> [@Somsak](#):
>
> Changing a text message to a Hex string

The examples in the sketch generator already send sensor data in a proper way. Like when selecting “Moisture, Temp and Light” then you’ll see:

```c
void build_data() {
  dataTX[0] = (light << 4) | (tempK / 256);
  dataTX[1] = tempK;
  dataTX[2] = moisture / 256;
  dataTX[3] = moisture;
}

```

This sends a total of 4 bytes (32 bits) for 3 sensors:

- 4 bits for light in a scale from 0 to 15 (hexadecimal `0x0` - `0xF`)
- 12 bits for temperature in Kelvin with one decimal, in a scale from 0.0 to 409.5 (`0x000` - `0xFFF`)
- 16 bits for moisture in a scale from 0 to 65535 (`0x0000` - `0xFFFF`)

If you’d send that as human-readable text, you’d need many more bytes (like 14 characters, so 14 bytes, when sending separated with semi-colons as `15;409.5;65535`, or `0x31353B3430392E353B3635353335` when displayed as hexadecimal ).

It even explains how to decode:

```plaintext
/* **************************************************************
 * build data to transmit in dataTX
 *
 * Suggested payload function for this data
 *
 * var light = (bytes[0] & 0xF0) >> 4;
 * var temp = (((bytes[0] & 0x0F) <<8 | bytes[1]) - 2731) / 10;
 * var moisture = bytes[2] << 8 | bytes[3];
 *  
 * return { payload: light + ";" + temp + ";" + moisture };
 *
 * ************************************************************* /

```

…which you could use to decode and then return the values any way you want:

```javascript
function Decoder(bytes, port) {

    // Test with 0A470000 for 0, -10, 0, or FB78FFFF for 15, 20.5, 65535
    var light = (bytes[0] & 0xF0) >> 4;
    var temp = (((bytes[0] & 0x0F) << 8 | bytes[1]) - 2731) / 10;
    var moisture = bytes[2] << 8 | bytes[3];
    return {
        light: light,
        celcius: temp,
        // Unary plus-operator to cast string result of toFixed to a number:
        fahrenheit: +(32 + 1.8 * temp).toFixed(1),
        moisture: moisture
    }
}

```

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/arduino-pro-mini-lmic-otaa-with-multi-channel-gateway/9400)._
