Search code examples
google-cloud-platformmqttgoogle-cloud-iot

IoT Core publish to topic on another registry


What I am trying to do is publish a message from a device in one registry to a device in another registry.

What I found out is that you can only publish to topics in the registry your device is in and if you try to publish to a topic in another registry you get a EOFException and you get disconnected from the MQTT server.

The flow I was trying to go for is I have a registry of mobile devices (phones) that have their own topics to do things but they also need to communicate to a hub registry that communicates with IoT devices (gets/updates device information) which also have their own IoT registry

As I said I can publish messages to topics in my registry without error but as soon as I try to do it outside my registry I get an error.

Is there no way to have inter-registry communication?

What is a "standard" way to communicate between devices through different topics if you cant do cross registry?


Solution

  • You can achieve your goal using Cloud Functions that handle the data received thought Cloud IoT Core and PubSub in a registry A then sending this data as a configuration message do a device on the registry B.

    The flow will be something like: Device 1 > MQTT Server Registry A > Pub/Sub Topic Registry A > Cloud Functions > HTTP Config message to > Registry B > MQTT Server Registry B > Devices 2

    You can see in this tutorial that I wrote about Cloud IoT Core and I show how to send configuration messages to the devices. In your case, the only change that you need is that the config message will go to a device in a different registry.

    Link to the tutorial: https://medium.com/google-cloud/gps-cellular-asset-tracking-using-google-cloud-iot-core-firestore-and-mongooseos-4dd74921f582

    Code part that sends config messages, but in my code, the registry is a constant variable: https://github.com/alvarowolfx/asset-tracker-gcp-mongoose-os/blob/master/functions/index.js#L22

    Hope that this can help you.