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....
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