module.exports = async function (context, req) { data = JSON.parse(req.body.Data) device = { deviceId: data.Packets[0].TerminalId } measurements = unpack_tracker(data.Packets[0].Value) try { await handleMessage({ ...parameters, log: context.log, getSecret: getKeyVaultSecret }, device, measurements, req.body.timestamp); } catch (e) { context.log('[ERROR]', e.message); context.res = { status: e.statusCode ? e.statusCode : 500, body: e.message }; } } /** * Unpacks a message from the tracker app into a format that can be used by IoT Central */ function unpack_tracker(packet) { const data = Buffer.from(packet, "hex") return { DeviceType: "Myriota Tracker", SequenceNumber: data.readUInt16LE(0), Tracking: { lat: data.readInt32LE(2)/1e7, lon: data.readInt32LE(6)/1e7 }, GNSSFixTimestamp: data.readUInt32LE(10)*1000, } }