uniquejava / blog

My notes regarding the vibrating frontend :boom and the plain old java :rofl.
Creative Commons Zero v1.0 Universal
11 stars 5 forks source link

mosquitto and MQTT #222

Open uniquejava opened 6 years ago

uniquejava commented 6 years ago

install/start/stop on macOS

I have installed mosquito broker on my mac using brew install mosquitto.

Normally I don't give any commands to start the mosquitto server. It is started automatically. I have verified that it is running by using the command ps -ef | grep mosquitto, which gives the following output

➜  ~ ps -ef|grep mosquitto
  501   896     1   0 Wed08AM ??         0:38.07 /usr/local/opt/mosquitto/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf

Usage

➜  ~ /usr/local/opt/mosquitto/sbin/mosquitto stop
Error: Unknown option 'stop'.
mosquitto version 1.4.14 (build date 2017-10-22 16:34:39+0100)

mosquitto is an MQTT v3.1.1/v3.1 broker.

Usage: mosquitto [-c config_file] [-d] [-h] [-p port]

 -c : specify the broker config file.
 -d : put the broker into the background after starting.
 -h : display this help.
 -p : start the broker listening on the specified port.
      Not recommended in conjunction with the -c option.
 -v : verbose mode - enable all logging types. This overrides
      any logging options given in the config file.

See http://mosquitto.org/ for more information.

stop: kill -9 above-pid or killall mosquitto start: /usr/local/opt/mosquitto/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf

Pub

Simple

mosquitto_pub -h 127.0.0.1 -p 1883 -t "hello" -m '123' -d

Watson

 mosquitto_pub -i d:orgId:watsonDeviceType:watsonDeviceId \
-h ORG_ID.messaging.internetofthings.ibmcloud.com \
-u "use-token-auth" -P 'testToken' \
-t "iot-2/evt/EVENT_TYPE/fmt/json" \
-m '{"hello":"world"}'

Sub

Simple

mosquitto_sub -t "iot-2/type/+/id/+/evt/+/fmt/json"
mosquitto_sub -t "#"

Watson

mosquitto_sub -i a:ORG_ID:myapp \
-h ORG_ID.messaging.internetofthings.ibmcloud.com \
-u "a-ORG_ID-fwdfcoq0kn" -P 'xxxxxxxxx' \
-t "iot-2/type/+/id/+/evt/+/fmt/json" -d

Troubleshoot

Connection refused的原因是mosquitto service未启动.

➜  ~ mosquitto_pub -t "hello" -m '123' -d
Error: Connection refused

References

  1. Restarting the mosquito broker
uniquejava commented 6 years ago

mosquitto settings

https://sclausen.github.io/ngx-mqtt/