Reputation: 3
In my application, messages are received (and sent) from a device to GC over MQTT. I want to retrieve (and send) messages from Pubsub (and later put that data in a Firebase RTDB) but I don't know which topic I have to susbcribe to: my device sends to /devices/[deviceID]/state but impossible to create a Sub for this topic in GC Console.
Thanks. J
Upvotes: 0
Views: 916
Reputation: 3332
Your device should send to the /events MQTT topic, not /state.
Once you do that, then the messages will go to the Pub/Sub topic that you set on the registry that holds the device.
So when you created the registry, you assigned a Pub/Sub topic to it. In order to respond to the messages coming from the device, you'll need to create a Subscription on that topic somewhere. The easiest/quickest way to set that up is to have a Google Cloud Function that triggers on Pub/Sub messages. So for each message your device sends, the GCF (Cloud Function) will fire.
If there's a LOT of messages coming in (by a lot, I mean like, thousands in a short amount of time) then you might want to look into something else, like a Cloud Run container that has a process running that subscribes to the Pub/Sub topic instead and processes them as they come in.
For going the other way, Cloud -> back to your device, you're looking at the IoT Core Admin SDK. So whatever it is that's initiating the messages, you'll want to implement the IoT Core Admin SDK. Depending on what you're doing, you also want to consider configuration messages vs. commands.
Configuration messages persist in the Cloud. So a device, even if it's offline when the message is sent, will eventually get it when they connect next to the Cloud. Commands are fire and forget. Once you send it, it's gone, so if the device isn't online and listening when it's sent, the message is lost. The tradeoff is commands are quite a bit faster.
I've written a couple step by step tutorials on how to do this stuff with Raspberry Pis and Python, first one is here:
https://medium.com/GabeWeiss/cloud-iot-step-by-step-connecting-raspberry-pi-python-2f27a2893ab5
That one's all about connecting to the Cloud, so you might be past it already, but I link at the bottom to the next, which is walking through sending messages back to the device from the Cloud which it sounds like would be helpful.
Upvotes: 2