Skip to content

Instantly share code, notes, and snippets.

@h-sakano
Last active Nov 28, 2017
Embed
What would you like to do?
Google Cloud IoT CoreでMQTTを試す ref: https://qiita.com/h-sakano/items/8a4960595e3359ad9ea4
$ openssl genrsa -out rsa_private.pem 2048
$ openssl rsa -in rsa_private.pem -pubout -out rsa_cert.pem
$ wget https://pki.goog/roots.pem
$ sudo apt-get install -y build-essential libssl-dev libffi-dev
$ sudo pip install -r requirements.txt
$ sudo pip install google-api-python-client
$ wget https://pki.goog/roots.pem
$ ls
cloudiot_mqtt_example.py requirements.txt rsa_private.pem roots.pem
$ python cloudiot_mqtt_example.py --registry_id=iot-gateway --project_id=my_project --device_id=gateway1 --algorithm=RS256 --private_key_file=./rsa_private.pem --cloud_region=asia-east1
Creating JWT using RS256 from private key file ./rsa_private.pem
Publishing message 1/100: 'iot-gateway/gateway1-payload-1'
('on_connect', 'Connection Accepted.')
on_publish
Publishing message 2/100: 'iot-gateway/gateway1-payload-2'
on_publish
Publishing message 3/100: 'iot-gateway/gateway1-payload-3'
on_publish
Publishing message 4/100: 'iot-gateway/gateway1-payload-4'
on_publish
Publishing message 5/100: 'iot-gateway/gateway1-payload-5'
on_publish
Publishing message 6/100: 'iot-gateway/gateway1-payload-6'
on_publish
Publishing
$ gcloud beta pubsub subscriptions create --topic events my-subscriptions
$ gcloud beta pubsub subscriptions pull --auto-ack my-subscriptions
┌────────────────────────────────┬─────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ DATA │ MESSAGE_ID │ ATTRIBUTES │
├────────────────────────────────┼─────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ iot-gateway/gateway1-payload-1 │ 173994752831401 │ deviceId=gateway1 deviceNumId=3104791428628451 deviceRegistryId=iot-gateway deviceRegistryLocation=asia-east1 projectId=factory-iot subFolder= │
└────────────────────────────────┴─────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment