8000 Add example for retrieving a large file from Cloud Storage onto a dev… · johnmanong/python-docs-samples@7a96771 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a96771

Browse files
noerogJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
Add example for retrieving a large file from Cloud Storage onto a device (GoogleCloudPlatform#1350)
1 parent d93f8e9 commit 7a96771

File tree

7 files changed

+948
-0
lines changed

7 files changed

+948
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
.. This file is automatically generated. Do not edit this file directly.
2+
3+
Google Cloud IoT Core Python Samples
4+
===============================================================================
5+
6+
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
7+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/README.rst
8+
9+
10+
This directory contains samples for Google Cloud IoT Core. `Google Cloud IoT Core`_ allows developers to easily integrate Publish and Subscribe functionality with devices and programmatically authorize devices.
11+
Before you run the sample, you must retrieve the Google root certificate. For example, ``wget https://pki.goog/roots.pem`` or ``curl https://pki.goog/roots.pem > roots.pem``.
12+
13+
14+
15+
16+
.. _Google Cloud IoT Core: https://cloud.google.com/iot/docs
17+
18+
Setup
19+
-------------------------------------------------------------------------------
20+
21+
22+
Authentication
23+
++++++++++++++
24+
25+
This sample requires you to have authentication setup. Refer to the
26+
`Authentication Getting Started Guide`_ for instructions on setting up
27+
credentials for applications.
28+
29+
.. _Authentication Getting Started Guide:
30+
https://cloud.google.com/docs/authentication/getting-started
31+
32+
Install Dependencies
33+
++++++++++++++++++++
34+
35+
#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions.
36+
37+
.. _Python Development Environment Setup Guide:
38+
https://cloud.google.com/python/setup
39+
40+
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
41+
42+
.. code-block:: bash
43+
44+
$ virtualenv env
45+
$ source env/bin/activate
46+
47+
#. Install the dependencies needed to run the samples.
48+
49+
.. code-block:: bash
50+
51+
$ pip install -r requirements.txt
52+
53+
.. _pip: https://pip.pypa.io/
54+
.. _virtualenv: https://virtualenv.pypa.io/
55+
56+
Samples
57+
-------------------------------------------------------------------------------
58+
59+
Server
60+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
61+
62+
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
63+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/gcs_example_mqtt_device.py;/README.rst
64+
65+
66+
67+
68+
To run this sample:
69+
70+
.. code-block:: bash
71+
72+
$ python gcs_example_mqtt_device.py
73+
74+
usage: gcs_example_mqtt_device.py [-h] --project_id PROJECT_ID --registry_id
75+
REGIST 8000 RY_ID --device_id DEVICE_ID
76+
--private_key_file PRIVATE_KEY_FILE
77+
--algorithm {RS256,ES256}
78+
[--cloud_region CLOUD_REGION]
79+
[--ca_certs CA_CERTS]
80+
[--num_messages NUM_MESSAGES]
81+
[--mqtt_bridge_hostname MQTT_BRIDGE_HOSTNAME]
82+
[--mqtt_bridge_port MQTT_BRIDGE_PORT]
83+
84+
Example Google Cloud IoT MQTT device connection code.
85+
86+
optional arguments:
87+
-h, --help show this help message and exit
88+
--project_id PROJECT_ID
89+
GCP cloud project name.
90+
--registry_id REGISTRY_ID
91+
Cloud IoT registry id
92+
--device_id DEVICE_ID
93+
Cloud IoT device id
94+
--private_key_file PRIVATE_KEY_FILE
95+
Path to private key file.
96+
--algorithm {RS256,ES256}
97+
Which encryption algorithm to use to generate the JWT.
98+
--cloud_region CLOUD_REGION
99+
GCP cloud region
100+
--ca_certs CA_CERTS CA root certificate. Get from
101+
https://pki.google.com/roots.pem
102+
--num_messages NUM_MESSAGES
103+
Number of messages to publish.
104+
--mqtt_bridge_hostname MQTT_BRIDGE_HOSTNAME
105+
MQTT bridge hostname.
106+
--mqtt_bridge_port MQTT_BRIDGE_PORT
107+
MQTT bridge port.
108+
109+
110+
111+
Device
112+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
113+
114+
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
115+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/gcs_send_to_device.py;/README.rst
116+
117+
118+
119+
120+
To run this sample:
121+
122+
.. code-block:: bash
123+
124+
$ python gcs_send_to_device.py
125+
126+
usage: gcs_send_to_device.py [-h] --project_id PROJECT_ID --bucket_name
127+
BUCKET_NAME --gcs_file_name GCS_FILE_NAME
128+
--source_file_name SOURCE_FILE_NAME
129+
--destination_file_name DESTINATION_FILE_NAME
130+
--registry_id REGISTRY_ID --device_id DEVICE_ID
131+
[--service_account_json SERVICE_ACCOUNT_JSON]
132+
[--cloud_region CLOUD_REGION]
133+
134+
Example of uploading a config (file) to Google Cloud Storage, then sending the
135+
bucket name and file name for the config to a Cloud IoT Core device.
136+
137+
optional arguments:
138+
-h, --help show this help message and exit
139+
--project_id PROJECT_ID
140+
GCP project name.
141+
--bucket_name BUCKET_NAME
142+
The name of the bucket containing the file.
143+
--gcs_file_name GCS_FILE_NAME
144+
The name of the file to be sent.
145+
--source_file_name SOURCE_FILE_NAME
146+
The name of file on the local file system.
147+
--destination_file_name DESTINATION_FILE_NAME
148+
The file to write to on the device.
149+
--registry_id REGISTRY_ID
150+
The registry for the device.
151+
--device_id DEVICE_ID
152+
The device to which to send the config update.
153+
--service_account_json SERVICE_ACCOUNT_JSON
154+
Path to service account json file.
155+
--cloud_region CLOUD_REGION
156+
Cloud region
157+
158+
159+
160+
161+
162+
.. _Google Cloud SDK: https://cloud.google.com/sdk/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is used to generate README.rst
2+
3+
product:
4+
name: Google Cloud IoT Core
5+
short_name: Cloud IoT Core
6+
url: https://cloud.google.com/iot/docs
7+
description: >
8+
`Google Cloud IoT Core`_ allows developers to easily integrate Publish and
9+
Subscribe functionality with devices and programmatically authorize
10+
devices.
11+
12+
Before you run the sample, you must retrieve the Google root certificate.
13+
For example, ``wget https://pki.goog/roots.pem`` or
14+
``curl https://pki.goog/roots.pem > roots.pem``.
15+
16+
setup:
17+
- auth
18+
- install_deps
19+
20+
samples:
21+
- name: Server
22+
file: gcs_example_mqtt_device.py
23+
show_help: True
24+
- name: Device
25+
file: gcs_send_to_device.py
26+
show_help: True
27+
28+
cloud_client_library: false

0 commit comments

Comments
 (0)
0