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/#endpointsHowever 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发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-12 17:33