Skip to content

Add the Python device and server files from the end-to-end-example #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Dec 7, 2017
Merged

Add the Python device and server files from the end-to-end-example #1218

merged 25 commits into from
Dec 7, 2017

Conversation

noerog
Copy link
Contributor

@noerog noerog commented Nov 14, 2017

They should live in GitHub.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 14, 2017
@theacodes theacodes requested a review from gguuss November 15, 2017 17:46
@theacodes
Copy link
Contributor

@gguuss can you review this?

@gguuss
Copy link
Contributor

gguuss commented Nov 15, 2017

I'll take a look when I can. This looks like a non-trivial amount of code without any tests so it will take me a little time to go through it.

Copy link
Contributor

@gguuss gguuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Missing requirements.txt
  • Lots of lint errors. Please run flake8 on your code
  • Missing tests (if you can't add them, I can add some when I do this for the MQTT / HTTP clients)
  • Please remove README.md use the script from scripts/readme-gen/readme_gen.py to generate from a template similar to the manager example


def discovery_url(api_key):
"""Construct the discovery url for the given api key."""
return '{}?version={}&key={}'.format(DISCOVERY_API, API_VERSION, api_key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API key is no longer necessary because the API is public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

description='Example of Google Cloud IoT registry and device management.')
# Required arguments
parser.add_argument(
'--project_id', required=True, help='GCP cloud project name.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we're not using the GOOGLE_CLOUD_PROJECT or GCLOUD_PROJECT environment variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added GOOGLE_CLOUD_PROJECT default.

'--pubsub_subscription',
required=True,
help='Google Cloud Pub/Sub subscription name.')
parser.add_argument('--api_key', required=True, help='Your API key.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we usually default to the API_KEY or GOOGLE_API_KEY environment variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove api_key argument.

parser.add_argument('--api_key', required=True, help='Your API key.')

# Optional arguments
parser.add_argument(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally default to the GOOGLE_APPLICATION_CREDENTIALS environment variable for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

data):
"""Push the data to the given device as configuration."""
config_data = None
print 'The device ({}) has a temperature of: {}'.format(device_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally avoid hanging indents like this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific? Unless it's been fixed.


# This is the topic that the device will receive configuration updates on.
mqtt_config_topic = '/devices/{}/config'.format(args.device_id)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may make sense to acknowledge the messages using the devices/{}/state MQTT topic

"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description='Example Google Cloud IoT MQTT device connection code.')
parser.add_argument(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe default some of these as described for the server:

  • GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT - used for the project ID
  • GOOGLE_API_KEY - used for API key (although the sample should not require it)
  • GOOGLE_APPLICATION_CREDENTIALS - path to service.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

$ python cloudiot_pubsub_example_server.py \
--project_id=my-project-id \
--pubsub_subscription=my-topic-subscription \
--api_key=YOUR_API_KEY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is API key still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Copy link
Contributor

@gguuss gguuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just get all the lints passing and we should be good.

@gguuss
Copy link
Contributor

gguuss commented Dec 7, 2017

@jonparrott LGTM, can squash and merge when you're ready.

pytest.ini Outdated
@@ -1,6 +0,0 @@
[pytest]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you deleting our pytest.ini?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was a local file of mine for some reason.

google-api-python-client==1.6.4
google-auth-httplib2==0.0.3
google-auth==1.2.1
google-cloud==0.30.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't pull in the broad google-cloud package, please include individual google-cloud-* packages that you actually need here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@theacodes theacodes merged commit 2a35eed into GoogleCloudPlatform:master Dec 7, 2017
@theacodes
Copy link
Contributor

@noerog @gguuss The system tests for this are failing: https://travis-ci.org/GoogleCloudPlatform/python-docs-samples/builds/313205503?utm_source=email&utm_medium=notification

Can one of you send a follow-up to fix?

@noerog noerog deleted the python-end-to-end-example branch December 7, 2017 22:49
@gguuss
Copy link
Contributor

gguuss commented Dec 8, 2017

I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants