Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Can a cloud function subscribe to an MQTT topic?

I am trying to listen to the MQTT commands topic. I am publishing messages to the MQTT commands topic through the IoT Core function sendCommandToDevice. Is there a way to use a cloud function to listen to the commands MQTT topic?

 

Here is the link to the documentation for the sendCommandToDevice function https://cloud.google.com/iot/docs/reference/cloudiot/rest/v1/projects.locations.registries.devices/s...

0 1 941
1 REPLY 1

As discussed in [1] , you have following options:

- set up a Pub/Sub topic to which all commands are sent and then trigger a function which relays them to the appropriate device via MQTT.

- have two listeners/functions (one to relay the command and the other to do whatever else you like).

- use a simulator to send messages that executes a cloud function which in turn sends the message to Cloud pub/sub topic. There can be a separate Cloud pub/sub topic for the response back from the bridge devices.

[1] https://stackoverflow.com/questions/71358751/can-a-google-cloud-function-subscribe-to-an-mqtt-topic

Top Solution Authors