I’m trying to configure the Join Accept using the lora-packet library as follows:
const NetIdHexString = "001122"; //network identifier
const AppNonceHexString = "334455"; // or JoinNonce non-repeating value provided by Join Server
const NetIdBuffer = Buffer.from(NetIdHexString, "hex");
const AppNonceBuffer = Buffer.from(AppNonceHexString, "hex");
const sessionKeys = lora_packet.generateSessionKeys10(AppKey, NetIdBuffer, AppNonceBuffer, Buffer.from(devNonce, "hex"));
keysInstance.setSessionKeys(sessionKeys.AppSKey, sessionKeys.NwkSKey);
if (debugMode) {
console.log("AppSKey:", sessionKeys.AppSKey.toString("hex"));
console.log("NwkSKey:", sessionKeys.NwkSKey.toString("hex"));
}
const constructedPacket = lora_packet.fromFields(
{
MType: "Join Accept", // (default)
NetID: NetIdBuffer,
AppNonce: AppNonceBuffer,
DevAddr: Buffer.from("01766f7f", "hex"), // big-endian
DLSettings: 0,
RxDelay: 0
},
null, // AppSKey
null, // NwkSKey
AppKey
);
if (debugMode) {
console.log("constructedPacket.toString()=n" + constructedPacket);
}
const base64 = constructedPacket.getPHYPayload().toString('base64');
if (debugMode) {
console.log("wireFormatPacket.toString()=" + constructedPacket.getPHYPayload().toString("hex") + " base64= " + base64 + " wireFormatPacket length:" + constructedPacket.MACPayloadWithMIC.length);
}
But when I check it in the LoRaWAN 1.0.x packet decoder, I get a message that the MIC is incorrect. What am I doing wrong?
Im trying to check constructedPacket.MACPayloadwithMIC but its inccorect too.