如何使用UWP将覆盆子pi3设备的消息发送到azure事件中心? [英] How to send message form raspberry pi3 device to azure event hub using UWP ?

查看:64
本文介绍了如何使用UWP将覆盆子pi3设备的消息发送到azure事件中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有运行windows 10 iot core和visual studio 2015社区的raspberry pi 3设备,

我想将数据从我的设备发送到azure事件hub,我在google上度过了几天的情侣我得到了一些控制台应用程序,我可以发送和接收天蓝色事件中心的数据,同样瘦我尝试使用UWP,但它不适合我,

Hi,
I have raspberry pi 3 device running windows 10 iot core and visual studio 2015 community,
I want to send the data from my device to azure event hub, I spent couples of day on google I got some console application where I can send and receive the data on azure event hub, same thin I tried with UWP but its not working for me,

await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(message)));


此行上的
继续等待,而不是前进。



我提到 是链接

https://docs.microsoft.com/en-us / azure / event-hubs / event-hubs-dotnet-standard-getstarted-send



http://stackoverflow.com/questions/36061131/uwp-app -for-recievering-messages-from-azure-iot-hub / 38195572#38195572

任何人都可以提供样本,帮助我向/从Azure Event Hub发送/接收数据。



谢谢

sushil



我尝试过:




on this line Keep on waiting only, not going forward.

I referred this link
https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send
and
http://stackoverflow.com/questions/36061131/uwp-app-for-recievering-messages-from-azure-iot-hub/38195572#38195572
Can any one have sample that will help me to send/receive data to/from Azure Event Hub.

thanks
sushil

What I have tried:

private static EventHubClient eventHubClient;
        private const string EhConnectionString = "Endpoint=sb://-----.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=-------";

private const string EhEntityPath = "------";

private async Task MainAsync()
        {
            try
            {
                var connectionStringBuilder = new EventHubsConnectionStringBuilder(EhConnectionString)
                {
                    EntityPath = EhEntityPath
                };

                eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
                await SendMessagesToEventHub();
                await eventHubClient.CloseAsync();
            }
            catch (Exception ex)
            {
                textBlock.Text = ex.Message;
            }
        }

private async Task SendMessagesToEventHub()
        {
            int avgSpeed = 10; // m/s
            Random rand = new Random();
            int seq = 0;
            while (true)
            {
                int currentSpeed = avgSpeed + rand.Next() * 4 - 2;
                var data = new
                {
                    guid = "guid_1",
                    organization = "Elpis_IT_2",
                    displayname = "Telemetry_2",
                    location = "Elpis_Lab_2",
                    measurename = "mn_2",
                    unitofmeasure = "n",
                    timecreated = DateTime.Now.ToString() + "__" + (++seq),
                    value = rand.Next()
                };
                var message = JsonConvert.SerializeObject(data); 
                try
                {
                    await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(message)));
                    textBlock1.Text = $"Sending message: {message}";
                    await Task.Delay(10);
                    //number--;
                }
                catch (Exception ex)
                {
                    textBlock2.Text = ex.Message;
                }
            }
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            MainAsync();
        }

推荐答案

发送消息:{message};
await Task.Delay( 10 );
// number - ;
}
catch (Exception ex)
{
textBlock2.Text = ex.Message;
}
}
私有 void btnSend_Click( object sender,RoutedEventArgs e)
{
MainAsync();
}
"Sending message: {message}"; await Task.Delay(10); //number--; } catch (Exception ex) { textBlock2.Text = ex.Message; } } private void btnSend_Click(object sender, RoutedEventArgs e) { MainAsync(); }


这篇关于如何使用UWP将覆盆子pi3设备的消息发送到azure事件中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆