Last active
December 25, 2021 12:40
-
-
Save DazWilkin/b59b390100db435309f4c66298a08764 to your computer and use it in GitHub Desktop.
Google Cloud IoT Core & Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@DazWilkin,
Could you please provide makejwt?
Thanks in advance!