mosquitto_pub や mosquitto_sub コマンドで合ってるパスワード入力したのに Unable to connect (This feature is not supported.). が出て解決したメモ

mosquitto_pub や mosquitto_sub コマンドで合ってるパスワード入力したのに Unable to connect (This feature is not supported.). が出て解決したメモです。

前提

Windows でも Linux でも起きる話だと思いますが、ここでは Windows です。

ひとまず Mosquitto をインストールして、

mosquitto_passwd -b pwfile username password

のような形でユーザー ID とパスワードを設定しているような状況で、

password_file c:\mosquitto\pwfile
allow_anonymous false
listener 1883

の conf ファイルをもとに起動されている状況の Mosquitto MQTT ブローカーです。

このあたりは一旦サッと始めるシンプルな MQTT ブローカーな状況です。

Mosquitto のバージョンは 、

mosquitto version 2.0.15 starting

でした。

合ってるパスワードを入れても Unable to connect (This feature is not supported.).

今回、授業で MQTT を使うときに、ハマっている人がいて自分もうまく解決できなかった、合ってるパスワードを入れても Unable to connect (This feature is not supported.). という状況。

繰り返しますが。パスワードは合っています。

さて、そのうえで、購読では、

mosquitto_sub -u username -p password -t test

のコマンドが、

Unable to connect (This feature is not supported.).

となり、発行でも、

mosquitto_pub -u username -p password -t test -m message

のコマンドが、

Unable to connect (This feature is not supported.).

となって、え?「This feature is not supported. って機能がサポートされてない!?なんで!?」となってしまいました。

パスワード用のパラメータは -p でなく -P なことに注意

はい。原因が分かればなんてことはないのですが、

mosquitto_pub -u username -p password -t test -m message

パスワード用のパラメータは -p でなく -P なことに注意です。

購読は、

mosquitto_sub -u username -P password -t test

で、発行は、

mosquitto_pub -u username -P password -t test -m message

これで通ります!

ユーザー指定が -u なので、うっかりパスワード指定も小文字で -p でやってしまったのが原因でした。

加えて、

  • -p 指定は本来ポート番号を指定なので数字だがパスワードと勘違いして文字列を入れるとポート番号が数字以外を指定されていて「Unable to connect (This feature is not supported.).」と、繋がらないよ&そんな機能は(ポート指定)にはないよとなる
  • -p と -P を間違えたときに「もしかしてポート指定とパスワード指定間違ってません?」といった親切なエラーは出ないのでそんな機能は(ポート指定)にはないよルートで原因を追おうとすると迷う

といった思考ミスが起こっていた次第です。

いやー。注意ですね!一つ勉強になりました!