Search code examples
google-cloud-platformmqttpublish-subscribe

Google Cloud MQTT message exchange between 2 devices in the same registry


I have a number of devices in the same registry, and a common topic (event, the default one). Let's see for 2 devices only. Device A and B are connected to IoT Core with their own credentials.

Device A need to send messages (publish) so the Device B can receive it, and viceversa. I would like to publish on events from Device A, and receive a command (devices/[device-id]/commands/#) on Device B. Then ,based on the message, I need to send "back" a command from Device B to A.

I have also subscribed Pub/Sub to that topic to be able to see published messages, but how to subscribe from the other Device B and instantiate a full duplex kind of communication?

Unfortunately, I can not use wildcards like device/+/commands/# etc on GCP.

Thanks.


Solution

  • You'll have to implement it, we don't have anything specific built-in I don't believe. So e.g. Device A publishes to Pub/Sub topic A, where a Cloud Function subscribes to topic A and sends command to device B via the Admin API. Then vice versa, device B publishes to Pub/Sub topic B, and a separate Cloud Function subscribes to topic B and publishes to device A.

    Via MQTT there's no way to subscribe to the other device directly, you have to go through the Cloud.