MQTT publish ,Does your topic contain '+' or '#'?

D:\Program Files (x86)\mosquitto>mosquitto_pub -t "iot-2/type/devicecbs1/id/+/evt/eid/fmt/json" -m alkjdklajdf
Error: Invalid input. Does your topic contain '+' or '#'?
Error: The connection was lost.

D:\Program Files (x86)\mosquitto>mosquitto_pub -t "iot-2/type/devicecbs1/id/a/evt/eid/fmt/json" -m 2374918324

D:\Program Files (x86)\mosquitto>mosquitto_pub -t "iot-2/type/devicecbs1/id/a/evt/eid/fmt/json" -m jaljdljakd


After modified the topic (delete the wildcard ‘+’ ):

mqtt onPublic----------- :iot-2/type/devicecbs1/id/a/evt/eid/fmt/json
mqtt onPublic----------- :2374918324
mqtt save data ....onPublish 
----------------------------------saveToDB--------------------------------------- = 2374918324
save to cloudant DB succeeded!
----------------------------------saveToDB--------------------------------------- = null
----------------------------------saveToDB--------------------------------------- = null
----------------------------------saveToDB--------------------------------------- = null
----------------------------------saveToDB--------------------------------------- = null
mqtt onPublic----------- :iot-2/type/devicecbs1/id/a/evt/eid/fmt/json
mqtt onPublic----------- :jaljdljakd
mqtt save data ....onPublish 
----------------------------------saveToDB--------------------------------------- = jaljdljakd
save to cloudant DB succeeded!


Note:
subscribe topic可以有wildcard,publish topic不可以有wildcard!!

MQTT协议中只有两种wildcard,一个是+,一个是#。
使用/表示一种 层次结构,意思就是比如在一个小区里有很多的device或者sensor,小区是一个层次,小区里面的每一个单元是一个层次,每个单元里每一个家庭是一个层次,每个家庭的里面可能是厨房里有温度sensor,卧室里有湿度sensor,大厅里有红外探测device,MQTT就是将这些使用”左斜杠“进行分层的,进而表示到每一个device和sensor。



你可能感兴趣的:(MQTT publish ,Does your topic contain '+' or '#'?)