{"id":13547935,"url":"https://github.com/androidthings/sensorhub-cloud-iot","last_synced_at":"2025-04-02T20:31:12.223Z","repository":{"id":97075539,"uuid":"91638315","full_name":"androidthings/sensorhub-cloud-iot","owner":"androidthings","description":"Sensor-based data collection device publishing to Cloud IoT Core","archived":false,"fork":false,"pushed_at":"2021-05-26T17:54:25.000Z","size":760,"stargazers_count":71,"open_issues_count":3,"forks_count":39,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-03T16:37:59.256Z","etag":null,"topics":["android-things"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/androidthings.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-05-18T02:07:06.000Z","updated_at":"2024-01-14T03:04:26.000Z","dependencies_parsed_at":"2023-10-20T17:16:24.172Z","dependency_job_id":"b0de77f0-12ca-4737-894b-444fb4ac5f2a","html_url":"https://github.com/androidthings/sensorhub-cloud-iot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/androidthings%2Fsensorhub-cloud-iot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/androidthings%2Fsensorhub-cloud-iot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/androidthings%2Fsensorhub-cloud-iot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/androidthings%2Fsensorhub-cloud-iot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/androidthings","download_url":"https://codeload.github.com/androidthings/sensorhub-cloud-iot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246887950,"owners_count":20850172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-things"],"created_at":"2024-08-01T12:01:03.330Z","updated_at":"2025-04-02T20:31:09.494Z","avatar_url":"https://github.com/androidthings.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"# Cloud IoT Core Sensor Hub\n\nThis sample shows how to implement a sensor hub on Android Things that collects\nsensor data from connected sensors and publish as telemetry events to Google\nCloud IoT Core.\n\n\u003e **Note:** The Android Things Console will be turned down for non-commercial\n\u003e use on January 5, 2022. For more details, see the\n\u003e [FAQ page](https://developer.android.com/things/faq).\n\n## Introduction\n\nThe sample showcases a sensor-based device publishing data to\n[Cloud IoT Core](https://cloud.google.com/iot-core/). Sensors can be\nadded or removed dynamically, and the device will reconnect automatically to the\ncloud when power or connectivity is lost.\n\nSensor data is collected and sent to Cloud IoT Core as telemetry events every 20 seconds by default,\nand it can be changed from the cloud with device config (cloud to device) messages.\n\n## Pre-requisites\n\n- Android Things compatible board\n- Android Studio 2.2+\n- 1 [bmp280 temperature and pressure](https://www.adafruit.com/product/2651)\n- 1 [PIR motion detector sensor](https://www.adafruit.com/product/189) or 1 button to simulate the\n    motion detection\n- [Google Cloud Platform](https://cloud.google.com/) project with Cloud IoT Core enabled\n\n## Schematics\n\n![Schematics for Raspberry Pi 3](rpi3_schematics.png)\n\n## Build and install\n\nOn Android Studio, click on the \"Run\" button.\nIf you prefer to run on the command line, type\n```\n./gradlew installDebug\nadb shell am start com.example.androidthings.sensorhub/.SensorHubActivity\n```\n\n## Prepare the device\n\nThis sample will create a key pair (private and public) on the device on the\nfirst run. The private key will be saved to the Android Keystore, using a\nsecure hardware if one is available. The public key will be printed to logcat\nand will be available as a file on your external storage location.\n\nYou will need the public key to register your device to Cloud IoT Core.\nHere's how you can fetch it:\n\n```\nadb pull /sdcard/cloud_iot_auth_certificate.pem\n```\n\nor, depending on your platform:\n\n```\nadb -d shell \"run-as com.example.androidthings.sensorhub cat /data/user/0/com.example.androidthings.sensorhub/files/cloud_iot_auth_certificate.pem\" \u003e cloud_iot_auth_certificate.pem\n```\n\nA new keypair is only generated again when the device is reflashed.\n\n## Register the device\n\nWith the `cloud_iot_auth_certificate.pem` file, you can register your device on\nCloud IoT Core:\n\n```\ngcloud iot devices create \u003cDEVICE_ID\u003e --project=\u003cPROJECT_ID\u003e --region=\u003cCLOUD_REGION\u003e --registry=\u003cREGISTRY_ID\u003e --public-key path=cloud_iot_auth_certificate.pem,type=\u003cCERTIFICATE_TYPE\u003e\n```\n\nWhere:\n- `DEVICE_ID`: your device ID (it can be anything that identifies the device for you)\n- `PROJECT_ID`: your Cloud IoT Core project id\n- `CLOUD_REGION`: the cloud region for project registry\n- `REGISTRY_ID`: the registry name where this device should be registered\n- `CERTIFICATE_TYPE`: either \"rsa-x509-pem\" or \"es256-x509-pem\" depending on\n  whether your device key algorithm is \"RSA\" or \"EC\" (see below)\n\n## Configure the device\n\nNow that your device's public key is registered, you can set\nthe device so that it can securely connect to Cloud IoT Core:\n\n```\nadb shell am start -e project_id \u003cPROJECT_ID\u003e -e cloud_region \u003cCLOUD_REGION\u003e -e registry_id \u003cREGISTRY_ID\u003e -e device_id \u003cDEVICE_ID\u003e -e key_algorithm \u003cDEVICE_KEY_ALGORITHM\u003e com.example.androidthings.sensorhub/.SensorHubActivity\n```\nWhere PROJECT_ID, CLOUD_REGION, REGISTRY_ID and DEVICE_ID must be the\ncorresponding values used to register the device on Cloud IoT Core, and\nDEVICE_KEY_ALGORITHM must be the standard name of the algorithm to be used for generating\nthe device authentication key. Currently \"RSA\" and \"EC\" are supported, and \"RSA\"\nis the default in case this argument is not defined.\n\n\n## Testing\n\nIf the registration and configuration steps were executed successfully, your\ndevice will immediately start publishing sensor data to Cloud IoT Core.\n\nYou can pipe this data into other Google Cloud services.\n\nIf you want to quickly check if messages are being published correctly, you\ncan create a topic subscription (replace SUBSCRIPTION_NAME with any unique name\nyou want):\n\n```\ngcloud pubsub subscriptions create projects/PROJECT_ID/subscriptions/SUBSCRIPTION_NAME --topic=projects/PROJECT_ID/topics/REGISTRY_ID\n```\n\nand then pull messages from this subscription:\n\n```\ngcloud pubsub subscriptions pull --auto-ack projects/PROJECT_ID/subscriptions/SUBSCRIPTION_NAME\n```\n\n\n## Next steps\n\nTake a look at the [Cloud IoT Core documentation](https://cloud.google.com/iot/docs/) to learn how to pipe the\ndata published by your devices into other Google Cloud services.\n\n## License\n\nCopyright 2018 The Android Open Source Project, Inc.\n\nLicensed to the Apache Software Foundation (ASF) under one or more contributor\nlicense agreements.  See the NOTICE file distributed with this work for\nadditional information regarding copyright ownership.  The ASF licenses this\nfile to you under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License.  You may obtain a copy of\nthe License at\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandroidthings%2Fsensorhub-cloud-iot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandroidthings%2Fsensorhub-cloud-iot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandroidthings%2Fsensorhub-cloud-iot/lists"}