蚊子向Azure IoTHub发送消息 [英] Mosquitto sending messages to Azure IoTHub

查看:76
本文介绍了蚊子向Azure IoTHub发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure在其IoTHub中实现了MQTT协议,因此我试图使用mosquitto从我的电脑发送消息.我正在使用设备资源管理器创建azure设备.在开始时,我从那里生成了SAS令牌,但是它没有& skn ="部分,因此我尝试使用Visual Studio中兼容的事件中心来生成新的SAS.之后,我尝试使用mosquitto代理使用CONNECT数据包中的参数向我的IoTHub发送MQTT消息,如下所述:

https://azure.microsoft.com/en-us/documentation/articles/iot-hub-devguide/#endpoints

但是连接不起作用,我也不知道我在哪里做错了.使用mosquitto_pub调试,我得到以下输出:客户Mosquitto发送CONNECT错误:连接丢失了"您能帮我解决这个问题吗?预先感谢.

这是我的mosquitto命令,第一个是使用设备浏览器生成的SAS令牌,第二个是使用Visual Studio的

mosquitto_pub -h {IotHub主机名} -p 8883 -t devices/{deviceId}/消息/事件-v -V mqttv311 -i {deviceId} -d -u {Hub名称} .azure-devices.net/{deviceId} -P"HostName = {Hub名称} .azure-devices.net; DeviceId = {deviceId}; SharedAccessSignature sr = https%3a%2f%2f {事件中心兼容名称} .servicebus.windows.net%2fdevices& sig= k030AmvBkmlNwy%2fLd47N8jQuj808jJg9EXnAGmEUan4%3d& se = 2913829726& skn = iothubowner"

mosquitto_pub -h {IotHub主机名} -p 8883 -t devices/{deviceId}/消息/事件-v -V mqttv311 -i {deviceId} -d -u {Hub名称} .azure-devices.net/{deviceId} -P"HostName = {Hub名称} .azure-devices.net; DeviceId = {deviceId}; SharedAccessSignature = SharedAccessSignature sr = {Hub名称} .azure-devices.net%2fdevices%2f {deviceId}& sig =BYvo8GE%2fcOdnD8G3wsP7VElU4SwsVTSaACnif%2ffBj1k%3d& se = 1456911258"

解决方案

Azure IoT中心仅使用SSL,他们不会在您可能查看的用户名/密码信息部分进行广告宣传.但是,在在此处结束章节.您不会在命令中使用SSL.

您的密码似乎也不对.如果查看前面提到的章节,则可以抓取DeviceId = *和HostName = *部分.另外,您的SharedAccessKey的一部分似乎已被转义.也许这只是因为您将其复制到了SO中,但是请确保在使用mosquitto时并非如此.您的密码应如下所示:

  -P"SharedAccessSignature sr = yourtarget.azure-devices.net& sig = a_string_here& se = a_number& skn = policyname" 

此外,目前(2016年3月)蚊子和Azure通信之间似乎存在问题.查看此问题以获取更多详细信息.

Azure has implemented MQTT protocol in its IoTHub so I'm trying to use mosquitto to send messages from my pc. I'm creating azure devices using Device Explorer. In the beginning I generated SAS token from there, but it hasn't the "&skn=" part, so I tried to generate a new SAS using compatible event hub from visual studio. After that i tried to use mosquitto broker to send an MQTT message to my IoTHub using parameters in the CONNECT packet as explained here:

https://azure.microsoft.com/en-us/documentation/articles/iot-hub-devguide/#endpoints

However the connection doesn't work and i don't really know where I'm doing wrong. Using mosquitto_pub debugging I get this output: "Client Mosquitto sending CONNECT Error: The connection was lost" Can you please help me solve this issue? Thanks in advance.

These are my mosquitto command, the first one is with SAS token generated using device explorer, the second using visual studio:

mosquitto_pub -h {IotHub Hostname} -p 8883 -t devices/{deviceId}/messages/events -v -V mqttv311 -i {deviceId} -d -u {Hub Name}.azure-devices.net/{deviceId} -P "HostName={Hub name}.azure-devices.net;DeviceId={deviceId};SharedAccessSignature sr=https%3a%2f%2f{Event hub compatible name}.servicebus.windows.net%2fdevices&sig=k030AmvBkmlNwy%2fLd47N8jQuj808jJg9EXnAGmEUan4%3d&se=2913829726&skn=iothubowner"

mosquitto_pub -h {IotHub Hostname} -p 8883 -t devices/{deviceId}/messages/events -v -V mqttv311 -i {deviceId} -d -u {Hub Name}.azure-devices.net/{deviceId} -P "HostName={Hub name}.azure-devices.net;DeviceId={deviceId};SharedAccessSignature=SharedAccessSignature sr={Hub name}.azure-devices.net%2fdevices%2f{deviceId}&sig=BYvo8GE%2fcOdnD8G3wsP7VElU4SwsVTSaACnif%2ffBj1k%3d&se=1456911258"

解决方案

Azure IoT Hub is only working with SSL, which they don't advertise at the section you probably looked at for the username/password information. It is however briefly mentioned at the endpoints chapter here. You don't use SSL in your command.

Also your Password seems wrong. If you look at the previously mentioned chapter you can scratch the DeviceId=* and HostName=* part. In addition part of your SharedAccessKey seems to be escaped. Maybe this is just because you copied it in to SO, but be sure it isn't like that when using mosquitto. Your password should look like this:

-P "SharedAccessSignature sr=yourtarget.azure-devices.net&sig=a_string_here&se=a_number&skn=policyname"

In addition, there seems to be a problem at the the moment (march 2016) between mosquitto and Azure communication. See this question for further details.

这篇关于蚊子向Azure IoTHub发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆