Hi Dasha, I’m using the HiveMQ Cloud Free account right now trying to get this to work.
I can connect without a problem locally (on my laptop) using nodejs. I got my webhost provider to white list all the IP’s that nslookup returns for my private HiveMQ URL so that solved my ECONNREFUSED problem on the webhost but now nothing is getting published from the webhost which was working when it was able to successfully connect to one of the ip addresses (52.31.149.80).
When I try using the mqtt-cli I on my laptop I get NOT_AUTHORIZED with the following command:
c:\code\apps\mqtt-test>mqtt-cli pub
-h ceed143f4b0947a9b3f40ae94badd9c7.s1.eu.hivemq.cloud
-p 8883 -u myuserid --password mypasswd
-t "my/test/topic" -m "hello"
-s --cafile isrgrootx1.pem
-d -v
The verbose output is included at the end of this post.
I am providing the correct username and password and cafile because:
- my hand coded nodejs example works on my laptop
- the mqtt node client version works on my laptop
c:\code\apps\mqtt-test>mqtt -version
MQTT.js version: 4.3.7
- the websocket test client on the HiveMQ site works
- mosquitto_sub & _pub running on my laptop will publishe & show topics successfully
However:
- mqtt-cli on my laptop doesn’t work for pub & sub – it throws NOT_AUTHORIZED
- the hand-coded nodejs example on my webhost doesn’t throw an error anymore but doesn’t publish anything either.
I don’t understand what I’m missing.
Let me know if there is something I can try. I’m waiting on my host provider to give me shell access to try mqtt-cli on my webhost, but for now I’d like to get mqtt-cli pub/sub working on my laptop.
Here is the verbose output from the mqtt-cli on my laptop for pub & sub:
PUBLISH: Command: Publish:: {topics=[‘my/test/topic’], qos=[AT_MOST_ONCE], retain=null, messageExpiryInterval=null, payloadFormatIndicator=null, contentType=null, responseTopic=null, correlationData=null, userProperties=null, Connect:: {host=ceed143f4b0947a9b3f40ae94badd9c7.s1.eu.hivemq.cloud, port=8883, version=null, identifier=null, user=‘websvc’, keepAlive=null, cleanStart=null, useDefaultSsl=true, sslConfig=false, willTopic=‘null’, willQos=null, willMessage=‘null’, willRetain=null, willMessageExpiryInterval=null, willDelayInterval=null, willPayloadFormatIndicator=null, willContentType=‘null’, willResponseTopic=‘null’, willCorrelationData=null, willUserProperties=null, sessionExpiryInterval= null, userProperties=null, receiveMaximum=null, sendMaximum=null, maximumPacketSize=null, sendMaximumPacketSize=null, topicAliasMaximum=null, sendTopicAliasMaximum=null, requestProblemInformation=null, requestResponseInformation=null}}
PUBLISH: Setting value of ‘version’ to default value: MQTT_5_0
PUBLISH: Created ‘identifier’: mqttClient-MQTT_5_0-5993af79-497f-4112-a937-5f8cc5ea0127
PUBLISH: Cache hasKey client {identifier=‘mqttClient-MQTT_5_0-5993af79-497f-4112-a937-5f8cc5ea0127’, host=‘ceed143f4b0947a9b3f40ae94badd9c7.s1.eu.hivemq.cloud’} - false
CLIENT mqttClient-MQTT_5_0-5993af79-497f-4112-a937-5f8cc5ea0127: sending CONNECT with Mqtt5Connect: MqttConnect{keepAlive=60, cleanStart=true, sessionExpiryInterval=0, restrictions=MqttConnectRestrictions{receiveMaximum=65535, sendMaximum=65535, maximumPacketSize=268435460, sendMaximumPacketSize=268435460, topicAliasMaximum=0, sendTopicAliasMaximum=16, requestProblemInformation=true, requestResponseInformation=false}, simpleAuth=MqttSimpleAuth{username and password}}
PUBLISH: com.hivemq.client.mqtt.mqtt5.exceptions.Mqtt5ConnAckException: CONNECT failed as CONNACK contained an Error Code: NOT_AUTHORIZED.
at com.hivemq.client.internal.mqtt.MqttBlockingClient.connect(MqttBlockingClient.java:91)
at com.hivemq.cli.mqtt.MqttClientExecutor.mqtt5Connect(MqttClientExecutor.java:83)
at com.hivemq.cli.mqtt.AbstractMqttClientExecutor.connectMqtt5Client(AbstractMqttClientExecutor.java:238)
at com.hivemq.cli.mqtt.AbstractMqttClientExecutor.connect(AbstractMqttClientExecutor.java:201)
at com.hivemq.cli.mqtt.MqttClientExecutor.connect(MqttClientExecutor.java:67)
at com.hivemq.cli.mqtt.AbstractMqttClientExecutor.getMqttClientFromCacheOrConnect(AbstractMqttClientExecutor.java:434)
at com.hivemq.cli.mqtt.AbstractMqttClientExecutor.publish(AbstractMqttClientExecutor.java:110)
at com.hivemq.cli.mqtt.MqttClientExecutor.publish(MqttClientExecutor.java:67)
at com.hivemq.cli.commands.cli.PublishCommand.run(PublishCommand.java:127)
at picocli.CommandLine.executeUserObject(CommandLine.java:1729)
at picocli.CommandLine.access$900(CommandLine.java:145)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2101)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2068)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:1935)
at picocli.CommandLine.execute(CommandLine.java:1864)
at com.hivemq.cli.MqttCLIMain.main(MqttCLIMain.java:73)
PUBLISH: CONNECT failed as CONNACK contained an Error Code: NOT_AUTHORIZED.
thank you for your help!