Coder Social home page Coder Social logo

weatherstation's Introduction

Weather Station

This sample integrates multiple Android Things peripheral drivers together to build a connected Weather Station.

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

Screenshots

Weather Station sample demo

(Watch the demo on YouTube)

Pre-requisites

Schematics

If you have the Raspberry Pi Rainbow Hat for Android Things, just plug it onto your Raspberry Pi 3.

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.weatherstation/.WeatherStationActivity

If you have everything set up correctly:

  • The segment display will show the current temperature.
  • If the button is pressed, the display will show the current pressure.
  • If a Piezo Buzzer is connected, it will plays a funny sound on startup.
  • If a APA102 RGB Led strip is connected, it will display a rainbow of 7 pixels indicating the current pressure.
  • If a Google Cloud Platform project is configured (see instruction below), it will publish the sensor data to Google Cloud PubSub.

Google Cloud Platform configuration (optional)

  1. Go to your project in the Google Cloud Platform console
  2. Under API Manager, enable the following APIs: Cloud Pub/Sub
  3. Under IAM & Admin, create a new Service Account, provision a new private key and save the generated json credentials.
  4. Under Pub/Sub: create a new topic and in the Permissions add the service account created in the previous step with the role Pub/Sub Publisher.
  5. Under Pub/Sub: create a new Pull subscription on your new topic.
  6. Import the project into Android Studio. Add a file named credentials.json inside app/src/main/res/raw/ with the contents of the credentials you downloaded in the previous steps.
  7. In app/build.gradle, replace the buildConfigField values with values from your project setup.

After running the sample, you can check that your data is ingested in Google Cloud Pub/Sub by running the following command:

gcloud --project <CLOUD_PROJECT_ID> beta pubsub subscriptions pull <PULL_SUBSCRIBTION_NAME>

Note: If there is no credentials.json file in app/src/main/res/raw, the app will run offline and will not send sensor data to the Google Cloud Pub/Sub.

Next steps

Now your weather sensor data is continuously being published to Google Cloud Pub/Sub:

Enable auto-launch behavior

This sample app is currently configured to launch only when deployed from your development machine. To enable the main activity to launch automatically on boot, add the following intent-filter to the app's manifest file:

<activity ...>

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.HOME"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

</activity>

License

Copyright 2016 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.

weatherstation's People

Contributors

atn832 avatar fleker avatar irataxy avatar jdkoren avatar kokoro-team avatar mangini avatar mistic92 avatar proppy 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

weatherstation's Issues

How to upgrade Gradle.

Not sure if this is the correct place to post this, but I keep getting this error while building this project.
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
From what I have found on this forum I need to upgrade the gradle version. Where can I learn how to do that so I can actually build the project?

Certificate exceptions with Google Cloud Platform

Hi all,

The Weather Station app runs fine on my board, when I add the google cloud bits into my project I get certificate errors as below. Any suggestions on what might be going on?
More details on my steps: I did not see a raw folder under /src/main/res after I cloned the project. I created the raw directory, created a new file called credentials.json and inserted the contents of myproject.json file that was downloaded.

01-01 01:18:51.245 8855-8894/com.example.androidthings.weatherstation E/PubsubPublisher: Error publishing message javax.net.ssl.SSLHandshakeException: Unacceptable certificate: CN=Google Internet Authority G2, O=Google Inc, C=US at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:361) at com.android.okhttp.Connection.connectTls(Connection.java:235) at com.android.okhttp.Connection.connectSocket(Connection.java:199) at com.android.okhttp.Connection.connect(Connection.java:172) at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367) at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java) at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981) at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283) at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384) at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) at com.example.androidthings.weatherstation.PubsubPublisher$3.run(PubsubPublisher.java:158) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.os.HandlerThread.run(HandlerThread.java:61) Caused by: java.security.cert.CertificateException: Unacceptable certificate: CN=Google Internet Authority G2, O=Google Inc, C=US at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:501) at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:401) at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:375) at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:304) at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94) at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88) at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:178) at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:596) at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357) at com.android.okhttp.Connection.connectTls(Connection.java:235)  at com.android.okhttp.Connection.connectSocket(Connection.java:199)  at com.android.okhttp.Connection.connect(Connection.java:172)  at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)  at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)  at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)  at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)  at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283)  at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)  at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)  at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)  at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)  at com.example.androidthings.weatherstation.PubsubPublisher$3.run(PubsubPublisher.java:158)  at android.os.Handler.handleCallback(Handler.java:751)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:154)  at android.os.HandlerThread.run(HandlerThread.java:61)  Caused by: java.security.cert.CertificateNotYetValidException: Certificate not valid until Wed Apr 01 00:00:00 GMT+00:00 2015 (compared to Thu Jan 01 01:18:51 GMT+00:00 1970) at com.android.org.conscrypt.OpenSSLX509Certificate.checkValidity(OpenSSLX509Certificate.java:229) 01-01 01:18:51.245 8855-8894/com.example.androidthings.weatherstation E/PubsubPublisher: at com.android.org.conscrypt.OpenSSLX509Certificate.checkValidity(OpenSSLX509Certificate.java:222) at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:498) ... 37 more

Issue with initialisation of BMP280

Hi,
I have Rasberry Pi 3 with BMP280 sensor. It is crashing on initializing BMP sensor.
Logs:

 FATAL EXCEPTION: main
                 Process: com.example.androidthings.weatherstation, PID: 1463
                                                                                        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidthings.weatherstation/com.example.androidthings.weatherstation.WeatherStationActivity}: java.lang.RuntimeException: Error initializing BMP280
                                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                                                            at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                            at android.os.Looper.loop(Looper.java:154)
                                                                                            at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                                                                                         Caused by: java.lang.RuntimeException: Error initializing BMP280
                                                                                            at com.example.androidthings.weatherstation.WeatherStationActivity.onCreate(WeatherStationActivity.java:180)
                                                                                            at android.app.Activity.performCreate(Activity.java:6662)
                                                                                            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
                                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                                                                                            at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                            at android.os.Looper.loop(Looper.java:154) 
                                                                                            at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                                                                                         Caused by: com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error
                                                                                            at com.google.android.things.pio.I2cDevice.readRegByte(I2cDevice.java:104)
                                                                                            at com.google.android.things.contrib.driver.bmx280.Bmx280.connect(Bmx280.java:171)
                                                                                            at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:149)
                                                                                            at com.google.android.things.contrib.driver.bmx280.Bmx280SensorDriver.<init>(Bmx280SensorDriver.java:54)
                                                                                            at com.example.androidthings.weatherstation.WeatherStationActivity.onCreate(WeatherStationActivity.java:174)
                                                                                            at android.app.Activity.performCreate(Activity.java:6662) 
                                                                                            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
                                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                                                                                            at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                            at android.os.Looper.loop(Looper.java:154) 
                                                                                            at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                                                                                         Caused by: android.os.ServiceSpecificException: I/O error
                                                                                            at android.os.Parcel.readException(Parcel.java:1697)
                                                                                            at android.os.Parcel.readException(Parcel.java:1636)
                                                                                            at com.google.android.things.pio.IPeripheralManagerClient$Stub$Proxy.I2cReadRegByte(IPeripheralManagerClient.java:1431)
                                                                                            at com.google.android.things.pio.I2cDevice.readRegByte(I2cDevice.java:102)
                                                                                            at com.google.android.things.contrib.driver.bmx280.Bmx280.connect(Bmx280.java:171) 
                                                                                            at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:149) 
                                                                                            at com.google.android.things.contrib.driver.bmx280.Bmx280SensorDriver.<init>(Bmx280SensorDriver.java:54) 
                                                                                            at com.example.androidthings.weatherstation.WeatherStationActivity.onCreate(WeatherStationActivity.java:174) 
                                                                                            at android.app.Activity.performCreate(Activity.java:6662) 
                                                                                            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
                                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                                                                                            at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                            at android.os.Looper.loop(Looper.java:154) 
                                                                                            at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

I used the same wiring as said in this repo. Could you please help me out here.

Temperature correction/calibration WRT CPU

Using the RP3 with Rainbow HAT (which features the BMP280), the temperature read by the app can be fairly incorrect compared to the actual ambient temperature. E.g., I was reading 40C when my indoor temperature is ~18.5C.

It seems to me like taking the CPU temperature into account somewhere is a decent solution (e.g., see Sense HAT Temperature Correction. Is there an API for this in Android Things (or should something in OEM land be accounting for CPU temperature)?

Need to throttle updates?

I'm using this with Raspberry Pi and Rainbow HAT. If I leave it running the temperature shown steadily increases. It might be case that I need to add heatsink to the processor but wondering if perhaps the code should throttle number of updates it does. Not a big issue in the scheme of things (realise this is just a demo).

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.