Last active
November 28, 2017 08:57
-
-
Save h-sakano/84dc4bd8371be4f0e8dddc9388974348 to your computer and use it in GitHub Desktop.
Google Cloud IoT CoreでMQTTを試す ref: https://qiita.com/h-sakano/items/8a4960595e3359ad9ea4
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
$ openssl genrsa -out rsa_private.pem 2048 | |
$ openssl rsa -in rsa_private.pem -pubout -out rsa_cert.pem |
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
$ wget https://pki.goog/roots.pem |
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
$ 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 |
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
$ 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 |
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
$ 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