Ithhubにメッセージを送信し、応答を受信しようとするラズベリーパイのための簡単なアプリを作ろうとしていますが、何も起こっていません。IOTハブがメッセージを受信しない、または送信しない
デバイスコントローラから接続文字列をコピーしました。 Ofcource私はこの質問のためにそれを隠しました。
メッセージが正常に送信されたことがわかりましたが、私がiothubを確認すると、受信したメッセージは0件でした。
iothubの無料層を使用しているIamはこれに制限がありますか?
public sealed partial class MainPage : Page
{
private const string DeviceConnectionString = "Hidden";
private readonly DeviceClient _deviceClient;
public MainPage()
{
this.InitializeComponent();
_deviceClient = DeviceClient.CreateFromConnectionString(DeviceConnectionString, TransportType.Amqp); //Already tried using different transport types but no succes.
}
public async Task SendEvent()
{
Debug.WriteLine("\t{0}> Sending message", DateTime.Now.ToLocalTime());
var commandMessage = new Message(Encoding.ASCII.GetBytes("Cloud to device message."));
await _deviceClient.SendEventAsync(commandMessage);
Debug.WriteLine("Succesfully sended message to IotHub");
}
public async Task ReceiveCommands()
{
Debug.WriteLine("\nDevice waiting for commands from IoTHub...\n");
while (true)
{
var receivedMessage = await _deviceClient.ReceiveAsync();
if (receivedMessage != null)
{
var messageData = Encoding.ASCII.GetString(receivedMessage.GetBytes());
Debug.WriteLine("\t{0}> Received message: {1}", DateTime.Now.ToLocalTime(), messageData);
var propCount = 0;
foreach (var prop in receivedMessage.Properties)
{
Debug.WriteLine("\t\tProperty[{0}> Key={1} : Value={2}", propCount++, prop.Key, prop.Value);
}
await _deviceClient.CompleteAsync(receivedMessage);
Debug.WriteLine("Finishing recieving message");
}
await Task.Delay(TimeSpan.FromSeconds(1));
}
}
private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
Debug.WriteLine("Sending event");
await SendEvent();
await ReceiveCommands();
Debug.WriteLine("Received commands");
}
}
[デバイスエクスプローラ]で送信したD2Cメッセージが表示されますか(https://github.com/Azure/azure-iot-sdk-csharp/tree/master/tools/DeviceExplorer#run-the-sample-応用)? –
ありがとうございます:イベントを受信しています... 2017-04-10 20:08:53>デバイス:[RaspberryPI]、データ:[Cloud to device message] – Barsonax
「私はiothubをチェックしますか?受信したメッセージが0件あります。 "あなたは 'ReceiveCommands()'を使ってこれらのD2Cメッセージを受け取ることを意味しますか? –