<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tieske</title>
	<atom:link href="http://www.thijsschreijer.nl/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.thijsschreijer.nl/blog</link>
	<description>Thijs Schreijer&#039;s techie stuff</description>
	<lastBuildDate>Wed, 27 Mar 2013 17:55:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Setting up a basic Lua installation on Windows</title>
		<link>http://www.thijsschreijer.nl/blog/?p=772</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=772#comments</comments>
		<pubDate>Tue, 26 Mar 2013 14:54:28 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[LuaDist]]></category>
		<category><![CDATA[LuaRocks]]></category>
		<category><![CDATA[MinGW]]></category>
		<category><![CDATA[ZeroBrane]]></category>
		<category><![CDATA[ZeroBrane Studio]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=772</guid>
		<description><![CDATA[The older LuaforWindows distribution is getting obsolete quickly these days. Also because the distribution is aging, many &#8220;batteries&#8221; are out dated and they are not easily replaced as the package managers do not integrate with it. So I started an endavour &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=772">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The older <a href="http://code.google.com/p/luaforwindows/">LuaforWindows distribution</a> is getting obsolete quickly these days. Also because the distribution is aging, many &#8220;batteries&#8221; are out dated and they are not easily replaced as the package managers do not integrate with it. So I started an endavour to update my windows system with a clean installation (minimal batteries) and a proper package manager to be able to update and extend packages as needed.</p>
<p><span id="more-772"></span></p>
<p>So it wasn&#8217;t such a smooth experience as expected&#8230;. So this post is merely a reminder to myself on how to get this all set up and working properly.</p>
<p>There are 2 <a href="http://www.lua.org/">Lua</a> package managers for Windows;</p>
<ul>
<li><a href="http://luadist.org/"><span style="line-height: 15px;">LuaDist</span></a></li>
<li><a href="http://www.luarocks.org/">LuaRocks</a></li>
</ul>
<p><a href="http://luadist.org/">LuaDist</a> seems to be the favourite as a successor for <a href="http://code.google.com/p/luaforwindows/">LuaforWindows</a>, but I ran into trouble because its dependencies (<a href="http://www.cmake.org/">CMake</a>) interfered with my Git installation. Hence I picked <a href="http://www.luarocks.org/">LuaRocks</a>. Despite my problems with <a href="http://luadist.org/">LuaDist</a>, <a href="http://www.luarocks.org/">LuaRocks</a> is also the one with a larger selection of packages available. On the other hand <a href="http://luadist.org/">LuaDist</a> has tighter control over the packages, so is less likely to run into trouble.</p>
<h1>Setting up <a href="http://www.luarocks.org/">LuaRocks</a></h1>
<p>There are some dependencies, for c modules, a compiler is required to build them. And besides the packages themselves (<a href="http://luarocks.org/repositories/rocks/">rocks</a>) I also need an editor, and my current favorite is <a href="http://studio.zerobrane.com/">ZeroBrane Studio</a>. One big problem I ran into is that the defacto standard socket library for Lua (<a href="http://w3.impa.br/~diego/software/luasocket/">LuaSocket</a>) does not compile with <a href="http://www.luarocks.org/">LuaRocks</a> and the <a href="http://www.mingw.org/">MinGW compiler</a>. But a workaround is available.</p>
<p>The paths are assumed to be;</p>
<ul>
<li><span style="line-height: 15px;">&#8220;c:\MinGW&#8221; for the MinGW compiler</span></li>
<li>&#8220;c:\users\public\Lua&#8221; for the Lua related stuff</li>
</ul>
<h1>MinGW</h1>
<p>To compile the binary modules, <a href="http://www.luarocks.org/">LuaRocks</a> needs a compiler. Simplest one is the <a href="http://www.mingw.org/">MinGW</a>, it&#8217;s good and it&#8217;s free.</p>
<ul>
<li><span style="line-height: 15px;">Download it as a <a href="http://sourceforge.net/projects/mingw/files/latest/download">windows installer package from its downloads page</a></span></li>
<li>Start the installer and make sure to;
<ul>
<li>install in &#8220;c:\MinGW&#8221; (for this tutorial this is used, anyway; <strong>do not</strong> use paths with spaces!)</li>
<li>check &#8220;Download latest repository catalogs&#8221;</li>
<li>check &#8220;C compiler&#8221; and &#8220;C++ compiler&#8221;</li>
</ul>
</li>
</ul>
<h1>LuaRocks</h1>
<p>The main package required, install as follows;</p>
<ul>
<li><a href="http://luarocks.org/releases/">Download the windows package</a> and pick the newest marked with &#8220;-win32.zip&#8221;</li>
<li>extract it into a temporary directory eg. &#8220;c:\temp\LuaRocks&#8221;</li>
<li>Open an elevated command prompt (in startmenu type &#8220;cmd&#8221; in the search box, then right-click and select &#8220;run as administrator&#8221;)
<ul>
<li>cd c:\temp\LuaRocks</li>
<li>install /p c:\users\public\lua\LuaRocks /MW</li>
<li>copy C:\Users\Public\Lua\LuaRocks\2.0\lua5.1.exe C:\Users\Public\Lua\LuaRocks\2.0\lua.exe</li>
</ul>
</li>
</ul>
<p>The &#8220;install&#8221; command invokes the LuaRocks installer and installs it in the directory provided. The &#8220;/MW&#8221; parameter instructs it to use the MinGW compiler. The copy command last in the list makes sure Lua can be accessed as &#8220;lua.exe&#8221; instead of the more awkward &#8220;lua5.1.exe&#8221;.</p>
<h1>Configure paths</h1>
<p>The paths (both system paths and Lua paths) are required so the individual elements can all find the tools and libraries they need.</p>
<ul>
<li><span style="line-height: 15px;">Right click on &#8220;My Computer&#8221;, &#8220;Properties&#8221;, &#8221;Advanced system settings&#8221;, &#8220;Environment variables&#8230;&#8221;</span></li>
<li>Lookup &#8220;PATH&#8221; in the bottom list, and <strong>append</strong> &#8220;;c:\mingw\bin;C:\Users\Public\Lua\LuaRocks\2.0;C:\Users\Public\Lua\LuaRocks\bin&#8221;</li>
<li>The following two should be added as new enviornment variables;</li>
<li>&#8220;LUA_PATH&#8221; with &#8220;.\?.lua;.\?\init.lua;C:\Users\Public\Lua\LuaRocks\share\lua\5.1\?.lua;C:\Users\Public\Lua\LuaRocks\share\lua\5.1\?\init.lua&#8221;</li>
<li>&#8220;LUA_CPATH&#8221; with &#8220;.\?.dll;C:\Users\Public\Lua\LuaRocks\lib\lua\5.1\?.dll&#8221;</li>
</ul>
<h1>LuaSocket</h1>
<p>This is such a standard library that many packages require it. But as mentioned MinGW cannot build it. So here is the workaround;</p>
<ul>
<li><span style="line-height: 15px;">Download the <a href="http://luarocks.org/repositories/rocks/luasocket-2.0.2-3.win32-x86.rock">binary LuaSocket package</a> into &#8220;c:\temp&#8221;</span></li>
<li>Open a command prompt (as administrator)
<ul>
<li>cd c:\temp</li>
<li>luarocks install luasocket-2.0.2-3.win32-x86.rock</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<h1>ZeroBrane studio</h1>
<p>This one is simple</p>
<ul>
<li><span style="line-height: 15px;">Download the <strong>ZIP archive</strong> from the <a href="http://studio.zerobrane.com/">ZeroBrane website</a></span></li>
<li>unzip in &#8220;c:\users\public\Lua\ZeroBraneStudio&#8221;</li>
<li>add shortcuts to ZeroBrane to the startmenu or the quick launch bar</li>
</ul>
<h1>Finalizing the installation</h1>
<ul>
<li>configure extension &#8220;.lua&#8221; to open with either ZeroBrane Studio (edit as default action) or to &#8220;C:\Users\Public\Lua\LuaRocks\2.0\lua.exe&#8221; (run as default action)</li>
<li>configure extension &#8220;.luac&#8221; to open with &#8220;C:\Users\Public\Lua\LuaRocks\2.0\lua.exe&#8221; (compiled Lua code, so can&#8217;t edit anyway)</li>
<li>configure extension &#8220;.rockspec&#8221; (which is just a Lua file) to open with ZeroBrane Studio</li>
</ul>
<h1>Some warnings&#8230;</h1>
<ul>
<li>The LuaSocket implementation used is a binary rock, it has probably been compiled against VS2005, which may cause problems on Windows (DLL dependency hell). So far I haven&#8217;t seen any, but no guarantees&#8230;</li>
<li>ZeroBrane also includes some packages, and when running from within the IDE, it might use those instead of the LuaRocks versions (type &#8220;print(package.path)&#8221; in the ZeroBrane console to see where it gets its modules)</li>
</ul>
<h1>Finally</h1>
<p>LuaRocks is a command line tool, which remains slightly awkward on Windows. But it is easy to understand the basics. Simply type &#8220;luarocks&#8221; on the command line and it will provide some basic help.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=772</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPnP gateway; first working sample</title>
		<link>http://www.thijsschreijer.nl/blog/?p=746</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=746#comments</comments>
		<pubDate>Tue, 26 Feb 2013 20:13:38 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[UPnP]]></category>
		<category><![CDATA[xPL]]></category>
		<category><![CDATA[Developer Tools for UPnP Technologies]]></category>
		<category><![CDATA[HomeEasy]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[RFXmitter]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=746</guid>
		<description><![CDATA[The UPnP gateway now gets to a point that might even justify a pre-release, finally! It can be started from a batch file and configured to run one or more drivers. Capable of publishing dozens of UPnP devices simultaneously (be &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=746">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The UPnP gateway now gets to a point that might even justify a pre-release, finally! It can be started from a batch file and configured to run one or more drivers. Capable of publishing dozens of UPnP devices simultaneously (be it as sub-devices)</p>
<p>A driver template is included so new drivers can quickly be setup. A fully functional xplrfx driver is included as well as 3 demo drivers. All c code is now compiled for distribution, no more development/debug libraries required.<span id="more-746"></span></p>
<p>Get the download and extract the zip file in a new folder. From there simply run the batch file <em><strong>LuaUPnP.bat</strong></em> to start the gateway. You&#8217;ll get instructions on command line parameters and usage.</p>
<p>To start the samples try;<em><strong> LuaUPnP &#8211;debug=debug demo1 demo2 demo3</strong></em><br />
This will start the gateway with verbose logging and the three demo drivers loaded (located in &#8220;<em><strong>lua/upnp/drivers</strong></em>&#8220;). The demodrivers are identical, but give a good idea of what you get when loading multiple drivers.</p>
<p>Once started checkout through <a href="http://www.appup.com/app-details/device-spy-for-upnp-technologies">devicespy</a> the gateway device with;</p>
<ol>
<li><span style="line-height: 15px;">its own service with a set of methods for controlling (restarting/stopping) the gateway</span></li>
<li>each driver as a separate sub device (demo 1/2/3)</li>
<li>within each driver more sub devices, being the actual devices published by that<br />
specific driver</li>
</ol>
<p>&nbsp;</p>
<div id="attachment_748" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2013/02/upnpgateway-devicespy-shot.png" target="_blank"><img class=" wp-image-748" style="color: #333333; font-style: normal; line-height: 24px;" alt="upnpgateway-devicespy-shot" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2013/02/upnpgateway-devicespy-shot-150x150.png" width="300" height="300" /></a><p class="wp-caption-text">Device Spy showing the gateway with demo 1/2/3 drivers</p></div>
<p>&nbsp;</p>
<p>To create your own driver, check out the <a href="https://github.com/Tieske/LuaUPnP/tree/219fba82901a8e4be9269961335592cdd7309460/lua_src/drivers">directory &#8220;<em><strong>lua/upnp/drivers</strong></em>&#8220;</a> which contains the fully functional xplrfx driver, the 3 demo drivers and a template for creating your own.</p>
<p>Through the xplrfx driver (and an <a href="http://www.rfxcom.com/store/Transceivers/11202">RFXLAN device</a> with xplrfx firmware) the gateway is now functional for the following homeautomation hardware;</p>
<ul>
<li>ANSLUT</li>
<li>ByeByeStandBy</li>
<li>Chacon</li>
<li>DI.O</li>
<li>Digimax</li>
<li>DomiaLite</li>
<li>Düwi</li>
<li>ELRO AB400</li>
<li>ELRO AB600</li>
<li>Flamingo</li>
<li>Harrison curtain</li>
<li>HomeEasy</li>
<li>HomeEasy (including HE105)</li>
<li>HomeEasy EU</li>
<li>Ikea Koppla</li>
<li>Intertechno</li>
<li>Intertek/Unitec</li>
<li>KD101</li>
<li>KlikAanKlikUit</li>
<li>NEXA</li>
<li>Waveman</li>
<li>X10 lighting</li>
</ul>
<p>And the fun part is that those devices that support preset-based dimming (homeeasy for example has levels 0 &#8211; 15) now also support ramping (load from 0% to 100% over 30 minutes for example) simply because that functionality has been integrated as standard feature in the gateway, indepedent of the underlying hardware.</p>
<p>Give it a try and let me know what you think. <a href="https://github.com/Tieske/LuaUPnP">Source code</a> is on github, as is the <a href="http://tieske.github.com/LuaUPnP/">documentation</a>.</p>
<p><a href="http://www.thijsschreijer.nl/blog/?download=luaUPnPgateway.zip">Here&#8217;s the download</a> (downloaded 22 times)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=746</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lua; states, threads, libraries and memory layout</title>
		<link>http://www.thijsschreijer.nl/blog/?p=693</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=693#comments</comments>
		<pubDate>Sat, 22 Dec 2012 15:09:51 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[libary]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[shared data]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=693</guid>
		<description><![CDATA[For a couple of years now I&#8217;ve been programming a lot in Lua. One of the things I had a hard time with was the relation between the states, threads (coroutines in Lua) and memory layout.  This is mostly simple &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=693">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>For a couple of years now I&#8217;ve been programming a lot in Lua. One of the things I had a hard time with was the relation between the states, threads (coroutines in Lua) and memory layout.  This is mostly simple when doing some basic scripting, but once you start writing C libraries or library bindings you really need to be aware of all the nitty gritty details. Now throw in some multi-threading and you&#8217;ll get yourself in trouble in no time, if you&#8217;re not careful.<br />
<span id="more-693"></span><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h1>How does all this work?</h1>
<p>Here&#8217;s a diagram I drew that would have helped me big time, if it would have been available when I needed it (it wasn&#8217;t so I drew it myself).</p>
<p><a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/12/luastateandmemory.png"><img class="aligncenter size-full wp-image-695" alt="Lua state layout" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/12/luastateandmemory.png" width="846" height="482" /></a></p>
<div>Host application</div>
<ul>
<li>This is the application that embeds the Lua environment. In case of the standalone Lua implementation, it&#8217;s just a wrapper around the Lua engine</li>
</ul>
<div>Lua engine</div>
<ul>
<li>This is the code part of the Lua environment, it includes the compiler, the virtual machine, etc. It does not have any data nor any Lua code, all its data will always be stored in the Lua states. From an OS perspective this makes it easy to run multiple Lua states (on the same Lua engine) in parallel on different OS threads.</li>
</ul>
<div>LuaState (L1 and L5 in the picture)</div>
<ul>
<li>Looking at a state from the perspective of a piece of Lua code, it is basically its universe. All Lua code runs within its own LuaState and cannot extent beyond that (unless specialized libraries like <a href="http://luaforge.net/projects/lanes/">Lua Lanes</a>, <a href="http://keplerproject.github.com/rings/">Rings</a> or likewise, are being used)</li>
<li>Multiple states can run in parallel on top of the same Lua engine</li>
<li>A LuaState is not thread safe, only a single thread can safely access the LuaState at any given time without causing problems. Multiple states can run on separate OS threads on top of the same Lua engine.</li>
<li>The state itself is in C represented as &#8216;<a href="http://www.lua.org/manual/5.2/manual.html#lua_State">lua_State *L</a>&#8216; it is just the same as a coroutine, except that in this case (as the <em>main thread</em>) it has the global environment attached to it.</li>
</ul>
<div>Shared global environment and the <a href="http://www.lua.org/manual/5.1/manual.html#3.5">registry</a></div>
<div>
<ul>
<li>Each LuaState has its own shared global environment accessible by all Lua code in that LuaState (except for the registry, which is not accessible from Lua)</li>
<li>Access to the global environment can be manipulated to some extent</li>
<li>The <a href="http://www.lua.org/manual/5.1/manual.html#3.5">registry</a> can be considered part of the global environment of a LuaState, but can only be accessed from C using the API. The registry is global, so it can be accessed from all C modules</li>
<li>The global environment is created together with the <em>main thread</em> (coroutine), these are L1 and L5 in the picture)</li>
</ul>
</div>
<div>
<div>Coroutines (L2, L3, L4, L6, L7, L8 in the picture)</div>
<div>
<ul>
<li>Each coroutine gets its own executionstack</li>
<li>Coroutines are the Lua equivalent of threads, and they are often called threads (which is a common cause of confusion with newcomers) . Lua uses <a href="http://en.wikipedia.org/wiki/Computer_multitasking#Cooperative_multitasking.2Ftime-sharing">cooperative multitasking</a> and not <a href="http://en.wikipedia.org/wiki/Computer_multitasking#Preemptive_multitasking.2Ftime-sharing">pre-emptive</a> as most OS’es use</li>
<li>The <em>main thread</em> in a LuaState (eg. L1 and L5), also behaves as a coroutine. It has its own execution stack, the only thing it cannot do is call yield(), to suspend execution and hand over control to its calling coroutine</li>
</ul>
</div>
<div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>‘<a href="http://www.lua.org/manual/5.2/manual.html#lua_State">lua_State *L</a>’ parameter  in API calls</p>
</div>
<div>
<ul>
<li>Whenever a C function is called (either a library, or an API call) a reference to the originating lua_State is passed.</li>
<li>It is tempting to think of this reference as an ID to the LuaState, but it is not. It is a reference to a coroutine (or execution stack), so in the picture this could be any of the L1 to L8 coroutines (this has been updated in the <a href="http://www.lua.org/manual/5.2/manual.html#lua_State">5.2 reference manual</a> over the <a href="http://www.lua.org/manual/5.1/manual.html#lua_State">5.1 version</a>).</li>
<li>In Lua 5.2 it is possible to get the L reference to the <em>main thread</em> of a LuaState (see <a href="http://www.lua.org/manual/5.2/manual.html#4.5">LUA_RIDX_MAINTHREAD</a>), which is the identifier for a state. Lua 5.1 has no means of doing this. For  Lua 5.1 to identify the LuaState it is using, it must store some identifier in either the registry, an upvalue or in a function environment (the function environment has been deprecated in Lua 5.2)</li>
</ul>
</div>
<div>Static variables vs <a href="http://www.lua.org/manual/5.1/manual.html#3.4">upvalues (for C functions)</a></div>
<div>
<ul>
<li><a href="http://www.lua.org/manual/5.1/manual.html#3.4">Upvalues</a> are stored in a LuaState, where static variables are part of the C library. Neither can be accessed from Lua, only from C. C libraries are loaded once (similar to the Lua engine), but can be used from multiple LuaStates</li>
<li><a href="http://www.lua.org/manual/5.1/manual.html#3.4">Upvalues</a> are local to the combination of a LuaState and a C library</li>
<li>Static variables are local to a C library, but shared to all LuaStates</li>
</ul>
</div>
</div>
<h1>Where to store and access data</h1>
<p>In general, data should be stored in the LuaState. If you store data local in the C library, then you need to take precautions so the library can be used with multiple Lua states. When used with multithreading, then this shared data also requires locks for safe access.</p>
<p>Here&#8217;s a table showing access to library data depending on where it is stored and from where it is being accessed;</p>
<p><a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/12/accesstable.png"><img class="aligncenter size-full wp-image-701" alt="Data accessibility" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/12/accesstable.png" width="810" height="317" /></a></p>
<p><strong>IMPORTANT</strong>: all of the above assumes &#8216;end-user&#8217; Lua. So in several occasions where it is mentioned that something is not accessible from Lua then it might very well be possible to access it through the debug library (eg. the registry through <a href="http://www.lua.org/manual/5.1/manual.html#pdf-debug.getregistry">debug.getregistry()</a>).</p>
<p>Once you get the way it works it isn&#8217;t all that hard. It&#8217;s just that the official docs are sometimes hard to grasp if you don&#8217;t get the definitons entirely right. And especially for newcomers that is pretty hard (at least that&#8217;s what I found).</p>
<p>If you happen to find an error or an omission, please drop me a note below.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=693</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HackersNL talk on home automation and Lua</title>
		<link>http://www.thijsschreijer.nl/blog/?p=678</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=678#comments</comments>
		<pubDate>Fri, 30 Nov 2012 20:36:46 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Girder]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[UPnP]]></category>
		<category><![CDATA[xPL]]></category>
		<category><![CDATA[bwired]]></category>
		<category><![CDATA[Developer Tools for UPnP Technologies]]></category>
		<category><![CDATA[hackersnl]]></category>
		<category><![CDATA[Koneki]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[mihini]]></category>
		<category><![CDATA[paho]]></category>
		<category><![CDATA[xPL protocol]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=678</guid>
		<description><![CDATA[So yesterday, I gave a talk on home automation at HackersNL in Utrecht, nice and friendly audience and plenty of new ideas. I&#8217;ve uploaded the slideset, available here (downloaded 132 times). Furthermore some additional comments and links; Home automation site; &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=678">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>So yesterday, I gave a talk on home automation at <a href="http://hackersnl.nl/">HackersNL</a> in Utrecht, nice and friendly audience and plenty of new ideas.</p>
<p>I&#8217;ve uploaded the slideset, <a href="http://www.thijsschreijer.nl/blog/?download=hackersnl.pptx">available here</a> (downloaded 132 times). Furthermore some additional comments and links;</p>
<ul>
<li>Home automation site; check out <a title="bwirde" href="http://www.bwired.nl">bwired.nl</a>, awesome. Nothing to add to that.</li>
<li>Bwired also has a <a href="http://www.domoticaforum.eu/">generic home automation forum</a>, not specifically related to a server product.</li>
<li>xPL and all its related info can be found on the <a href="http://xplproject.org.uk/">xPL project site</a></li>
<li>For the internet-of-things there is a great open source project started by Sierra-Wireless. It is being run under the Eclipse umbrella and already delivered some nice results. Check out <a href="http://www.eclipse.org/koneki/">Koneki</a> (<a href="http://www.eclipse.org/koneki/ldt/">LDT</a> and <a href="http://www.eclipse.org/koneki/simulators/omadm/">OMA</a>), <a href="http://www.eclipse.org/mihini/">Mihini</a> and <a href="http://www.eclipse.org/paho/">Paho</a>.</li>
</ul>
<p><a href="http://upnp.org"><img class="alignright size-full wp-image-689" title="UPnP" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/11/upnp1.png" alt="UPnP forum logo" width="157" height="93" /></a><br />
For a start with UPnP there is a lot of documentation on the <a href="http://upnp.org/">forum pages</a>. But there is no real shortcut to UPnP, but here&#8217;s where to start</p>
<ul>
<li>To get a feel of what it can do, download the <a href="http://opentools.homeip.net/dev-tools-for-upnp">UPnP Developer Tools</a> (runs on .NET, so might also work on Mono, but never tried). Use the DeviceSpy utility to examine some of your own devices and fiddle with the actions (Tip: right-click on a service and subscribe to events). Also give the included &#8220;Network Light&#8221; sample application a try (to fiddle with from Device Spy).</li>
<li>Read the <a href="http://upnp.org/sdcps-and-certification/standards/device-architecture-documents/">UPnP Device Architecture 1.1 document (UDA)</a>, even if you don&#8217;t make it through, focus on sections;
<ul>
<li>1 Discovery (introduction only)</li>
<li>2 Description (introduction only)</li>
<li>2.3 Device Description</li>
<li>2.5 Service Description</li>
<li>3 Control (introduction only)</li>
<li>4 Eventing (introduction only)</li>
</ul>
</li>
<li>Browse the <a href="http://upnp.org/sdcps-and-certification/standards/sdcps/">device and service specifications</a>. Start with &#8220;<a href="http://upnp.org/specs/ha/lighting/">Lighting Controls_1</a>&#8221; which are fairly easy to read, and once you get the concept of those try something more challenging like the Media Server/Renderer stuff.</li>
</ul>
<p>It was a fun evening, thanks for the invitation guys! If you have any questions or want some more info, just drop a message below.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=678</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPnP gateway; third proof of concept</title>
		<link>http://www.thijsschreijer.nl/blog/?p=660</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=660#comments</comments>
		<pubDate>Tue, 13 Nov 2012 23:46:55 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[UPnP]]></category>
		<category><![CDATA[Developer Tools for UPnP Technologies]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[Lua]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=660</guid>
		<description><![CDATA[It&#8217;s been a while, but some major additions have been made to the UPnP gateway engine. Previously the engine would parse xml description files to generate objects. Now it includes both an xml factory and a device factory that generate &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=660">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a title="Update to the UPnP – Lua gateway engine" href="http://www.thijsschreijer.nl/blog/?p=650">It&#8217;s been a while</a>, but some major additions have been made to the UPnP gateway engine. Previously the engine would parse xml description files to generate objects. Now it includes both an xml factory and a device factory that generate everything on the fly.</p>
<p>The code now includes a <a title="Descriptions on upnp.org" href="http://upnp.org/specs/ha/lighting/"><em>BinaryLight</em> and a <em>DimmableLight</em> (both standardized DCPs)</a>, they are based on standardized services <em>SwitchPower</em> and <em>Dimming</em> (also included). Implementing a fully functional <em>DimmableLight</em> device now only takes 4 lines of code;<span id="more-660"></span></p>
<div class="codesnip-container" >
<div class="lua codesnip" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">&#8211; create the device from a default implementation</span></div>
</li>
<li class="li1">
<div class="de1">device, err <span class="sy0">=</span> upnp.devicefactory.builddevice<span class="br0">&#40;</span><span class="st0">&quot;urn:schemas-upnp-org:device:DimmableLight:1&quot;</span>, <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;    friendlyName <span class="sy0">=</span> <span class="st0">&quot;Dimmable NetworkLight 3 Lua test device&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;    customList <span class="sy0">=</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;      statetodevice <span class="sy0">=</span> printstatus<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;    <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;  <span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
</div>
<p>The promise of all this is that any device type needs to be coded only once, and can then be reused over and over again. Will be nice to implement the HEMS (Home Energy Management Systems) DCPs that are currently being developed on this engine as one of the initial implementations.</p>
<p>Please give the code a try. It&#8217;s fully functional, including dimming, ramping and stepping. Same as before, windows only, unpack and run the batchfile, then control through the <a title="Download DeviceSpy here" href="http://opentools.homeip.net/dev-tools-for-upnp">UPnP DeviceSpy</a>. Documentation is also available now <a title="LuaUPnP library documentation" href="http://tieske.github.com/LuaUPnP/">from the github pages</a>.</p>
<p><a href="http://www.thijsschreijer.nl/blog/?download=lualightsample3.zip">Here&#8217;s the download</a> (downloaded 55 times)</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=660</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Update to the UPnP &#8211; Lua gateway engine</title>
		<link>http://www.thijsschreijer.nl/blog/?p=650</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=650#comments</comments>
		<pubDate>Thu, 02 Aug 2012 14:37:33 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Girder]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[UPnP]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[UPnP stack]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=650</guid>
		<description><![CDATA[Just posting this as I&#8217;ll be away for a couple of weeks, so what did I fix since last post; Todo: UPnP security service has not been implemented (must have!) Todo: Some of the wrapper code (mutexes, waithandles and sockets) &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=650">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Just posting this as I&#8217;ll be away for a couple of weeks, so what did I fix since <a href="http://www.thijsschreijer.nl/blog/?p=634">last post</a>;</p>
<ul>
<li>Todo: UPnP security service has not been implemented (must have!)</li>
<li>Todo: Some of the wrapper code (mutexes, waithandles and sockets) are not complete for all platforms yet, currently it only runs on Windows, but this should be limited as the wrappers themselves have all been created already</li>
<li><del>Todo: Solid logger, as its designed to be used in the background without an interface, it must provide solid logging, even if only for troubleshooting and debugging</del></li>
<li>Todo: Serial library; currently network connections are supported through the LuaSocket library, but serial connections must be added to (probably through <a href="http://linux.die.net/man/8/ser2net">ser2net</a>, but that lacks a windows version AFAIK)</li>
<li><del>Todo: The demo is a single Lua file (which is totally crap code), and should be replaced by a Lua side object oriented framework to access and modify UPnP devices/controlpoints<br />
</del></li>
</ul>
<p><span id="more-650"></span></p>
<p>The framework is ready and working (probably needs to see some more testing, but its here). So check the download and compare the previous NetworkLight.lua file with the new NetworkLight2.lua file. Major cleanup. Also when you run the sample, all output is now generated by the added logger module. Allows for logging to files, console, email, tcp, etc. (<a href="http://www.keplerproject.org/lualogging/">thank you Kepler project!</a>)</p>
<p>The demo code now only consists of the web folder (xml device/service descriptions) and the NetworkLight2.lua file (the remainder is the UPnP-Lua engine). The framework will parse the xml descriptions and generate the objects from it. All that is left is creating a list of action implementations and optionally set default values, these can be set using a &#8217;creator&#8217; function, and that is exactly the code in the NetworkLight2.Lua file.</p>
<p><a href="http://www.thijsschreijer.nl/blog/?download=lualightsample2.zip">Here&#8217;s the download</a> (downloaded 105 times)</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=650</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>All new UPnP gateway concept; a scriptable UPnP engine</title>
		<link>http://www.thijsschreijer.nl/blog/?p=634</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=634#comments</comments>
		<pubDate>Wed, 18 Jul 2012 22:41:33 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Girder]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[UPnP]]></category>
		<category><![CDATA[Developer Tools for UPnP Technologies]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[UPnP stack]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=634</guid>
		<description><![CDATA[Today I finished the first working sample of the new UPnP gateway I&#8217;ve been working on, a major milestone! Stepped out of .NET and changed to platform independent code and libraries. Punished myself with hardcore C, multi-threading and multi-platform all &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=634">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Today I finished the first working sample of the new UPnP gateway I&#8217;ve been working on, a major milestone! Stepped out of .NET and changed to platform independent code and libraries. Punished myself with hardcore C, multi-threading and multi-platform all at once, but it all seems to start working now.</p>
<p>&nbsp;</p>
<h2>So what is it?</h2>
<p>Its a <a href="http://www.lua.org">Lua scripting engine</a>, glued to the <a href="http://pupnp.sourceforge.net/">pupnp library</a>. Lua is a small, fast and very portable dynamic scripting language and pupnp is a portable UPnP library. This creates an engine that will run on any platform (Windows, Mac, Linux, or even embedded on a NAS or your wifi router), while at the same time allowing users/developers to write code in Lua. So it takes away the need to do all the complex stuff in hardcore C, threading, platforms, etc. The Lua scripts will simply run on all platforms, unmodified.</p>
<p><span id="more-634"></span><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>Why create it?</h2>
<p>This is a bit of a long-term vision I have on the subject; homeautomation is very fragmented, lots of opensource stuff and many commercial products, each can do a lot, but none can do all. Check out <a href="http://www.eventghost.org/">EventGhost</a>, <a href="http://www.homeseer.com/">HomeSeer</a>, <a href="http://www.promixis.com/">Girder</a>, and then some. That&#8217;s software, hardware is even worse, X10, HomeEasy, Zigbee, Zwave, EIB-KNX either unreliable or competing for market dominance and hence closed technology (especially Zwave). Now all server products try to implement as much hardware support as they can, so they write drivers for a lot, but still not all, hardware. Hardware vendors have to implement drivers for their products for as many products as possible as well, to be able to sell to customers who are well bought into existing hard and software.</p>
<p>A lot of energy is wasted here, with a sub-optimal result. So put the UPnP script engine in between, de-couple the homeautomation server and the hardware support layer. Develop  1 driver for each hardware type, using the UPnP engine. And have each homeautomation server implement 1 UPnP controlpoint. All servers will be able to get along with all hardware. Server developers can focus on implementing state-of-the-art GUI&#8217;s and compete on that without having to worry about hardware support. Hardware suppliers can focus on delivering top-notch hardware instead of wasting energy on supporting all kinds of different setups. Users can run it on any platform, even small 24&#215;7 devices.</p>
<p>In the end; everybody wins!</p>
<h2>How will this compete with existing hard and software?</h2>
<p>Not. The gateway is solely intended to bridge proprietary hardware to generic and open UPnP. I have no intent to create anything else, no homeautomation server/GUI, nor a logic engine. Lets just make sure evereybody does what he/she does best.</p>
<h2>Is it ready?</h2>
<p>Nope, its a first demo. Lots needs to be done, in no particular order;</p>
<ul>
<li>UPnP security service has not been implemented (must have!)</li>
<li>Some of the wrapper code (mutexes, waithandles and sockets) are not complete for all platforms yet, currently it only runs on Windows, but this should be limited as the wrappers themselves have all been created already</li>
<li>Solid logger, as its designed to be used in the background without an interface, it must provide solid logging, even if only for troubleshooting and debugging</li>
<li>Serial library; currently network connections are supported through the LuaSocket library, but serial connections must be added to (probably through <a href="http://linux.die.net/man/8/ser2net">ser2net</a>, but that lacks a windows version AFAIK)</li>
<li>The demo is a single Lua file (which is totally crap code), and should be replaced by a Lua side object oriented framework to access and modify UPnP devices/controlpoints</li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>Show me the demo!</h2>
<p>The demo is a Lua version (Windows only until the todo&#8217;s have been fixed) of the NetworkLight from the former Intel UPnP toolset, but lacking the fancy images. Download the zip file and extract it in a single folder, then start the batchfile (&#8216;_start.bat&#8217;). Now you can use the DeviceSpy utility (also from the <a href="http://opentools.homeip.net/dev-tools-for-upnp/">UPnP toolset</a>) to inspect the variables and execute actions. If you&#8217;re not familiar with the tool;</p>
<ul>
<li>right-click a service and tick &#8216;subscribe&#8217; to get updates</li>
<li>double-click an action to set parameters and execute it</li>
</ul>
<p><a href="http://www.thijsschreijer.nl/blog/?download=lualightsample.zip">Here&#8217;s the download</a>, at only 272Kb! (downloaded 66 times), and below a screenshot of a testrun.</p>
<p><a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/07/LuaLight_screen.jpg"><img class="aligncenter size-full wp-image-644" title="Lua light demo run" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/07/LuaLight_screen.jpg" alt="" width="1600" height="900" /></a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=634</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Update to the 1-on-1 8 bit byte-2-string conversion tip on CodeProject</title>
		<link>http://www.thijsschreijer.nl/blog/?p=624</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=624#comments</comments>
		<pubDate>Wed, 29 Feb 2012 16:13:19 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[byte array]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=624</guid>
		<description><![CDATA[About a year ago I posted a tip/trick type article on CodeProject. Recently a comment proved a problem with my code, hence I updated it. Because I couldn&#8217;t add any downloads to the post, I&#8217;ll provide it here. Here&#8217;s the &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=624">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>About a year ago I posted a <a href="http://www.codeproject.com/Tips/144792/String-to-byte-conversion-using-NET-encoders-8bit" target="_blank">tip/trick type article on CodeProject</a>. Recently a comment proved a problem with my code, hence I updated it. Because I couldn&#8217;t add any downloads to the post, I&#8217;ll provide it here.</p>
<p><a href="http://www.codeproject.com/Tips/144792/String-to-byte-conversion-using-NET-encoders-8bit" target="_blank">Here&#8217;s the article</a></p>
<p><a href="http://www.thijsschreijer.nl/blog/?download=bytestringconversions.zip">Here&#8217;s the download</a> (downloaded 146 times)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=624</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Lua Development Tools with Koneki, for local development</title>
		<link>http://www.thijsschreijer.nl/blog/?p=604</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=604#comments</comments>
		<pubDate>Fri, 24 Feb 2012 22:12:38 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Koneki]]></category>
		<category><![CDATA[LDT]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Lua Development Tools]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=604</guid>
		<description><![CDATA[Recently, while looking for a better Lua IDE I tried the Lua Development Tools by the Koneki project. The Koneki project focusses on machine-2-machine (M2M) development and hence does not yet support local run and debug configurations. With a support link &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=604">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Recently, while looking for a better <a href="http://www.lua.org" target="_blank">Lua</a> IDE I tried the <a href="http://www.eclipse.org/koneki/ldt/" target="_blank">Lua Development Tools</a> by the <a href="http://www.eclipse.org/koneki/" target="_blank">Koneki project</a>. The Koneki project focusses on machine-2-machine (M2M) development and hence does not yet support local run and debug configurations. With a <a href="http://www.eclipse.org/forums/index.php/t/296547/" target="_blank">support link</a> to some <a href="http://mwebhack.blogspot.com/2012/01/lua-development-tools-koneki-ide-based.html" target="_blank">helpful pages</a> (which didn&#8217;t work straight away), I fiddled around a bit and got it working through the &#8216;external tools&#8217; workaround, though still with some quirks. Also not sure it all works as it should, especially adding command line parameters is something I&#8217;ll be needing to fix still.<span id="more-604"></span></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Here&#8217;s how to set it up (on Windows that is, but with some scripting also on other platforms);</p>
<ol>
<li>Download and install the standalone version (that&#8217;s what I used)</li>
<li>Start it and create a simple new project called &#8216;test&#8217;; menu File &gt; New &gt; Lua project</li>
<li>Create a new external tool config; menu Run &gt; External Tools &gt; External Tools Configurations&#8230;</li>
<li>On the left pane right-click &#8216;Program&#8217; and select New, then configure it as follows;<a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt1.png"><img class="aligncenter size-medium wp-image-605" title="koneki_ldt1" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt1-295x300.png" alt="" width="295" height="300" /></a></li>
<li>Obviously, &#8216;Location&#8217; should point to your local Lua VM</li>
<li>Now add a statement to your test project; print(&#8220;Hello world&#8221;) and click the &#8216;External Tools&#8217; button and select &#8216;lua_run&#8217; as configured in step 4.<br />
<span style="text-decoration: underline;"><strong>IMPORTANT</strong></span>: you must first select &#8216;main.lua&#8217; in the script explorer or you&#8217;ll get an error;<a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt2.png"><img class="aligncenter size-medium wp-image-606" title="koneki_ldt2" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt2-300x123.png" alt="" width="300" height="123" /></a></li>
<li>You should now see &#8220;Hello world&#8221; in the console window</li>
</ol>
<p>&nbsp;</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Now that&#8217;s for running a Lua script directly, so how about debugging? The debug features go through a network connection to a remote device (or &#8216;localhost&#8217;), but it will require the script to be running with the Lua debugger modules loaded. So I created a batch file to do this.</p>
<ol>
<li>Download the <a href="http://wiki.eclipse.org/Koneki/LDT/Concepts/Debugger#DBGP_Client" target="_blank">debugger files (DBGP client)</a> and store them in a folder &#8216;luadebug&#8217; inside the directory where Eclipse is installed, for example; &#8220;C:\Program Files\EclipseLDT\debuglua&#8221;</li>
<li>Download <a href="http://www.thijsschreijer.nl/blog/?download=ldtdebug.zip">this batch file</a> (downloaded 320 times) and store it in the same directory as the debugger files</li>
<li>Create another &#8216;external tool&#8217; config as detailed above, with the following settings;<a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt3.png"><img class="aligncenter size-medium wp-image-607" title="koneki_ldt3" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt3-295x300.png" alt="" width="295" height="300" /></a></li>
<li>The path to the Lua VM is now in the &#8216;Arguments&#8217; pane, so make sure it is correct for your local Lua VM.</li>
<li>Add a debug configuration via menu; Run &gt; Debug configurations&#8230;</li>
<li>Configure it with the following settings;<a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt4.png"><img class="aligncenter size-medium wp-image-608" title="koneki_ldt4" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt4-300x261.png" alt="" width="300" height="261" /></a></li>
<li>Start the debugger by selecting &#8216;lua_debugger&#8217; from the<strong> debug button</strong> drop-down;<a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt5.png"><img class="aligncenter size-medium wp-image-609" title="koneki_ldt5" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt5-300x109.png" alt="" width="300" height="109" /></a></li>
<li> Then start the application by selecting &#8216;lua_debug&#8217; from the &#8216;External Tools&#8217; button;<a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt6.png"><img class="aligncenter size-medium wp-image-610" title="koneki_ldt6" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/02/koneki_ldt6-300x124.png" alt="" width="300" height="124" /></a></li>
<li>The application will start with the debugger module loaded, it will connect to the debugger GUI within Eclipse.</li>
</ol>
<p>In the debug configuration, a batch file is used. The batch file takes two parameters; <strong>a)</strong> path to the Lua VM, <strong>b)</strong> path to the debug target. The batch file will run the following steps;</p>
<ol>
<li>update the LUA_PATH environment variable such that the debugger modules will be in the search path</li>
<li>start the Lua VM and initially execute the debugger modules</li>
<li>then start the target Lua script</li>
<li>after exiting it will restore the LUA_PATH variable</li>
</ol>
<p>This approach prevents me from having to add the debugger code to the actual code. Though it is a windows batch file, it should be easy to port it to other platforms.</p>
<p>What&#8217;s to be improved still;</p>
<ul>
<li>start debugger and debug target with a single click</li>
<li>allow for adding command line parameters to the target</li>
<li>having some sort of default start file, instead of manually having to select the correct file before starting it</li>
<li>the debugger requires a link to a specific project in its setup, so probably a specific setup is required per project (haven&#8217;t tested that yet)</li>
<li>the batch file does not support setting the remote debugger IP, port or IDE key, so it always uses the defaults (127.0.0.1, 10000, luaidekey)</li>
</ul>
<p>I&#8217;m interested in solutions to these, so if you find one let me know&#8230;</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=604</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Fixing the UPnP stack issues</title>
		<link>http://www.thijsschreijer.nl/blog/?p=589</link>
		<comments>http://www.thijsschreijer.nl/blog/?p=589#comments</comments>
		<pubDate>Fri, 06 Jan 2012 21:54:59 +0000</pubDate>
		<dc:creator>Thijs Schreijer</dc:creator>
				<category><![CDATA[UPnP]]></category>
		<category><![CDATA[Developer Tools for UPnP Technologies]]></category>
		<category><![CDATA[UPnP stack]]></category>

		<guid isPermaLink="false">http://www.thijsschreijer.nl/blog/?p=589</guid>
		<description><![CDATA[The last few days I spent some time fixing the .NET UPnP stack to be more resilient. The stack itself it pretty ok, but the problem is that you do not have control over all the other UPnP devices out there. &#8230; <a href="http://www.thijsschreijer.nl/blog/?p=589">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The last few days I spent some time fixing the <a href="http://opentools.homeip.net/dev-tools-for-upnp" target="_blank">.NET UPnP stack</a> to be more resilient. The stack itself it pretty ok, but the problem is that you do not have control over all the other UPnP devices out there. If these are faulty and don&#8217;t play by the rules, you can either ignore them (what the UPnP stack did until now) or try and handle only those parts that are ok.</p>
<p>Supporting for the <a title="UPnP-2-xPL gateway" href="http://www.thijsschreijer.nl/blog/?page_id=550">UPnP gateway</a> showed that several devices would simply not show up. Some fiddling <a href="http://coherence.beebits.net/wiki/UPnP-Inspector" target="_blank">with other UPnP tools</a> and the debug facilities showed that the devices had faulty description xml&#8217;s (bad UPnP implementations by their vendors). The cases were the <a href="http://www.gracedigitalaudio.com/tuner-wifi-ethernet-radio-tuner-gdiirdt200-p-91.html" target="_blank">Grace Digital tuner </a>and the <a href="http://micasaverde.com/" target="_blank">Vera home automation box</a> (the Grace Digital has a <a title="Updated descriptions after the firmware update" href="http://www.promixis.com/forums/showthread.php?21127-UPnP-and-Girder&amp;p=145814#post145814" target="_blank">firmware update, beta, available</a> that fixes the issue)</p>
<p>I had to take a pretty steep dive into the code to fix all the undelying elements. What happened was that the code for parsing device and service xml&#8217;s only had exception handling on the highest level. This means that you get either <em>all</em> or <em>nothing</em>.<span id="more-589"></span></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>The update now includes more error checking so that individual elements that do not adhere to the UPnP standards are now left out. So any faulty device or service will still get parsed, for all the proper elements it has. To know whether there are any issues with the description xml&#8217;s, the debug window can be used.</p>
<p>Showing the debug window can be done from the menu, or via the &#8216;/DEBUG&#8217; commandline option.</p>
<p>As an example using the faulty service description of the <a href="http://www.gracedigitalaudio.com/tuner-wifi-ethernet-radio-tuner-gdiirdt200-p-91.html" target="_blank">Grace Digital tuner</a>, that device has/had a <a title="RenderingControl1.xml" href="http://www.promixis.com/forums/showthread.php?21127-UPnP-and-Girder&amp;p=145801#post145801">RenderingControl1.xml</a> service description with an action argument that referenced a non-existing statevariable. If you load this xml into the Service Author tool, it would simply display an error and do nothing;</p>
<div id="attachment_593" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/01/UPnP_Resilience_before.png"><img class="size-medium wp-image-593" title="UPnP_Resilience_before" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/01/UPnP_Resilience_before-300x140.png" alt="" width="300" height="140" /></a><p class="wp-caption-text">Error message before the fix, simply wouldn&#39;t load</p></div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3106191361299034";
/* 468x60, gemaakt 2-6-10 */
google_ad_slot = "2317741540";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>With the fixed version of the stack, it now logs the errors, but commences with parsing the proper parts of the device;</p>
<div id="attachment_592" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/01/UPnP_Resilience_after.png"><img class="size-medium wp-image-592" title="UPnP_Resilience_after" src="http://www.thijsschreijer.nl/blog/wp-content/uploads/2012/01/UPnP_Resilience_after-300x240.png" alt="" width="300" height="240" /></a><p class="wp-caption-text">The debug window indicates what&#39;s wrong, but it still loads</p></div>
<p>In the screenshot you can see in the top pane of the debug window that the errors pertain to the actions <strong>GetLoudness</strong> and <strong>SetLoudness</strong>. In the bottom pane it is mentioned that there is an invalid reference to the <strong>Loudness</strong> statevariable. In the main <em>Service Author</em> window, all proper defined actions are now shown (note that <strong>Get/SetLoudness</strong> are absent here).</p>
<p>The practical use for the <em>Service Author</em> application is very limited, but I have no access to the device itself, so this was the only way to show the effects. Any way, the same UPnP stack can be used with the <em>Device Spy</em>, which basically means that from now on even the bad behaving devices will show up in the <em>Device Spy</em>, which is great for troubleshooting UPnP devices, and of course, the stack can be used to build controlpoints that are also capable of controlling those bad behaving devices.</p>
<p>I mailed the input to <a title="Ylian Saint-Hilaire (Intel)" href="http://software.intel.com/en-us/blogs/author/ylian-saint-hilaire/" target="_blank">Ylian Saint-Hilaire (Intel)</a>, who currently maintains the <a title="Developer Tools for UPnP Technologies" href="http://opentools.homeip.net/dev-tools-for-upnp" target="_blank">Developer Tools for UPnP Technologies</a>. So I&#8217;m expecting the update to become available soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thijsschreijer.nl/blog/?feed=rss2&#038;p=589</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
