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

This LUA Code Falls Asleep


Question

Posted

The following works for a little while then stops? any idea why? driving me crazy!

--[[

%% properties

%% globals

Dean

--]]

tcpSocket = Net.FTcpSocket("192.168.0.11", 5555);

bytes, errorCode = tcpSocket:write("");

if errorCode == 0 then

if tonumber(fibaro:getGlobalValue("Dean")) == 1 then

fibaro:setGlobal("Dean", "1");

fibaro:log("Ping Successful");

fibaro:call(1304, "setProperty", "ui.Label1.value", "Ping Successful");

end

else

if tonumber(fibaro:getGlobalValue("Dean")) == 0 then

fibaro:setGlobal("Dean", "0");

fibaro:log("Ping Failed");

fibaro:call(1304, "setProperty", "ui.Label1.value", "Ping Failed");

end

end

tcpSocket:disconnect();

fibaro:sleep(10000);

14 answers to this question

Recommended Posts

  • 0
Posted

Hi Dean,

Not sure the logic in the code makes sense.

What are you trying to achieve?

  • 0
  • Inquirer
  • Posted

    keep pinging device so if its in range popup a notification on xbmc... it works but just drops dead on me after a few minutes

    it seems if i remove the 'if statement' so its pings regardless of previous value it just keeps working but of course this means hundreds of on screen prompts a day on my tv

    Please login or register to see this image.

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

    [ Added: 2013-09-28, 21:13 ]

    scrap that stops even if i remove the 'if statement' and its not the phone as the log stops on hc2...

    • 0
    Posted

    is this in a virtualdevice?

    • 0
    Posted

    do you want it in a button or mainloop?

    • 0
  • Inquirer
  • Posted

    i used mainloop so it was refreshed automatically rather than using button plus scene made no sense...

    [ Added: 2013-09-28, 21:54 ]

    interesting little thing i spotted... all the devices that fail to ping are still working but all the devices that successfully ping have died? no more :log notifications even on 10 sec loop devices like my tv / htpc etc... i wonder if the tcp("write") is junking something up?

    • 0
    Posted

    try this based on Krikroff's code

    it has some error handling see if you get errors use debug

    don't think you want this bit

    --[[

    %% properties

    %% globals

    Dean

    --]]

    Please login or register to see this code.

    [ Added: 2013-09-28, 23:06 ]

    so all it does is set Dean to 0 or 1...? what next

    • 0
  • Inquirer
  • Posted

    that is it Robert... from there i have a scene that take the variable and if Dean = 1 then show prompt on screen "Dean has returned home" and a push notification to the wifes phone and if Dean = 0 then "Dean has left home" and a push notification to the wifes phone and if Dean = 0 and Wife = 0 then press Virtual Device button to Arm all devices

    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" /> if Wife or Dean = 1 then disarm!

    • 0
    Posted

    Nice

    • 0
  • Inquirer
  • Posted

    That code also stops just after Start Process... something is upsetting this! very odd... may just cut my losses on this its not code related i am sure even to a beginner like me it reads perfectly! old and new code!

    • 0
    Posted

    old code had an error

    if tonumber(fibaro:getGlobalValue("Dean")) == 1 then

    fibaro:setGlobal("Dean", "1");

    [ Added: 2013-09-28, 23:20 ]

    I think the sleep may be an issue

    the loop is every 1s so sleeping for 10 may cause some fun

    [ Added: 2013-09-28, 23:26 ]

    I don't like main loop. Why not make it like a scene? This looping is a pain and adds nothing.

    Please login or register to see this attachment.

    • 0
  • Inquirer
  • Posted

    .Net not supported in scene is it?

    • 0
    Posted

    no

    Please login or register to see this image.

    /emoticons/default_icon_cry.gif" alt=":cry:" />

    but you can put the code i posted in a button and call it from an autostart scene with a while loop and sleep for a few minutes in each loop

    you can call a few buttons from the scene so check for many devices

    [ Added: 2013-09-29, 00:15 ]

    Please login or register to see this code.

    [ Added: 2013-09-29, 00:18 ]

    Please login or register to see this code.

    • 0
    Posted

    robmac,

     

    i have still a issue whit the port

    when i run the script either the mainloop or the VDbutton and Lua

    after say 3 to 4 min mij port on the phone is gone

    i juse the app PortForward to open a port like 8187 on my android

    port is also in my router geconfigurate

     

    please can and will you help me

     

    regards kage

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