Git Product home page Git Product logo

iot-smart-home-cloud's Introduction

Smart Home Device Manager

This projects contains sample code that demonstrates the use of Firebase and Google Cloud IoT Core to build a cloud service for consumer smart home devices.

Quickstart

Set up Google Cloud

  1. Select or create a new project in the Google Cloud Console.

  2. Visit the Cloud IoT Core page to enable the API.

  3. Follow these instructions to create a device registry and a new device entry.

    • When creating a new device entry, generate an ES256 key. You can find details on creating an ES256 key pair here.
    • Use device-events as the Default telemetry topic.
  4. Save the project values as environment variables so you can use them later on:

    $ export PROJECT_ID=my-project
    $ export REGION=us-central1
    $ export REGISTRY=my-registry
    $ export DEVICE_ID=my-device
    $ export PRIVATE_KEY_FILE=./ec_private.pem
    
  5. Visit the Firebase console and click Add Project from the dashboard. Choose the name of your existing Google Cloud project under Project name, then select Add Firebase.

Set up Actions on Google

  1. Navigate to the Actions console.

  2. Select Add/import project.

  3. Choose the name of your existing Google Cloud project under Project name, then select IMPORT PROJECT.

  4. Choose Home control, followed by Smart home.

  5. Select SetupInvocation and give your action a name.

  6. Create a unique client id and secret that you will assign to Google for use during smart home account linking.

    $ export CLIENT_ID=my-client-id
    $ export CLIENT_SECRET=my-client-secret
    

NOTE: These values enable the Google Assistant to identify itself to your action during account linking. This is not used to identify any particular user.

Deploy project modules

  1. Deploy the server module to Firebase using the instructions in Device Manager Cloud.
  2. Deploy the web application using the instructions in Device Manager Web.
  3. Deploy the mobile application using the instructions in Device Manager Mobile.
  4. Run a virtual sample device as either a light or thermostat using the private key generated in the previous step.

Complete smart home setup

  1. Navigate to the Actions console, and select the your project.

  2. Configure account linking for your action. Set Linking type to OAuthAuthorization Code, then enter the following Client Information:

    • Client ID: Value exported as CLIENT_ID during initial setup.
    • Client secret: Value generated for CLIENT_SECRET during initial setup.
    • Authorization URL: https://<your-firebase-hosting-app>/link-account
    • Token URL: https://<your-cloud-functions-url>/token
  3. Click SAVE.

  4. Provide fulfillment for your action. Select BuildActions from the sidebar and click ADD YOUR FIRST ACTION. Enter the following Fulfillment URL:

    • https://<your-cloud-functions-url>/fulfillment
  5. Click DONE.

Testing your action

Follow these instructions to enable testing for your smart home action. You can use the Google Home app to link your account and control devices.

Handle online status changes (Optional)

By default, the sample assumes a device is online once it begins receiving state change events from that device. You can use the following steps to export the MQTT logs from Stackdriver, which will report connection state changes.

  1. Enable logging for IoT Core Registry.

    • Navigate to IoT Core Registries page in the Cloud Console.
    • Click the ID of the Registry, and then click EDIT REGISTRY at the top of the page.
    • Under Stackdriver Logging, select Info log level.
    • Click Update.
  2. Visit the Stackdriver Logs in the Cloud Console.

  3. Enter the following advanced filter:

    resource.type="cloudiot_device"
    jsonPayload.eventType="DISCONNECT" OR "CONNECT"
    
  4. Click CREATE EXPORT

  5. Enter a value for Sink Name

  6. Select Cloud Pub/Sub for Sink Service

  7. Create a new Cloud Pub/Sub topic called online-state as the Sink Destination

iot-smart-home-cloud's People

Contributors

anson-vandoren avatar mamidipalli avatar manuvergujjar 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

iot-smart-home-cloud's Issues

AAPT: error: resource android:attr/fontVariationSettings not found.

Hello @devunwired , I've successfully followed the flutter-mobile part till setting up Firebase google-services.json and GoogleService-Info.plist files in their respective directories. But still i got stuck here with this error..

/home/ck/.gradle/caches/transforms-1/files-1.1/support-compat-28.0.0.aar/9e33028a37e6b11fe4991f1b7c19ebd6/res/values/values.xml: AAPT: error: resource android:attr/fontVariationSettings not found.

/home/ck/.gradle/caches/transforms-1/files-1.1/support-compat-28.0.0.aar/9e33028a37e6b11fe4991f1b7c19ebd6/res/values/values.xml: AAPT: error: resource android:attr/ttcIndex not found.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:processDebugResources'.

Failed to process resources, see aapt output above for details.

Barcode scanner is not working

QR Code with TEXT, to register a new device is not being scanned.
_detector.detectInImage(firebaseImage) is not returning any Barcode objects.

I can login (in web/mobile) and register the device via qr code But registered devices do not appear on the screen

Hi,

images issue:
https://drive.google.com/drive/folders/1XUyiYYeXAVH0RKYTfdsKfqjX1KryvP8R?usp=sharing

log file:
https://gist.github.com/neuberfran/9cbd0b5ea41b80e8acf338fb1172db7e

I can see the devices registered in the firestore, but they do not appear on the mobile screen or in the web/angular application

I already registered 1 device using the tutorial below, which also does not appear
http://nilhcem.com/iot/cloud-iot-core-with-the-esp32-and-arduino

How to solve

ios app error

hi, when run an tap on button ios app

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Your app is missing support for the following URL schemes:
Zrzut ekranu 2020-09-30 o 12 38 31

Firebase deploy fails

Firebase deploy fails with the following error:

Cannot find module ./service-account.json

const homegraph = smarthome({
  jwt: require('./service-account.json')

Documents don't mention the creation of a service-account key. What IAM scope is required for this?

cloud function registerDevice showing error

registerDevice
Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync (/srv/node_modules/googleapis/node_modules/google-auth-library/build/src/auth/googleauth.js:155:19) at at process._tickDomainCallback (internal/process/next_tick.js:229:7)

registerDevice
(node:2) MetadataLookupWarning: received unexpected error = URL is not defined code = UNKNOWN

registerDevice
Function execution took 54 ms, finished with status: 'error'

register a new device without building ios app

Is there a way to register a new device without building the ios app?

I've deployed everything after hours of struggle, but I have no experience with apps building and I wanted to skip this step as I haven't been able to get a bundle id.

Invalid configuration message SyntaxError: Unexpected end of JSON input

After running sample_device.js following error occurs:

Starting Smart Home Device
connect
Config message received:
Invalid configuration message SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at MqttClient.<anonymous> (d:\Projects\Projects\Upwork\Kimberly Hachaso\iot-smart-home-cloud-master\sample-device\sample_device.js:164:29)
    at MqttClient.emit (events.js:311:20)
    at MqttClient._handlePublish (d:\Projects\Projects\Upwork\Kimberly Hachaso\iot-smart-home-cloud-master\sample-device\node_modules\mqtt\lib\client.js:975:12)
    at MqttClient._handlePacket (d:\Projects\Projects\Upwork\Kimberly Hachaso\iot-smart-home-cloud-master\sample-device\node_modules\mqtt\lib\client.js:336:12)
    at work (d:\Projects\Projects\Upwork\Kimberly Hachaso\iot-smart-home-cloud-master\sample-device\node_modules\mqtt\lib\client.js:292:12)
    at Writable.writable._write (d:\Projects\Projects\Upwork\Kimberly Hachaso\iot-smart-home-cloud-master\sample-device\node_modules\mqtt\lib\client.js:302:5)
    at doWrite (d:\Projects\Projects\Upwork\Kimberly Hachaso\iot-smart-home-cloud-master\sample-device\node_modules\readable-stream\lib\_stream_writable.js:428:64)
    at writeOrBuffer (d:\Projects\Projects\Upwork\Kimberly Hachaso\iot-smart-home-cloud-master\sample-device\node_modules\readable-stream\lib\_stream_writable.js:417:5)
    at Writable.write (d:\Projects\Projects\Upwork\Kimberly Hachaso\iot-smart-home-cloud-master\sample-device\node_modules\readable-stream\lib\_stream_writable.js:334:11)

exception when event is triggered.

After update the engine to 12, I can deploy the functions. but got this exception when event is triggered. Please advice how to fix it.

TypeError: Cannot read property 'name' of undefined
at beforeSnapshotConstructor (/workspace/node_modules/firebase-functions/lib/providers/firestore.js:136:75)
at changeConstructor (/workspace/node_modules/firebase-functions/lib/providers/firestore.js:142:49)
at cloudFunctionNewSignature (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:119:34)
at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:151:20)
at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:140:25)
at process._tickCallback (internal/process/next_tick.js:68:7)

HTTP Error: 400, This operation is not available for Cloud Firestore projects in Datastore Mode.

I'm getting following error after firebase deploy:

firebase deploy
  functions: package.json indicates an outdated version of firebase-functions.
 Please upgrade using npm install --save firebase-functions@latest in your functions directory.

=== Deploying to 'smarthome-272813'...

  deploying database, storage, firestore, functions, hosting
  database: checking rules syntax...
  database: rules syntax for database smarthome-272813 is valid
  firebase.storage: checking storage.rules for compilation errors...
  [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
  firebase.storage: rules file storage.rules compiled successfully
  firestore: reading indexes from firestore.indexes.json...
  cloud.firestore: checking firestore.rules for compilation errors...
  [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
  cloud.firestore: rules file firestore.rules compiled successfully
  functions: ensuring necessary APIs are enabled...
  functions: all necessary APIs are enabled
  storage: uploading rules storage.rules...

Error: HTTP Error: 400, This operation is not available for Cloud Firestore projects in Datastore Mode.
  firestore: uploading rules firestore.rules...

How can I solve this issue?

Devices stuck on Pending in Firebase

I believe I was able to jump through most if the authentication hoops. but now when I scan a QR code the information is added to the pending collection in firebase, but it appears the function to process it does not run (module.exports = functions.firestore.document('pending/{device}').onWrite(async (change, context) =>) What could be causing this?
(Sorry I'm new to firebase and cloud)

Also the link is broken under
Testing your action
Follow these instructions (https://developers.google.com/actions/smarthome/testing-deploying)
Thanks

Nothing on screen after app building ... these errors are showing

2020-05-19 01:48:55.116 8348-8348/? E/e.devicemanage: Unknown bits set in runtime_flags: 0x8000
2020-05-19 01:48:55.928 8348-8381/com.example.devicemanager E/Perf: Fail to get file list com.example.devicemanager
2020-05-19 01:48:55.929 8348-8381/com.example.devicemanager E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-05-19 01:48:55.929 8348-8381/com.example.devicemanager E/Perf: Fail to get file list com.example.devicemanager
2020-05-19 01:48:55.929 8348-8381/com.example.devicemanager E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-05-19 01:48:57.064 8348-8385/com.example.devicemanager E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
If you're running an application and need to access the binary messenger before runApp() has been called (for example, during plugin initialization), then you need to explicitly call the WidgetsFlutterBinding.ensureInitialized() first.
If you're running a test, you can call the TestWidgetsFlutterBinding.ensureInitialized() as the first line in your test's main() method to initialize the binding.
#0 defaultBinaryMessenger. (package:flutter/src/services/binary_messenger.dart:76:7)
#1 defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:89:4)
#2 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:140:62)
#3 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:146:35)
#4 OptionalMethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:435:18)
#5 SystemChrome.setPreferredOrientations (package:flutter/src/services/system_chrome.dart:239:35)
#6 main (package:devicemanager/main.dart:24:22)
#7 _runMainZoned.. (dart:ui/hooks.dart:241:25)
#8 _rootRun (dart:async/zone.dart:1184:13)
#9 _CustomZone.run (dart:async/zone.dart:1077:19)
#10 _runZoned (dart:async/zone.dart:1619:10)
#11 runZonedGuarded (dart:async/zone.dart:1608:12)
#12 _runMainZoned. (dart:ui/hooks.dart:233:5)
#13 _startIsolate. (dart:isolate-patch/isolate_patch.dart:301:19)
#14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Unable to sign in

While i am signing into app with google account following errors are being displayed

W/ActivityThread( 5781): handleWindowVisibility: no activity for token android.os.BinderProxy@16ddf5e
I/flutter ( 5781): PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

and these errors in logcrat
2020-06-04 12:12:38.091 9415-9415/? E/e.devicemanage: Unknown bits set in runtime_flags: 0x8000
2020-06-04 12:12:39.157 9415-9444/com.example.devicemanager E/Perf: Fail to get file list com.example.devicemanager
2020-06-04 12:12:39.158 9415-9444/com.example.devicemanager E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-06-04 12:12:39.159 9415-9444/com.example.devicemanager E/Perf: Fail to get file list com.example.devicemanager
2020-06-04 12:12:39.159 9415-9444/com.example.devicemanager E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array

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.