We have moved at community.getvera.com

Author Topic: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code  (Read 5009 times)

Offline whoamib

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +1/-3
Sorry but I have to ask a dumb question.  I just got code from a Vera developer to check my Vera's up time. 

He said that I could run the code below in this area to get the up time information: MiOS Developers >> Test Luup code

local fh = io.popen("uptime") -- Execute command.
if (fh ~= nil) then
    local data = fh:read("*a") -- Capture the output of the executed command.
    fh:close()
    luup.task(tostring(data), 4, "Uptime", -1)
else
    luup.task("failed to get the uptime.", 2, "Uptime", -1)
end

So I did exactly that and it says "Message successfully sent" I put a 0 in the device number or take it out and have nothing in there and it does the same thing.

My problem is... Where the heck does it output the information I'm looking for?
Thanks,
« Last Edit: January 18, 2012, 09:30:40 am by whoamib »

Offline chixxi

  • Hero Member
  • *****
  • Posts: 1036
  • Karma: +37/-14
Re: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code
« Reply #1 on: January 18, 2012, 10:04:33 am »
Maybe in the log, try the following Link in your browser (with your Vera's IP address):
http://10.0.0.XXX/cgi-bin/cmh/log.sh?Device=LuaUPnP
Developer of Plugins: Virtual Switch, Variable Container, Popcorn Hour Remote, Vacation Ghost. => PLUGINS HAVE BEEN UNPUBLISHED BY ME.

Offline whoamib

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +1/-3
Re: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code
« Reply #2 on: January 18, 2012, 10:14:22 am »
Thank you Chixxi for the reply, I didn't know about that logging interface.  Unfortunately I couldn't see that output there.  I saw the code when I ran it but none of the output was shown.  I attached a picture of what I saw.

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code
« Reply #3 on: January 18, 2012, 10:35:10 am »
Where the heck does it output the information I'm looking for?
It's supposed to show up in the status window.

If you don't see anything there, try changing this:
Code: [Select]
    luup.task(tostring(data), 4, "Uptime", -1)
to
Code: [Select]
    luup.task(tostring(data), 2, "Uptime", -1)
Dezwaved at the moment...

Offline whoamib

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +1/-3
Re: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code
« Reply #4 on: January 18, 2012, 10:45:39 am »
Brilliant!  That worked!  It's now showing up in the status box in the top right corner where the time usually is.
Thank you oTi@!
Now I can validate that my scheduled event to reboot the Vera 2 box daily at 3am works!  Vera Support rocks!

Offline kartcon

  • Full Member
  • ***
  • Posts: 158
  • Karma: +7/-0
Re: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code
« Reply #5 on: January 18, 2012, 10:55:31 am »
whoamib,

Would you mind sharing how you did the scheduled reboot? This is something I'm interested in, but didn't know it could be done. Thanks,

kartcon

Offline whoamib

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +1/-3
Re: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code
« Reply #6 on: January 18, 2012, 11:02:38 am »
I'm happy to share how I have the Vera reboot daily!  That's why I mentioned it because I figured others would be interested.

You just need to put this command in the "Luup" tab in a scheduled scene:  os.execute("reboot")

Then just schedule the scene you just created to run whenever you want it to reboot. 

Then to verify that it rebooted you just need to put this code in the "Test Luup Code (Lua)" tab under the Mios Developers option on  your dashboard

local fh = io.popen("uptime") -- Execute command.
if (fh ~= nil) then
    local data = fh:read("*a") -- Capture the output of the executed command.
    fh:close()
    luup.task(tostring(data), 1, "Uptime", -1)
else
    luup.task("failed to get the uptime.", 2, "Uptime", -1)
end

I've attached screenshots showing all of this.
« Last Edit: January 18, 2012, 12:19:17 pm by whoamib »

Offline chixxi

  • Hero Member
  • *****
  • Posts: 1036
  • Karma: +37/-14
Re: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code
« Reply #7 on: January 18, 2012, 12:12:18 pm »
sorry, didn't give you the correct information.  :-[ but I guess we both learned something from this thread...
Developer of Plugins: Virtual Switch, Variable Container, Popcorn Hour Remote, Vacation Ghost. => PLUGINS HAVE BEEN UNPUBLISHED BY ME.

Offline whoamib

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +1/-3
Re: Newbie to Luup code in the Vera??? MiOS Developers >> Test Luup code
« Reply #8 on: January 18, 2012, 12:20:46 pm »
Chixxi, no problem at all, I definitely learned a lot. 

I wish I could mark this thread solved because it is more than solved.