Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Changing state images with variables

I am having intermittent issues with using variables to alter the images shown in iRule depending on the state of my lights.
I have images defined for LightON and for LightOFF, but iRule does not seem to consistently be able to load them, resulting in a blank image.
Some times it works successfully, but not always, which I don't understand.

I have the following set on an Entrance:

Command: execute 'Query Lights' code on 'Light Feedback' device

Set Variable: $iconLightON$ = 1547724071
Set Variable: $iconLightOFF$ = 1530194060

IF $stateLight1$ != 0
Set Variable $buttonLight1$ = $iconLightON$
ELSE
Set Variable $buttonLight1$ = $iconLightOFF$
ENDIF

The first two variables are set as 'values' and those in the condition are 'expressions'.

Is anything obviously incorrect?
1 person has
this problem
+1
Reply
  • When entering variables,, like $variable$, you MUST use the Gear icons to enter or select the variable you want. If you just type it in, it will not work. Once you enter a variable a time or two, a list will pop up and you can just select the right one.

    Try this code:

    Command: execute 'Query Lights' code on 'Light Feedback' device

    IF $stateLight1$ = 0
    Set Variable $buttonLight1$ = 1530194060
    ELSE
    Set Variable $buttonLight1$ = 1547724071
    ENDIF

    On buttonLight1, set the variable controlling the Default Image to $buttonLight1$. Leave Pressed and Selected set to nothing, no images or variables.

    You could also try:

    Command: execute 'Query Lights' code on 'Light Feedback' device

    IF $stateLight1$ = 0
    Set Variable $buttonLight1$ = 1530194060
    ELSEIF $stateLight1$ = 1
    Set Variable $buttonLight1$ = 1547724071
    ENDIF

    My code is not as pretty or correct as yours, but it is compact and fast. You want your code to run as fast as possible so it feels responsive to the user.

    You will probably need to run this code in different places. In the Entrance it will set the image when you first open the page. You will need to add it to buttons on the page that control Light1. You may not need to Query the feedback for Light1 on the buttons if the source sends it automatically on changes.

    If you have been working with this program for a while, you may need to start over with a clean slate. I was working with similar code, and it would not work until I started over. You may even need to use "clean" variable names, mine somehow got corrupted or something.

    I also found it helpful to set up labels to display variable values for troubleshooting purposes. I deleted these labels, or moved them off the screen, after I got things working.

    Check your code carefully for typos! iRule will happily run with typos in the code that keep it from working correctly!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Thanks for the tips, Mike.

    I did originally have the code as shown in your first example, but I have pages of this stuff all referring to the variable names, making if 'interesting' to change them all again!

    I do like the idea of using labels to fault find, that should give me an idea of which bits are actually working properly and where the issues may be coming from.

    The main issue I am having is that the code seems to work intermittently, so I am not sure where the bugs are creeping in from.

    Off to hunt them down now!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Intermittent execution is the same problem I was having. It seemed to me that all my editing eventually got iRule so out of wack that I couldn't fix it. You could try starting a clean project and use all different variable names. Just try controlling 1 light, and see if you can get that working. Once that is working, you can either expand it or go back and fix your original project.

    In my project, I took the feedback data and stored it in a variable, essentially a buffer. Then I controlled the images on the buttons from the data in the buffer. I did this because I wasn't sure what the feedback data actually was all the time. Seems to work fairly well.

    Good Luck!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Hi, an old thread but something I also found and asked the Irule team about. It seemed like the images weren't syncing to the device in some cases and I even found the same page would work on one device but not another executed side by side,

    I found that by adding the image manually on the page that was displaying blank it would work, probably because the image was now synced to the device.

    Is it better to use a macro as a repeatable entrance rather that a standard variable and feedback?

    John
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated

  • In my opinion, it is better to run a simple query in the Entrance to a Page, which will update the feedback when the page is first loaded. If you have multiple feedbacks on the Page, you will need a query command for each one.

    Most components return a feedback message after they receive a network or serial command, so no additional query is usually necessary. For the few components that don't send feedback automatically, you could make a small macro by adding a .5 second delay after the command, and then send the query command. You could also use a repeating Entrance and send a query every X seconds, but I don't like the overhead to do that.

    Also, Entrances to Drawers don't work, although iRule will let you add them. The work-around I use is to put feedback queries into the Page Entrance wherever the Drawer is used.

    I guess I am also assumming that somebody is not using another remote or another iRule Handset, in which case the feedback values may change even if you don't push a button. Another exception would be if you are showing time played in a movie or a song.

    Mike
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated