How to debug JS transformation

Hello,
i am trying to parse the result of this url: http://gpsgadget.buienradar.nl/data/raintext/?lat=51.7&lon=7.35
with this javascript:

(function(param) {
log("tansform: " + param);
rows = param.split(/\r?\n/);
log("rows: " + rows);

rain = 0;
val =0;

for (i = 0; i < rows.length; i++) {
    log(rows[i]);
    matches = rows[i].match(/(\d+)\|(\d{2}:\d{2})?/m);
    log ("Matches: " + matches);
    if (matches === null)
      continue;
    matchedRain = matches[1]; //# 0-255
    matchedTime = matches[2];
    val = Math.pow(10, (matchedRain - 109) / 32);
    log("Regen: " +  val);
    // # Convert to mm/hour
    rain += val;
}
return rain;
})(input) 

It throws an error in the karaf console but i dont know why. The log(…) statement does not work and i dont know how to debug a script in openhab.

Can somebody give me a hint to deal with this problem?

Greeting

Ludger

I have no idea about programming, forgive me if I say something stupid. But I tried this url from my browser (but with my coordinates) and it seems to be broken for several days now. I get nothing back, so maybe that is the reason of your errors.

I asked at buienradar, they had a technical problem. There is a workaround, use the following url. It does redirect, but better keep using this url, cause the redirect will change in the near future.

https://gps.buienradar.nl/getrr.php?lat=51&lon=3

@lubeda Did you find a solution for this? I want to implement the same thing but as stated, I have little programming skills.

Hi there,
Had a quick look.
continue is not defined… try this…

(function(param) {
log("tansform: " + param);
rows = param.split(/\r?\n/);
log("rows: " + rows);

rain = 0;
val =0;

for (i = 0; i < rows.length; i++) {
    log(rows[i]);
    matches = rows[i].match(/(\d+)\|(\d{2}:\d{2})?/m);
    log ("Matches: " + matches);
    if (matches !== null) {
      matchedRain = matches[1]; //# 0-255
      matchedTime = matches[2];
      val = Math.pow(10, (matchedRain - 109) / 32);
      log("Regen: " +  val);
      // # Convert to mm/hour
      rain += val;
  }
}
return rain;
})(input)

That should do what the continue statement was meant to do.

Regards

To debug javascript transform you need to do it step by step by commenting out sections of the code until you stumble on the error.

The other way to do it in to put the code into a js environment like node-red
Paste the code into a function node and test

Regards

The solution from @vzorglub is working, when you omit the log-statements.
With the log-statements i got exeptions.

I think i will try the node-red way to code.

Thanx