发送数据到ListView

问题描述

这是一个UWP应用程序,我想将在“有效负载”中获得的数据不仅发送到IoT中心,而且还发送到应用程序中获得的ListView。 原始功能起作用。也就是说,将JSON有效负载发送到我的IoT中心,但是我想扩展功能,以便我也可以在ListView中查看消息。

在这里发送我的有效载荷的代码:

namespace SharedLibrary.Services
{
    public class TemperatureService
    {
        public static readonly Random rnd = new Random();

        public static async Task SendMessageAsync(DeviceClient deviceClient)
        {
            while(true)
            {
                var data = new TamperatureModel
                {
                    Temperature = rnd.Next(10,30),Humidity = rnd.Next(30,60)
                };

                var json = JsonConvert.SerializeObject(data);

                var payload = new Message(Encoding.UTF8.GetBytes(json));
                await deviceClient.SendEventAsync(payload);

                Console.WriteLine($"Message sent: {json}");

                break;
            }        
        }
        
        public static async Task SendMessageToDeviceAsync(MAD.ServiceClient serviceClient,string targetDeviceId,string message)
        {
            var payload = new MAD.Message(Encoding.UTF8.GetBytes(message));
            await serviceClient.SendAsync(targetDeviceId,payload);
        }        
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)