Iviewer - TCP Noob question

Hi All,

I just bough a Vera 2 and I want to rebuid the iviewer server (command fusion) I made in python into a Luup plugin. I have made a D_Ivierwer.xml and a I_Ivierwer.xml but I don’t think I complety understand it already because I don’t seen anything relating to messages I send to Vera in the verbose logging.

Is there someone who wants to point me in the right direction, I just want to receive TCP/ip messages on port 5554 to start with, and see the in the logging.

I think I missed a step, can someone tell me the simplest way for this first step?

Any help is appreciated.



Edit: Attached used .xml files for review, but maybe that’s already the wrong way to go for the first simple test.

No one is able to give this beginner some help?

As I finshed a simpler plugin to start en stop my xbmc mediacenter, I have an additional question what is a nicer way to send a json roc command to xbmc via lump?

Currently i use (simplified example):

local lul_json = [[‘{“jsonrpc”: “2.0”, “method”: “System.Shutdown”, “id”: 1}’]]
os.execute(“curl -i -X POST -d " … lul_json … " -u xbmc:xbmc”)

But I am sure you can send this also without using os.execute…



Folks probably assumed, like me, that you were following the same question on HTTP POST in the general programming track… ESP since it was asked before you posted this, and was an active discussion at the time

Hi guessed,

Thanks for your answer, I searched the forum in order to find the thread you are referring to but didn’t find it, could you tell me which thread you meant?

BTW sorry, for the my question. I am new to this and couldn’t find an answer after searching the forum and the wiki’s (based on the wiki it looks like it is very easy), my apologies.

I hope some one can point me in the direction.




It also comes up with a search criteria of ‘http post lua’

[quote=“guessed, post:5, topic:169062”]http://forum.micasaverde.com/index.php?topic=7549.msg48721#msg48721

It also comes up with a search criteria of ‘http post lua’[/quote]

guessed thnx! I was under the impression you were referring to the original question not my off topic question. This was a adhoc question so sorry for not searching good enough.

For the record it worked with:

local http=require(“socket.http”)
local lul_json = [[{“jsonrpc”: “2.0”, “method”: “System.Shutdown”, “id”: 1}]]
local result = socket.http.request(“http://xbmc:xbmc@”,lul_json)

Perfectly ;D

Could you also help me in the right direction with my ‘main’ question on receiving TCP traffic in a plugin (for migrating my iviewer server to luup)?

Typically, plugins connect “out” to a specific entity to be controlled. In turn, that entity is “listening” for these inbound connections. These outbound connections from the Plugin can be done in HTTP, Serial, Raw TCP or UDP using libs available in Lua… but the Plugin is always the initiator of these types of connections.

Vera itself can have things connect “in” to it from Control Points (like SQBlaster, Automator.app, Home Buddy, iVera etc, etc). To do this, these callers can use the [MiOS] protocols outlined in the links below - a specific set of “inbound” URLs to Vera or, supposedly, UPnP (the latter seems a little unicorn-like in it’s implementation)

From past discussions, iViewer needs a specific [TCP] Socket listener running on the entity it’s connecting to, something that runs iViewer’s specific protocol. Now this isn’t natively do-able with the MiOS Framework, since it operates per the above (rough) descriptions, but you may be able to experiment with LuaSocket, and either Timer-based polling, or Lua’s Lightweight threads options…

To date, I’ve not seen anyone actually do that, so I’m sure the road will be bumpy.

The alternate would be to place some sort of adapter entity between the two, since both seem immovable on their stance (see historical discussions below)

I’ve included some of the most recent posts on elements of this topic, but it’s had a scattering of discussion over the last 2-3 yrs…

How to communicate with Vera, from outside, using it’s native model (HTTP, most recent posts only):

Most recent discussion on using a Socket Listener

Historical discussions on iViewer integration

Hi guessed,

Thanks for all the info (and your time) , (I did indeed already read most of it), if I understand you correct there is no simple way to make a plugin which just listens on a port?

So something like

local server = socket.tcp()
server:bind(“”, 5554)
local conn = server:accept()

Won’t work?



[quote=“deraaij, post:8, topic:169062”]So something like

Won’t work?[/quote]

Something that simple, no. The real issue is where to put that code: All plugins are, on the whole, only invoked on demand. You may get some love from using call_timer(), and polling the listen on a regular basis, ensuring that you don’t block. But as @guessed said, no one’s really tried yet. You’ll be charting new territory.

If that doesn’t work, you’re probably stuck writing a thin proxy, as @guessed suggests. Put your above code into a Lua source file on your Vera, arrange for it to start up outside of the LuaUPnP process (say, through an init script), and get it to communicate with your plugin over Vera’s traditional HTTP mechanism.

You may be able to do it by looking at something like:
oZone3D.Net Tutorials - The LUA Socket Lib and Coroutines - Setting up a simple TCP server

but it will be an experiment…

Thanks Guys,

I guess “option 2” is the first way to go as I have read somewhere that polling frequently using the timer option could impact VERA 's behavior.

But just to be sure one important questions remains, If I understand you guys correct this would mean that apart from probably z-wave and insteon other device (e.g. via rs232, tcp et cetera) can’t have ‘instant’ bi-directonally communication? You need to poll for changes or be able to let the device give feedback in accordance with Vera’s protocol? I guess i am still missing a piece of the puzzle because i think for example the OnkyoReceiver plugin will receive i remote button press e.g. power down and send the feedback over tcp to vera?

Sorry, but I want to understand it :slight_smile:

EDIT: Or is the difference that in this case the ipad, iphone, etc is not always ‘online’?

I wouldn’t be so pessimistic. If you go the proxy route then you can make the proxy “push” an event to the Luup plugin over HTTP as soon as it’s received.

For actual devices, things that Vera controls, response time is great. I have many examples of direct serial, ethernet (wired and wifi) devices that respond instantly.

I also have one devices that requires polling as its API doesn’t permiy notification, I poll every 2-3 seconds and it doesn’t materially impact my setup (I have a large # of things under control)

For Control Points using the HTTP interface they also work very fast. Theyte basically blocking on the HTTP call for shortish periods until something changee in Vera so the visual update to change is almost instant. I primarily use SQRemote, but have tried Automator.app as well as Home Buddy (on a Nook Color)

In this equation, IViewer is a Control Point… one that doesn’t work well with a HTTP protocol it would seem.

thanks guys!

I am not pessemistic only figuring out why device can have bi-directional feedback and iviewer/ipad not. Because than I will understand why I would no be able to setup ‘iviewer’ as a device like e.g. the onkyo receiver plugin i reviewed ;D (probably because this ‘device’ is not always availalbe for vera?)

Because in that case I can evaluate inbound traffic and fire action via luup.

e.g. like for example this part from I_OnkyoReceiver1.xml:

local data = tostring(lul_data)

– Process the returning status…
local cmd, value = buffer:match(“^(%u%u%u)(.*)$”)
if (cmd ~= nil) then
if (cmd == “PWR”) then
if (value == “01”) then
luup.variable_set(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, “1”, lul_device)



PS I am very pleased with the feedback!

Per my description a few posts up, a Device is typically something that Vera initiates a connection to.
A Control Point is something that initiates a connection to Vera.

You have a Conttol Point (iViewer) that doesn’t speak the same API that Vera uses. If, and this is a big if, you can initiate a connection BACK to iViewer then it would br able to behave like a device.

Ok, understood.

So either try to setup a static ip on my ipad/iphone and try to initiate a first ‘heartbeat’ signal from vera to the device and if that no work go for “option 2” .

Will try somestuff tonight when I finshed my simple xbmc plugin :smiley:

Thanks and I will report back.

EDIT: One more question, If I use the thin proxy option I cannot use the advantages of function: variable_watch so I need a different solution?

Just to give an update:

It works with making a separate LUA server (I used COPAS) created via SSH. It listens on a port and clients (ipad’s, iphone’s etcetera) can connect. Vera2 also connects as a client via a simple plugin and gives state changes via luup.variabele.watch. Which get forwarded to all clients but VERA.

Eventually I switched to a homebrew iviewer server running on my NAS using python just to make sure the resources on the VERA are minimized.

Thanks for the all the help so far.




It would be awesome if there was a plugin for Vera to interface with iViewer, but it may not be needed. According to Jarrod of CommandFusion, “our built in protocol is published on our downloads page in the Developers Manual, or we can of course send ANY message and parse ANY feedback via the System Manager”

Jarrod is aware of Vera & MiCasaVerde, See here, There was also a YouTube video on their site showcasing the iViewer interfaced with HA, so it is possible to control everything…I’ll see if I can find it…

Maybe send Jarrod an email and see what he can do?

*Edit. The Video is on the bottom of their Blog page. Blog - CommandFusion