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

Virtual device debugging tips - my main loop hangs after a while


Question

Posted

Hi!
 
I'm making a virtual device for my Marantz stereo system. I have a HC2 running 3.6 firmware. (I'll share the virtual device with the world when it's working nicely.

Please login or register to see this image.

/emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" /> It uses a simple telnet protocol which is a bit unstable if you have multiple connections to it - which happens once in while. So usually I'll send "SI?\r" and get for example "SIAUXD\r" back (according to the protocol), but sometimes the responses get a bit tangled up, which makes the communication a bit error prone.
 
The buttons on the virtual device are working nicely, including volume slider and balance slider. But the main loop has a tendency to just hang after a while, and the only way I've found to get it working again from a hung state is to either save the configuration through the UI, or to power cycle the HC2. Does the debug buffer fill up and cause problems due to fibaro:debug? Will a crash due to accessing nil values cause the virtual device to stop responding like this? As a workaround - is there any way to trigger what happens when I save the device, which gets it un-stuck?
 
Does anyone have any good debug tips for this kind of situation? Also... Is there any API documentation for the 3.6 HC2? It would be good to know what the errors codes one gets from various Net.FTcpSocket function calls, for example.
 
Current code:

Please login or register to see this code.

18 answers to this question

Recommended Posts

  • 0
Posted

I think it's a bug. Have the same error with v4. You can put the main-loop in a button and create a scene, which is push the button every second. Then it works. But it's just a workaround...

  • 0
Posted

I think it's a bug. Have the same error with v4. You can put the main-loop in a button and create a scene, which is push the button every second. Then it works. But it's just a workaround...

 

True that. Never put codes under the main loop, it hangs over some time.

  • 0
Posted

It seems that it only hangs if the code is opening socket connections. Likely its having trouble terminating connections and it just keeps opening more and more until it reaches some kind of limit for concurrent open connections.

  • 0
Posted

I had the same problem with my alarm monitor which opens connection.

I put everything in the main loop into a function and called it with pcall and its never failed since

pcall(monitor)

function monitor()

..... Connection code

end

Cheers

Mike

  • 0
Posted

entire, I actually tried that solution. And it did not work for me. The main loop still kept freezing on me. Granted, it did not do it as often, but it still did it. Using an "Update" button is the only 100% solution I have found so far.

  • 0
  • Inquirer
  • Posted

    Ah, thanks for the help. That's certainly not what I expected as an answer... it seems to work, though. (I went for the "refresh button" approach.)

    • 0
    Posted

    entire, I actually tried that solution. And it did not work for me. The main loop still kept freezing on me. Granted, it did not do it as often, but it still did it. Using an "Update" button is the only 100% solution I have found so far.

    Oh well worth mentioning

    Cheers

    Mike

    • 0
    Posted

    Hi,

    I have the same problem with my Philips HUE-VDs and my Yamaha-VD. They stop working after 1-2h (Firmware 4.047). They just stop- no message in the debug window. The only way to start the device again is to save it again and again and again (every hour).  I have already tried to put the GET command or the complete code in a function, but this doesnt work for me. Also tried to insert long fibaro:sleep commands- nothing changes.

    Any other suggestions? Is the only way to work around to edit all my 12 VDs and put the codes from the main loop in a seperate scene?

    Is there already a post in bugzilla?

    Thanks in advance!

    • 0
    Posted

    Hi,

    I have the same problem with my Philips HUE-VDs and my Yamaha-VD. They stop working after 1-2h (Firmware 4.047). They just stop- no message in the debug window. The only way to start the device again is to save it again and again and again (every hour).  I have already tried to put the GET command or the complete code in a function, but this doesnt work for me. Also tried to insert long fibaro:sleep commands- nothing changes.

    Any other suggestions? Is the only way to work around to edit all my 12 VDs and put the codes from the main loop in a seperate scene?

    Is there already a post in bugzilla?

    Thanks in advance!

    Try the "Update" button solution.

     

    Create a new button and put your current main loop code inside it. The main loop should only contain:

    Please login or register to see this code.

    • 0
    Posted

    I am quite interested in your Virtual Device. Could you share your VD or maybe send it to me through a private message? I just got my Marantz Receiver yesterday

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    • 0
    Posted

    Thank you, sounds like a easy to manage soloution- would be done fast for all faulty devices!  I will give this a try tonight when I am back home and give feedback.

    • 0
    Posted

    The "Update button" is indeed a good solution. What also works for me is to make a while loop in your VD. with a sleep in the end of x seconds.

    Please login or register to see this code.

    If the loop ends or the HC2 is restarted it will also restart the mainloop agian.

    • 0
    Posted

    Both solutions are worging fine for me- now since 2 hours without interruption. Perfect! Since Stevenvds solution is even more simple i will use this one- only 2 lines in every main loop, thats really no effort.

    Tänan väga Rait and dank je well Stevenvd!!

    • 0
    Posted

    Hi all, 

     

    I have just get the same problem with this topic. 

    But this topic is very long time ago. 

    Do you update any new solution/ advice for this case. 

     

    Thanks all. 

    • 0
    Posted

    Hi @cuong.mhome ,

     

    this thread is indeed very old and there where tons of updates in the meantime. I have dozen of VD's with running Main loop that never stops, but code is written to avoid any unexpected situations. There is still very slight chance that main loop which uses HTTP or TCP socket calls stop running without any errors but in my case that is very very rare. It is possible that request just get stuck and indefinitely waiting for answer from the device.

     

    Anyway if you can give some more information about what debug info you have when VD main loop stops working there might be also a solution.

    Have a nice day

    Enjoy coding :-) 

    • 0
    Posted

    Hi @Sankotronic

     

    Thank you your answers alot. 

    I got 2 time problem in this month

    - 1 time error happen when after we synchronized 2 HC2.

    - 1 time when we reconfigure the Z-wave networks. 

     

    So, after read topics, I so worry about is it can stop in future. 

    I'm changing from using VD + Scenes -> VD alone program. 

    So it will the bad thing with me if it get error.

     

    My code just very simple to prevent errors:

     

    local thisdevice = fibaro:getSelfId();
    local countValue = fibaro:getValue( thisdevice , "ui.lblCountDown.value");
    local sensorId = fibaro:getValue( thisdevice , "ui.lblSensor.value");

    fibaro:debug(countValue);
    if(countValue ~= "0") then   
      local _intValue = tonumber(countValue);  
      if(type(_intValue) ~= "number") then -- Check the type is correct or not. Because some time unknown error here.
          fibaro:call(thisdevice, "setProperty", "ui.lblCountDown.value", "0"); 
      else        
          _intValue =_intValue - 1;
          if(_intValue == 0) then
            fibaro:call(thisdevice, "pressButton", "5")
          end
          fibaro:call(thisdevice, "setProperty", "ui.lblCountDown.value", _intValue); 
      end
    end

    if(sensorId ~= "")then
        local sensorStatus = fibaro:getValue(sensorId, "value")
        if(sensorStatus == "1") then
            fibaro:call(thisdevice, "pressButton", "4")
            fibaro:debug("Press button"); 
        end
    end

     

    Thank you. 
    Cường. 

    • 0
    Posted

    Just to make sure that device really exists on your system and getting it's value is correct you can try this version of code:

     

    Please login or register to see this spoiler.

     

     

     

    • 0
    Posted

    Yes, I understand your suggestion, and apply it.

    One more time, thanks for your support. 

    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...