I have written an angularjs application. There is a form where users can type in notes. The application uses a specific mqtt topic like "app/form/notes". The paho js client in this app publish and subscribe to the same topic. If a user is typing in somthing, the onchange event occurs and publish the new value to the topic.
Now the client is receiving the message which he was sending to the broker, because he is subscribed to this topic. But the received message is useless, because the value is the same. What is the best way to handle this problem?
I have written an angularjs application. There is a form where users can type in notes. The application uses a specific mqtt topic like "app/form/notes". The paho js client in this app publish and subscribe to the same topic. If a user is typing in somthing, the onchange event occurs and publish the new value to the topic.
Now the client is receiving the message which he was sending to the broker, because he is subscribed to this topic. But the received message is useless, because the value is the same. What is the best way to handle this problem?
Share Improve this question edited May 8, 2016 at 21:46 Irshu 8,4468 gold badges55 silver badges66 bronze badges asked May 8, 2016 at 20:57 trm1904trm1904 211 silver badge2 bronze badges2 Answers
Reset to default 4If you find that you are subscribing to the same channel you are publishing to, there may be something you can do to your topic structure to make that not so. For example, if you follow the semantic MQTT topic naming suggested in this post: http://tinkerman.cat/mqtt-topic-naming-convention/ you will find a lot of these types of issues go away. If you are a temperature sensor, you care about publishing your temperature, not subscribing to it.
If you are already semantically named, and you have a chatty topic that a lot of players are pub'ing and sub'ing to, some brokers will add the publisher to the MQTT message automatically, and if they do not, add it to the payload. This obviously makes it easy to spoof, so do not rely on that publisher identity being correct for any sensitive transactions.
Include a client id with in the message so when a message arrives it can easily be identified as having originated locally and can be ignored.
e.g.
{
'source': 'client1',
'payload': 'asdfghjklqwertyuiop...'
}