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)));
on this line Keep on waiting only, not going forward.
I referred th
is 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;
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);
}
catch (Exception ex)
{
textBlock2.Text = ex.Message;
}
}
private void btnSend_Click(object sender, RoutedEventArgs e)
{
MainAsync();
}