Lua Modules

Does anyone know how to include external modules for use in a Luup plugin? I would like to make use of the LuaSocket module at, so my plugin can make and process HTTP requests.

That Library has a C-based component that would need to be compiled and pre-installed on Vera in order for the Lua component to work.

I suspect there will be some interest in having that lib in the system, but you’ll likely need MCV to add/package it.

The Lua component of it should be loaded using the “Extra Lua Files” UI in Vera, from which you’re supposed to be able to use the [tt]require “libraryName”[/tt] directive to get it “included” so you can reference it in your code. This part you might want to experiment with a pure Lua extension first. I’ve been meaning to try it, but haven’t needed library services just yet.

For rudimentary HTTP access, you can use the built in [tt]lu_wget(…)[/tt] (or [tt]luup.inet.wget(…)[/tt] in the really new builds), but the package you’ve listed is very nice (it’s also used by Ansca Mobile’s iPhone programming Toolkit)

Thanks for the info about lu_wget(). Assuming that has similar functionality to wget on a *nix system it should be enough to do what I need initially. I missed with when I was looking at the Vera Lua extensions wiki page.

Where did you find information that it had been renamed to luup.inet.wget() in the latest build? I’m trying to get a handle on how the APIs are documented.

See the following thread, which contains the changes in the 8xx series builds:

The latest published build is 790, which has the older naming conventions as referenced in the Wiki documentation here:

Note that [tt]lu_wget[/tt] returns 2 values so you need to call it like:

local webStatusCode, webResponse = lu_wget("")
once the new build is out, it’ll look more like:

local webStatusCode, webResponse = luup.inet.wget("")

You can use a string replace to go from the older style to the newer style…

I ended up with a slightly newer build as MCV was going rounds debugging a number of Luup, and Serial IO, issues I was having in developing some stuff for my Alarm panel. As a side-effect, I’m on a slightly different build which has the [tt][/tt] conventions.

MCV: I would also like LuaSocket to be included in Vera. It would allow me to reach out to all sorts of [non-HTTP] devices (HTTP, SMTP, FTP and low Level UDP and/or TCP for everything else)

In addition, it’s needed to support libraries like:


With it, things like CalDAV would be relatively easy to integrate for remote scheduling of Vera events (per someone elses thread).

They mentioned that socket level connectivity is there, isn’t it what you’re looking for?

It’s a little different.

The luup hooks allow us to read/write the raw stream to handle talking to simple stuff.

The specific socket API referenced would permit a wide array of higher level protocols without having to impl the various low level RFCs for things like HTTP, CalDAV, SMTP etc

that’s a non trivial excercise if all you want to do is reliably call Google calendar or Send an Email or FTP some data

[quote=“guessed, post:5, topic:164669”] local webStatusCode, webResponse = luup.inet.wget("") [/quote]

I’m using this to read a web page that takes longer than the default 5000 ms to be produced. How do I extend the timeout - either by each wget call or for all wget calls?


Looks like the Wiki doc got damaged on Aug8th. Here’s the original snippet:


This reads the URL and returns 2 variables: The first is a numeric error code which is 0 if successful, and the second is a string containing the contents of the page. If Timeout is specified, the function will timeout after that many seconds. If Username and Password are specified, they will be used for HTTP authentication.

I’ll go repair the Wiki page for others. Please note that the Syntax would now be:

[tt] local webStatusCode, webResponse = luup.inet.wget(URL, Timeout, Username, Password)[/tt]

Perfect, all working now!

Thanks for replying so quickly.


Has any one of you made some experience with the lua socket module?
I’d like to create a device which recognizes if iTunes has been lauched, so I can turn on my stereo. ;D
iTunes announces itself (if your music library is shared locally) by sending UTP multicast DNS-SD messages.

So if someone could share some example UDP code in the luup context, I’d be very happy.

Not yet, it’s on my list so I can call Google Calendar to have Vera “do things” based upon a remote schedule.

eg. Put “specially labeled” events into a share Calendar like “House: Bedroom 1: Lights On” and have Vera poll and respond to them.

I suspect I can do most of it with luacurl, without having to go the full blown socket layet, but time will tell.

My current focus is on adding Scene awareness to the Alarm events, which I’m having issues with. (Native Scene events like “Area Armed”, “Area Stay Armed”, “Area Breach” etc) so I can eliminate the Armed/StayArmed/AreaBreach MotionSensor Devices that I currently cheat with…

'not enough time in the day sometimes :wink:

You are lucky to have at least some time for projects of this complexity…

@325xi, I code on weekends and/or if I wake early. Sometimes I squeeze in a few extras after late/long debugging session for work, where you can’t get back to sleep…

Like probably everyone here, it’s done in fits and starts, so not really the best way to learn this stuff… but it’s a hobby, so there’s as much fun in the process as with the outcome. 8)

@TedStriker, I suspect you’ll have problems being a [UDP] Server since it would require that you more or less “block”, or start messing with Lua coroutines that “hang around” to process the incoming data (if you can attach to the MCAST notification)

How comfortable are you with Threads and Socket programming?

If you’ve done this before in either C and/or Java it shouldn’t be too much of a jump given the API’s (although I’m not convinced you’ll be able to capture the MCAST stuff)

Well guys, I got my Vera since three weeks now, and I guess you know how it works when you got some new toys :slight_smile:
For the rest I agree with guessed. That’s the way it goes.

The Calendar plugin is also on my list. To not be depending on google alone, I would like to parse the iCal-file itself. So you can use any webserver where your calendar lies on instead of supporting calDAV or googles calendar api (which is pretty complex).
At least this would be the first step, and then we’ll see where it goes.

Back to the UDP-stuff. I made some experience with sockets a plenty years ago. I have a clue how threads work, but never tried it out.
The coroutines are the point I’m stuck. I don’t know how to start (and control) a thread which is listening to incoming data and hand it to the actual lua script interpreting it. Binding it to a MCAST-address should be not

Thinking about this problems, it seems I will start with the google plugin earlier than expected :wink:
If you want to, we can do it together. Just drop me a line.

[quote=“TedStriker, post:17, topic:164669”]Back to the UDP-stuff. I made some experience with sockets a plenty years ago. I have a clue how threads work, but never tried it out.
The coroutines are the point I’m stuck. I don’t know how to start (and control) a thread which is listening to incoming data and hand it to the actual lua script interpreting it. Binding it to a MCAST-address should be not[/quote]

I wish we could run Java on Vera… Java concurrency, especially the new stuff from Java 5 and later, is pure joy, and so mind boggling.
Shouldn’t we ask to make Java enabled Vera available to public? :wink:

I think Java requires a lot more memory/cpu than Vera can provide. Lua is running in about 500k of RAM.

Java runs even on mobile phones

Best Home Automation shopping experience. Shop at getvera!

© 2021 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules