Supplier eBooks

Microchip - Concept to Creation

Issue link: https://resources.mouser.com/i/1442841

Contents of this Issue

Navigation

Page 24 of 31

25 / Use gcloud to create a monitoring subscription (substitute your own project name in place of lithe-lens-228601): gcloud --project lithe-lens-228601 pubsub \ subscriptions create --topic events monitor-sub Install the Google Cloud Pub/Sub Python client package on your PC: pip install google-cloud-pubsub Create a new file named monitor-sub.py containing the following Python code; replace lithe-lens-228601 with your own project name: import time from google.cloud import pubsub_v1 project_id = "lithe-lens-228601" subscription_name = "monitor-sub" subscriber = pubsub_v1.SubscriberClient() # The `subscription_path` method creates a fully qualified identifier # in the form `projects/{project_id}/subscriptions/ {subscription_name}` subscription_path = subscriber.subscription_path (project_ id, subscription_name) def callback (message): print('Received message: {}'.format(message.data)) message.ack() subscriber.subscribe(subscription_path, callback=callback) # The subscriber is non-blocking. We must keep the main thread from # exiting to allow it to process messages asynchronously in the background. print('Listening for messages on {}'. format(subscription_path)) while True: time.sleep(60) Run the Python program using this command: python monitor-sub.py As new messages are published to the Google Cloud, they will be printed on your PC like this: Received message: {"Light":26,"Temp":"27.43"} Press Control-C to terminate the monitor program. Remember to power off the board when you're done so it doesn't continue to send messages to the Google Cloud and consume cloud resources. WHERE TO GO NEXT This project created an end-to-end sensor-to-cloud application that you can modify and extend in various ways. Here are a few examples: • Dive deeper into the application code by reading Atmel START's example-project user guide and studying its source code. • Learn more about the ATECC608A cryptographic coprocessor by reading the datasheet and studying its source code. • Change the Wi-Fi access point and/or Google Cloud connection parameters by modifying the source code. • Modify the sensor publishing-time interval by modifying the source code. • Include a timestamp in the sensor data message. • Use a different Atmel START example project that uses sensors on a Click board connected to the mikroBUS connector. • Connect the pub/sub topic to a Google Cloud BigQuery table to record sensor data for further analysis. • Develop a data display application that subscribes to the sensor data topic and displays received data values.

Articles in this issue

Links on this page

view archives of Supplier eBooks - Microchip - Concept to Creation