标签 - mqtt

html mqtt websockets 网页mqtt收发消息    2022-12-03 00:08:15    4    0    0

目录结构

title

注意:hostport一定是数值,不能加引号

title

  • 上图中的IP和hostport是websockets服务,如何开启websockets服务点击这里
mqtt    2021-03-14 22:06:03    30    0    0

步骤

  1. apt-get update
  2. apt-get install mosquitto
  3. apt-get install mosquitto mosquitto-clients
  • 修改 /etc/mosquitto/mosquitto.conf , 在相应位置添加以下内容
  1. log_type error
  2. log_type warning
  3. log_type notice
  4. log_type information
  5.  
  6. connection_messages true
  7. log_timestamp true
  8.  
  9. include_dir /etc/mosquitto/conf.d
  • 启动Mosquitto Server
  1. root@raspberrypi:~# /etc/init.d/mosquitto start
  2. [ ok ] Starting mosquitto (via systemctl): mosquitto.service.
  • Testing the Mosquitto server

Open up two more terminal windows.

In Terminal window 1 type:
mosquitto_sub -d -t hello/world

n Terminal window 2 type: mosquitto_pub -d -t hello/world -m "Hello from Terminal window 2!"

最后,可以去看看相关

判断主人手机是否在家的方法

自问、自答

自问

请教一下,mosquitto的配置文件怎么设置可以改 端口和IP? 我现在是 如下图的IP,造成用访问主机IP地址无法连接服务器.

  • netstat -ntulp |grep 1883

title

我试过在 mosquitto.conf中加入listener 1883 0.0.0.0 没效果啊

自答

  • 解决方法: 在mosquitto.conf中加入如下两句:
  1. listener 1883
  2. allow_anonymous true

title

注意:开启webs