Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Repeat / until loop not working, need help


Guest samuelboerhoop

Question

Guest samuelboerhoop

When I plugin the plug in the power socket from my denon receiver, internally the unit is initializing different settings, like network, etc...  when i plugin the unit, the receiver is set to standby, ok. I want to make a lua code whereby it makes a loop with repeat / until...until i get a code back from the unit if it's in standby mode, or on mode, from there it should continue, see below. but it's skips the repeat/until... When the unit is plugged in, no code is been returned... So i was thinking:

 

instead of this: "if not(trim(result) == "PWON" or "PWSTANDBY") then"

 

use "if (trim(result) == """) then" 

Are there other ways to detect an empty string ? 

 

With other words:  When no code is been returned, stay in this loop until PWON or PWSTANDBY is been returned.

Please login or register to see this code.

Please some help would be appreciated. Thankss a lot

 

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

I guess it should be like this:

Please login or register to see this code.

Link to comment
Share on other sites

  • 0

Alex is right.

Both are valid lua. Let's see what these expressions print:

Please login or register to see this code.

Result:

PWSTANDBY

false

Link to comment
Share on other sites

  • 0
Guest samuelboerhoop
  • Inquirer
  • I changed the result to  

     

    if not(trim(result) == "PWON" or trim(result) == "PWSTANDBY") then

     

    See photo from the debug button.

     

    The denon receiver is unplugged, so no data should return. but still it skips the loop ??

    How come...?

     

    It should say: 

    denon receiver... (result)

    ... is Initializing

     

    loops for every 3 seconds, case on top you have a 2second sleep and after iif not line.. = 1 second

     

    but the result is as the photo, ones you press the button...

     

    more suggestions ? 

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
    Guest samuelboerhoop
  • Inquirer
  • ok, now i got the following:

     

    i changed the "until" line to:

     

    until (trim(result) == "PWON" or trim(result) == "PWSTANDBY")

     

    now my debug gives me, see photo

     

    now it goes in endless loop, until i plugin the receiver

     

    but because action is false ... it should tell me

    Denon receiver... (result)

    ... is Initializing.

     

    this should be the loop, why not?

     

     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    Did you change both lines that were wrong?

    Please login or register to see this code.

    and

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
    Guest samuelboerhoop
  • Inquirer
  • Yes, as in:

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0

    I've reworked the script a bit, so it has some more error checking plus error checks. I can't test it on a real Denon, but I can simulate it. So could you please give it a try?

     

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
    Guest samuelboerhoop
  • Inquirer
  • I tested your code: this is the result...

    First i restarted the HC2. to start from scratch.. (clear memory)

     

    situation - denon receiver is unplugged

    See photo, when i press start in debug... no code is been generated for the first time..

    Press the button: see photo

    see next photo = 3 times pressed the button

     

    hope to hear from you again

     

    Thanks already

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    I see. I think the repeat-until is working now... But the tcp socket error 2 is not good... In any case it means the TCP/IP communication failed. How sure are you about address, port and command sent to the Denon? Is the sleep right above the read() sufficient? I don't have a lot of experience with that, but I'll see what I can find out.

    Link to comment
    Share on other sites

    • 0

    Right. I misunderstood something. So you really want to power off the Denon, so actually "socket error 2" is in this particular case not an error, but an indication that you should "keep trying". Usually you want to abort the loop, but here it's actually not a failure.

    Just replace the "break" statement with:

    initialized = false

    Now I expect the script keeps printing "socket error" in a loop, until TCP/IP of the receiver is working. Then it should start checking for "PWON" or the other thin.

    Does this make sense?

    Link to comment
    Share on other sites

    • 0
    Guest samuelboerhoop
  • Inquirer
  • As i mentioned : situation - denon receiver is unplugged, i am working from the office, by means of teamviewer. the denon receiver isn't plugged into the 230V, that's why I get a time out. Will have to test it when i am home again

     

    I did a search on error 2 also - find out it was a timeout , ip + port address are correct

     

    what happened when I increase tcpSocket:setReadTimeout(1000); to tcpSocket:setReadTimeout(10000) ?

     

    Because normally it takes about 30-40 seconds before the denon receiver is returning data on the network bus to the hc2. So when i activated the button after the power from the denon is been switch on (standby mode), after that it takes around 30-40 seconds before i got a respond from the denon.

     

    Will let you know by asap if it works.

    Link to comment
    Share on other sites

    • 0
    Guest samuelboerhoop
  • Inquirer
  • behind the denon receiver i am using a wallplug from fibaro, with some other equipment connected to it.

     

    When i turn on the wallplug then the denon receiver gets 230V and in a scene this button is been pressed... while it waits until the denon is been initialized > then it will turn on the receiver > selects the input and sets the volume.

     

    When the denon is on or in standby when its been initialized then it skips the repeat/until, because it returns with PWON or PWSTANDBY.. status and follows the rest of the code... etc.... 

     

    That's the idea behind it... if this loop repeat / until is not there i have to press the scene for a second after the denon is been powered up for a second time.. you got it? 

    Link to comment
    Share on other sites

    • 0

    Yes, understood, and that's what this VD code will do. There's maybe one improvement to be done. If the receiver doesn't come online, for example because it's not plugged in, this code will keep looping. I think counting the number of tries and breaking the loop after X attempts + a status label on the VD might be a good idea.

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...