OH3 and HTTP regex ... items not refreshed

Another good point :slight_smile: I’m struggling to see my logs :frowning:

I’ve added

(function(i) {
    var log = Java.type("org.slf4j.LoggerFactory").getLogger("meteoalarm-wind");
    var value = /.*aw1([1-4])\..*/.exec(i);
    log.debug("Value" + value)
    if (value === null) {
        return 0;
    }
    if (value[1] > 1 && value[1] < 5) {
       return value[1];
    } 
})(input)

but I see nothing in my logs :frowning: do I need to enable something else? perhaps via karaf?

thanks
Andrea

Reminder

I have no idea. There are other threads about this.

this is what you are saying?

(function(i) {
    var log = Java.type("org.slf4j.LoggerFactory").getLogger("meteoalarm-wind");
    var value = /.*aw1([1-4])\..*/.exec(i);
    log.debug("Value" + value)
    if (value === null) {
        return 0;
    }
    if (value[1] > 1 && value[1] < 5) {
       return value[1];
    }
    return 0
})(input)

why don’t put only “return 0” at the end? also null should hit this (as null is not a value between 1 and 5)

because

Perhaps the missing puzzle piece for you is that if you get an errorin your javascript, you won’t get 0 returned.

1 Like

it seems a chicken-egg situation … regex creates arrays, but if regex doesn’t match, result is null that is not an array …

Sorry, I’m completely lost … :frowning: I’m trying to find a way to have some info by logs, but till now nothing :frowning: … troubleshooting

I think this script should work

(function(i) {
    var value = /.*aw10([1-4])\..*/.exec(i);
    if(value === null){
        return 0;
    }else{
        return value[1];
    }   
})(input)

and it works the first time. But if I change website to change the value, it doesn’t work any more.

I suspect it should be linked with lastIndex:

edit: mmm no, this is influencing only if the regex is “g”. Exec() is already starting from the beginning every time it works

I was thinking more like

// variable "input" contains data passed by OpenHAB binding
//  function scrapes image filename
(function(i) {
    var value = /.*aw1([1-4])\..*/.exec(i);
    if (value == null) {
        return 0;
     }
    if (value[1] > 1 && value[1] < 5) {
       return value[1];
    } 
    return 0;    
})(input)

It’s just one step at a time.

How are you changing the remote website exactly?
If you are editing the binding Thing you will almost certainly need to restart the binding. Small Thing edits are very often not implemented in-flight, especially when a scheduled job is involved as here.

I change the thing file (only baseURL, pointing to another region) and I restart the binding via Karaf

the script doesn’t work yet :frowning:

just thinking loud … and if we set the “value” to 0 before checking the regex? If the regex reports ‘null’, the value should be untouched right? so return value should do the trick

not sure, perhaps my idea is just rubbish :slight_smile:

Oh come on. “doesn’t work”? Be specific.

Set value to what you like.
The regex code is going to return something, whether you want it or not. The something may be null, That’s how it works.
If you put whatever regex returns into value, it will overwrite any previous content. That’s how assignment works. It doesn’t matter if the return is null or “bananas”.

If you don’t want to destroy some previously assigned value, then you’ll have to put the regex return somewhere else - othervalue say.

I can’t imagine how that helps. It’s not exactly onerous to test the return for null

I would be specific, my friend … but I’m not able to receive any log by this script, and I don’t know where the script fails, or simply the regex is reporting null but the value 0 is not returned. Or whatever.

I don’t know.

What I know is: if I point with baseURL to a region with a warning, the warning is reported correctly. But if I change the baseURL where that warning is off, for the God sake I’m not able to reset that warning. I’m not able to overwrite with “0” the previous content.

Hope this helps. I really appreciate your help, but at the moment I’m completely blind (and not having a proper logging system is crazy, let me say)

Andrea