Giter Club home page Giter Club logo

cloud-iot-core-androidthings's Introduction

Cloud IoT Core Client for Android Things

The Cloud IoT Core Client makes it simple to integrate Android Things with Cloud IoT Core by providing abstractions for all of Cloud IoT Core's device functions:

  • Publishing telemetry events
  • Publishing device state
  • Receiving device configuration from Cloud IoT Core
  • Receiving device commands from Cloud IoT Core

The library handles all concurrency so clients can use it in the main thread. It also manages interactions with the Cloud IoT Core MQTT bridge so users don't have to worry about low-level networking protocols.

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

Getting started

There are three steps to using this library: set up Cloud IoT Core, download the library, and then start using the library to communicate with Cloud IoT Core.

Set up Cloud IoT Core

Follow the instructions on the Cloud IoT Core website to enable the Cloud IoT Core API, create a device registry, and register your device.

Add the library as a dependency

Add the following lines to your app's build.gradle:

dependencies {
    implementation 'com.google.android.things:cloud-iot-core:1.0.0'
}

Communicate with Cloud IoT Core

After Cloud IoT Core is configured, getting your device connected takes only a few lines of code:

// Load the keys used to register this device
KeyPair keys =  ...

// Configure Cloud IoT Core project information
ConnectionParams connectionParams = new ConnectionParams.Builder()
    .setProjectId("<your Google Cloud project ID>")
    .setRegistry("<your Cloud IoT Core registry ID>", "<your registry's cloud region>")
    .setDeviceId("<the device's ID in the registry>")
    .build();

// Initialize the IoT Core client
IotCoreClient client = new IotCoreClient.Builder()
    .setConnectionParams(connectionParams)
    .setKeyPair(keys)
    .build();

// Connect to Cloud IoT Core
client.connect();

// Start sending data!
client.publishDeviceState("Hello world!\n".getBytes());

Check out the Android Things Sensorhub sample app for an example. The library's full documentation is available on the Cloud IoT Core website.

Learn more

License

Copyright 2018 Google LLC

Licensed 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

https://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.

cloud-iot-core-androidthings's People

Contributors

babyimp avatar blakelawson avatar dennisg avatar mangini avatar noerog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloud-iot-core-androidthings's Issues

Larger KEEPALIVE not working as expected

Hi,

We are working on a google IoT based native android application. Currently App is sending Keep alive every 1 min. We are trying to increase this period.
We are using Paho library for Native development. When we use the KEEPALIVE for default 60 seconds, it works fine. When we try to increase the time (5/10/15 mins), device get disconnected periodically and takes time to connect back

When we tried 5 mins, 10 mins & 15 mins KEEPALIVE values, then we never see PINGREQ in IoT server logs
We are seeing 2 errors regard to the disconnects:
a: The connection broke or was closed by client
b: SERVER: The connection was closed because there is another active connection with the same device ID.

Note: We don't have the duplicate device listed in IoT core when we receive the "connection closed due to same device ID" error.

QoS value: Default channel is available with IoT registry, but we are publishing the messages from Server to Devices as command. So no QoS being set from device side while making MQTT connection.

Note:

    With 15 mins keep alive
1. Client app sent a PINGREQ, say at 00 Hrs. This PINGREQ never reaches to IoT Core server
2. For IoT core server, MQTT idle time (without heartbeat or message) is 20 mins. As IoT core Server never receive PINGREQ from client app (we are not seeing the PINGREQ in device registry log), it closes the connection after 0020 Hrs
3. Client app, after sending PINGREQ at 00 Hrs, waiting for PINGRESP. It never receives the PINGRESP from server, and closes the connection at 0030 Hrs.
4. Client app tries to reconnect again immediately after 0030 Hrs.
5. Client app never gets any disconnect message from server when server disconnect the MQTT connection at #2

With 10 mins keep alive
1. Disconnects every 20 mins & then takes 5 mins to connect back
2. Not seeing any PINGREQ in IoT core
3. Paho library at client throws error "Client timed out while waiting for a response from the server. The server is no longer responding to keep-alive messages." and then connects back again.
4. When server disconnects the client, client never gets notified.

Client app is using the IotCoreClient class to manage the connection/reconnection. The connection/reconnection logic is being done by IotCoreClient class which is in cloud-iot-core-androidthings' library.

Any suggestions?

Thanks,
Rahul

Unable to resolve dependencies

Hello:

Adding implementation 'com.google.android.things:cloud-iot-core:1.0.0' as suggested results in:

Failed to resolve: com.google.android.things:cloud-iot-core:1.0.0
Add Google Maven repository and sync project
Show in Project Structure dialog
Affected Modules: app

This issue occurs in android studio and not in IntelliJ IDEA... any clues?

Error: Program type already present: androidx.core.app.NavUtils

I can't use the cloud-iot-core-androidthings with the firebase packages, the error i get is :

Error: Program type already present: androidx.core.app.NavUtils

I'm try to use the package with the firebase packages :

/** Firebase Stuff */
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-database:16.0.5'

onConfigurationReceived called multiple times upon connecting

Is this the expected behavior that onConfigurationChanged gets called multiple times (twice from my testing) when you first connect to the mqtt server?

I know you are suppose to get the current configuration when you connect to IoT core but I always get it twice right in a row. After the initial 2x call I get them only when they change the configuration like I should.

Possible bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.