Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


Cloud IoT Core MQTT Communication Example

Found it hard to understand the docs here: https://cloud.google.com/iot/docs/how-tos/mqtt-bridge and no examples online, so wrote my own.

Using MQTT to talk between an AndroidThings board and Cloud IoT Core Pub/Sub

Based on the example here:


but written for AndroidThings instead of Java. Also tried to keep it simpler and separated.

See MainActivity.java for use.

You connect like this

communicator = new IotCoreCommunicator.Builder()
        .withCloudRegion("your-region") // ex: europe-west1
        .withProjectId("your-project-id")   // ex: supercoolproject23236
        .withRegistryId("your-registry-id") // ex: my-devices
        .withDeviceId("a-device-id") // ex: my-test-raspberry-pi

and publish a message like this:

communicator.publishMessage("subtopic", "Hello World");

finally when finished: