Search code examples
ibm-cloudmqttiotmosquittowatson-iot

mosquitto and ibm watson iot on raspberry pi Connection Refused


I am new to IoT. I just installed mosquitto on my rpi and registered my devices and gateway in Watson IoT Platform using this tutorial: https://developer.ibm.com/recipes/tutorials/using-mosquitto-as-a-gateway-for-watson-iot/

Mosquitto works fine local mode. However, I am facing a problem subscribing/publishing using these commands:

 mosquitto_sub -d -h pxci52.messaging.internetofthings.ibmcloud.com  -i 'g:pxci52:myfstream:gateway' -t iot-2/type/myfstream/id/gateway/evt/status/fmt/raw

and

sudo mosquitto_pub -d -h pxci52.messaging.internetofthings.ibmcloud.com  -i 'g:pxci52:myfstream:gateway' -t iot-2/type/myfstream/id/gateway/evt/status/fmt/raw -m "hello"

Here is my conf file:

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest topic


log_type error
log_type warning
log_type notice
log_type information

connection_messages true
log_timestamp true

include_dir /etc/mosquitto/conf.d
connection bridge-to-watsoniot
address pxci52.messaging.internetofthings.ibmcloud.com:1883
cleansession true
try_private false
bridge_attempt_unsubscribe false
notifications false
notification_topic iot-2/type/myfstream/id/gateway/evt/status/fmt/raw
remote_username token
remote_password xxxxxx
remote_clientid g:pxci52:myfstream:gateway
notifications true
topic iot-2/type/+/id/+/cmd/+/fmt/+ in iot-2/type/+/id/+/cmd/+/fmt/+
topic iot-2/type/+/id/+/evt/+/fmt/+ out iot-2/type/+/id/+/evt/+/fmt/+
connection_messages true


Solution

  • I see in the log Invalid userID (token) for device auth: ClientID='g:pqci52:myfstream:gateway' Instead of just "token" try "use-token-auth" That is what is specified in the recipe example you were following.