<?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>Håkon Nessjøen</title>
	<atom:link href="http://lunatic.no/feed/" rel="self" type="application/rss+xml" />
	<link>http://lunatic.no</link>
	<description>Just another life hacker</description>
	<lastBuildDate>Sat, 27 Feb 2010 19:16:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>More verbose logging of queue-call attempts in Asterisk</title>
		<link>http://lunatic.no/2010/02/more-verbose-logging-of-queue-call-attempts-in-asterisk/</link>
		<comments>http://lunatic.no/2010/02/more-verbose-logging-of-queue-call-attempts-in-asterisk/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 19:12:54 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=106</guid>
		<description><![CDATA[Not much to write about lately, but many of you, me included, use queue_log to generate important statistics about a company&#8217;s queue calls. It is important to see how many times a user have been called, how many times they answered, how long the calls last, etc.
But one thing missing, has been how many calls [...]]]></description>
			<content:encoded><![CDATA[<p>Not much to write about lately, but many of you, me included, use queue_log to generate important statistics about a company&#8217;s queue calls. It is important to see how many times a user have been called, how many times they answered, how long the calls last, etc.</p>
<p>But one thing missing, has been how many calls failed because of telephony failure, or configuration errors. So i&#8217;ve uploaded this:</p>
<p><a title="0016925: [patch] app_queue: Log failed attempts to call members" href="https://issues.asterisk.org/view.php?id=16925" target="_blank">https://issues.asterisk.org/view.php?id=16925</a></p>
<p>This patch makes app_queue more verbose to queue_log, reporting problems calling out, as well as marking them as &#8220;congestion&#8221; with a new parameter to the RINGNOANSWER queue_log entry. (also to the AMI event)</p>
<p>More information in the issue tracker.</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/02/more-verbose-logging-of-queue-call-attempts-in-asterisk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asterisk, DAHDI and TDMoE</title>
		<link>http://lunatic.no/2010/02/asterisk-dahdi-and-tdmoe/</link>
		<comments>http://lunatic.no/2010/02/asterisk-dahdi-and-tdmoe/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 13:40:07 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=95</guid>
		<description><![CDATA[A few years ago, I read this wiki page at voip-info.org, where I was informed of this nifty thing called TDMoE. TDMoE is TDM over Ethernet. This nifty DAHDI driver (dahdi_dynamic_eth), provides any dahdi signalling via Ethernet. So if you need to have PRI signalling between two asterisk servers in the same room. Look no [...]]]></description>
			<content:encoded><![CDATA[<p>A few years ago, I read this wiki page at voip-info.org, where I was informed of this nifty thing called TDMoE. TDMoE is <a title="Time Division Multiplexing" href="http://en.wikipedia.org/wiki/Time-division_multiplexing" target="_blank">TDM</a> over Ethernet. This nifty DAHDI driver (dahdi_dynamic_eth), provides <span style="text-decoration: underline;">any</span> dahdi signalling via Ethernet. So if you need to have PRI signalling between two asterisk servers in the same room. Look no further! Instead of buying expensive T1/E1 cards, to be able to talk PRI, you can just use your ethernet cards. TDMoE uses your network interface card to talk to the other asterisk box. To do this, both machines needs to know eachothers MAC addresses. Why? Because TDMoE uses it&#8217;s own ethernet type. Packets between the boxes goes through the ethernet via ethernet type 0xd00d. Inside the ethernet frame, lies a dahdi_dynamic packet, which in turn has the packet/frame from your chosen signalling standard.</p>
<p>But beware. You <span style="text-decoration: underline;">should</span> have DAHDI compatible hardware in at least one of the asterisk boxes. This is because of timing, so you can use the timing from that card, to time the TDMoE. TDM packets needs to be sent every 1ms at a very stable rate. A normal computer without extra hardware cannot acheive 100% the correct timing requirements of DAHDI signalling protocols on it&#8217;s own. The kernel module dahdi_dummy (former ztdummy) can give you a signal close to ~99.4%(my results, testing with dahdi_test -v) of what the timing should be.</p>
<p>In my testing results, TDMoE works nice with dahdi_dummy, but I am unsure if this is stable over time. So better have some DAHDI hardware somewhere.</p>
<p>Before we start, I need to say that, by no means think that I am an expert at DAHDI or TDMoE, or that everything I write here is correct. I take no responsibility of what you do with the information on this post, or the correctness of the information here. If you see something that is plain wrong, please inform me, and I&#8217;ll update the post :)</p>
<p>So suddenly I came to the point where something like TDMoE would be very nice to have, and it worked like a charm. But on the &#8216;tutorials&#8217; out there, almost all of them use the &#8216;em&#8217; signalling. So I thought I could write a bit of what you need to do, and what I did to get PRI signalling to work over ethernet with dahdi_dummy as timing source. So, to set up this, you first need to compile and install libpri, dahdi-kernel, and dahdi-tools on both machines. And then recompile asterisk, so they get dahdi and pri support.</p>
<p>After I did this, in my box with dahdi_dummy loaded I edited /etc/dahdi/system.conf and added the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">dynamic</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">eth,eth1/00:00:01:00:00:00/<span style="">0</span>,<span style="">31</span>,0</span>
<span style="color: #000099;">echocanceller</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">mg2,<span style="">1</span>-<span style="">15</span>,<span style="">17</span>-31</span>
<span style="color: #000099;">bchan</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"><span style="">1</span>-<span style="">15</span>,<span style="">17</span>-31</span>
<span style="color: #000099;">dchan</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">16</span>
<span style="color: #000099;">alaw</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"><span style="">1</span>-<span style="">15</span>,<span style="">17</span>-31</span></pre></div></div>

<p>Where 00:00:01:00:00:00 is replaced by the MAC address of the <span style="text-decoration: underline;">other</span> server, and eth1 reflects the network interface I&#8217;d like to use for this. Then in /etc/asterisk/chan_dahdi.conf, I added the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>channels<span style="">&#93;</span></span>
<span style="color: #000099;">context</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">default</span>
<span style="color: #000099;">usecallerid</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">hidecallerid</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">no</span>
<span style="color: #000099;">callwaiting</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">usecallingpres</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">callwaitingcallerid</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">threewaycalling</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">transfer</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">facilityenable</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">canpark</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">cancallforward</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">callreturn</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">echocancel</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">echocancelwhenbridged</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">relaxdtmf</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">immediate</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">no</span>
&nbsp;
<span style="color: #000099;">switchtype</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">euroisdn</span>
<span style="color: #000099;">context</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">inbound</span>
<span style="color: #000099;">group</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
<span style="color: #000099;">echocancel</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">signalling</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">pri_net</span>
<span style="color: #000099;">channel</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt;<span style="">1</span>-<span style="">15</span>,<span style="">17</span>-31</span></pre></div></div>

<p>Here you see I set the signalling type to &#8216;pri_net&#8217;, which means that this will be the network side of the pri signalling. Let&#8217;s call this the pri_net server. Then i configured dahdi by modprobing dahdi, modprobing dahdi_dummy, and running dahdi_cfg -vvv</p>
<p>If everything worked well, you should also be able to do dahdi_test -v, and see the precision to be close to 100%. You can now configure the other server. In /etc/dahdi/system.conf on this server, I had the same setup as the pri_net server, but here you put the MAC address of the pri_net server. So they point to eachother.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">dynamic</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">eth,eth0/00:00:01:00:00:01/<span style="">0</span>,<span style="">31</span>,1</span>
<span style="color: #000099;">echocanceller</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">mg2,<span style="">1</span>-<span style="">15</span>,<span style="">17</span>-31</span>
<span style="color: #000099;">bchan</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"><span style="">1</span>-<span style="">15</span>,<span style="">17</span>-31</span>
<span style="color: #000099;">dchan</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">16</span>
<span style="color: #000099;">alaw</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"><span style="">1</span>-<span style="">15</span>,<span style="">17</span>-31</span></pre></div></div>

<p>Remember to change the MAC adress.</p>
<p>Then in /etc/asterisk/chan_dahdi.conf on this server, I had:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>channels<span style="">&#93;</span></span>
<span style="color: #000099;">context</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">default</span>
<span style="color: #000099;">usecallerid</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">hidecallerid</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">no</span>
<span style="color: #000099;">callwaiting</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">usecallingpres</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">callwaitingcallerid</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">threewaycalling</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">transfer</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">facilityenable</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">canpark</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">cancallforward</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">callreturn</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">echocancel</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">echocancelwhenbridged</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">relaxdtmf</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">immediate</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">no</span>
&nbsp;
<span style="color: #000099;">switchtype</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">euroisdn</span>
<span style="color: #000099;">context</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">inbound</span>
<span style="color: #000099;">group</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">0</span>
<span style="color: #000099;">echocancel</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
<span style="color: #000099;">signalling</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">pri_cpe</span>
<span style="color: #000099;">channel</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt;<span style="">1</span>-<span style="">15</span>,<span style="">17</span>-31</span></pre></div></div>

<p>Now here I set signalling to be pri_cpe, which means the customer side of the PRI line.</p>
<p>Now all you need to do is to modprobe dahdi, run dahdi_cfg -vv and hope for the best, and start asterisk.</p>
<p>If you type dahdi show status in asterisk, you should se a &#8220;OK&#8221; in the Alarms section, on your span. If you see RED, they don&#8217;t see eachother. Or if it&#8217;s Yellow, i think you have link, but the timing is not correct.</p>
<p>If you have problems with timing, you can check tcpdump -i eth0 ether proto 0xd00d, and you should see a buckload of packets flowing in. Also try to use the dahdi_test tool on both machines to compare timing. the pri_cpe machine will get the timing over ethernet, so it may be a bit off, if your network is not perfect.</p>
<p>I can now successfully make calls with DAHDI/g0/number with callerid etc. working spotless. :) Hope you can too!</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/02/asterisk-dahdi-and-tdmoe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New AMI commands for Asterisk</title>
		<link>http://lunatic.no/2010/01/new-ami-commands-for-asterisk/</link>
		<comments>http://lunatic.no/2010/01/new-ami-commands-for-asterisk/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 19:49:25 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=91</guid>
		<description><![CDATA[Our mobile-phone operator has given us access to live status information about all the phones in our subscription. What this means is that when one of our phones are being called to, or turned of, or even roaming to another country; they automagically notifies us instantly via a private API.
What this means, is that we [...]]]></description>
			<content:encoded><![CDATA[<p>Our mobile-phone operator has given us access to live status information about all the phones in our subscription. What this means is that when one of our phones are being called to, or turned of, or even roaming to another country; they automagically notifies us instantly via a private API.</p>
<p>What this means, is that we can make this information available to our existing phone system. Since we are using Asterisk, I was going to connect to AMI and update the device state of the mobile phone in question, when we received a status update via the API. The problem is. Asterisk didn&#8217;t have any <a title="Asterisk Manager Interface" href="http://www.voip-info.org/wiki/view/Asterisk+manager+API" target="_blank">AMI</a> commands for updating Custom device states, only inside the dialplan. Luckily, it&#8217;s easy to add new commands to the AMI interface, and it was done in a jiffy.</p>
<p>If anyone is interested, the patch is up at <a title="0016732: [patch] Add AMI support for device states" href="https://issues.asterisk.org/view.php?id=16732" target="_blank">https://issues.asterisk.org/view.php?id=16732</a>.</p>
<p>Now, my <a href="http://www.aastra.com/cps/rde/xchg/04/hs.xsl/19703.htm" target="_blank">Aastra 57i</a> phone correctly lights up a red led, and shows a &#8220;un-hooked&#8221; icon in front of my extension on the <a href="http://www.aastra.com/cps/rde/xchg/SID-3D8CCB6A-9A52B04E/04/hs.xsl/20684.htm" target="_blank">expansion module</a> on phone(or on the phone itself), when my mobile phone is in use.</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/01/new-ami-commands-for-asterisk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New penalty function for Asterisk Queue</title>
		<link>http://lunatic.no/2010/01/new-penalty-function-for-asterisk-queue/</link>
		<comments>http://lunatic.no/2010/01/new-penalty-function-for-asterisk-queue/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 15:40:53 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=87</guid>
		<description><![CDATA[This patch was developed because Asterisk was missing a ACD feature that our customer has on their previous IVR system. The feature is that if a person(read: agent) goes away from his/her phone, and forgets to log out from the queue, the agent gets &#8216;paused&#8217; for a specific amount of &#8216;penalty&#8217;-time, where the agent won&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>This patch was developed because Asterisk was missing a <a title="Automatic call distributor" href="http://en.wikipedia.org/wiki/Automatic_call_distributor" target="_blank">ACD</a> feature that our customer has on their previous <a title="Interactive Voice Response" href="http://en.wikipedia.org/wiki/Interactive_voice_response" target="_blank">IVR</a> system. The feature is that if a person(read: agent) goes away from his/her phone, and forgets to log out from the queue, the agent gets &#8216;paused&#8217; for a specific amount of &#8216;penalty&#8217;-time, where the agent won&#8217;t receive any more call attempts. This is almost like the &#8220;autopause&#8221; function, already present in Asterisk. Except that this one will unpause the user again after a given amount of time.</p>
<p>Lets say we have 3 agents in a queue.. The two first agents have priority 1, and the last one has priority 2. This means that as long as one of the first two agents are off their phones, the queue system will try to call those phones. It will not go to priority 2 unless both agents are busy on their phones, because, they&#8217;re free, right? With my patch, the two first agents are temporarily removed from the queue after they don&#8217;t answer before the timeout specified for the queue. Now the queue system will try agents in priority 2 automatically. This way, people who wait in line for an agent doesn&#8217;t have to wait for ages because one agent forgot to log off.</p>
<p>To accomplish this, I note the time when a member fails to answer his phone in time, and then neglects to call him anymore until (current time &#8211; no-answer time) is more than X seconds.</p>
<p>The amount of seconds to wait is defined in queues.conf with the new <em>notpresent-penalty</em> option, or in a realtime database, by a integer field with the name <em>notpresent_penalty</em>.</p>
<p>You can find the patch at <a title="0016722: [patch] app_queue: Give members a penalty time for not answering" href="https://issues.asterisk.org/view.php?id=16722" target="_blank">Asterisks issue tracker</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/01/new-penalty-function-for-asterisk-queue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming in Akelos</title>
		<link>http://lunatic.no/2010/01/programming-in-akelos/</link>
		<comments>http://lunatic.no/2010/01/programming-in-akelos/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 16:31:41 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[hobby]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=81</guid>
		<description><![CDATA[For some while I have been using the Akelos library for MVC development within PHP. The reason I like this library over other well-known libraries like Zend Framework, CakePHP etc, is that this library is very much coded with &#8220;Convension over configuration&#8221; which means that you don&#8217;t have to over-configure everything. And it&#8217;s easy to [...]]]></description>
			<content:encoded><![CDATA[<p>For some while I have been using the <a href="http://akelos.org/" target="_blank">Akelos</a> library for <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" target="_blank">MVC</a> development within PHP. The reason I like this library over other well-known libraries like <a href="http://framework.zend.com/" target="_blank">Zend Framework</a>, <a href="http://cakephp.org/" target="_blank">CakePHP</a> etc, is that this library is very much coded with &#8220;Convension over configuration&#8221; which means that you don&#8217;t have to over-configure everything. And it&#8217;s easy to learn new people how to use it.<span id="more-81"></span></p>
<p>For example, when you create a database, you fill inn the fields you like, in a &#8216;installer&#8217;. Each time you need to add fields, you add new up() revisions in the installer, so versioning systems like SVN or git can see that &#8220;in revision x, a new fields was added to the sql table&#8221;. This means that the versioning system can keep track of the database as well as the files.</p>
<p>Something I also love about Akelos is the ease of translation. In the Views you can write so called &#8220;sintags&#8221;. Which is basically the template language in Akelos. To write out the contents of a variable, you write {variable name} if you write text that needs translating, you write _{translate this text}. Thats variables and simple translations. Then you have functions, like a form:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= form_tag <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'myid'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>= text_field <span style="color:#996600;">'blog'</span>, <span style="color:#996600;">'name'</span>, <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'myclass'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&lt;/form&gt;</pre></div></div>

<p>Now I wanted to be able to translate inside function tags, so I made a little <a href="http://trac.akelos.org/ticket/229#comment:2" target="_blank">adjustment</a> to the Akelos source which made it possible to do:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to _<span style="color:#996600;">'translated text'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'about'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    or
 <span style="color:#006600; font-weight:bold;">&lt;%</span>= something <span style="color:#996600;">'name'</span>, <span style="color:#ff3333; font-weight:bold;">:vals</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">'plain text'</span>, _<span style="color:#996600;">'translated text'</span>, _<span style="color:#996600;">'translated text with %variable'</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Here you also see that translated text also can contain variables from the view scope, which is pretty nifty in regards to dynamic translating. This &#8220;adjustment&#8221; was added to trunk in October 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/01/programming-in-akelos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Perl based Icecast clone</title>
		<link>http://lunatic.no/2010/01/simple-perl-based-icecast-clone/</link>
		<comments>http://lunatic.no/2010/01/simple-perl-based-icecast-clone/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 00:23:08 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[hobby]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=69</guid>
		<description><![CDATA[This is acctually a mini project I did a while ago, but I thought I could write a small post about it here, and give out the source code.
The reason I did this, was because I used icecast, and had 5 streams up with a lot of users, but sometimes you would get sound from [...]]]></description>
			<content:encoded><![CDATA[<p>This is acctually a mini project I did a while ago, but I thought I could write a small post about it here, and give out the source code.</p>
<p>The reason I did this, was because I used icecast, and had 5 streams up with a lot of users, but sometimes you would get sound from other streams on the same server, or old sound in the middle of the stream. I tried googling after other people with the same problems as me. But found nothing. So I thought; it&#8217;s quite simple software, how hard can it be to make a stable myself?</p>
<p>So first I made a proof-of-concept perl script to receive data, and send out to several listeners. Worked great at first try. Only a minior problems. If I paused the stream on one client, the whole server started waiting for that one listener, before sending any more data to all the other listeners. (more about this later) The other problem was that I didn&#8217;t have any in-stream &#8220;title&#8221; support.</p>
<p>The reason the stream stopped when one of the clients stopped listening for data (and blocked further data), is that I was sending data with a blocking socket. Now I tried googling about how to _send_ nonblocking, but coulnd&#8217;t find anything. So I made my own little workaround. (someone please give me a better solution)</p>
<p>Instead of:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">syswrite</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>I wrote a new send subroutine using IO::Select to check if the client is ready for data:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000066;">send</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sock</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'sock'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$select</span> <span style="color: #339933;">=</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sock</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">can_write</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">return</span> <span style="color: #0000ff;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">syswrite</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This finally did the work for me. The &#8220;send()&#8221; subroutine now returns how many bytes it sent to the client, and if it couldn&#8217;t send any, then it returns zero of course.</p>
<p>Then over to the problem of sending title updates inside the stream. I googled this and found a nice informative page about <a href="http://www.smackfu.com/stuff/programming/shoutcast.html" target="_blank">Shoutcast MetaData</a>.  To bring it into a short explanation; if the client supports shoutcast metadata, it sends the following request header &#8220;<code>Icy-MetaData:1</code>&#8221; to inform the server that it knows about metadata. Then the server, my script, sends &#8220;icy-metaint: 123&#8243; back in the response header, where &#8220;123&#8243; is the amount of mp3 bytes before a metadata string should arrive. After exactly 123 (or whatever the server decides) bytes, the server sends a byte containing information about how long the metadata block is, and then the metadata right after. The &#8220;length byte&#8221; must be multiplied by 16 to get the real length of the metadata string. So the largest metadata string possible would be 4096 bytes long. Just after the metadata, the mp3 data continues as usual. Usually you won&#8217;t send the title data each time the metaint-counter goes around. You&#8217;re probably good by sending zero length metadata (just sending a &#8216;\0&#8242; byte as metadata-length) all the time, until the title actually changes.</p>
<p>So at this time I rewrote the script, and mode it more module based, and added support for several streams, and yaml configuration file for access control, and some status pages, using <a href="http://template-toolkit.org/" target="_blank">TemplateToolkit</a>.</p>
<p>So anyways, the script is still in early beta stage, but it should work fluently. It did however seem that the title-data got out of sync after about a day of listening to a stream, until you reconnected. Can&#8217;t seem to understand how it would get out of sync, unless a malformed tcp packet would arrive. So either I was testing it with a really crappy internet connection that time, or there is a bug berried deep in the simple code. You are free to have fun with the script, and tell me whats wrong. I also think it&#8217;s still full of debug printing. But I have already warned you, this is still in the proof of concept &#8220;whack-some-shit-together&#8221; stage. I&#8217;ts just one of those projects that ends up collecting dust.</p>
<p>If you fire the script up, and go to http://127.0.0.1:8001/ it should give you a list of the current connected streams. Also http://127.0.0.1:8001/xml should give you xml output of current streams. I&#8217;ve been using oddcast to send icecast stream to it.</p>
<p>Here&#8217;s the full script: <a href="http://lunatic.no/wp-content/uploads/2010/01/perlcast.tar.gz">perlcast.tar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/01/simple-perl-based-icecast-clone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Asterisk contributions</title>
		<link>http://lunatic.no/2009/12/asterisk-contributions-2/</link>
		<comments>http://lunatic.no/2009/12/asterisk-contributions-2/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 13:50:32 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">urn:myopera-lunatic-blog-5363281</guid>
		<description><![CDATA[At work, I use Asterisk as the main system behind our IVR sollution. And sometimes we get into stuff that Asterisk just cant handle/do.So I&#8217;ve started to peek a bit on the * source code, and started posting a few &#8220;quick fixes/mini features&#8221;.Heres the list so far:[manager] AMI Redirect: Posibility to send two channels in [...]]]></description>
			<content:encoded><![CDATA[<p>At work, I use Asterisk as the main system behind our IVR sollution. And sometimes we get into stuff that Asterisk just cant handle/do.<br/><br/>So I&#8217;ve started to peek a bit on the * source code, and started posting a few &#8220;quick fixes/mini features&#8221;.<br/><br/>Heres the list so far:<br/><br/>[manager] AMI Redirect: Posibility to send two channels in different direcitons <br/>  <a href="https://issues.asterisk.org/view.php?id=15853" target="_blank">https://issues.asterisk.org/view.php?id=15853</a><br/><br/>[app_queue] Bugfix: app_queue segfaults if realtime field uniqueid is NULL<br/>  <a href="https://issues.asterisk.org/view.php?id=16385" target="_blank">https://issues.asterisk.org/view.php?id=16385</a><br/><br/>[app_queue] Add support for ring indication when calling member <br/>  <a href="https://issues.asterisk.org/view.php?id=16384" target="_blank">https://issues.asterisk.org/view.php?id=16384</a><br/><br/>All in trunk now :)</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2009/12/asterisk-contributions-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big timecode display</title>
		<link>http://lunatic.no/2009/10/big-timecode-display-2/</link>
		<comments>http://lunatic.no/2009/10/big-timecode-display-2/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 23:18:49 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[hobby]]></category>
		<category><![CDATA[jackd]]></category>
		<category><![CDATA[pic]]></category>
		<category><![CDATA[timecode]]></category>

		<guid isPermaLink="false">urn:myopera-lunatic-blog-4383464</guid>
		<description><![CDATA[So, in the last blog entry I told you about the perl DMX backend that we are doing for the party project of ours.We have concluded that we will have a bitchin&#8217; intro show. And it will be timecode controlled. Every little audio / DMX / Video effect will be timed to the millisecond.To do [...]]]></description>
			<content:encoded><![CDATA[<p>So, in the last blog entry I told you about the perl DMX backend that we are doing for the party project of ours.<br/><br/>We have concluded that we will have a bitchin&#8217; intro show. And it will be timecode controlled. Every little audio / DMX / Video effect will be timed to the millisecond.<br/><br/>To do this, we have (for now) concluded that we will use Ardour as the audio platform, and use jackd as the timecode server.<br/><br/>The nice part about this, is that it&#8217;s very easy to code a jack client that fetches the timecode in realtime, and then transmit it via UDP to our external timecode display. And thats where this blog post comes in place; we are creating a cool 8 digit 7-segment display to display our timecode.<br/><br/><span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/bilde%284%29.jpg' /></span><br/>William got 8 of these modules from Kay, who agian bought them for almost nothing at eBay. :D (in Norway they cost about $25 each at the time of writing)<br/><br/>Anyways. As you see in the picture, william has glued the 8 digits together, wich we will put inside a box, and wire up with some pic18f4520 and some ENC28J60 for ethernet connectivity. Yes, the module will be stand-alone, only connected to ethernet, and display the current timestamp/timecode in Ardour/our DMX system.<br/><br/>Do we _really_ need it? no. Is it really cool? yes.<br/><br/>So, so far we have finally gotten the box for the device. It&#8217;s acctually a image frame, with an exceptionally deep frame on the backside to contain the whole shebang.<br/><br/>Here are some more &#8220;under construction&#8221; photos:<br/><span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/28092009056.jpg' /></span> <span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/28092009053.jpg' /></span><br/><br/>In the first photo you can (almost) see the PIC18F4520 on a vero board, with a connected prototype board with the ENC28J60 chip, which works perfectly and successfully outputs data to the (soon to be connected) displays when it receives timecode UDP data on port 1337 ;P<br/><br/>This project has not been the easiest, even though the concept is simple. I&#8217;m not the greatest engineer in regards to analog electronics. The problem is that the 7segment displays needs 7.2v, and uses common anode. This means that I cannot use the displays directly from the PIC processor. So i went on using a ULN2803A to drive the display. This solves the &#8220;common anode&#8221; problem. Now on to solving the 7.2v problem. I have as I said, not very much to say in the analog electronics world. So I went on, and found the first PNP transistor I could find. Kay was kind enough to donate them to us.<br/><br/>He had a bunch of 2N3906 transistors, wich seemed to be &#8220;workable&#8221;. So i set them up on a breadboard and after some fidling with resistors and pulling up the signal, to let the PIC pull it down, to enable the flow trough collector and emitter. This seemed to work great, so I soldered the whole shebang together.<br/><br/>Everything works great now, except that the display &#8220;fluctuates&#8221;. Seems like either the 5v regulator is too weak (it gets pretty hot, but I can&#8217;t check it, because my multimeter doesn&#8217;t want to measure current), or the transistors are a bit too sensitive. Sometimes, when there is traffic on the network the display fluctuates when the ethernet-leds light up. So something is not at it&#8217;s fully potential yet. But I&#8217;ll measure a bit when I get a working multimeter.<br/><br/>So here are the latest images(only thing missing is the 4 dots at the bottom):<br/><span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/bilde%286%29.jpg' /></span> <span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/bilde%287%29.jpg' /></span></p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2009/10/big-timecode-display-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DMX system in perl</title>
		<link>http://lunatic.no/2009/08/dmx-system-in-perl-2/</link>
		<comments>http://lunatic.no/2009/08/dmx-system-in-perl-2/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 13:25:57 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[dmx]]></category>
		<category><![CDATA[hobby]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">urn:myopera-lunatic-blog-4226181</guid>
		<description><![CDATA[William and me are starting to prepare for the next Exploit party, and this year we have decided to control all the lightning and video equiptment by perl.
We started for two days ago. William has a ENTTEC USB Pro which is fine for interfacing. In Linux, it is recognized as a standard COM port, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://williamviker.net/" target="_blank">William</a> and me are starting to prepare for the next Exploit party, and this year we have decided to control all the lightning and video equiptment by perl.</p>
<p>We started for two days ago. William has a <a href="http://www.enttec.com/index.php?main_menu=Products&amp;prod=70304&amp;show=description" target="_blank">ENTTEC USB Pro</a> which is fine for interfacing. In Linux, it is recognized as a standard COM port, and the API consists of sending characters to the virtual COM port.</p>
<p>So as an example of how easy it is to send DMX with this device from perl, I&#8217;ll give an example below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #000000; font-weight: bold;">use</span> Device<span style="color: #339933;">::</span><span style="color: #006600;">SerialPort</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Time<span style="color: #339933;">::</span><span style="color: #006600;">HiRes</span> <span style="color: #009966; font-style: italic;">qw/usleep/</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$PORT</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/dev/ttyUSB0'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ob</span> <span style="color: #339933;">=</span> Device<span style="color: #339933;">::</span><span style="color: #006600;">SerialPort</span><span style="color: #339933;">-</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span>new<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$PORT</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't Open $PORT: $!&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$packet</span> <span style="color: #339933;">=</span> <span style="color: #000066;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #009900;">&#41;</span> x <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$length</span> <span style="color: #339933;">=</span> <span style="color: #000066;">length</span> <span style="color: #0000ff;">$packet</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$write</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ob</span><span style="color: #339933;">-</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span>write<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>7E<span style="color: #000099; font-weight: bold;">\x</span>06&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000066;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$length</span> <span style="color: #0000ff;">&amp;amp</span><span style="color: #339933;">;</span> 0xFF<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000066;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$length</span> <span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&amp;amp</span><span style="color: #339933;">;</span> 0xFF<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$packet</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>E7&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Wrote $write bytes to DMX controller<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This little script will send 30 channels of value 128 to the DMX controller, which will keep repeating this information, until it gets new information.</p>
<p>To clarify, the first byte 0&#215;7E is the start byte for the enttec api. The next byte 0&#215;06 is the function we are using, which is DMX OUT. Then there is two bytes of length information, describing how many channels we are going to send. And then the package is sent. It&#8217;s important to remember to send a 0&#215;00 byte as the first channel, since this is the start byte of the actual DMX data. (also called the SC in the DMX standard specification)</p>
<p>We needed a central area to save our current channel data, and william found a nice perl module called Cache::FastMmap which uses mmap to save data. This way we can have several scripts using the same memory buffer, where we will putt the current DMX channel data. The first byte in the shared memory holds the current &#8216;version number&#8217; of the data. Each time any data is changed, the first byte&#8217;s value is increased. This way each &#8220;reader&#8221; can check if there are new data asyncronically.</p>
<p>So after some initial successful testing, I created a module called Exploit::Scene. This is the module that all scripts that need direct DMX control will use. The external methods are pretty simple. You have get(), set(), to get and set a single channel value, isNew() and resetNew() to check if the DMX channel data has changed since last time you checked. commit() to save new channel data you have edited, and getDMXpacket() to get full 513 bytes of channel data. (or less, if you have set a smaller universe_size)</p>
<p>Now we could start to create some small test scripts. So William made a script that tests a single RGB LED fixture. And I created a console application to show/edit the DMX data. Of course these scripts are just for testing, and will not be used in the finished &#8216;product&#8217;, since everything will be centralized in a web interface to combine effects, etc.</p>
<p><span class="imgcenter"><img src="http://files.myopera.com/lunatic/blog/dmx_test.png" alt="" /></span></p>
<p>Here you can se the console application i wrote with the Curses perl module. The green cursor on the left is moved with your up and down keys, to select a channel. If you use the left or right keys, you increase or decrease the channel value. If you press space, you toggle the channel to full 0xff or null 0&#215;00 values. Page Up and Page Down will show you next &#8216;page&#8217; of channels, up to 512. The color on the bars is reflecting the channel value, first 1/3 is red, next is yellow, and last is green. The console is live, so if any other processes is changing DMX data, it will immediately show the new data while you are editing. So it&#8217;s both a monitor and editor. Which will be nice to have when the full system is done. So we can monitor the dmx channels live without the actual fixtures.</p>
<p>We have created two backend scripts. backend-dmx and backend-udp. These connect to the mmap with the Exploit::Scene module as explained, and use the getDMXpacket() function to get the data to send to either the DMX controller, or udp. By UDP I mean that we are sending all the DMX data to a local multicast address. 239.255.0.$universe. This way, any computer on the network can connect to this stream, and get out the data it needs. So we can have several computers on the network triggering on DMX data. For this we have the Exploit::UDPScene module, which behaves similar to the MMAP version, but used multicast to get it&#8217;s data.</p>
<p>More info will come when we are further along with the project.</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2009/08/dmx-system-in-perl-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>13 Input USB Temperature Sensor for PC</title>
		<link>http://lunatic.no/2009/08/13-input-usb-temperature-sensor-for-pc-2/</link>
		<comments>http://lunatic.no/2009/08/13-input-usb-temperature-sensor-for-pc-2/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 22:42:00 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[hobby]]></category>
		<category><![CDATA[pic microcontroller]]></category>

		<guid isPermaLink="false">urn:myopera-lunatic-blog-4221683</guid>
		<description><![CDATA[I love doing statistics of everything, because data is power. So we thought we would put a temperature sensor in every server-rack in this server housing facility, and I checked the prices of some standard components. First I thought of the DS1820, which is fine, but two drawbacks. It&#8217;s somewhat expensive, and takes a full [...]]]></description>
			<content:encoded><![CDATA[<p>I love doing statistics of everything, because data is power. So we thought we would put a temperature sensor in every server-rack in this server housing facility, and I checked the prices of some standard components. First I thought of the DS1820, which is fine, but two drawbacks. It&#8217;s somewhat expensive, and takes a full second to read value from. So if you wire a lot of sensors serially, you&#8217;ll need to wait one second for each sensor on the same line.<br/><br/>Then I found these cute analog temperature sensors, called MCP9700A. And they cost only €0.37 each. Or if you buy larger quantites, you&#8217;ll get even lower prices. So I thought.. the PIC18F4520 has 13 analog ports. Why not create a small pcb with a pic18f4520, and some connectors, and wire it to the computer via RS232.<br/><br/>The problem then, is that i&#8217;d have to buy max232 chip, and then I&#8217;d need a RS232->USB cable, and thats pretty expensive. But then I found the life-saver chip FT232R. This awesomeness in a chip enclosure is a RS232(or any serial data in TTL levels)-to-USB &#8216;converter&#8217;. It has drivers for windows *, Mac, Linux. And you can even modify the eeprom inside it, to make it use a different VID and PID or just change the device description of it. And it also have two GP pins, which you can connect to LEDs to show when it sends or receives data. The BEST part about this already awesome chip, is it&#8217;s price. Here in Norway a RS232->USB cable costs from €42 an up. But this device, practically the same (except for missing RS232 level converter), costs only €2.87. And thats with all the leetnes of being able to change the device description and all, included.<br/><br/>So I wired it all up in Eagle, and it came out to be like this.<br/>Schematics:<br/><span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/Schematics.png' /></span><br/>Board:<br/><span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/Tempsensor%20MK%20I.png' /></span> <span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/Tempsensor%20MK%20I%20-%20bottom.png' /></span><br/><br/>So here I have a PIC18F4520 processor, 20Mhz XTAL for it (because I had some laying around), FT232R chip, 100K Resistor pack, and a few LEDs. All in all, about €20 worth of components.<br/><br/>So, now that I had designed the board, how to get it made, and cheap? Well, I found this site called [link]www.batchpcb.com[/link]. Which is fabulous. They collect PCB boards for a bunch of people who need cheap prototype boards, and send everything together to China, where they produce the boards, and return them in about 12 days. They often set up your board several times, in case some of them should be bad. (bleedout on the copper). And the best part. If more than one of your boards are ok, they even send you the extras, with no extra charge. So I received two pcs of the PCB I ordered, and couldn&#8217;t be happier :)<br/><br/>Here&#8217;s the result, (image quality courtesy of iPhone 3G)<br/><span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/bilde%282%29.jpg' /></span> <span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/IMG_0266.JPG' /></span><br/><br/>Then we add all the components. And bobs your uncle: (image quality courtesy of iPhone 3G)<br/><span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/IMG_0275.JPG' /></span> <span class='imgcenter'><img alt='' src='http://files.myopera.com/lunatic/blog/bilde.jpg' /></span><br/><br/>And it even works! ;)<br/><br/>The software I have uploaded to the PIC18F4520 sends all the temperature info, and the 8 general purpose inputs to the computer via a virtual com port on the computer, 20 times a second.</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2009/08/13-input-usb-temperature-sensor-for-pc-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
