todbot / Blink1Control2

Blink1Control GUI to control blink(1) USB RGB LED devices.
http://blink1.thingm.com/
Apache License 2.0
154 stars 26 forks source link

Meta pattern "~pattern-stop" not functional on renamed pattern. Pattern rename doesn't regen pattern id #162

Closed dkozinn closed 2 years ago

dkozinn commented 2 years ago

I have a configuration in Blink1Control2 that monitors a test file on a server using a URL. The system will set that file to a specific pattern if a reboot is required (pattern: reboot). As per patterns.md, I'm trying to turn that pattern off at all other times. (It's set to repeat forever, so I need to explicitly turn it off). I've tried ~pattern-stop:reboot and even ~off but Blink1Control2 reports "no pattern" for these. Am I doing something wrong or is this a bug?

Here's the section of the configuration for that:

 {
      "type": "url",
      "enabled": true,
      "name": "Check example.com/blink",
      "actionType": "parse-pattern",
      "actOnNew": true,
      "blink1Id": "0",
      "path": "https://my.example.com:8443/blink1",
      "intervalSecs": "15",
      "errormsg": ""
    }
todbot commented 2 years ago

Looking into this now. Thank you for the detailed issue report.

todbot commented 2 years ago

Are you trying to trigger a pattern already stored in Blink1Control2 (like say policecar) or specifying a new pattern (like bob in patterns.md)?

If the pattern already exists, then your URL should return pattern:policecar (or {"pattern":"policecar"} if in parse JSON mode)

dkozinn commented 2 years ago

I failed to mention that the initial trigger to turn on that pattern works, it's only the "turn off" that doesn't work.

I've set up (on another system) two files that demonstrate what I'm trying to do:

Start blinking: https://kozinn.com/blink-reboot - This works as expected Stop blinking: https://kozinn.com/blink-off - This doesn't work

Pattern reboot exists: image

On the actual system where I'm using this, I write to the same file (just one trigger) which is what I presented in my initial post.

I hope that makes it a little more clear.

todbot commented 2 years ago

Hi David, I see the error now and it is definitely a bug that ~pattern-stop triggers. I have a fix I'm testing that will address this.

Until a new release is out (in a few days), two possible workarounds for you, depending on which approach you prefer:

btw, if you want a faster way to test this, you can also use the built-in HTTP REST API server in Blink1Control2. The equivalent commands using that would look like:

curl 'http://localhost:8934/blink1/pattern/play?name=~pattern-play:reboot'
curl 'http://localhost:8934/blink1/pattern/play?name=~pattern-stop:reboot'
curl 'http://localhost:8934/blink1/pattern/play?name=~off'
dkozinn commented 2 years ago

I changed the pattern in the config file so that it now looks like this:

{
      "name": "reboot",
      "id": "reboot",
      "pattern": "0,#ffff00,0.5,0,#000000,0.5,0",
      "locked": false
}

It seems to be working both via curl and URL fetch, although I had to change the pattern I was using in the URL fetch to pattern:~pattern-stop:reboot rather than ~pattern-stop:reboot which I had been using. The documentation was a little unclear about this, sorry if I misinterpreted.

The only other thing would be that I guess it's hit or miss as to when the stop gets processed as to whether the LED remains lit or not, I guess that makes sense.

The problem with setting the URL to ~off is that I have a number of different things monitored, and by having the URL always return ~off except when a reboot is needed it would just turn off anything else set.

At this point I've got your workaround in place so thanks for the help.