Skip to content

Instantly share code, notes, and snippets.

@DazWilkin
Last active December 25, 2021 12:40
Show Gist options
  • Save DazWilkin/b59b390100db435309f4c66298a08764 to your computer and use it in GitHub Desktop.
Save DazWilkin/b59b390100db435309f4c66298a08764 to your computer and use it in GitHub Desktop.
Google Cloud IoT Core & Golang
echo "Installing Mosquitto (MQTT) client tools"
opkg update > /dev/null
opkg install mosquitto mosquitto-client > /dev/null
echo "Configure GCP Cloud IoT"
SERVICE_ENDPOINT="mqtt.googleapis.com:8883"
read -p "GCP Project ID : " PROJECT
read -p "GCP Region : " REGION
read -p "GCP IoT Registry ID: " REGISTRY
read -p "GCP IoT Device ID : " DEVICE
LONG_REGISTRY=projects/${PROJECT}/locations/${REGION}/registries/${REGISTRY}
echo "Generate JWT good for 24 hours"
PASSWORD=$(\
./makejwt \
--duration=24 \
--project=${PROJECT} \
--private_key=./${DEVICE}.key.pem)
echo "Publish test message to Cloud IOT"
mosquitto_pub \
--host mqtt.googleapis.com \
--port 8883 \
--id ${LONG_REGISTRY}/devices/${DEVICE} \
--username unused \
--pw ${PASSWORD} \
--cafile /roots.pem \
--tls-version tlsv1.2 \
--protocol-version mqttv311 \
--debug \
--qos 1 \
--topic /devices/${DEVICE}/events \
--message "Hello Henry!"
@plche
Copy link

plche commented Dec 25, 2021

@DazWilkin,
Could you please provide makejwt?
Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment