rtthread 以太网 (LAN8720A)
基于以太网的应用mqtt,在**rtthread 以太网 (LAN8720A)**中已经实现了tcp/ip通信正常,接下需要启用mqtt模块,
在rtthread中田间 pahomqtt 软件包,并右键详细配置
软件包
|---->property
| |---->Paho MQTT:嵌入式平的的Eclipse Paho MQTT C/C++客户端 √
| |---->使能MQTT示例 √
路径:rtthread\packages\pahomqtt-v1.1.0\samples
#define MQTT_URI "tcp://192.168.1.100:61613" //设置mqtt服务器ip和端口
#define MQTT_USERNAME "admin" //设置mqtt连接用户名
#define MQTT_PASSWORD "password" //设置mqtt连接用户密码
#define MQTT_SUBTOPIC "mqtt_test" //设置订阅topic
#define MQTT_PUBTOPIC "mqtt_test" //设置发送消息topic
mqtt服务器软件 apache-apollo-1.7.1-windows-distro.zip 下载地址
解压apache-apollo-1.7.1-windows-distro.zip
cd apache-apollo-1.7.1\bin
apollo.cmd create mymqtt_server //创建服务器实例
创建成功后会在bin目录中创建一个 mybroker
|----->mymqtt_server
| |----->bin 运行脚本
| |----->etc 环境配置
| |----->users.properties 用来配置可以使用服务器的用户以及相应的密码。
| |----->groups.properties 持有群体的用户映射,可以通过组而不是单个用户简化访问控制列表。
| |----->black-list.txt 用来存放不允许连接服务器的IP地址,相当于黑名单类似的东西。
| |----->login.config 是一个服务器认证的配置文件,
| |----->apollo.xml 服务器主配置文件该配置文件用于控制打开的端口,队列,安全,虚拟主机设置等。
| |----->data 存储持久化数据
| |-----> log 运行日志
| |----->tmp 临时文件密码
返回信息
------------------------------------------------------------
Creating apollo instance at: mymqtt_server
Generating ssl keystore...
Warning:
JKS ├▄╘┐┐Γ╩╣╙├╫¿╙├╕±╩╜íú╜¿╥Θ╩╣╙├ "keytool -importkeystore -srckeystore keystore -destkeystore keystore -deststore
type pkcs12" ╟¿╥╞╡╜╨╨╥╡▒Ω╫╝╕±╩╜ PKCS12íú
You can now start the broker by executing:
"D:\Program Files\MQTT_server\apache-apollo-1.7.1\bin\mymqtt_server\bin\apollo-broker" run
Or you can setup the broker as Windows service and run it in the background:
"D:\Program Files\MQTT_server\apache-apollo-1.7.1\bin\mymqtt_server\bin\apollo-broker-service" install
"D:\Program Files\MQTT_server\apache-apollo-1.7.1\bin\mymqtt_server\bin\apollo-broker-service" start
mymqtt_server/bin/etc/apollo.xml
修改服务器ip信息
cd apache-apollo-1.7.1\bin\mymqtt_server\bin
apollo-broker.cmd run
返回信息
------------------------------------------------------------
_____ .__ .__
/ _ \ ______ ____ | | | | ____
/ /_\ \\____ \ / _ \| | | | / _ \
/ | \ |_> > <_> ) |_| |_( <_> )
\____|__ / __/ \____/|____/____/\____/
\/|__| Apache Apollo (1.7.1)
oading configuration file 'D:\Program Files\MQTT_server\apache-apollo-1.7.1\bin\mymqtt_server\etc\apollo.xml'.
NFO | OS : Windows 10 10.0
NFO | JVM : Java HotSpot(TM) 64-Bit Server VM 1.8.0_271 (Oracle Corporation)
NFO | Apollo : 1.7.1 (at: D:\Program Files\MQTT_server\apache-apollo-1.7.1)
NFO | Starting store: leveldb store at D:\Program Files\MQTT_server\apache-apollo-1.7.1\bin\mymqtt_server\data
NFO | Accepting connections at: tcp://192.168.1.100:61613
NFO | Accepting connections at: tls://192.168.1.100:61614
NFO | Accepting connections at: ws://192.168.1.100:61623/
NFO | Accepting connections at: wss://192.168.1.100:61624/
NFO | Administration interface available at: https://192.168.1.100:61681/
NFO | Administration interface available at: http://192.168.1.100:61680/
通过返回信息可以看到
MQTT服务器TCP连接端口:tcp://192.168.1.100:61613
后台登录接口:
https://192.168.1.100:61681/
http://192.168.1.100:61680/
初始默认帐号是admin,密码password
进入后台管理
在浏览器中输入 http://192.168.1.100/
输入账户admin,密码password
即可看到mqtt管理控制页
选择 Virtual Hosts -->点击Topics创建主题 mqtt_test
路径:apache-apollo-1.7.1/examples/mqtt/websocket/index.html
浏览器中打开index.html
在Destination中填写一下信息
host:192.168.1.100
port:默认
Destination: mqtt_test (需要订阅的主题)
COMNET 下载地址
打开 COMNET.exe
选择网络,选择MQTT
服务器端IP:192.168.1.100
端口号:61613
用户名:admin
密码:password
点击启用
订阅主题:mqtt_test并点击订阅主题
发布主题:mqtt_test
点击启用后反馈信息
[2020/12/4 13:18:02 369] 正在连接MQTT服务器...
[2020/12/4 13:18:33 497] MQTT连接成功
启动设备连接mqtt服务器
msh />mqtt_start
[D/mqtt.sample] inter mqtt_connect_callback!
[D/mqtt] ipv4 address port: 61613
[D/mqtt] HOST = '192.168.1.100'
msh />[I/mqtt] MQTT server connect success.
[I/mqtt] Subscribe #0 test OK!
[D/mqtt.sample] inter mqtt_online_callback!
启动设备发送mqtt
msh />mqtt_publish mqtt_test
msh />[D/mqtt.sample] mqtt sub callback: mqtt_test test
启动设备接受mqtt
msh />mqtt_subscribe mqtt_test
[D/mqtt] MQTT client topic(mqtt_test) is already subscribed.
设备提示意见连接到了mqtt服务器中
在mqtt demo页中发送信息栏中填写信息点击send
[2020/12/4 14:06:41 124] MQTT[TOPIC:mqtt_test]接收9字节:
[2020/12/4 14:06:41 132] send_test
[D/mqtt.sample] mqtt sub callback: mqtt_test send_test
在mqtt客户端填写信息,点击发布消息–>即可在测试网页中看到接收到的信息
rtthread 设备接受信息
[D/mqtt.sample] mqtt sub callback: mqtt_test send_test
在mqtt demo页中看到接收到的信息
send_test
msh />mqtt_publish mqtt_test
msh />[D/mqtt.sample] mqtt sub callback: mqtt_test test
在mqtt demo页中看到接收到的信息
test
[2020/12/4 14:06:41 124] MQTT[TOPIC:mqtt_test]接收9字节:
[2020/12/4 14:06:41 132] test