transistorsoft / background-geolocation-console

A field-testing & analysis server for the Background Geolocation plugin
MIT License
151 stars 157 forks source link

Server configuration #110

Closed VolodymyrTelenko closed 4 years ago

VolodymyrTelenko commented 4 years ago

Hi. I want to start with you server for tests. I've installed it according to your instruction. But (maybe because of my weak knowledge of JS world (i'm a .net developer) i still have some troubles with it.

Environment variables:

export DATABASE_URL=postgres://postgres:password@localhost:5432/geolocation export GOOGLE_MAPS_API_KEY=AIz...vNkg export SHARED_DASHBOARD=1 # with auth export ADMIN_TOKEN=admin256 # admin login export PASSWORD=test # admin password

what does it mean? is it just an information? or i need to configure such parameters/variables? do i need it? Is db installed after "nmp install"/"npm run" or i need to install\configure it manually? what is the easiest way to do it in that case?

when i open http://localhost:9000/ in my browser i see "Cannot GET /" text only

when i open http://localhost:9000/locations/aaa i see "{"message":"ENOENT: no such file or directory, stat 'D:\TollNet\eobu\background-geolocation-console-master\build\index.html'"}"

What i need to do to configure server correctly?

Thank you.

christocracy commented 4 years ago

The web app is served at port 8080.

http://localhost:8080

VolodymyrTelenko commented 4 years ago

ok. but... i see some activity on server log when i do something on http://localhost:9000/locations/aaa and.. just "This site can’t be reached" when i trying http://loc alhost:8080/

image

VolodymyrTelenko commented 4 years ago

maybe its because of different modes. i just called npm run and it looks like ist === npm run server

image

VolodymyrTelenko commented 4 years ago

heh... it works now. i've tried npm run dev there where some errors 'BABEL_ENV' is not recognized as an internal or external command, ...

so i just installed https://www.npmjs.com/package/cross-env and have changed "BABEL_ENV=node node --inspect=9229 ./bin/server.js\" \"BABEL_ENV=webpack node ./bin/dev.js\"",

on

"cross-env BABEL_ENV=node node --inspect=9229 ./bin/server.js\" \"cross-env BABEL_ENV=webpack node ./bin/dev.js\"",

and it works now.

thank you!

VolodymyrTelenko commented 4 years ago

Sorry for issue reopening but i still have problems with myapp <-> console <-> web communication...

  1. It's really not clear for me how to configure client calls correctly. I saw few different examples

    BackgroundGeolocation.ready({ url: url + "/v2/locations",

    BackgroundGeolocation.ready({ url: "https://my-server.com/locations"

BackgroundGeolocation.ready({ url: ENV.TRACKER_HOST + '/api/locations',

which one i need to use?

  1. now in local server i see a lot of errors :

    GET /api/site/devices?company_id=1&company_token= 500 0.681 ms - 34 Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at ServerResponse.setHeader (_http_outgoing.js:526:11) at ServerResponse.header (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\respons s:771:10) at ServerResponse.send (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\response. 170:12) at ServerResponse.json (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\response. 267:15) at ServerResponse.send (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\response. 158:21) at D:\TollNet\eobu\background-geolocation-console-master\src\server\/index.js:72:21 at Layer.handle_error (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\lay js:71:5) at trim_prefix (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:3 13) at D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\route ndex.js:335:12) at next (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:275:10) at Layer.handle_error (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\lay js:67:12) at trim_prefix (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:3 13) at D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\route ndex.js:335:12) at next (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:275:10) at Layer.handle_error (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\lay js:67:12) at trim_prefix (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:3 13) at D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\route ndex.js:335:12) at next (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:275:10) at Layer.handle_error (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\lay js:67:12) invalid signature JsonWebTokenError: invalid signature at D:\TollNet\eobu\background-geolocation-console-master\node_modules\jsonwebtoken\verify.js:133:19 at getSecret (D:\TollNet\eobu\background-geolocation-console-master\node_modules\jsonwebtoken\verify.js:90:14) at Object.verify (D:\TollNet\eobu\background-geolocation-console-master\node_modules\jsonwebtoken\verify.js:94:1

    at verifier (D:\TollNet\eobu\background-geolocation-console-master\src\server\libs\/jwt.js:66:22) at D:\TollNet\eobu\background-geolocation-console-master\src\server\libs\/utils.js:117:21 at Layer.handle [as handle_request] (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\ \router\layer.js:95:5) at next (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\route.j 12:3) at Layer.handle [as handle_request] (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\ \router\layer.js:95:5) at D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:281:22 at Function.process_params (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\route ndex.js:335:12) at next (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:275:10) at Function.handle (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index. 174:3) at router (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:47:12)

    at Layer.handle [as handle_request] (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\ \router\layer.js:95:5) at trim_prefix (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:3 13) at D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\route ndex.js:335:12) at next (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:275:10) at D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:635:15 at next (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index.js:260:14) at Function.handle (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\router\index. 174:3)

could you please explain what i'm doing wrong?

Thank you

christocracy commented 4 years ago

Everything required to configure the plugin to post to the demo server is explained in the API docs TransistorAuthorizationToken. You do no need to provide the url, it's all automatic.

let token = await BackgroundGeolocation.findOrCreateTransistorAuthorizationToken(orgname, username, url);

BackgroundGeolocation.ready({ transistorAuthorizationToken: token })


- Flutter:
```dart
String orgname = "my-company-name";
String usernmae = "my-username";
String url = 'http://192.168.0.100:9000';

// Fetch an authoriztion token from server.
// The SDK will cache the received token and return it if found locally.
TransistorAuthorizationToken token = await
  TransistorAuthorizationToken.findOrCreate(orgname, username, url);

BackgroundGeolocation.ready(Config(
  transistorAuthorizationToken: token
))
VolodymyrTelenko commented 4 years ago

thank you for your answer and... what about server error ? image

christocracy commented 4 years ago

and... what about server error ?

No idea.

VolodymyrTelenko commented 4 years ago

image

christocracy commented 4 years ago

You're not supposed to execute #start until callback to #ready resolves.

VolodymyrTelenko commented 4 years ago

Maybe complete server log could help understand whats going wrong?

I've spent a lot of time with this test configuration... i really need your help.

thank you.

1.log

VolodymyrTelenko commented 4 years ago

Hi, Chris. Unfortunately i need to complete mission this night :) So... again

Running

Environment variables:

export DATABASE_URL=postgres://postgres:password@localhost:5432/geolocation
export GOOGLE_MAPS_API_KEY=AIz...vNkg
export SHARED_DASHBOARD=1      # with auth
export ADMIN_TOKEN=admin256    # admin login
export PASSWORD=test           # admin password

what does it mean? I need to change some variables?
--------------------------

And this

### Firestore

export FIREBASE_URL=https://YOUR-PROJECT-DATABASE.firebaseio.com export FIREBASE_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\nMII...=\n-----END PRIVATE KEY-----\n



do i need to change firestore configuration? Is it necessary?
(i just need to see that call from mobile app fixed on server (stored in db and showed in web console. that's all what i need)
-------------------------
Right now i have some notifications "can't load google maps on that page correctly"
It's because of api key, i think. Is it important? Actually i don't need maps. I just want to see correct communication between your demo app and your server installed locally on my pc

But now i have errors even without starting mobile app on emulator/mobile.
So
1. I need some additional explanation to your instructions on install;

2. Warning from google. Is it important? I don't need maps...

3.  error 1
[0] invalid signature JsonWebTokenError: invalid signature
[0]     at D:\TollNet\eobu\background-geolocation-console-master\node_modules\jsonwebtoken\verify.js:133:19
[0]     at getSecret (D:\TollNet\eobu\background-geolocation-console-master\node_modules\jsonwebtoken\verify.js:90:14)
[0]     at Object.verify (D:\TollNet\eobu\background-geolocation-console-master\node_modules\jsonwebtoken\verify.js:94:1
0)

4. error 2

[0] GET /api/site/devices?company_id=1&company_token= 500 10.691 ms - 34
[0] Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
[0]     at ServerResponse.setHeader (_http_outgoing.js:526:11)
[0]     at ServerResponse.header (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\respons
e.js:771:10)
[0]     at ServerResponse.send (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\response.
js:170:12)

Please, help me :) Its easy fir you and really important for me.

Thank you
Sigura commented 4 years ago

do i need to change firestore configuration? Is it necessary? .. (i just need to see that call from mobile app fixed on server (stored in db and showed in web console. that's all what i need)

a) GOOGLE_MAPS_API_KEY needs to be correct only for map. b) About Firebase. The answer depends on DB what using. Available options: sqllite, pg or firestore.

I need some additional explanation to your instructions on install;

Sorry, I have no idea about what a details you need. It's not the first try to use this example and README has been enough.

The backend side has the same structure and logic as .net open stack.

Maybe you need o try again with a clean configuration and from the start of README with this knowledge.

Good luck.

VolodymyrTelenko commented 4 years ago

@Sigura , thank you for your answer!

As i wrote, i'm new in js word and there a lot sings ... strange for me :)

  1. Environment variables? What is it? It's not about windows environment variables, i think... Do i need specify them somewhere? Are there some defaults? Firestore.. The same.. environment variables... and additional article on firestore configuration... Do i need it? Can i use defaults?

  2. Available options: sqllite, pg or firestore Which one is default? Do i need to configure it?

For me... any working configuration (db etc) would be enough. I just want to check that i can send requests from my mobile app to the server. After that we will implement such interface in our .net sever but for now, for the beginning, i need to check everything on your server.

Again... thank you for your reply.

image

VolodymyrTelenko commented 4 years ago

A have reinstalled it few times. The same situation.

  1. 'BABEL_ENV' is not recognized as an internal or external command, ...

so i just installed https://www.npmjs.com/package/cross-env and have changed "BABEL_ENV=node node --inspect=9229 ./bin/server.js" "BABEL_ENV=webpack node ./bin/dev.js"",

on

"cross-env BABEL_ENV=node node --inspect=9229 ./bin/server.js" "cross-env BABEL_ENV=webpack node ./bin/dev.js"",

After that

  1. invalid signature JsonWebTokenError: invalid signature

  2. GET /api/site/devices?company_id=1&company_token= 500 10.691 ms - 34 [0] Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client [0] at ServerResponse.setHeader (_http_outgoing.js:526:11) [0] at ServerResponse.header (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\respons e.js:771:10) [0] at ServerResponse.send (D:\TollNet\eobu\background-geolocation-console-master\node_modules\express\lib\response. js:170:12)

Sigura commented 4 years ago

'BABEL_ENV' is not recognized ...

Looks like it's windows command line error. This example does not work in windows. Please try to translate execute commands to windows word. Maybe it's the next task for me.

SHARED_DASHBOARD

1 - for a lot of users (login and password make sense) 0 - for self-using (the password does not need)

ADMIN_TOKEN/PASSWORD

login/password for SHARED_DASHBOARD=1 use case

Do i need it? Can i use defaults?

SHARED_DASHBOARD=0 is a simple way

Available options: sqllite, pg or Firestone. Which one is default?

Sqllite for localhost. But it does not compatible with Heroku. Other words "working configuration" depends on requirements.

VolodymyrTelenko commented 4 years ago

ok. so again i've reinstalled it one more time after that cross-env fix after that

SET DATABASE_URL=postgres://postgres:password@localhost:5432/geolocation SET GOOGLE_MAPS_API_KEY=AIz...vNkg SET SHARED_DASHBOARD=0 SET ADMIN_TOKEN=admin256 SET PASSWORD=test

(in my ps session)

after that

npm run dev

and... the same situation :

im my ps log

VolodymyrTelenko commented 4 years ago

so... one step further we have started server on linux (imho it's absolutely not possible now on windows : critical errors)

it works so i can see console at http://xxx..228.31:8080/

in my app i have

const trackerHost = "http://xxx..228.31:8080/"; ...

// Step 1:  Listen to events:

BackgroundGeolocation.onLocation(this.onLocation.bind(this)); BackgroundGeolocation.onMotionChange(this.onMotionChange.bind(this)); BackgroundGeolocation.onActivityChange(this.onActivityChange.bind(this)); BackgroundGeolocation.onProviderChange(this.onProviderChange.bind(this)); BackgroundGeolocation.onPowerSaveChange(this.onPowerSaveChange.bind(this)); BackgroundGeolocation.onHttp(this.onHttp.bind(this)); BackgroundGeolocation.onHeartbeat(this.onHeartbeat.bind(this)); BackgroundGeolocation.onAuthorization(this.onAuthorization.bind(this));

let token: TransistorAuthorizationToken = await BackgroundGeolocation.findOrCreateTransistorAuthorizationToken(
  "someorg",
  "wild2",
  trackerHost
);

// Step 2:  #configure:
BackgroundGeolocation.ready(
  {
    transistorAuthorizationToken: token,
    reset: false,
    stopTimeout: 1,
    debug: true,
    logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
    foregroundService: true,
    autoSync: true,
    stopOnTerminate: false,
    startOnBoot: true,
    notification: {
      title: "react-native-background-geolocation",
      text: "Tracking engaged"
    },
    distanceFilter: 10,
    enableHeadless: true,
    heartbeatInterval: 60,
    params: {
      user_id: "wild2"
    }
  },
  state => {
    console.log("- Configure success: ", state);

    BackgroundGeolocation.start(); //TODO
  }
);

and... it posts and looks like it stores data in db!

[0] v2:locations:post org:name someorg device:id 1 [0] v1:location:create org:name someorg org:id 1 device:id AOSP on IA Emulator-wild2 [0] v1:location:create {"id":1,"device_id":"AOSP on IA Emulator-wild2","device_model":"AOSP on IA Emulator","company_id":1,"company_token":"someorg"} {"latitude":37.3304217,"longitude":-121.9054533,"data":"{\"event\":\"motionchange\",\"is_moving\":false,\"uuid\":\"756d9e48-77f1-4cb6-ac5f-46a9cfa9fe79\",\"timestamp\":\"2020-05-18T09:26:56.000Z\",\"odometer\":11162677,\"coords\":{\"latitude\":37.3304217,\"longitude\":-121.9054533,\"accuracy\":20,\"speed\":0,\"heading\":90,\"altitude\":0},\"activity\":{\"type\":\"still\",\"confidence\":100},\"battery\":{\"is_charging\":false,\"level\":1},\"extras\":{}}","recorded_at":"2020-05-18T09:26:56.000Z","created_at":"2020-05-18T09:26:56.361Z","company_id":1,"device_id":1} [0] Executing (default): INSERT INTO "locations" ("id","latitude","longitude","data","recorded_at","created_at","company_id","device_id") VALUES (DEFAULT,$1,$2,$3,$4,$5,$6,$7) RETURNING *; [0] Executing (default): UPDATE "companies" SET "updated_at"=$1 WHERE "id" = $2 [0] Executing (default): UPDATE "devices" SET "updated_at"=$1 WHERE "id" = $2 [0] POST /api/locations 200 38.099 ms - 16

but... in console web... i can't see any data because of

[0] GET /api/site/devices?company_id=1&company_token= 500 1.446 ms - 44 [0] Authorization Bearer not found Error: Authorization Bearer not found [0] at /home/mouseman/Work/background-geolocation-console/src/server/libs/utils.js:104:17


server runs in dev configuration

Sigura commented 4 years ago

please try this one:

export DATABASE_URL=postgres://postgres:.../geolocation && \
export GOOGLE_MAPS_API_KEY=AIz...Nkg && \
export SHARED_DASHBOARD= && \
export ADMIN_TOKEN= && \
export PASSWORD= && \
npm run dev

then open http://localhost:8080/ then clean site data then reload page.

Sigura commented 4 years ago

PS: node (javascript) development absolutely impossible on windows in common cases. Maybe just in the simplest things. That is why I did not understand it from the beginning. Sorry about that.

VolodymyrTelenko commented 4 years ago

so it's somehow works and we've decided to start implement server om our .net platform. i have one small question for now

according to our specification we need such info for each event

    <xs:element minOccurs="0" name="Course" type="xs:int" />
    <xs:element minOccurs="0" name="Hdop" type="xs:int" />
    <xs:element minOccurs="0" name="NumberOfSatellites" type="xs:int" />

is it possible put such info into event? maybe its already there but under different name?

thank you.

christocracy commented 4 years ago