collect service envelopes

This commit is contained in:
liamcottle
2024-03-16 18:32:19 +13:00
parent 4d10dc5fc8
commit d94bfe471e
3 changed files with 57 additions and 0 deletions

View File

@ -86,6 +86,27 @@ client.on("message", async (topic, message) => {
// decode service envelope
const envelope = ServiceEnvelope.decode(message);
if(!envelope.packet){
return;
}
// create service envelope in db
try {
await prisma.serviceEnvelope.create({
data: {
mqtt_topic: topic,
channel_id: envelope.channelId,
gateway_id: envelope.gatewayId ? BigInt('0x' + envelope.gatewayId.replaceAll("!", "")) : null, // convert hex id "!f96a92f0" to bigint
to: envelope.packet.to,
from: envelope.packet.from,
protobuf: message,
},
});
} catch (e) {
console.error(e, {
envelope: envelope.packet,
});
}
// attempt to decrypt encrypted packets
const isEncrypted = envelope.packet.encrypted?.length > 0;