GCP IoT

Quick setup and test

  • Node.js MQTT Client Sample

    1. Creating Public/Private Key Pairs

  • Generating an RS256 Key

    • To generate an RSA-256 private key with a 2048-bit key size
      1
      2
      
        openssl genrsa -out gce_rsa_private.pem 2048
        openssl rsa -in gce_rsa_private.pem -pubout -out gce_rsa_cert.pem
      
    • To generate an RSA-256 private key with a 2048-bit key size, and a self-signed X.509 certificate
      1
      2
      
        openssl req -x509 -nodes -newkey rsa:2048 -keyout gce_rsa_private_x509.pem \
        -days 1000000 -out gce_rsa_cert_x509.pem -subj "/CN=unused"
      
  • Generating an ES256 key

    • To generate an ES256 key pair using the Eliptic Curve algorithm, run the following commands:
      1
      2
      
        openssl ecparam -genkey -name prime256v1 -noout -out gce_ec_private.pem
        openssl ec -in gce_ec_private.pem -pubout -out gce_ec_public.pem
      
    • To generate an ES256 key with a self-signed X.509 certificate that expires far in the future, run the following commands:
      1
      2
      
        openssl ecparam -genkey -name prime256v1 -noout -out gce_ec_private_x509.pem
        openssl req -x509 -new -key gce_ec_private_x509.pem -days 1000000 -out gce_ec_public_x509.pem -subj "/CN=unused"
      

      2. Google Cloud Account

3. Create a registry and a device in the registry, in Google Cloud IoT

4. Upload the Public Cert to the device.

5. RUN Client:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
gcloud pubsub subscriptions create \
    projects/asavie-iot/subscriptions/asavie-topics-subscription \
    --topic=projects/asavie-iot/topics/test

node cloudiot_mqtt_example_nodejs.js \
    --projectId=asavie-iot \
    --registryId=asavie-registry \
    --deviceId=asavie-device \
    --privateKeyFile=gce_rsa_private.pem \
    --numMessages=25 \
    --algorithm=RS256

gcloud pubsub subscriptions pull --auto-ack \
    projects/asavie-iot/subscriptions/asavie-topics-subscription

Java Client connect to Mqtt Bridge of GCP IoT Core

Network layer

Equinix Megaport

comments powered by Disqus