Sending messages to specific MQTT devices


#1

Hi there

I have multiple devices that I’m setting up and managing through the API

I want to target specific messages to each device, and only that device should have access to that message. No device should be able to publish.

It seems MQTT doesn’t let you target like this, so I’m looking at doing it another way.

Option A.

  1. Filter all devices so they can’t publish (looks like it can be done)
  2. Filter all devices so they can’t subscribe to any channels (looks like it can be done)
  3. Now I need to subscribe them to a specific channel, related to their device_id, say ‘message/device1’ but because of the above step 2 (no subscribing) I’m unable to do this.

Is there a way to add a subscription to a device, say from the admin user, while keeping the filter in place? (This also needs to be through the API as I have a large number of devices)

Option B.

  1. Filter all devices so they can’t publish (looks like it can be done)
  2. Subscribe device to a channel relating to their device_id, say ‘message/device1’
  3. Freeze their subscription through the API, so they are then locked to only that subscription (I see I can do this through the website, but I’ll need to this for a large number of devices and so need to use the API)

Option C.
Is there another way to do this through the API? For example creating filters dynamically through the API.

Thanks

Richard


How to isolate a device in a topic related to its clientid?
#3

Hello Ricard,

Here is what you can do:

  1. You can install some filters to limit PUBLISH and SUBSCRIBE to all devices using web interface:

    Managing MQTT filters with MyQttHub to control what can be published

    …and also you can use API to list, add and remove these filters:

  2. Then, use the API to install “forced” subscriptions for targeting devices using administrator user. For that use the following to create a subscription for each device:

About that “forced” tag we are using to talk about subscriptions, it is more related to your user case description than anything else that is really forced: they are plain subscriptions that are installed through the API (instead of using MQTT SUBSCRIBE cmd).

This way, every time you need to create/start up a device, you can:

  1. Register a device using the API:

  2. Make that device to be subscribed to certain topics (some exclusive ones for your use case), using the API too:

After that, these devices will receive any “directed” MQTT message because they are subscribed (through the API) to exclusive topics and at the same time they won’t be able to UNSUBSCRIBE/SUBSCRIBE/PUBLISH anything because there are administrator filters in place that limits those operations.

Best Regards


#4

Thanks, this looks like it should work.