问题
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"
回答1:
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.
来源:https://stackoverflow.com/questions/35754485/mosquitto-sending-messages-to-azure-iothub