All Projects → androidthings → sensorhub-cloud-iot

androidthings / sensorhub-cloud-iot

Licence: Apache-2.0 license
Sensor-based data collection device publishing to Cloud IoT Core

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to sensorhub-cloud-iot

Sample Usbenum
Discover connected devices using the Android USB Host APIs
Stars: ✭ 81 (+10.96%)
Mutual labels:  android-things
Drivers Samples
Peripheral driver samples
Stars: ✭ 153 (+109.59%)
Mutual labels:  android-things
sample-lowpan
Discover and connect to Thread mesh networks on Android Things
Stars: ✭ 28 (-61.64%)
Mutual labels:  android-things
Android Robocar
Build your own robocar, remote-controlled or autonomous, with Android Things.
Stars: ✭ 95 (+30.14%)
Mutual labels:  android-things
Sample Bluetooth Audio
Bluetooth A2DP sample using Android Things
Stars: ✭ 146 (+100%)
Mutual labels:  android-things
Sample Simplepio
Basic Peripheral I/O examples with Android Things
Stars: ✭ 191 (+161.64%)
Mutual labels:  android-things
Androidthings Drivers
Android Things open source peripheral drivers
Stars: ✭ 30 (-58.9%)
Mutual labels:  android-things
edison-candle
Production sample using Android Things
Stars: ✭ 42 (-42.47%)
Mutual labels:  android-things
Jlibmodbus
JLibModbus is an implementation of the Modbus protocol v1.1b in java language.
Stars: ✭ 149 (+104.11%)
Mutual labels:  android-things
FRILLER
FRILLER is a 3D printed compact robot that can change the radius of its wheels to overcome obstacles.
Stars: ✭ 15 (-79.45%)
Mutual labels:  android-things
Sample Button
Basic input and output using a button and LED
Stars: ✭ 107 (+46.58%)
Mutual labels:  android-things
Android Things Electricity Monitor
Electricity Monitor using Android Things and Firebase Realtime Database
Stars: ✭ 118 (+61.64%)
Mutual labels:  android-things
Weatherstation
Sensor-based peripheral sample using Android Things
Stars: ✭ 210 (+187.67%)
Mutual labels:  android-things
Surviving With Android
Source code related to the posts in the blog
Stars: ✭ 1,275 (+1646.58%)
Mutual labels:  android-things
Fool
Simple Russian voice assistant based on Android Things and Raspberry Pi 3
Stars: ✭ 26 (-64.38%)
Mutual labels:  android-things
Android Sitemap
👓 Every link ever to Android Developer site.
Stars: ✭ 61 (-16.44%)
Mutual labels:  android-things
Sample Bluetooth Le Gattserver
Build a Bluetooth GATT server with Android Things
Stars: ✭ 159 (+117.81%)
Mutual labels:  android-things
atdocs
Android Things Translation 中文翻译
Stars: ✭ 19 (-73.97%)
Mutual labels:  android-things
androidthings-mqtt-alarm-panel
Android Things Alarm Control Panel for Home Assistant
Stars: ✭ 69 (-5.48%)
Mutual labels:  android-things
photobooth
Cloud-connected talking photobooth using TensorFlow
Stars: ✭ 40 (-45.21%)
Mutual labels:  android-things

Cloud IoT Core Sensor Hub

This sample shows how to implement a sensor hub on Android Things that collects sensor data from connected sensors and publish as telemetry events to Google Cloud IoT Core.

Note: The Android Things Console will be turned down for non-commercial use on January 5, 2022. For more details, see the FAQ page.

Introduction

The sample showcases a sensor-based device publishing data to Cloud IoT Core. Sensors can be added or removed dynamically, and the device will reconnect automatically to the cloud when power or connectivity is lost.

Sensor data is collected and sent to Cloud IoT Core as telemetry events every 20 seconds by default, and it can be changed from the cloud with device config (cloud to device) messages.

Pre-requisites

Schematics

Schematics for Raspberry Pi 3

Build and install

On Android Studio, click on the "Run" button. If you prefer to run on the command line, type

./gradlew installDebug
adb shell am start com.example.androidthings.sensorhub/.SensorHubActivity

Prepare the device

This sample will create a key pair (private and public) on the device on the first run. The private key will be saved to the Android Keystore, using a secure hardware if one is available. The public key will be printed to logcat and will be available as a file on your external storage location.

You will need the public key to register your device to Cloud IoT Core. Here's how you can fetch it:

adb pull /sdcard/cloud_iot_auth_certificate.pem

or, depending on your platform:

adb -d shell "run-as com.example.androidthings.sensorhub cat /data/user/0/com.example.androidthings.sensorhub/files/cloud_iot_auth_certificate.pem" > cloud_iot_auth_certificate.pem

A new keypair is only generated again when the device is reflashed.

Register the device

With the cloud_iot_auth_certificate.pem file, you can register your device on Cloud IoT Core:

gcloud iot devices create <DEVICE_ID> --project=<PROJECT_ID> --region=<CLOUD_REGION> --registry=<REGISTRY_ID> --public-key path=cloud_iot_auth_certificate.pem,type=<CERTIFICATE_TYPE>

Where:

  • DEVICE_ID: your device ID (it can be anything that identifies the device for you)
  • PROJECT_ID: your Cloud IoT Core project id
  • CLOUD_REGION: the cloud region for project registry
  • REGISTRY_ID: the registry name where this device should be registered
  • CERTIFICATE_TYPE: either "rsa-x509-pem" or "es256-x509-pem" depending on whether your device key algorithm is "RSA" or "EC" (see below)

Configure the device

Now that your device's public key is registered, you can set the device so that it can securely connect to Cloud IoT Core:

adb shell am start -e project_id <PROJECT_ID> -e cloud_region <CLOUD_REGION> -e registry_id <REGISTRY_ID> -e device_id <DEVICE_ID> -e key_algorithm <DEVICE_KEY_ALGORITHM> com.example.androidthings.sensorhub/.SensorHubActivity

Where PROJECT_ID, CLOUD_REGION, REGISTRY_ID and DEVICE_ID must be the corresponding values used to register the device on Cloud IoT Core, and DEVICE_KEY_ALGORITHM must be the standard name of the algorithm to be used for generating the device authentication key. Currently "RSA" and "EC" are supported, and "RSA" is the default in case this argument is not defined.

Testing

If the registration and configuration steps were executed successfully, your device will immediately start publishing sensor data to Cloud IoT Core.

You can pipe this data into other Google Cloud services.

If you want to quickly check if messages are being published correctly, you can create a topic subscription (replace SUBSCRIPTION_NAME with any unique name you want):

gcloud pubsub subscriptions create projects/PROJECT_ID/subscriptions/SUBSCRIPTION_NAME --topic=projects/PROJECT_ID/topics/REGISTRY_ID

and then pull messages from this subscription:

gcloud pubsub subscriptions pull --auto-ack projects/PROJECT_ID/subscriptions/SUBSCRIPTION_NAME

Next steps

Take a look at the Cloud IoT Core documentation to learn how to pipe the data published by your devices into other Google Cloud services.

License

Copyright 2018 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].