Scripting Data source not running or updating script points.
-
I could really use some advice on this scripting issue...
I have an es polling data once a minute and on these data calculating a few hundred metapoints every minute as well. This data is then published to a cloud server where I run a script datasource to calculate the aggregate of the piped in metapoints. Although the script tests fine in the edit window, the cron does not appear to be running the script or for some reason the point values are not being saved in the point variables? I do not know how to differentiate the problem, The point variable says "Active source point has no value". Why won't this calculate this on the minute as the script says.
This is the script...var acc1 = 0 ;
for (i=1;i<25;i++){
eval('acc1 += (h1'+i+'.value)');
}
F1_Flow = acc1; //(where F1_Flow is the script's point variable.)Runtime Status shows its polling every minute but nothing is being saved in the variable history?
2017/04/10 22:07:00.000 1ms
2017/04/10 22:08:00.000 2ms
2017/04/10 22:09:00.000 2ms
2017/04/10 22:10:00.000 1ms
2017/04/10 22:11:00.000 1ms
2017/04/10 22:12:00.000 2ms
2017/04/10 22:13:00.000 2ms
2017/04/10 22:14:00.000 8ms
2017/04/10 22:15:00.000 4ms
2017/04/10 22:16:00.000 1msAny help appreciated.
-
Hi Phillip,
Scripts have context points assigned to variable names in the script's context. So,
F1_Flow = acc1;
is assigning over the variable! What it sounds to me like you're looking for is the set() function. Something like,F1_Flow.set(h11.value + h12.value + h13.value + h14.value + h15.value + h16.value + h17.value + h18.value + h19.value + h110.value + h111.value + h112.value + h113.value + h114.value + h115.value + h116.value + h117.value + h118.value + h119.value + h120.value + h121.value + h122.value + h123.value + h124.value);
-
@phildunlap When I use
F1_Flow.set(acc1); or
F1_Flow.set(h11.value + h12.value + h13.value + h14.value +h15.value + h16.value + h17.value + h18.value + h19.value +h110.value + h111.value + h112.value + h113.value + h114.value +h115.value + h116.value + h117.value + h118.value + h119.value +h120.value + h121.value + h122.value + h123.value + h124.value);When I do this it generates a script error?
-
Odd. You can always try something like
print(F1_Flow);
-
yes this is what I was saying the script seems to be working as I
the print(F1_Flow) produces a value
1.7963696000000002
but does not seem to store it when the cron runs it.
This is weird. -
It should look more like:
{ value: 86.7805828398729, time: 1491923992866, millis: 866, second: 52, minute: 19, hour: 9, day: 11, dayOfWeek: 3, dayOfYear: 101, month: 4, year: 2017, last(count): PointValueTime[count], lastValue: PointValueTime(86.7805828398729@2017/04/11 09:19:52.866), lastValue(count): PointValueTime, set(value): , set(value, timestamp): , pointValuesBetween(timestamp, timestamp): PointValueTime[], pointValuesSince(timestamp): PointValueTime[], pointValuesBefore(timestamp): PointValueTime[], pointValuesAfter(timestamp): PointValueTime[], pointValueAt(timestamp): PointValueTime, ago(periodType): double, ago(periodType, periods): double, past(periodType): AnalogStatisticsWrapper, past(periodType, periods): AnalogStatisticsWrapper, prev(periodType): AnalogStatisticsWrapper, prev(periodType, periods): AnalogStatisticsWrapper, previous(periodType): AnalogStatisticsWrapper, previous(periodType, periods): AnalogStatisticsWrapper, stats(from, to): AnalogStatisticsWrapper, }
So something is amiss. You are not still assigning a value to F1_Flow are you? F1_Flow should be either the "variable name" of the context point, or if it's a point on the scripting data source it should have its variable name field set to
F1_Flow
-
Yes I have 3 scripting data sources and each contain one scripting point and within each point the variables names are F1_Flow F2_Flow 3_Flow respectfully to the three sources.
when I use set function, verification complains of an error at that line containing this set function. Both
F1_Flow.set(1);
and
F1_Flow.set(acc);
generate error across all three scripting data sources. -
The only thing unusual from how I've used scripting variables before is that the context variables are metapoints from persistent TCP from the es and not actual modbus points.
please explain how the script below works.. RESETSLAVES_ON is a binary in the script context and ITERATION_COUNTER is a numeric with a value 2. My understanding was it was decrementing 2 before doing the reset I assume using a default method?. otherwise how can this script work and it does work.if (RESETSLAVES_ON.value){
Hard_Reset_Slaves(RESETSLAVES_ON);
if (ITERATION_COUNTER<=0){
RESETSLAVES_ON.set(false);
Hard_Reset_Slaves(!RESETSLAVES_ON.value);
}else{
ITERATION_COUNTER -= 1;
}
} -
To the scripting data source, all points in Mango are just points, their origin doesn't change the handling.
The script you have posted has some issues, but let's go through it:
if (RESETSLAVES_ON.value){ //if this point is true or nonzero, Hard_Reset_Slaves(RESETSLAVES_ON); //call this function with that point object, //fortunately for the control logic if( {"object":true} ) == if( true ) //ITERATION_COUNTER may be pointed at an object since it looks like a variable name, but after the first -= 1 it will become NaN if (ITERATION_COUNTER<=0){ //NaN is never <= 0 nor is {"object":true} <= 0 RESETSLAVES_ON.set(false); //Doesn't happen, but would call set function on context point Hard_Reset_Slaves(!RESETSLAVES_ON.value); //call this function with a value this time! a trivial true? } else { ITERATION_COUNTER -= 1; //Turn that context point into a NaN as: a = {"object":true}; a -= 1; print(a); shows ITERATION_COUNTER becomes NaN if it was an object } }
Hard_Reset_Slaves is probably declared in a global script if it's not in this script body. It is not an included function provided by us.
My guess is Hard_Reset_Slaves takes a point instead of a boolean, and it sets RESETSLAVES_ON to false, and that's how the script works. Otherwise I would expect it to keep calling Hard_Reset_Slaves every time it runs, any time RESETSLAVES_ON is true.
-
OK I will digest all that shortly however I have good news in that I now have the points setting properly. I added a new numeric point to each script context and set them to 0 sucessfully. so for some reason yet unclear the script is now setting the point values as it should have F1.set(acc); works yeah
As you pointed out there were inconsistencies in that code only because mistakenly thought an object would default the get and set. functions my mistake.
Thanks for your analysis and overall help.. I did not realize that NaN was being created.
I will correct the script and from now on differentiate between passing the objects vs. its variable value. -
Certainly! Glad you got it working!