Iam试图为我的树莓派制作一个简单的应用程序,它会向IOThub发送消息,然后尝试接收响应,但没有任何事情发生。物联网集线器没有收到或发送消息
我从设备控制器复制了连接字符串。我把这个问题隐藏起来了。
我看到它打印出消息已成功发送给iothub,但是当我检查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");
}
}
您能看到您在[Device Explorer]中发送的D2C消息吗(https://github.com/Azure/azure-iot-sdk-csharp/tree/master/tools/DeviceExplorer#run-the-sample-应用)? –
是iam得到这个:接收事件... 2017-04-10 20:08:53>设备:[RaspberryPI],数据:[云到设备消息。] – Barsonax
那么,你是什么意思“我检查iothub我看到0个收到的消息。“?你的意思是你使用'ReceiveCommands()'来接收这些D2C消息? –