public async Task SensorDecoder_HttpBased_ValueSensorDecoder_DecodesPayload() { var device = this.testFixture.Device11_OTAA; Console.WriteLine($"Starting {nameof(SensorDecoder_HttpBased_ValueSensorDecoder_DecodesPayload)} using device {device.DeviceID}"); await lora.setDeviceModeAsync(LoRaArduinoSerial._device_mode_t.LWOTAA); await lora.setIdAsync(device.DevAddr, device.DeviceID, device.AppEUI); await lora.setKeyAsync(device.NwkSKey, device.AppSKey, device.AppKey); await lora.SetupLora(this.testFixture.Configuration.LoraRegion); var joinSucceeded = await lora.setOTAAJoinAsyncWithRetry(LoRaArduinoSerial._otaa_join_cmd_t.JOIN, 20000, 5); if (!joinSucceeded) { Assert.True(joinSucceeded, "Join failed"); } // wait 1 second after joined await Task.Delay(Constants.DELAY_FOR_SERIAL_AFTER_JOIN); await lora.transferPacketWithConfirmedAsync("1234", 10); await Task.Delay(Constants.DELAY_BETWEEN_MESSAGES); // +CMSG: ACK Received await AssertUtils.ContainsWithRetriesAsync("+CMSG: ACK Received", this.lora.SerialLogs); // Find "0000000000000011: message '{"value":1234}' sent to hub" in network server logs await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: message '{{\"value\":1234}}' sent to hub"); this.lora.ClearSerialLogs(); testFixture.ClearNetworkServerLogEvents(); }
public async Task OTAA_Join_With_Valid_Device_Updates_DeviceTwin() { var device = this.testFixture.Device1_OTAA; Console.WriteLine($"Starting {nameof(OTAA_Join_With_Valid_Device_Updates_DeviceTwin)} using device {device.DeviceID}"); var twinBeforeJoin = await testFixture.GetTwinAsync(device.DeviceID); await lora.setDeviceModeAsync(LoRaArduinoSerial._device_mode_t.LWOTAA); await lora.setIdAsync(device.DevAddr, device.DeviceID, device.AppEUI); await lora.setKeyAsync(device.NwkSKey, device.AppSKey, device.AppKey); await lora.SetupLora(this.loraRegion); var joinSucceeded = await lora.setOTAAJoinAsyncWithRetry(LoRaArduinoSerial._otaa_join_cmd_t.JOIN, 20000, 5); if (!joinSucceeded) { Assert.True(joinSucceeded, "Join failed"); } await Task.Delay(Constants.DELAY_FOR_SERIAL_AFTER_JOIN); // After join: Expectation on serial // +JOIN: Network joined // +JOIN: NetID 010000 DevAddr 02:9B:0D:3E //Assert.Contains("+JOIN: Network joined", this.lora.SerialLogs); await AssertUtils.ContainsWithRetriesAsync( (s) => s.StartsWith("+JOIN: NetID", StringComparison.Ordinal), this.lora.SerialLogs ); // verify status in device twin await Task.Delay(TimeSpan.FromSeconds(60)); var twinAfterJoin = await this.testFixture.GetTwinAsync(device.DeviceID); Assert.NotNull(twinAfterJoin); Assert.NotNull(twinAfterJoin.Properties.Reported); Assert.True(twinAfterJoin.Properties.Reported.Contains("FCntUp"), "Property FCntUp does not exist"); Assert.True(twinAfterJoin.Properties.Reported.Contains("FCntDown"), "Property FCntDown does not exist"); Assert.True(twinAfterJoin.Properties.Reported.Contains("NetId"), "Property NetId does not exist"); Assert.True(twinAfterJoin.Properties.Reported.Contains("DevAddr"), "Property DevAddr does not exist"); Assert.True(twinAfterJoin.Properties.Reported.Contains("DevNonce"), "Property DevNonce does not exist"); Assert.True(twinAfterJoin.Properties.Reported.Contains("NwkSKey"), "Property NwkSKey does not exist"); Assert.True(twinAfterJoin.Properties.Reported.Contains("AppSKey"), "Property AppSKey does not exist"); Assert.True(twinAfterJoin.Properties.Reported.Contains("DevEUI"), "Property DevEUI does not exist"); var devAddrBefore = (string)twinBeforeJoin.Properties.Reported["DevAddr"]; var devAddrAfter = (string)twinAfterJoin.Properties.Reported["DevAddr"]; var actualReportedDevEUI = (string)twinAfterJoin.Properties.Reported["DevEUI"]; Assert.NotEqual(devAddrAfter, devAddrBefore); Assert.Equal(device.DeviceID, actualReportedDevEUI); Assert.True((twinBeforeJoin.Properties.Reported.Version) < (twinAfterJoin.Properties.Reported.Version), "Twin was not updated after join"); // Verify network server log // 0000000000000001: join request received await testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: join request received"); // 0000000000000001: querying the registry for device key await testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: querying the registry for device key"); // 0000000000000001: saving join properties twins await testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: saving join properties twins"); // 0000000000000001: join accept sent await testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: join accept sent"); }
public async Task Test_ABP_Confirmed_And_Unconfirmed_Message() { const int MESSAGES_COUNT = 10; var device = this.testFixture.Device5_ABP; Console.WriteLine($"Starting {nameof(Test_ABP_Confirmed_And_Unconfirmed_Message)} using device {device.DeviceID}"); await lora.setDeviceModeAsync(LoRaArduinoSerial._device_mode_t.LWABP); await lora.setIdAsync(device.DevAddr, device.DeviceID, null); await lora.setKeyAsync(device.NwkSKey, device.AppSKey, null); await lora.SetupLora(this.testFixture.Configuration.LoraRegion); // Sends 10x unconfirmed messages for (var i = 0; i < MESSAGES_COUNT; ++i) { var msg = (101 + i).ToString(); Console.WriteLine($"{device.DeviceID}: Sending unconfirmed '{msg}' {i+1}/{MESSAGES_COUNT}"); await lora.transferPacketAsync(msg, 10); await Task.Delay(Constants.DELAY_BETWEEN_MESSAGES); // After transferPacket: Expectation from serial // +MSG: Done await AssertUtils.ContainsWithRetriesAsync("+MSG: Done", this.lora.SerialLogs); // 0000000000000005: valid frame counter, msg: 1 server: 0 await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: valid frame counter, msg:"); // 0000000000000005: decoding with: DecoderValueSensor port: 8 await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: decoding with: {device.SensorDecoder} port:"); // 0000000000000005: message '{"value": 51}' sent to hub await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: message '{{\"value\":{msg}}}' sent to hub"); this.lora.ClearSerialLogs(); testFixture.ClearNetworkServerLogEvents(); } // Sends 10x confirmed messages for (var i = 0; i < MESSAGES_COUNT; ++i) { var msg = (51 + i).ToString(); Console.WriteLine($"{device.DeviceID}: Sending confirmed '{msg}' {i+1}/{MESSAGES_COUNT}"); await lora.transferPacketWithConfirmedAsync(msg, 10); await Task.Delay(Constants.DELAY_BETWEEN_MESSAGES); // After transferPacketWithConfirmed: Expectation from serial // +CMSG: ACK Received await AssertUtils.ContainsWithRetriesAsync("+CMSG: ACK Received", this.lora.SerialLogs); // 0000000000000005: valid frame counter, msg: 1 server: 0 await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: valid frame counter, msg:"); // 0000000000000005: decoding with: DecoderValueSensor port: 8 await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: decoding with: {device.SensorDecoder} port:"); // 0000000000000005: message '{"value": 51}' sent to hub await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: message '{{\"value\":{msg}}}' sent to hub"); this.lora.ClearSerialLogs(); testFixture.ClearNetworkServerLogEvents(); } }
public async Task Test_OTAA_Confirmed_And_Unconfirmed_Message() { const int MESSAGES_COUNT = 10; var device = this.testFixture.Device4_OTAA; Console.WriteLine($"Starting {nameof(Test_OTAA_Confirmed_And_Unconfirmed_Message)} using device {device.DeviceID}"); await lora.setDeviceModeAsync(LoRaArduinoSerial._device_mode_t.LWOTAA); await lora.setIdAsync(device.DevAddr, device.DeviceID, device.AppEUI); await lora.setKeyAsync(device.NwkSKey, device.AppSKey, device.AppKey); await lora.SetupLora(this.testFixture.Configuration.LoraRegion); var joinSucceeded = await lora.setOTAAJoinAsyncWithRetry(LoRaArduinoSerial._otaa_join_cmd_t.JOIN, 20000, 5); if (!joinSucceeded) { Assert.True(joinSucceeded, "Join failed"); } // wait 1 second after joined await Task.Delay(Constants.DELAY_FOR_SERIAL_AFTER_JOIN); // Sends 10x unconfirmed messages for (var i = 0; i < MESSAGES_COUNT; ++i) { var msg = (100 + i).ToString(); await lora.transferPacketAsync(msg, 10); await Task.Delay(Constants.DELAY_FOR_SERIAL_AFTER_SENDING_PACKET); // After transferPacket: Expectation from serial // +MSG: Done await AssertUtils.ContainsWithRetriesAsync("+MSG: Done", this.lora.SerialLogs); // 0000000000000005: valid frame counter, msg: 1 server: 0 await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: valid frame counter, msg:"); // 0000000000000005: decoding with: DecoderValueSensor port: 8 await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: decoding with: {device.SensorDecoder} port:"); // 0000000000000005: message '{"value": 51}' sent to hub await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: message '{{\"value\":{msg}}}' sent to hub"); this.lora.ClearSerialLogs(); testFixture.ClearNetworkServerLogEvents(); await Task.Delay(Constants.DELAY_BETWEEN_MESSAGES); } // Sends 10x confirmed messages for (var i = 0; i < MESSAGES_COUNT; ++i) { var msg = (50 + i).ToString(); await lora.transferPacketWithConfirmedAsync(msg, 10); await Task.Delay(Constants.DELAY_FOR_SERIAL_AFTER_SENDING_PACKET); // After transferPacketWithConfirmed: Expectation from serial // +CMSG: ACK Received await AssertUtils.ContainsWithRetriesAsync("+CMSG: ACK Received", this.lora.SerialLogs); // 0000000000000005: valid frame counter, msg: 1 server: 0 //await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: valid frame counter, msg:"); // 0000000000000005: decoding with: DecoderValueSensor port: 8 await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: decoding with: {device.SensorDecoder} port:"); // 0000000000000005: message '{"value": 51}' sent to hub await this.testFixture.ValidateNetworkServerEventLogStartsWithAsync($"{device.DeviceID}: message '{{\"value\":{msg}}}' sent to hub"); this.lora.ClearSerialLogs(); testFixture.ClearNetworkServerLogEvents(); await Task.Delay(Constants.DELAY_BETWEEN_MESSAGES); } }
public async Task Test_OTAA_Confirmed_Receives_C2D_Message() { var device = this.testFixture.Device9_OTAA; Console.WriteLine($"Starting {nameof(Test_OTAA_Confirmed_Receives_C2D_Message)} using device {device.DeviceID}"); await lora.setDeviceModeAsync(LoRaArduinoSerial._device_mode_t.LWOTAA); await lora.setIdAsync(device.DevAddr, device.DeviceID, device.AppEUI); await lora.setKeyAsync(device.NwkSKey, device.AppSKey, device.AppKey); await lora.SetupLora(this.testFixture.Configuration.LoraRegion); var joinSucceeded = await lora.setOTAAJoinAsyncWithRetry(LoRaArduinoSerial._otaa_join_cmd_t.JOIN, 20000, 5); if (!joinSucceeded) { Assert.True(joinSucceeded, "Join failed"); } // wait 1 second after joined await Task.Delay(Constants.DELAY_FOR_SERIAL_AFTER_JOIN); // Sends 2x confirmed messages for (var i = 1; i <= 2; ++i) { var msg = (10 + i).ToString(); Console.WriteLine($"{device.DeviceID}: Sending confirmed '{msg}' {i}/10"); await lora.transferPacketWithConfirmedAsync(msg, 10); await Task.Delay(Constants.DELAY_BETWEEN_MESSAGES); // +CMSG: ACK Received await AssertUtils.ContainsWithRetriesAsync("+CMSG: ACK Received", this.lora.SerialLogs); this.lora.ClearSerialLogs(); testFixture.ClearNetworkServerLogEvents(); } // sends C2D - between 10 and 99 var c2dMessageBody = (100 + random.Next(90)).ToString(); await this.testFixture.SendCloudToDeviceMessage(device.DeviceID, c2dMessageBody); Console.WriteLine($"Message {c2dMessageBody} sent to device, need to check if it receives"); var foundC2DMessage = false; var foundReceivePacket = false; var expectedRxSerial = $"+CMSG: PORT: 1; RX: \"{ToHexString(c2dMessageBody)}\""; Console.WriteLine($"Expected C2D received log is: {expectedRxSerial}"); // Sends 8x confirmed messages, stopping if C2D message is found for (var i = 2; i <= 10; ++i) { var msg = (10 + i).ToString(); Console.WriteLine($"{device.DeviceID}: Sending confirmed '{msg}' {i}/10"); await lora.transferPacketWithConfirmedAsync(msg, 10); await Task.Delay(TimeSpan.FromSeconds(5)); // After transferPacketWithConfirmed: Expectation from serial // +CMSG: ACK Received await AssertUtils.ContainsWithRetriesAsync("+CMSG: ACK Received", this.lora.SerialLogs); // check if c2d message was found // 0000000000000009: C2D message: 58 (var foundC2DMessageInNetworkServerLog, _) = await this.testFixture.FindNetworkServerEventLog((e, deviceID, messageBody) => { return(messageBody.StartsWith($"{device.DeviceID}: C2D message: {c2dMessageBody}")); }, new FindNetworkServerEventLogOptions { Description = $"{device.DeviceID}: C2D message: {c2dMessageBody}", MaxAttempts = 1 }); // We should only receive the message once if (foundC2DMessageInNetworkServerLog) { Console.WriteLine($"{device.DeviceID}: Found C2D message in log (after sending {i}/10) ? {foundC2DMessage}"); Assert.False(foundC2DMessage, "Cloud to Device message should have been detected in Network Service module only once"); foundC2DMessage = true; } var localFoundCloudToDeviceInSerial = this.lora.SerialLogs.Contains(expectedRxSerial); if (localFoundCloudToDeviceInSerial) { Assert.False(foundReceivePacket, "Cloud to device message should have been received only once"); foundReceivePacket = true; } this.lora.ClearSerialLogs(); testFixture.ClearNetworkServerLogEvents(); await Task.Delay(Constants.DELAY_BETWEEN_MESSAGES); } Assert.True(foundC2DMessage, $"Did not find '{device.DeviceID}: C2D message: {c2dMessageBody}' in logs"); // checks if log arrived if (!foundReceivePacket) { foundReceivePacket = this.lora.SerialLogs.Contains(expectedRxSerial); } Assert.True(foundReceivePacket, $"Could not find lora receiving message '{expectedRxSerial}'"); }