Git Product home page Git Product logo

nora-service's Introduction

nora-service

NORA (https://node-red-google-home.herokuapp.com) backend service deployed in Heroku.

Deployment instructions: (small guide on how to run nora-service on your own Heroku)

Needed:

HEROKU

  • Create a new Account and then a new app. From Overview, add new add-on "Heroku Postgres" To deploy, you can either use the heroku cli or connect your github account. (do not deploy anything yet)
  • Keep this browser tab open

FIREBASE

  • Create a new Firebase Project and name it accordingly.
  • Navigate to Project Overview - Project Settings - General and create a new web app.
  • Navigate to Project Overview - Project Settings - Service Accounts and generate new private key
  • Navigate to Develop - Authentication - Users - Set up sign-in method - Google - enable - check that Web SDK configuration is filled in.
  • Keep this browser tab open

Google Api Console

Google Actions

CONFIG HEROKU ENV VARS

In Heroku go to Settings - Config Vars and add

env vars

JWT_COOKIE = nora:auth
JWT_SECRET = downloaded service account json from firebase - private_key
OAUTH_ID = api console - credentials - oauth 2.0 client ids - web client - Client ID
OAUTH_SECRET = api console - credentials - oauth 2.0 client ids - web client - Client secret
PROJECT_ID = firebase - settings -general - your apps - project id
SERVICE_ACCOUNT_ISSUER =  downloaded service account json from firebase - client_email
SERVICE_ACCOUNT_KEY =  downloaded service account json from firebase - private_key (format it as multiline)
FIREBASE_APIKEY = firebase - settings -general - your apps
FIREBASE_AUTHDOMAIN = firebase - settings -general - your apps

USER.REPOSITORY.TS

Modify src/services/user.repository.ts

To create the Database Tables modify this lines:

(async function () {
    const service = new PostgressService();
    await service.query(`
        CREATE TABLE IF NOT EXISTS appuser (
            uid VARCHAR(30) CONSTRAINT pk PRIMARY KEY,
            linked boolean DEFAULT false
        )`
    );

    await service.query('ALTER TABLE appuser ADD COLUMN IF NOT EXISTS noderedversion integer DEFAULT 1');
	await service.query('ALTER TABLE appuser ADD COLUMN IF NOT EXISTS refreshtoken integer DEFAULT 1');
})().catch(err => {
    console.error(err);
}).then(() => {
    console.log('done');
});

PUSH

THAT'S IT, you are ready to deploy to Heroku! Build the app and the schema with npm run heroku-postbuild before deploying. To deploy follow the instructions from the Heroku website or if you linked your account in Heroku with Github just push to github.

README DISCLAIMER

The instructions might be incomplete. For issues with the instructions please create an issue and we'll take another look,

nora-service's People

Contributors

andrei-tatar avatar mabels avatar nicandris avatar rgerrans 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nora-service's Issues

Lock Updates

@andrei-tatar When you get a chance can you look at the pull request for the lock updates and let me know if I got everything in this time. Once you get a chance to update the Services, I'll test the new lock node.

Thanks.

Locks

@andrei-tatar I saw you merged in the lock changes to the service. Has that been deployed? I'm getting an "Invalid object for sync" error and don't see any obvious disconnects in naming between the node and services files. I'll keep looking in the meantime.

Thanks

How to add devices?

Google keeps on adding devices and I think Nora could use a few more as well (TV for instance).

How can someone add a device? What is the way to go?

unable to redirect to <home> after login

hi,
I am facing an issue, like, after successful login, the user is not able to redirect to the HOME,

again it'll redirect to the login page.

2020-09-13T08:55:05.840970+00:00 app[web.1]: login: { error: password authentication failed for user "ohubflebemtayr"

Help with Google API console

Hi, I am trying to make the NORA-Service work on my server and I am going through the short tutorial from the main page. However, in the Google API console section, it is explained too short. I cannot get through it. Could you describe this part more precisely? Thank you.

How to get the state of the Device

Hi andrei,
first of all iam very glad i found Nora services to work on my test bench.
Actually iam working on Nodered since a couple of months and created a Dashboard with local server.
i could control all my devices also can find the live ness of my modules with the help of LWT(
Last Will and Testament). Now all my conditions got satisfied with local Dashboard.
when it comes to Google home with the help of your Nora Services, i could able to get payload from Nora - nodes and device respond to the command very well. Now i have 2 problems:

  1. I could not get the status of the module (aliveness ) Even if the module is in off condition google shows it is alive and gives the command. (attaching a screen which i required)
    offline

  2. If i operate the device with my local Dashboard, the status of the relay could not be updated on google immediately as i need to refresh my page to get it.

Is there anything iam missing in my loop.. please help me in this regard

Thanking you in advance

Tutorial

Can someone provide a guide on how to run this? I added a new device in node-red-contrib-nora and I think the config for the service, but I can't test it.

Push Failed

Hello Andrei,

I´m trying to test the service but I have problems to deploy on heroku.

The log show this:

**-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected

-----> Creating runtime environment

   NPM_CONFIG_LOGLEVEL=error
   NODE_VERBOSE=false
   NODE_ENV=production
   NODE_MODULES_CACHE=true

-----> Installing binaries
engines.node (package.json): 10
engines.npm (package.json): unspecified (use default)

   Resolving node version 10...
   Downloading and installing node 10.24.0...
   Using default npm version: 6.14.11

-----> Installing dependencies
Installing node modules

   > [email protected] postinstall /tmp/build_615ec1b7/node_modules/protobufjs
   > node scripts/postinstall
   
   
   > [email protected] install /tmp/build_615ec1b7/node_modules/grpc
   > node-pre-gyp install --fallback-to-build --library=static_library
   
   [grpc] Success: "/tmp/build_615ec1b7/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc/grpc_node.node" is installed via remote
   
   > [email protected] install /tmp/build_615ec1b7/node_modules/bcrypt
   > node-pre-gyp install --fallback-to-build
   
   [bcrypt] Success: "/tmp/build_615ec1b7/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote
   added 548 packages in 14.818s

-----> Build
Detected both "build" and "heroku-postbuild" scripts
Running heroku-postbuild

   > [email protected] heroku-postbuild /tmp/build_615ec1b7
   > npm run build && npm run copyhtml && npm run schema
   
   
   > [email protected] build /tmp/build_615ec1b7
   > tsc
   
   src/google/execute.ts(1,37): error TS2307: Cannot find module '../nora-common/google/execute'.
   src/google/query.ts(1,27): error TS2307: Cannot find module '../nora-common/models'.
   src/http/services/execute.service.ts(6,54): error TS2307: Cannot find module '../../nora-common/google/execute'.
   src/http/services/execute.service.ts(7,36): error TS2307: Cannot find module '../../nora-common/util'.
   src/http/services/query.service.ts(3,24): error TS2307: Cannot find module '../../nora-common/models'.
   src/http/services/query.service.ts(4,27): error TS2307: Cannot find module '../../nora-common/util'.
   src/http/services/sync.service.ts(5,30): error TS2307: Cannot find module '../../nora-common/models'.
   src/http/services/sync.service.ts(6,25): error TS2307: Cannot find module '../../nora-common/util'.
   src/http/services/sync.service.ts(42,38): error TS2339: Property 'name' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(43,43): error TS2339: Property 'nicknames' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(45,38): error TS2339: Property 'roomHint' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(57,32): error TS2339: Property 'type' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(69,36): error TS2339: Property 'brightnessControl' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(72,36): error TS2339: Property 'colorControl' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(82,53): error TS2339: Property 'sceneReversible' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(89,67): error TS2339: Property 'availableModes' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(90,63): error TS2339: Property 'temperatureUnit' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(91,56): error TS2339: Property 'bufferRangeCelsius' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(92,67): error TS2339: Property 'commandOnlyTemperatureSetting' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(93,65): error TS2339: Property 'queryOnlyTemperatureSetting' does not exist on type 'unknown'.
   src/http/services/sync.service.ts(125,49): error TS2339: Property 'state' does not exist on type 'unknown'.
   src/services/devices.repository.ts(6,58): error TS2307: Cannot find module '../nora-common/models'.
   src/services/devices.repository.ts(7,25): error TS2307: Cannot find module '../nora-common/util'.
   src/services/report-state.service.ts(5,30): error TS2307: Cannot find module '../nora-common/models'.
   src/socket/types.ts(1,38): error TS2307: Cannot find module '../nora-common/models'.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.GlUgz/_logs/2021-03-27T17_24_53_649Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] heroku-postbuild: npm run build && npm run copyhtml && npm run schema
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] heroku-postbuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.GlUgz/_logs/2021-03-27T17_24_53_668Z-debug.log
-----> Build failed

   We're sorry this build is failing! You can troubleshoot common issues here:
   https://devcenter.heroku.com/articles/troubleshooting-node-deploys
   
   Some possible problems:
   
   - A module may be missing from 'dependencies' in package.json
     https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
   
   Love,
   Heroku

! Push rejected, failed to compile Node.js app.
! Push failed**

------ THANKS FOR YOUR HELP -----

nora-firebas-service?

do you plan to publish the firebase variant of the service and write instructions for it so that everbody can run it itself? Thanks in advance

Nora Home not getting added to Google Home

Hi @andrei-tatar,
Thanks for your great work.
I've completed all the setup and were able to go to google home and search for my test app.
The issue is that I can successfully login to my app's within Google Home but after confirming that I allow Google to access my account nothing happens.
Can you direct me towards a direction that I could troubleshoot the issue?
Below is the final log I see on Heroku's app:
2020-09-29T22:12:21.243191+00:00 heroku[router]: at=info method=POST path="/token" host=test-nora.herokuapp.com request_id=87giudb2397d3-3177-47d0-2ed7gd7gd fwd="108.177.70.127" dyno=web.1 connect=1ms service=3ms status=404 bytes=421 protocol=https

I don't know why the status is 404! Also no idea where that forward IP address is coming from.

Many thanks in advance
Cheers

Erros building the app

Hello @andrei-tatar
I have successfully completed all steps of the setups but am stuck with building the app.
I tried to run the command on my windows terminal as well as Raspberry Pi but both failed.
Here is the npm error log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]prebuild: [email protected]
6 info lifecycle [email protected]
build: [email protected]
7 verbose lifecycle [email protected]build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]
build: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/pi/nora-service/node_modules/.bin:/usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/pi/nora-service/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
9 verbose lifecycle [email protected]build: CWD: /home/pi/nora-service
10 silly lifecycle [email protected]
build: Args: [ '-c', 'tsc' ]
11 info lifecycle [email protected]~build: Failed to exec build script
12 verbose stack Error: [email protected] build: tsc
12 verbose stack spawn ENOENT
12 verbose stack at ChildProcess. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack at ChildProcess.emit (events.js:315:20)
12 verbose stack at maybeClose (internal/child_process.js:1021:16)
12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
13 verbose pkgid [email protected]
14 verbose cwd /home/pi/nora-service
15 verbose Linux 5.4.51-v7+
16 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
17 verbose node v12.18.4
18 verbose npm v6.14.8
19 error code ELIFECYCLE
20 error syscall spawn
21 error file sh
22 error errno ENOENT
23 error [email protected] build: tsc
23 error spawn ENOENT
24 error Failed at the [email protected] build script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]

What am I missing?

Many thanks in advance

FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing

@andrei-tatar Got my heroku installation working previously, but suddenly I got the error Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail, and seems that my database is empty, resulting in login: { error: password authentication failed for user "ohubflebemtayr"

Traced the error to line 61 of login.ts:
await this.userRepository.value.createUserRecordIfNotExists(decoded.uid);

Inspected my postgres db on Heroku and gasp it is empty!

Continuing to develop going forward?

@andrei-tatar I noticed you've been quiet in the forums and didn't move forward with the code refactoring to run local . I was thinking about adding sensors to the devices now that Imperihome shutdown) but didn't want to spend the time if you weren't still working on this / available to push code updates?

If it's reached end of life, I don't know if there is an easy way to give a few of us access to the backend to push in nora-service updates so we can keep the great work you did moving forward (would need to be someone more technical than me ;-).

Thanks,

Ron

is the Thermostat Humidity Service broken?

no matter which value is submit the answer from Google Assistant is 0% Humidity.

queryOnlyHumiditySetting

Boolean. Optional. Defaults to false. Indicates if the device can only
be queried for state information and cannot be controlled. Sensors that can only 
report humidity should set this field to true. Avoid setting both commandOnlyHumiditySetting
and queryOnlyHumiditySetting to true.

do i need to set queryOnlyHumiditySetting to true? and how? which topic?

Is this a Google or NORA Problem?

Google Project API

I have deployed my own Heroku app and am having error with RequestSyncService.requestSync, response is 400, API key is not valid.

Looking at the code, it requires PROJECT_API_KEY read from the config. But the readme does not mention that parameter to configure in Heroku's config vars. So what API key should be provided here?

Login corrupted

While integrating nora in my node-red on Hassio I ran into a problem where node-red is reporting that:

04/01/2021, 11:51:21
msg : string[53]
"nora (-9gJ4): socket connection error: not authorized"
04/01/2021, 11:51:21
msg : string[37]
"nora (-9gJ4): reconnecting in 8.5 sec"
04/01/2021, 11:51:31
msg : string[61]
"nora (-9gJ4): socket connection error: user already connected"
04/01/2021, 11:51:31
msg : string[36]
"nora (-9gJ4): reconnecting in 51 sec"

This is only when I login on a particular gmail account (my main one). If I login on my different gmail it does work, so it seems something got corrupted on the server side with my main gmail account.
Please wipe "[email protected]" from your project https://node-red-google-home.herokuapp.com/ if you could.
Thanks!

Login fails - Cert issues

Hi Guys,
I followed the instruction on the main page and ran into the following:

login: Error: Could not resolve FirebaseService - "Failed to parse private key: Error: Too few bytes to read ASN.1 value."
Few question:

  • As per instruction, the value of JWT_SECRET and SERVICE_ACCOUNT_KEY should be the same? is this correct?
    I formatted the Private_Key to multiline, removed all the \n from the key and can not seem to resolve it, as soon as I login, I get re-directed to the main login page again.

Also I get this "warning" Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail

Nora is amazing! and if there is anything I can do help troubleshoot, please let me know.
BTW, the DB is created, as I can see 1 table, however, 0 rows.

Setting up on heroku

I'm stuck at setting up on heroku.

I got it all deployed at heroku bu cant login to the app, it says
Screenshot 2020-04-28 at 12 11 09

I added it to firebase of course as per the instructions,

Screenshot 2020-04-28 at 13 23 10

but it still doesnt work. Any idea's ?

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.