dScript function

Hello

SUBJECT Devantech ethernet relay boards (specifically dS3484)
All the analog inputs display unstable values on the webpage (index.htm), which apparently is normal.

I am looking for an averaging function written in dScript.
Does anyone have any experience with these boards?

TIA
MartyK

Hello @martyk!

Unfortunately, I’m not familiar with dScript so I won’t be able to provide much help in that regard.

However, if you simply want the webpage to display an average value instead of the instant values then you could try modifying the javascript part on the index.htm code to create an array and “fill it” with the analog input values and then simply average that and display that value.

I hope that helps

Hi Geraldin

Thanks for the reply.

That is exactly the code I’m looking for.
Maybe you can do it in HTML/Java? (dScript is a subset)

Regards

I think it would be something similar to this

image

But I’m not able to test it so you might have to change a few things to make it work.

BTW I deleted some lines of the code to take the screenshot with only the relevant variables but you shouldn’t delete them.


function getAVG(array,value) {
  const n = 10; //Number of sample points
  if (array.length <= n){
    array.push(value);
  }
  else{
    array.shift();
    array.push(value);
  }
  return array.reduce((a, b) => a + b) / array.length;
}

var AD1 = [];

function ajaxUpdate()
{
...
    document.getElementById('AD1').value = getAVG(AD1,getValue('AD1'));
...
}
1 Like

Thanks. Much appreciated.

Will let you know when I get this working.

Regards