コード例 #1
0
        [HttpGet] public async Task SendCloudToDeviceAsync(string id)
        {
            ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(iotHubConnectionString);

            Task.Run(() => { ReceiveFeedbackAsync(serviceClient); });
            var commandMessage = new Microsoft.Azure.Devices.Message(Encoding.ASCII.GetBytes("Cloud to device message."));

            commandMessage.Ack = Microsoft.Azure.Devices.DeliveryAcknowledgement.Full;
            await serviceClient.SendAsync(id, commandMessage);

            Response.StatusCode = 200; // OK = 200
        }
コード例 #2
0
 //Service client = iot Hub
 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);
 }