Thursday, 13 September 2018

Tinkering OpenWRT (13) : Setup MQTT




Step 1: Install on openWRT
opkg update 
opkg install mosquitto mosquitto-client libmosquitto
Step 2: Start up
/etc/init.d/mosquitto enable
/etc/init.d/mosquitto restart

Step 3: Install on PC with Ubuntu
Many suggest test on the same machine with localhost. But once the mosquitto_sub will hang the terminal on openwrt, so I installed MQTT on my PC and used it as the client.

$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa 
$ sudo apt-get update 
$ sudo apt-get install mosquitto 
$ sudo apt-get install mosquitto-clients
Step 4: Start the sub on openwrt
root@JoySince:~# mosquitto_sub  -t "topic" -v

Step 5: Ping the openwrt on PC
$ mosquitto_pub -h OPENWRT_IP_ADDRESS -t "topic" -m "test message"
$ mosquitto_pub -h OPENWRT_IP_ADDRESS -t "topic" -m "enjoy"

Result on openwrt:
root@JoySince:~# mosquitto_sub  -t "topic" -v
topic test message
topic enjoy


ref:
https://mosquitto.org/blog/2011/08/mosquitto-on-openwrt/
https://blog.csdn.net/hehexiaoxia/article/details/72834625
https://loralandia.com/mosquitto-mqtt-broker-installation-on-openwrt/
https://blog.csdn.net/xiaoreqing/article/details/77571881

No comments:

Post a Comment