Exemplo n.º 1
0
        public async Task NoComponentSendTelemetry()
        {
            await pnpClient.SendTelemetryValueAsync("{t1:2}");

            Assert.Equal("application/json", mockClient.MessageSent.ContentType);
            Assert.Equal("utf-8", mockClient.MessageSent.ContentEncoding);
            Assert.False(mockClient.MessageSent.Properties.ContainsKey("$.sub"));
            Assert.Equal("{t1:2}", Encoding.UTF8.GetString(mockClient.MessageSent.GetBytes()));
        }
Exemplo n.º 2
0
        private async Task EnterDeviceLoopAsync()
        {
            await Task.Run(async() =>
            {
                this.logger.LogWarning("Entering Device Loop");
                while (!this.quitSignal.IsCancellationRequested)
                {
                    temperatureSeries1.Add(DateTime.Now, CurrentTemperature1);
                    temperatureSeries2.Add(DateTime.Now, CurrentTemperature2);

                    await pnpClient.SendTelemetryValueAsync(
                        JsonConvert.SerializeObject(new { workingSet = Environment.WorkingSet }));

                    await pnpClient.SendComponentTelemetryValueAsync("thermostat1",
                                                                     JsonConvert.SerializeObject(new { temperature = CurrentTemperature1 }));

                    await pnpClient.SendComponentTelemetryValueAsync("thermostat2",
                                                                     JsonConvert.SerializeObject(new { temperature = CurrentTemperature2 }));

                    logger.LogInformation($"Telemetry sent. t1 {CurrentTemperature1}, t2 {CurrentTemperature2}, ws:{Environment.WorkingSet}");
                    await Task.Delay(1000);
                }
            });
        }