- You probably don’t need 32bits (4bytes) precision but 24 bits (3 bytes). So, you can send 2 bytes less.
In my case it seems ok this:
// https://github.com/ricaun/esp32-ttnmapper-gps/blob/8d37aa60e96707303ae07ca30366d2982e15b286/esp32-ttnmapper-gps/lmic_Payload.ino#L21
// accuracy till 5-6 decimal
lat = ((fix.latitude() + 90) / 180) * 16777215;
lon = ((fix.longitude() + 180) / 360) * 16777215;
loraData[0] = lat >> 16; // MSB
loraData[1] = lat >> 8;
loraData[2] = lat; // LSB
loraData[3] = lon >> 16;
loraData[4] = lon >> 8;
loraData[5] = lon;
On decoder (js) TTN V2
decoded.latitude = +((bytes[0] << 16 | bytes[1] << 8 | bytes[2]) / 16777215.0 * 180.0 - 90).toFixed(6);
decoded.longitude = +((bytes[3] << 16 | bytes[4] << 8 | bytes[5]) / 16777215.0 * 360.0 - 180).toFixed(6);
Thanks to: How to send float value and convert it into bytes - #8 by arjanvanb