Using JSON Store for Data Point tagging - Can it be done?
-
Can JSON Store be used to link additional attributes to a DataPoint? Use-case might be tagging circuit breaker readings with a customer or department name and then retrieving information or running reports by customer.
Can a JSON Store value be made available to Meta Data Points via the Script context drop-down?
Any small examples would be greatly appreciated.
-
We have talked about adding more flexible data point tagging, its something we definitely see the value in. Hopefully we can add this to a release soon!
But in regards to your question, yes you can add additional information about a data point to the JSON store and access it from a meta data point. This is something we have been doing a fair recently for our customer projects.
Here's an example meta data point script that retrieves settings for its data point XID. It only retrieves the JSON data when the point starts not every poll.
var pointConfig = this.pointConfig; if (!pointConfig) { var dao = com.serotonin.m2m2.db.dao.JsonDataDao.instance; var jsonDataVo = dao.getByXid('point-configuration'); var dataAsString = jsonDataVo.jsonData.toString(); var data = JSON.parse(dataAsString); pointConfig = this.pointConfig = data[point.dataPointWrapper.xid]; } var result = contextPoint.value * pointConfig.multiplier + pointConfig.offset; return isFinite(result) ? result : UNCHANGED;
-
Thank you, Jared.
I have tried to apply this using the example from the maJsonStore demo to input a value to "phone".<ma-json-store xid="phoneData" item="myItem" value="myValue"></ma-json-store> <input ng-model="myValue.phone"> <md-button class="md-raised md-primary md-hue-3" ng-click="myItem.$save()"> <md-icon>save</md-icon> Save </md-button> <p>Phone # from JSON store: {{myItem.jsonData.phone}}</p>
I then have a Meta Data Point that attempts to retrieve the value of "phone" utilizing the code you provided. I am having trouble understanding the context of the following line and how it should be modified to return the phone.value that was added via the UI.
data[point.dataPointWrapper.xid]
Using this....
var pointConfig = this.pointConfig; if (!pointConfig) { var dao = com.serotonin.m2m2.db.dao.JsonDataDao.instance; var jsonDataVo = dao.getByXid('phoneData'); var dataAsString = jsonDataVo.jsonData.toString(); var data = JSON.parse(dataAsString); pointConfig = this.pointConfig = data[point.dataPointWrapper.xid]; } var result = pointConfig.phone;
I receive this error....
ReferenceError: "point" is not defined
Thank you.
-
point
is the variable name I gave to the meta data point the script is in. It defaults tomy
I believe, there is a text box for it on the meta data point edit page.