Demonstrates how to relay messages from one device to another device using Google Cloud functions.
Make sure that you have enabled the Cloud IoT Core API from the Google Cloud Console.
From the Google Cloud Console create a Google Cloud IoT Core Device Registry. When you create it, either set the event notification topic to an existing PubSub topic or create a new topic to be used for the demo.
The dev2dev instructions explain how to upload the Google Cloud function to relay messages from one device to another.
Set it to trigger on the topic configured with your device registry.
gcloud beta functions deploy relayCloudIot \
--stage-bucket=gs://your-gcs-bucket \
--trigger-topic=your-topic-id
- Generate an RSA256 keypair:
openssl req -x509 -newkey rsa:2048 -days 3650 -keyout rsa_private.pem -nodes -out \
rsa_cert.pem -subj "/CN=unused"
- Use the keypair to register your device:
gcloud beta iot devices create \
--registry=<your-registry-id> \
--region "europe-west1" \
--public-key path=rsa_cert.pem,type=rs256 <deviceId>
cd virtualdevice
npm install
node virtualdev.js --cloudRegion=<region-from-console> \
--projectId<your-project-id> \
--deviceId=<your-device-id>\
--privateKeyFile=../rsa_private.pem \
--algorithm=RS256 \
--numMessages=1 \
--registryId=<your-registry-id>
When the sample runs, the virtual device will trigger configuration updates from the Google Cloud Functions.
When you run the sample code, run the following command to print the output from the Google Cloud Function:
gcloud beta functions logs read
This is useful for debugging aspects of the demo that run on the Google Cloud Functions callback.