Files
sensorapi_influxtst/actions/getproperties.js
Reinhard X. Fürst bd44740649 API-Auth dazu
automatisch auf INFLUX schalten, wenn es Chi-ID gibt
zuzsätzlich option db=m zum erzwingen von Moing
Anzeige Mongo/Influx im Datenstrom
2025-11-05 09:47:25 +00:00

43 lines
1.7 KiB
JavaScript

// Fetch the properties for the given sensor
import * as mongo from "../databases/mongo.js"
import {returnOnError} from "../utilities/reporterror.js"
import checkParams from "../utilities/checkparams.js"
let readProperties = mongo.readProperties
// Read properties for sensorid and properties for all other sensors on same location
export const getOneProperty = async (params) => {
let properties = {err: null, props: {}, chip: {}}
let {opts, err} = checkParams(params, {mandatory:[{name:'sensorid', type: 'int'}], optional:[]})
if (err) {
return returnOnError(properties, err, getOneProperty.name)
}
let sensorEntries = [];
try {
let pp = await readProperties({sid: opts.sensorid}); // read for given sensorID
if ((pp.properties == null) || (pp.error)) {
return returnOnError(properties, 'NOPROPSREAD', getOneProperty.name, opts.sensorid)
}
// now find sensors with same location
let query = {"location.0.id": pp.properties.location[0].id}
let others = await readProperties(query)
if (others.err) {
return returnOnError(properties, 'NOPROPSREAD', getOneProperty.name, others.errortext)
}
if (others.properties.length > 0) {
for (const x of others.properties) {
if(x._id === pp.properties._id) {
continue
}
sensorEntries.push({name: x.name[0].name, sid: x._id})
}
}
properties.props = pp.properties
properties.props.othersensors = sensorEntries;
} catch (e) {
return returnOnError(properties, e, getOneProperty.name)
}
return properties
}