Skip to content
This repository was archived by the owner on Oct 29, 2023. It is now read-only.

Commit e715c14

Browse files
committed
docs: Add readme
1 parent 1aeda48 commit e715c14

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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=iot/api-client/mqtt_example/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 manage device authorization.
11+
This example connects a device to `Google Cloud IoT Core`_ via MQTT, using a JWT for authentication. After connecting, the device publishes messages to the device's MQTT topic at a rate of one per second.
12+
Note that before you can run this sample, you must register a device as described in the parent README. For the gateway samples, you must register and bind a device as described in the `Cloud IoT gateway docs <https://cloud.google.com/iot/docs/how-tos/gateways/#setup>`_.
13+
14+
15+
16+
17+
.. _Google Cloud IoT Core: https://cloud.google.com/iot/docs
18+
19+
20+
21+
22+
23+
Setup
24+
-------------------------------------------------------------------------------
25+
26+
27+
Authentication
28+
++++++++++++++
29+
30+
This sample requires you to have authentication setup. Refer to the
31+
`Authentication Getting Started Guide`_ for instructions on setting up
32+
credentials for applications.
33+
34+
.. _Authentication Getting Started Guide:
35+
https://cloud.google.com/docs/authentication/getting-started
36+
37+
Install Dependencies
38+
++++++++++++++++++++
39+
40+
#. Clone python-docs-samples and change directory to the sample directory you want to use.
41+
42+
.. code-block:: bash
43+
44+
$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
45+
46+
#. 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.
47+
48+
.. _Python Development Environment Setup Guide:
49+
https://cloud.google.com/python/setup
50+
51+
#. Create a virtualenv. Samples are compatible with Python 3.6+.
52+
53+
.. code-block:: bash
54+
55+
$ virtualenv env
56+
$ source env/bin/activate
57+
58+
#. Install the dependencies needed to run the samples.
59+
60+
.. code-block:: bash
61+
62+
$ pip install -r requirements.txt
63+
64+
.. _pip: https://pip.pypa.io/
65+
.. _virtualenv: https://virtualenv.pypa.io/
66+
67+
Samples
68+
-------------------------------------------------------------------------------
69+
70+
MQTT example
71+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
72+
73+
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
74+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=iot/api-client/mqtt_example/cloudiot_mqtt_example.py,iot/api-client/mqtt_example/README.rst
75+
76+
77+
78+
79+
To run this sample:
80+
81+
.. code-block:: bash
82+
83+
$ python cloudiot_mqtt_example.py
84+
85+
usage: cloudiot_mqtt_example.py [-h] --algorithm {RS256,ES256}
86+
[--ca_certs CA_CERTS]
87+
[--cloud_region CLOUD_REGION] [--data DATA]
88+
--device_id DEVICE_ID
89+
[--gateway_id GATEWAY_ID]
90+
[--jwt_expires_minutes JWT_EXPIRES_MINUTES]
91+
[--listen_dur LISTEN_DUR]
92+
[--message_type {event,state}]
93+
[--mqtt_bridge_hostname MQTT_BRIDGE_HOSTNAME]
94+
[--mqtt_bridge_port {8883,443}]
95+
[--num_messages NUM_MESSAGES]
96+
--private_key_file PRIVATE_KEY_FILE
97+
[--project_id PROJECT_ID] --registry_id
98+
REGISTRY_ID
99+
[--service_account_json SERVICE_ACCOUNT_JSON]
100+
{device_demo,gateway_send,gateway_listen} ...
101+
102+
Example Google Cloud IoT Core MQTT device connection code.
103+
104+
positional arguments:
105+
{device_demo,gateway_send,gateway_listen}
106+
device_demo Connects a device, sends data, and receives data.
107+
gateway_send Sends data from a gateway on behalf of a device that
108+
is bound to it.
109+
gateway_listen Listens for messages sent to the gateway and bound
110+
devices.
111+
112+
optional arguments:
113+
-h, --help show this help message and exit
114+
--algorithm {RS256,ES256}
115+
Which encryption algorithm to use to generate the JWT.
116+
--ca_certs CA_CERTS CA root from https://pki.google.com/roots.pem
117+
--cloud_region CLOUD_REGION
118+
GCP cloud region
119+
--data DATA The telemetry data sent on behalf of a device
120+
--device_id DEVICE_ID
121+
Cloud IoT Core device id
122+
--gateway_id GATEWAY_ID
123+
Gateway identifier.
124+
--jwt_expires_minutes JWT_EXPIRES_MINUTES
125+
Expiration time, in minutes, for JWT tokens.
126+
--listen_dur LISTEN_DUR
127+
Duration (seconds) to listen for configuration
128+
messages
129+
--message_type {event,state}
130+
Indicates whether the message to be published is a
131+
telemetry event or a device state message.
132+
--mqtt_bridge_hostname MQTT_BRIDGE_HOSTNAME
133+
MQTT bridge hostname.
134+
--mqtt_bridge_port {8883,443}
135+
MQTT bridge port.
136+
--num_messages NUM_MESSAGES
137+
Number of messages to publish.
138+
--private_key_file PRIVATE_KEY_FILE
139+
Path to private key file.
140+
--project_id PROJECT_ID
141+
GCP cloud project name
142+
--registry_id REGISTRY_ID
143+
Cloud IoT Core registry id
144+
--service_account_json SERVICE_ACCOUNT_JSON
145+
Path to service account json file.
146+
147+
148+
149+
150+
151+
.. _Google Cloud SDK: https://cloud.google.com/sdk/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 manage device
10+
authorization.
11+
12+
This example connects a device to `Google Cloud IoT Core`_ via MQTT, using a JWT for
13+
authentication. After connecting, the device publishes messages to the device's
14+
MQTT topic at a rate of one per second.
15+
16+
Note that before you can run this sample, you must register a device as described
17+
in the parent README. For the gateway samples, you must register and bind a device
18+
as described in the
19+
`Cloud IoT gateway docs <https://cloud.google.com/iot/docs/how-tos/gateways/#setup>`_.
20+
21+
setup:
22+
- auth
23+
- install_deps
24+
25+
samples:
26+
- name: MQTT example
27+
file: cloudiot_mqtt_example.py
28+
show_help: True
29+
30+
cloud_client_library: false
31+
32+
folder: iot/api-client/mqtt_example

0 commit comments

Comments
 (0)