Add this to node in ttn
from network import LoRa
import ubinascii
lora = LoRa()
print("DevEUI: %s" % (ubinascii.hexlify(lora.mac()).decode('ascii').upper()))
function bytesToFloat32(bytes) {
var sign = (bytes & 0x80000000) ? -1 : 1;
var exponent = ((bytes >> 23) & 0xFF) - 127;
var significand = (bytes & ~(-1 << 23));
if (exponent == 128)
return sign * ((significand) ? Number.NaN : Number.POSITIVE_INFINITY);
if (exponent == -127) {
if (significand == 0) return sign * 0.0;
exponent = -126;
significand /= (1 << 22);
} else significand = (significand | (1 << 23)) / (1 << 23);
return sign * significand * Math.pow(2, exponent);
}
function Decoder(bytes, port) {
var t = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
var h = bytes[7] << 24 | bytes[6] << 16 | bytes[5] << 8 | bytes[4];
return{
temperature: bytesToFloat32(t).toFixed(5),
humidity: bytesToFloat32(h).toFixed(4)
};
}
function bytesToFloat32(bytes) {
var sign = (bytes & 0x80000000) ? -1 : 1;
var exponent = ((bytes >> 23) & 0xFF) - 127;
var significand = (bytes & ~(-1 << 23));
if (exponent == 128)
return sign * ((significand) ? Number.NaN : Number.POSITIVE_INFINITY);
if (exponent == -127) {
if (significand == 0) return sign * 0.0;
exponent = -126;
significand /= (1 << 22);
} else significand = (significand | (1 << 23)) / (1 << 23);
return sign * significand * Math.pow(2, exponent);
}
function Decoder(bytes, port) {
var lat = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
var long = bytes[7] << 24 | bytes[6] << 16 | bytes[5] << 8 | bytes[4];
return{
latitude: bytesToFloat32(lat).toFixed(7),
longitude: bytesToFloat32(long).toFixed(7)
};
}