Data point with non-linear output?
-
I have a sensor that's designed to measure volume water content in the soil. However, it's output is non-linear so it's value needs to be calculated by a series formulas or a non-linear mapping.
I managed to create a global script to interpret the data using five different formulas. Similar to this:function mapMoisture( voltage ) { if ( voltage < 1 ) { return 34 * voltage - 5; } else if ( voltage < 2 ) { return 56 * voltage - 15; } ... }
So far, the only way I found to apply this to my sensor reading (modbus data point) is to create a meta point relating to the modbus point and use the global script against it. If I need to add 100+ sensors, that would use up 2 data points per sensor effectively doubling my data point usage.
Is there another solution to interpreting non-linear data points other than creating a corresponding meta data point like I have done?
Thanks
-
@tomatopi are you trying to display the modified values or do you need to store them??
If you only want to display, I'd advise writing an angularJS directive to manipulate the data for you then passing that into your chart.The alternative is storing the data in a separate database then using mango to parse the DB and use the data that has been modified in this other database...
Find a way to take this data and store it in a csv file, then write a java class (there are examples here) to parse and modify the raw data into the format required.
Means you'd natively fix your data before pushing it into mango..
Fox
-
@MattFox The AngularJS Directive may be an option. I haven't dove that deep into Mango yet so I'm rather clueless as to where to start. Are there any documentation links/examples/tutorials around that you know of? The v4 documentation gives some very basic information, but not enough for me to wrap my brain around pulling in a data point and applying a formula.
Failing that, I could probably re-program all my sensor transmitters to a pre-parsed output format. I was hoping not to do that since it would tie each controller to a specific sensor requiring hardware flashing if the hardware changes down the line. That would have the advantage of storing historic values for reporting.
Thanks for the help.
-
@tomatopi stick to raw, especially if you find you need to amend your values again later.
You'll need to understand angularJS if you want to extend the dashboard for your own benefit.
Alternatively if you're in the position where you can share your conversion factors, learn about the mango userModule and read about angularJS directives and we can work together to enable you to create your first custom component.-Fox
-
@MattFox I usually program more server-side stuff in PHP so it will take me time to wrap my brain around AngularJS, but I'm starting to try getting familiar with it.
I made that basic userModule based on the docs, but I don't see any good documentation beyond the basic scaffold. It would be cool to see a snippet or two of sample code.
My code to translate the raw voltage from the sensor to a %VWC is:
function percentMoisture( voltage ) { if( voltage < 1.1 ) { return ( 10 * voltage ) - 1; } else if ( voltage < 1.3 ) { return ( 25 * voltage ) - 17.5; } else if ( voltage < 1.85 ) { return ( 48.08 * voltage ) - 47.5; } else if ( voltage < 2.2 ) { return ( 26.32 * voltage ) - 7.89; } else if ( voltage < 3 ) { return ( 62.5 * voltage ) - 87.5; } else { return 100; } }
This may be a silly question, but when I look up AngularJS, I keep getting notices that's depreciated in favour of the new Angular Framework. Do we know what this means for Mango down the road?
Thanks
-
@tomatopi a lot of people have asked the same thing, nobody knows... I'm of the opinion they will stick with angular. I'm more of a Vue3 person myself....
Thanks for the logic, can show you something basic to get you started
Fox
-
@tomatopi Hello, one way to achieve what you are looking for is the create a Global Script such as the one shown below;
here is the text for the script for easy editing, (I just expanded what you had in your question);function mapMoisture(voltage) { print (voltage) if ( voltage > 0 && voltage < 1 ) { return 34 * voltage - 5; } else if ( voltage >= 1 && voltage < 2 ) { return 56 * voltage - 15; } else if ( voltage >= 2 && voltage < 3 ) { return 78 * voltage - 22; } else if ( voltage >= 3 && voltage < 4 ) { return 100 * voltage - 30; } else if ( voltage >= 4 && voltage < 5 ) { return 135 * voltage - 36; } return 0 }
Once this is done you will be able to call the script from a meta point such as this;
-
@joeamiraglia appreciate the input, but he wants to avoid using two datapoints for every individual sensor which is why i suggested showing the data parsed through a directive.
Fox
-
@tomatopi
For non-linear scaling, you will be best off using 2 data points. If you do a front scaling like @MattFox you will soon run into issues when you want to chart, alarm, or display the points with the built-in angularJS components. Other options would be to scale the point at the edge with a PLC before you ingest into Mango. -
@joeamiraglia That is exactly what I have running now on a test point and it does work.
@MattFox Your solution would work, but as @CraigWeb said, charting and displaying the data proved to be a little more difficult.
I'm hoping to avoid re-programming my sensor units to pre-parse the data (I'm using custom make microcontrollers). That would make them less flexible if I add/remove/change sensors.
I originally assumed I'd just need a parsed value to determine if it's moist or dry. Since then, I noticed the history chart was very useful. Since we're tracking soil moisture in a pot, displaying the values in a chart compared to sunlight, temperature, humidity, etc. is proving a lot more useful that I expected.
It would be nice if the modbus datapoint (or others) were able to call a global script instead of just the multiplier/added function. That would be the bees knees.
I'm not entirely sure the direction I will go, but I'm leaning to biting the bullet and using the two points per solution just to get the future flexibility to chart and trigger events.