I am not an expert on Google IoT, but few days ago I got the same doubts about it. Apparently, although we can publish to /events
, /config
and /state
topics, using MQTT protocol, only topic /config
and, maybe, /state
can work through subscriptions with the same protocol.
The conclusion I got, after reading many times the documentation, that is not so clear, and asking some questions here at stackoverflow is: you can not use MQTT to subscribe to any topic in order to receive those data sent to /events
topic.
To accomplish this, you have to create a Pub/Sub topic associating it to your device:
- On Google Cloud IoT Core Console, click on your registry ID;
- Create a standard telemetry topic;
- After topic created, click on the topic to see its details;
- Its details will open on Google Cloud Pub/Sub panel;
- In this panel, you can create a subscription to the created topic, by clicking on the "create subscription button".
Now that you have a "google cloud pub/sub topic" linked to "google cloud iot core /events
telemetry MQTT topic" and a respective subscription, you can use the google pub/sub library to receive notifications through created subscription when data are sent to /events
topic.
Maybe the following link can also help:
https://cloud.google.com/iot/docs/how-tos/devices#creating_a_device_registry_with_multiple_pubsub_topics
I hope this can help you. If I made any mistake in my answer, may someone edit it with some improvement or correction.