用mqtt客户端发数据到 thingsboard Error: Connection refused: Not authorized

根据官方教程用nodejs那个 mqtt pub尝试多次发布到thingsboard都出错

mqtt pub -v -q 1 -h "$THINGSBOARD_HOST_NAME" -t "v1/devices/me/telemetry" -u '$ACCESS_TOKEN' -m "{"temperature":42}"

Error: Connection refused: Not authorized

解决办法就是换 mosquitto_pub 就可以!

apt install mosquitto-clients -y
mosquitto_pub -d -q 1 -h "$THINGSBOARD_HOST_NAME" -t "v1/devices/me/telemetry" -u "$ACCESS_TOKEN" -m "{"temperature":42}"

详细格式参考 https://thingsboard.io/docs/reference/mqtt-api/

root@xxx:/home/xxx# mosquitto_pub -d -q 1 -h "xxxxx" -t "v1/devices/me/telemetry" -u "xxx" -m "{"temperature":42}"
Client mosq-JICzALFi4ZaOvR3awd sending CONNECT
Client mosq-JICzALFi4ZaOvR3awd received CONNACK (0)
Client mosq-JICzALFi4ZaOvR3awd sending PUBLISH (d0, q1, r0, m1, 'v1/devices/me/telemetry', ... (16 bytes))
Client mosq-JICzALFi4ZaOvR3awd received PUBACK (Mid: 1, RC:0)
Client mosq-JICzALFi4ZaOvR3awd sending DISCONNECT

另一个坑:如果用windows版本的 emqx 的客户端能够连上的,但不能订阅主题,所以就没有pub功能了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 当出现"Error: Connection refused: Not authorized"错误时,这意味着连接被拒绝,因为没有授权。这通常是由于未正确配置用户名和密码所导致的。在引用\[1\]中,可以看到在使用mosquitto_sub和mosquitto_pub命令时,连接被拒绝并显示"Connection Refused: not authorised"错误。而在引用\[2\]中,开启服务器时也出现了类似的错误,显示"Error: Invalid password hash for user nick"和"Error opening password file"。这些错误表明密码验证出现了问题,可能是密码文件的路径或密码哈希值不正确。为了解决这个问题,您需要确保正确设置了用户名和密码,并将密码文件的路径正确配置在mosquitto.conf文件中。另外,还需要确保密码文件中的密码哈希值与配置文件中的一致。引用\[3\]中提到,通过使用无密码验证方式可以成功通过测试,但是当关闭匿名访问并设置密码文件后,需要确保密码文件的正确性。 #### 引用[.reference_title] - *1* *2* *3* [MQTT入门2 -- “Error: Invalid password hash for user nick.”和“Connection Refused: not authorised....](https://blog.csdn.net/dongaoren8380/article/details/101887912)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值