Události
Vytváření inteligentních aplikací
17. 3. 21 - 21. 3. 10
Připojte se k řadě meetupů a vytvořte škálovatelná řešení AI založená na skutečných případech použití s kolegy vývojáři a odborníky.
ZaregistrovatTento prohlížeč se už nepodporuje.
Upgradujte na Microsoft Edge, abyste mohli využívat nejnovější funkce, aktualizace zabezpečení a technickou podporu.
Azure IoT Hub is a fully managed service that enables reliable and secure bi-directional communications between millions of devices and a solution back end.
Devices and data sources in an IoT solution can range from a simple network-connected sensor to a powerful, standalone computing device. Devices may have limited processing capability, memory, communication bandwidth, and communication protocol support. The IoT device SDKs enable you to implement client applications for a wide variety of devices and back-end applications.
The device SDK for .NET facilitates building devices running .NET that connect to Azure IoT Hub.
The service SDK for .NET facilitates building back-end applications using .NET that manage and allow controlling devices from the Cloud.
Use the .NET IoT devices client to connect and send messages to your IoT Hub.
Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.
Install-Package Microsoft.Azure.Devices.Client
dotnet add package Microsoft.Azure.Devices.Client
This example connects to the IoT Hub and sends one message per second.
string deviceKey = "<deviceKey>";
string deviceId = "<deviceId>";
string iotHubHostName = "<IoTHubHostname>";
var deviceAuthentication = new DeviceAuthenticationWithRegistrySymmetricKey(deviceId, deviceKey);
DeviceClient deviceClient = DeviceClient.Create(iotHubHostName, deviceAuthentication, TransportType.Mqtt);
while (true)
{
double currentTemperature = 20 + Rand.NextDouble() * 15;
double currentHumidity = 60 + Rand.NextDouble() * 20;
var telemetryDataPoint = new
{
messageId = _messageId++,
deviceId = deviceId,
temperature = currentTemperature,
humidity = currentHumidity
};
string messageString = JsonConvert.SerializeObject(telemetryDataPoint);
Message message = new Message(Encoding.ASCII.GetBytes(messageString));
message.Properties.Add("temperatureAlert", (currentTemperature > 30) ? "true" : "false");
await deviceClient.SendEventAsync(message);
Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);
await Task.Delay(1000);
}
View the complete list of Azure IoT Upsamples.
View the Azure IoT Hub developer guide for more guidance.
Zpětná vazba k produktu Azure SDK for .NET
Azure SDK for .NET je open source projekt. Vyberte odkaz pro poskytnutí zpětné vazby:
Události
Vytváření inteligentních aplikací
17. 3. 21 - 21. 3. 10
Připojte se k řadě meetupů a vytvořte škálovatelná řešení AI založená na skutečných případech použití s kolegy vývojáři a odborníky.
Zaregistrovat