Package.json updated
getporpertie leist nun auch die Chipdaten aus prop_flux
This commit is contained in:
Vendored
+5
-3
@@ -11,15 +11,16 @@
|
|||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
"program": "${workspaceFolder}/bin/www.js",
|
|
||||||
"env": {
|
"env": {
|
||||||
|
"DEBUG": "sensorapi:*",
|
||||||
"INFLUXHOST": "192.168.178.190",
|
"INFLUXHOST": "192.168.178.190",
|
||||||
"INFLUXTOKEN": "gHGGgjaK0lmM6keMa01JeuDpqOE_vRq8UimsU4QKb2miI5BDh2PfWynEbwKizdJapXy8jVbTat5mVZLQTNmSdw==",
|
"INFLUXTOKEN": "gHGGgjaK0lmM6keMa01JeuDpqOE_vRq8UimsU4QKb2miI5BDh2PfWynEbwKizdJapXy8jVbTat5mVZLQTNmSdw==",
|
||||||
"MONGOHOST": "192.168.178.190",
|
"MONGOHOST": "192.168.178.190",
|
||||||
"MONGOAUTH": "true",
|
"MONGOAUTH": "true",
|
||||||
"MONGOUSRP": "admin:mongo4noise",
|
"MONGOUSRP": "admin:mongo4noise",
|
||||||
// "DBASE": "influx"
|
// "DBASE": "influx",
|
||||||
}
|
},
|
||||||
|
"program": "${workspaceFolder}/bin/www.js"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
],
|
],
|
||||||
"program": "${workspaceFolder}/bin/www.js",
|
"program": "${workspaceFolder}/bin/www.js",
|
||||||
"env": {
|
"env": {
|
||||||
|
"DEBUG": "sensorapi:*",
|
||||||
"MONGOUSRP": "admin:mongo4noise",
|
"MONGOUSRP": "admin:mongo4noise",
|
||||||
"MONGOPORT": "27037",
|
"MONGOPORT": "27037",
|
||||||
"MONGOHOST": "217.72.203.152",
|
"MONGOHOST": "217.72.203.152",
|
||||||
|
|||||||
@@ -5,14 +5,20 @@ import {returnOnError} from "../utilities/reporterror.js"
|
|||||||
import checkParams from "../utilities/checkparams.js"
|
import checkParams from "../utilities/checkparams.js"
|
||||||
|
|
||||||
let readProperties = mongo.readProperties
|
let readProperties = mongo.readProperties
|
||||||
|
let readChipData = mongo.readChipData
|
||||||
|
|
||||||
// Read properties for sensorid and properties for all other sensors on same location
|
// Read properties for sensorid and properties for all other sensors on same location
|
||||||
export const getOneProperty = async (params) => {
|
export const getOneProperty = async (params) => {
|
||||||
let properties = {props: {}, err: null}
|
let properties = {err: null, props: {}, chip: {}}
|
||||||
let {opts, err} = checkParams(params, {mandatory:[{name:'sensorid', type: 'int'}], optional:[]})
|
let {opts, err} = checkParams(params, {mandatory:[{name:'sensorid', type: 'int'}], optional:[]})
|
||||||
if (err) {
|
if (err) {
|
||||||
return returnOnError(properties, err, getOneProperty.name)
|
return returnOnError(properties, err, getOneProperty.name)
|
||||||
}
|
}
|
||||||
|
// read 'chip'-data (special for noise sensors)
|
||||||
|
const chipdata = await readChipData(opts.sensorid)
|
||||||
|
if (chipdata.err == undefined) {
|
||||||
|
properties.chip = chipdata
|
||||||
|
}
|
||||||
let sensorEntries = [];
|
let sensorEntries = [];
|
||||||
try {
|
try {
|
||||||
let pp = await readProperties({sid: opts.sensorid}); // read for given sensorID
|
let pp = await readProperties({sid: opts.sensorid}); // read for given sensorID
|
||||||
|
|||||||
@@ -84,9 +84,11 @@ function onError(error) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function onListening() {
|
function onListening() {
|
||||||
|
console.log('DEBUG:', process.env.DEBUG, process.env.INFLUXHOST)
|
||||||
const addr = server.address();
|
const addr = server.address();
|
||||||
const bind = typeof addr === 'string'
|
const bind = typeof addr === 'string'
|
||||||
? 'pipe ' + addr
|
? 'pipe ' + addr
|
||||||
: 'port ' + addr.port;
|
: 'port ' + addr.port;
|
||||||
debug('Listening on ' + bind);
|
debug('Listening on ' + bind);
|
||||||
|
console.log('Listening on ' + bind);
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-4
@@ -28,9 +28,9 @@ export const properties_collection = 'properties'
|
|||||||
|
|
||||||
export const connectMongo = async () => {
|
export const connectMongo = async () => {
|
||||||
try {
|
try {
|
||||||
// logit(`Try to connect to ${MONGO_URL}`)
|
logit(`Try to connect to ${MONGO_URL}`)
|
||||||
let client = await MongoClient.connect(MONGO_URL)
|
let client = await MongoClient.connect(MONGO_URL)
|
||||||
// logit(`Mongodbase connected to ${MONGO_URL}`)
|
logit(`Mongodbase connected to ${MONGO_URL}`)
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
catch(error){
|
catch(error){
|
||||||
@@ -52,10 +52,10 @@ const listDatabases = async (client) => {
|
|||||||
// Read properties from the database
|
// Read properties from the database
|
||||||
export const readProperties = async (query, limit = 0) => {
|
export const readProperties = async (query, limit = 0) => {
|
||||||
let ret = {err: null, properties: null}
|
let ret = {err: null, properties: null}
|
||||||
let client = await connectMongo()
|
let client = await connectMongo()
|
||||||
try {
|
try {
|
||||||
if ("sid" in query) { // if sid is given, read property for sid
|
if ("sid" in query) { // if sid is given, read property for sid
|
||||||
ret.properties = await client.db(MONGOBASE).collection(properties_collection).findOne({_id: query.sid})
|
ret.properties = await client.db(MONGOBASE).collection('properties_collection').findOne({_id: query.sid})
|
||||||
} else { // otherwise read props corresponding to query
|
} else { // otherwise read props corresponding to query
|
||||||
ret.properties = await client.db(MONGOBASE).collection(properties_collection).find(query).limit(limit).toArray()
|
ret.properties = await client.db(MONGOBASE).collection(properties_collection).find(query).limit(limit).toArray()
|
||||||
}
|
}
|
||||||
@@ -68,6 +68,21 @@ export const readProperties = async (query, limit = 0) => {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const readChipData = async (sid) => {
|
||||||
|
let ret = { err: null, chipdata: null}
|
||||||
|
let client = await connectMongo()
|
||||||
|
try {
|
||||||
|
ret.chipdata = await client.db(MONGOBASE).collection('prop_flux').findOne({_id: sid},{projection: {chip: 1, _id: 0}})
|
||||||
|
} catch (e) {
|
||||||
|
ret.err = e
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
client.close()
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// read mapdata from database
|
// read mapdata from database
|
||||||
export const readMapdata = async (query, limit) => {
|
export const readMapdata = async (query, limit) => {
|
||||||
let ret = {err: null, mapdata: []}
|
let ret = {err: null, mapdata: []}
|
||||||
|
|||||||
Generated
+4896
-1807
File diff suppressed because it is too large
Load Diff
+15
-15
@@ -12,24 +12,24 @@
|
|||||||
"www": "./bin/www.js"
|
"www": "./bin/www.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@influxdata/influxdb-client": "^1.24.0",
|
"@influxdata/influxdb-client": "^1.35.0",
|
||||||
"@influxdata/influxdb-client-apis": "^1.24.0",
|
"@influxdata/influxdb-client-apis": "^1.35.0",
|
||||||
"axios": "^0.26.1",
|
"axios": "^1.12.2",
|
||||||
"cookie-parser": "~1.4.4",
|
"cookie-parser": "~1.4.7",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"debug": "~2.6.9",
|
"debug": "~4.4.3",
|
||||||
"express": "^4.18.2",
|
"express": "^5.1.0",
|
||||||
"http-errors": "~1.6.3",
|
"http-errors": "~2.0.0",
|
||||||
"i18next": "^22.4.15",
|
"i18next": "^25.5.2",
|
||||||
"i18next-http-middleware": "^3.3.0",
|
"i18next-http-middleware": "^3.8.0",
|
||||||
"i18next-node-fs-backend": "^2.1.3",
|
"i18next-node-fs-backend": "^2.1.3",
|
||||||
"luxon": "^2.3.1",
|
"luxon": "^3.7.2",
|
||||||
"mongodb": "^4.4.1",
|
"mongodb": "^6.19.0",
|
||||||
"morgan": "~1.9.1",
|
"morgan": "~1.10.1",
|
||||||
"pug": "^3.0.2",
|
"pug": "^3.0.3",
|
||||||
"ws": "^8.5.0"
|
"ws": "^8.18.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "^9.2.2"
|
"mocha": "^11.7.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user