<?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>eval.nu blog &#187; Python</title>
	<atom:link href="http://eval.nu/blog/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://eval.nu/blog</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 10:08:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Managing your music library and digital audio player with musync</title>
		<link>http://eval.nu/blog/2010/03/05/managing-your-music-library-and-digital-audio-player-with-musync/</link>
		<comments>http://eval.nu/blog/2010/03/05/managing-your-music-library-and-digital-audio-player-with-musync/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 10:56:24 +0000</pubDate>
		<dc:creator><span property="dc:creator" resource="http://eval.nu/blog/2010/03/05/managing-your-music-library-and-digital-audio-player-with-musync/">Albin</span></dc:creator>
				<category><![CDATA[in English]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[musync]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://eval.nu/blog/?p=274</guid>
		<description><![CDATA[One of my few (or rather: my only) successful programmi [...]]]></description>
			<content:encoded><![CDATA[<p>One of my few (or rather: my <em>only</em>) successful programming projects is musync. It began as a weekend hack to solve the growing problem of how to selectively synchronize music to my portable digital audio player into a somewhat coherent file/directory structure.</p>

<p>Shortly after musync became practically usable, however, <a href="http://github.com/udoprog">udoprog</a> started hacking on it, and <a href="http://github.com/udoprog/musync">the current version</a> is only loosely related to my old code (that was, for all I know, lost &#8212; for the better I believe). My current role in musync&#8217;s development is more or less reduced to finding bugs and hammering udo on IRC until he fixes them.</p>

<p>So, what musync does is it takes a number of music files (or folders if running in recursive mode) runs a specified command to add them to the file/folder structure according to a given rule, optionally filtering and/or replacing non-wanted characters in the process. The file-folder structure may for example be »artist/album/NN-title.ext«, and the add command could be simply copying the files.</p>

<p>But starting with recent musync versions, commands are Python lambda expressions, and can thus mean running several commands in sequence per file; I, for example, have my add command set to both copying the files to their calculated targets and then telling <a href="http://wiki.xmms2.xmms.se/wiki/Main_Page">xmms2</a>, my music player, to add them to its database. Here&#8217;s a code snippet for the relevant parts of musync.conf:
<code> </code>
<pre>[site]
root:           "/var/storage/Musik"
xmms2_sync_lib: lambda file: m.execute("/usr/bin/nyxmms2", "server", "import", file)
add:            lambda src, dest: (sh.copy(src, dest), xmms2_sync_lib(dest))</pre>
The rest of the file is, more or less, <a href="http://github.com/udoprog/musync/blob/master/share/musync.conf">the sample configuration file</a>; <code>sh</code> and <code>m</code> are imported in the <code>[import]</code> section as explained there, among other things, and they provide musync&#8217;s helper functions and the Python <code>shutil</code> library respectively.</p>

<p>To add newly ripped or downloaded music to my collection with musync, all I now need to do is running <code>musync -c site add &lt;files or directories&gt;</code>.</p>

<p>Other uses would include transferring music files (or directories) to a music player, optionally transcoding them to a format of choice in the process  (I keep my collection mostly in FLAC but transcode it to vorbis to save space when I put it on my DAP), maintaining multiple different directory structures of the same music files using (symbolic-) links or making a »shadow root« with sorted symbolic links to unsorted originals still left in the downloads/incoming directory.</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://eval.nu/blog/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://eval.nu/blog/2010/03/05/managing-your-music-library-and-digital-audio-player-with-musync/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Winky, an arduino-based temperature logger: project plan</title>
		<link>http://eval.nu/blog/2010/01/06/winky-an-arduino-based-temperature-logger-project-plan/</link>
		<comments>http://eval.nu/blog/2010/01/06/winky-an-arduino-based-temperature-logger-project-plan/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 00:12:47 +0000</pubDate>
		<dc:creator><span property="dc:creator" resource="http://eval.nu/blog/2010/01/06/winky-an-arduino-based-temperature-logger-project-plan/">Albin</span></dc:creator>
				<category><![CDATA[in English]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[Makefile]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Open hardware]]></category>
		<category><![CDATA[PIC-based temperature monitor/logger]]></category>
		<category><![CDATA[plans]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://eval.nu/blog/?p=139</guid>
		<description><![CDATA[I spent New Year's with my cousins (also known as T [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_144" class="wp-caption alignleft" style="width: 347px"><a href="http://eval.nu/blog/wp-content/uploads/2010/01/winky.jpg"><img class="size-full wp-image-144" title="winky" src="http://eval.nu/blog/wp-content/uploads/2010/01/winky.jpg" alt="An early version of winky, an arduino-based temperature logger." width="337" height="586" /></a><p class="wp-caption-text">I know my camera&#39;s horrible.</p></div>

<p>I spent New Year&#8217;s with my cousins (also known as <a href="http://www.last.fm/music/The+Swedish+Shortsnouts">The Swedish Shortsnouts</a>), where I came in contact with a project of their father&#8217;s, a PIC-based temperature monitor/logger named Dobby. When I returned home, I felt rather inspired, and dug up my <a href="http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove">Arduino Duemilanove</a> and a <a href="http://www.sensirion.com/en/01_humidity_sensors/03_humidity_sensor_sht15.htm">SHT15 sensor</a> I bought earlier.</p>

<p>At this point, I&#8217;d like to mention I had some rather bad experiences with micro controllers (and don&#8217;t get me started on interrupts!) during my time at <a href="http://en.wikipedia.org/wiki/Royal_Institute_of_Technology">The RIOT</a>, and I haven&#8217;t exactly been keen on hardware hacking since then. Low-level work never suited my short attention span. If I have to think about memory allocation or pin voltages I&#8217;m quickly loosing sight the big picture, and end up making <a href="http://en.wikipedia.org/wiki/List_of_The_Big_Bang_Theory_episodes#Season_1:_2007-08">luminous fish</a> in stead. Or, to take an example from reality, researching the possibility of keeping pet jellyfish.</p>

<p>Fortunately, after a quick WWW search, I found both <a href="http://www.glacialwanderer.com/hobbyrobotics/?p=5">wiring shemes</a> and <a href="http://github.com/practicalarduino/SHT1x">a library for communication with the SHT15</a>. The hard part turned out to be getting the code onto the Arduino, since the IDE is Java-based, and Swing is written by people who clearly know nothing about the X windowing system and since the command-line approach for code uploading is heavily based on a semi-official Makefile that was apparently dropped from the recent versions of the Arduino SDK because it didn&#8217;t really work and nobody bothered fixing it.</p>

<p>Thanks to <a href="http://tools.suckless.org/wmname">wmname</a> (Suckless to the rescue­­­ as usual!), recommended in <a href="http://identi.ca/notice/18112162">a helpful dent</a>, I got the official IDE working. It&#8217;s really nothing I&#8217;d like to spend much time in, but it works for loading code and communicating over the USB TTY, which was all I needed.</p>

<p>So now I&#8217;ve got some rather messy code to log temperatures from the Arduino and send them once every second to anything listening on the USB TTY. Which happens to be a small, also rather messy Python program that logs the temperature and humidity in a text file with a Unix time stamp. This file is then read by a second Python program, using <a href="http://matplotlib.sourceforge.net/">mathplotlib</a>. My error handling is horrible: I just let Python disregard any non-sane values (i.e. any where string-&gt;float conversion of the incoming data fails or where the values are clearly invalid), but it works. Rather well, I might add.</p>

<p>However, my goal is a much more stand-alone-ish logging device, so I&#8217;ve set up a project plan to try to keep my focus at least somewhat intact.</p>

<ol>
    <li>Try soldering the sensor, and connect it with network (RJ 45?) connectors. Make sure it&#8217;s working.</li>
    <li>Add a RTC module and make sure it&#8217;s working. Have Winky time stamp its own messages, in stead of the PC doing it as it&#8217;s recieving them.</li>
    <li>Implement an administrational interface for the USB serial console.</li>
    <li>JSON-encode the data. Preferrably through some already existing library.</li>
    <li>Fix persistent data storage somehow
<ol>
    <li>Find a suitable physical storage medium (probably SD or CF)</li>
    <li>Implement it. Probably without FAT or any other file system.</li>
    <li>Make sure space is being re-used, i.e. when the medium is full, the oldest stored entries are automatically replaced with the newest. Without messing up the output order, of course (possibly, this could be fixed by sorting on time stamps during print-out).</li>
</ol>
</li>
    <li>Buy or make an <a href="http://www.arduino.cc/en/Main/ArduinoEthernetShield">ethernet shield</a> and get it to work. DHCP may be needed. Implement as much HTTP as required to hand over the logs in JSON, and not a single line of code more. Somewhat RESTful:y.</li>
    <li>Buy a new or convert an old separate power supply.</li>
    <li>Find a suitable box. An old hub, router or switch is probably perfect.</li>
    <li>Make it work with a variable number of sensors.
<ol>
    <li>How are these supposed to be detected?</li>
    <li>Should I just try to initiate all sensors, and skip those that fail?</li>
    <li>What about plug-and-play? Writing code to continuously loop to see if there&#8217;s a new sensor attached isn&#8217;t really my idea of fun.</li>
</ol>
</li>
    <li>Write some cool client code, perhaps real-time graphing with Javascript? There&#8217;s probably a library for that. I hope. Or else I will have to rely on <a href="http://github.com/udoprog">Udoprog</a> writing me one for cookies.</li>
</ol>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '10996';
var flattr_url = 'http://eval.nu/blog';
var flattr_lng = 'sv_SE';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'eval.nu blog';
var flattr_dsc = '';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://eval.nu/blog/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://eval.nu/blog/2010/01/06/winky-an-arduino-based-temperature-logger-project-plan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.271 seconds -->
