To ensure I was only handling messages with valid contents I added code to appended a cyclic redundancy check(CRC) onto outbound messages and validate the CRC on inbound messages.
First step was to update the initialise method parameter list (the parameter list is huge but for most scenarios the defaults are fine)
public void Initialise(RegOpModeMode regOpModeAfterInitialise, // RegOpMode double frequency = FrequencyDefault, // RegFrMsb, RegFrMid, RegFrLsb bool rxDoneignoreIfCrcMissing = true, bool rxDoneignoreIfCrcInvalid = true, bool paBoost = false, byte maxPower = RegPAConfigMaxPowerDefault, byte outputPower = RegPAConfigOutputPowerDefault, // RegPaConfig bool ocpOn = true, byte ocpTrim = RegOcpOcpTrimDefault, // RegOcp RegLnaLnaGain lnaGain = LnaGainDefault, bool lnaBoost = false, // RegLna RegModemConfigBandwidth bandwidth = RegModemConfigBandwidthDefault, RegModemConfigCodingRate codingRate = RegModemConfigCodingRateDefault, RegModemConfigImplicitHeaderModeOn implicitHeaderModeOn = RegModemConfigImplicitHeaderModeOnDefault, //RegModemConfig1 RegModemConfig2SpreadingFactor spreadingFactor = RegModemConfig2SpreadingFactorDefault, bool txContinuousMode = false, bool rxPayloadCrcOn = false, ushort symbolTimeout = SymbolTimeoutDefault, ushort preambleLength = PreambleLengthDefault, byte payloadLength = PayloadLengthDefault, byte payloadMaxLength = PayloadMaxLengthDefault, byte freqHoppingPeriod = FreqHoppingPeriodDefault, bool lowDataRateOptimize = false, bool agcAutoOn = false, byte ppmCorrection = ppmCorrectionDefault, RegDetectOptimizeDectionOptimize detectionOptimize = RegDetectOptimizeDectionOptimizeDefault, bool invertIQ = false, RegisterDetectionThreshold detectionThreshold = RegisterDetectionThresholdDefault, byte syncWord = RegSyncWordDefault)
The rxPayloadCrcOn needs to be set to True for outbound messages to have a CRC.
Then in the RxDone interrupt handler the CRC is checked (regHopChannel & regIrqFlagsMask) if this feature is enabled. Any messages with missing\invalid CRCs will currently be silently discarded and I’m not certain this is a good idea.
// Check to see if payload has CRC if (RxDoneIgnoreIfCrcMissing) { byte regHopChannel = this.Rfm9XLoraModem.ReadByte((byte)Registers.RegHopChannel); if ((regHopChannel & (byte)RegHopChannelFlags.CrcOnPayload) != (byte)RegHopChannelFlags.CrcOnPayload) { return; } } // Check to see if payload CRC is valid if (RxDoneIgnoreIfCrcInvalid) { if (((byte)IrqFlags & (byte)RegIrqFlagsMask.PayLoadCrcErrorMask) == (byte)RegIrqFlagsMask.PayLoadCrcErrorMask) { return; } }
The conversion of the payload from an array of bytes to a string for display stopped failing with an exception. When I had a number of clients running up to 10% of the messages were getting corrupted.
Pingback: Low power LoRaWan Node Model A328 Payload Addressing Client | devMobile's blog
Pingback: Maduino LoRa Radio 868MHz | devMobile's blog
Pingback: Low power LoRaWan Node Model B1248 Payload Addressing Client | devMobile's blog