<?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>Windows on Last Miles</title>
	<atom:link href="http://dukevisualstudies.org/lastmiles/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://dukevisualstudies.org/lastmiles</link>
	<description>documenting the production and uses of an interactive digital artifact</description>
	<lastBuildDate>Sun, 19 Apr 2009 23:02:35 +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>Last Miles Refactored</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=36</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=36#comments</comments>
		<pubDate>Sun, 19 Apr 2009 23:00:31 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=36</guid>
		<description><![CDATA[After a substantial hiatus, I returned to the Last Miles installations a few months ago, trying to figure out what the next steps might be. The experience with the installation in last spring demonstrated what a challenge issues of internet connectivity can pose. Most available open-source software that coordinates live video, audio, and ssh feeds [...]]]></description>
			<content:encoded><![CDATA[<p>After a substantial hiatus, I returned to the Last Miles installations a few months ago, trying to figure out what the next steps might be. The experience with the installation in last spring demonstrated what a challenge issues of internet connectivity can pose. Most available open-source software that coordinates live video, audio, and ssh feeds just doesn't work well without extremely good internet connections -- and flaky internet connections is all that's available when putting things in public spaces in Durham and Duke.</p>
<p>Yet the idea of having the installation "connect" the user with another place that she or he may or may not be familiar with -- but that is geographically close -- remains compelling. And working with live audio and video created plenty of space for the unexpected to sneak in. <em>Last Miles Refactored</em>, as I'll call this second version, is going to try to preserve as much of the initial vision for the project while making sure that the installation's technological supports are more reliable.</p>
<p>For now my ideas include:</p>
<ul>
<li>Interfacing with <a href="http://www.flickr.com/">Flickr</a> or similar service to pull down photos from Durham of public spaces (this latter may need to be flagged by users themselves)</li>
<li>Better user interface with support for arbitrary display types -- I'm considering <a href="http://www.pygtk.org/">PyGTK</a> or <a href="http://www.pygame.org/">pygame</a>. I'd really like to find something that lets me create nice looking transparent widgets out of the box. I used gtk last time but spent way too much time styling the interface.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=36</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last Miles at HASTAC 2</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=29</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=29#comments</comments>
		<pubDate>Wed, 21 May 2008 23:03:10 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Installation]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[HASTAC 2]]></category>
		<category><![CDATA[HASTAC II]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=29</guid>
		<description><![CDATA[I'll be presenting Last Miles at a poster session at the HASTAC 2 conference at UCLA on Saturday.
For the conference I've revised the project description considerably, adding a bunch of visual aids and updating the description to reflect the current state of the project.
Update 2008-5-6. Here's a photo from the poster session on Saturday:

]]></description>
			<content:encoded><![CDATA[<p>I'll be presenting <em>Last Miles</em> at a poster session at the <a href="http://www.uchri.org/page-home.php?page_id=1289&amp;cat_id=2">HASTAC 2</a> conference at <a href="http://www.uchri.org/page-home.php?page_id=1289&amp;cat_id=2#saturday">UCLA on Saturday</a>.</p>
<p>For the conference I've revised the <a href="http://dukevisualstudies.org/lastmiles/?page_id=2">project description</a> considerably, adding a bunch of visual aids and updating the description to reflect the current state of the project.</p>
<p><strong>Update </strong>2008-5-6. Here's a photo from the poster session on Saturday:</p>
<p><a href="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/06/hastac.jpg"><img class="alignnone size-medium wp-image-35" title="HASTAC II Poster Session" src="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/06/hastac-300x225.jpg" alt="HASTAC II Poster Session" width="300" height="225" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=29</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Successful test of installations</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=25</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=25#comments</comments>
		<pubDate>Mon, 19 May 2008 00:46:59 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Production]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=25</guid>
		<description><![CDATA[Lots of last minutes problems, but around 3:30pm things started working. Thanks to all the volunteers!

]]></description>
			<content:encoded><![CDATA[<p>Lots of last minutes problems, but around 3:30pm things started working. Thanks to all the volunteers!</p>
<p><a href="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/05/installationtest2.png"><img class="alignnone size-full wp-image-27" title="Installation Test, May 15, 2008" src="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/05/installationtest2.png" alt="Installation Test, May 15, 2008" width="500" height="210" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=25</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Public Demo (Beta) Thursday May 15th</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=24</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=24#comments</comments>
		<pubDate>Wed, 14 May 2008 14:06:50 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Production]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=24</guid>
		<description><![CDATA[There will be a public demonstration of a beta version of the project tomorrow, May 15th at 3pm in the John Hope Franklin Center. Everyone is welcome.
]]></description>
			<content:encoded><![CDATA[<p>There will be a public demonstration of a beta version of the project tomorrow, May 15th at 3pm in the John Hope Franklin Center. Everyone is welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=24</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial on Arduino-Python Servo Control</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=23</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=23#comments</comments>
		<pubDate>Sun, 27 Apr 2008 16:04:46 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[arduino]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=23</guid>
		<description><![CDATA[There's a group of folks over at Principia Labs who have documented how to control servos via a python script: Arduino-Python 4-Axis Servo Control &#124; Principia Labs
Their discussion of Ardunio's Serial.read() was especially helpful; it's prompted me to make some changes in my code.
]]></description>
			<content:encoded><![CDATA[<p>There's a group of folks over at Principia Labs who have documented how to control servos via a python script: <a href="http://principialabs.com/arduino-python-4-axis-servo-control/">Arduino-Python 4-Axis Servo Control | Principia Labs</a></p>
<p>Their discussion of Ardunio's <code>Serial.read()</code> was especially helpful; it's prompted me to make some changes in my code.</p>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=23</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arduino and the Wii Nunchuck</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=20</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=20#comments</comments>
		<pubDate>Mon, 21 Apr 2008 00:34:24 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[nunchuck]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wii nunchuck]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=20</guid>
		<description><![CDATA[Seems like a Wii Nunchuck will make a great input device for the project. I'm deeply indebted to folks who have put up such great tutorials on how to do this, Tod E. Kurt in particular.

For anyone interested in using the nunchuck with Arduino, there's a nice adapter piece that allows for a much nicer [...]]]></description>
			<content:encoded><![CDATA[<p>Seems like a Wii Nunchuck will make a great input device for the project. I'm deeply indebted to folks who have put up such great tutorials on how to do this, <a href="http://todbot.com/blog/2007/10/25/boarduino-wii-nunchuck-servo/">Tod E. Kurt in particular</a>.</p>
<p><span id="more-20"></span></p>
<p>For anyone interested in using the nunchuck with Arduino, there's a nice <a href="http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/">adapter</a> piece that allows for a much nicer interface with the nunchuck:<a href="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/wiichuck_adapter1.jpg"><img class="alignnone size-full wp-image-21" title="Wii Nunchuck Adapter" src="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/wiichuck_adapter1.jpg" alt="" width="450" height="338" /></a></p>
<p>Not knowing about the adapter, I cut the cable to get at the cords. It's not pretty (below). Hopefully I'll find a more elegant way to deal with this kind of wire..</p>
<p><a href="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/abr_hack.png"><img class="alignnone size-medium wp-image-22" title="Poor Arduino Nunchuck Interface" src="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/abr_hack-300x225.png" alt="" width="300" height="225" /></a></p>
<p><em>p.s. Here's a <a href="http://www.youtube.com/watch?v=rFN0P7389O8">vid</a> showing the potential of the nunchuck..</em></p>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=20</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Carpentry!</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=14</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=14#comments</comments>
		<pubDate>Wed, 16 Apr 2008 15:33:40 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Production]]></category>
		<category><![CDATA[carpentry]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=14</guid>
		<description><![CDATA[We're building the platforms for the project this week. Here are some pictures from the shop.

]]></description>
			<content:encoded><![CDATA[<p>We're building the platforms for the project this week. Here are some pictures from the shop.</p>
<p><a title="Early stage photo from the scene shop" href="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/sceneshop1.png"><img src="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/sceneshop1.thumbnail.png" alt="Early stage photo from the scene shop" /></a><a title="Further along.." href="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/sceneshop2.png"><img src="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/sceneshop2.thumbnail.png" alt="Further along.." /></a><a title="first platform finished" href="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/carpentry1.png"><img src="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/04/carpentry1.thumbnail.png" alt="first platform finished" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=14</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Two Arduinos Connected By an SSL Relay</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=13</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=13#comments</comments>
		<pubDate>Wed, 16 Apr 2008 15:07:29 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=13</guid>
		<description><![CDATA[A critical part of the project involves allowing one arduino board to communicate with a remote arduino board. Two computers mediate the connection and send the information via a secure connection (SSL). The code is below. At this stage it's very simple, all the action happens in the arduino code. What this python script does [...]]]></description>
			<content:encoded><![CDATA[<p>A critical part of the project involves allowing one arduino board to communicate with a remote arduino board. Two computers mediate the connection and send the information via a secure connection (SSL). The code is below. At this stage it's very simple, all the action happens in the arduino code. What this python script does is take the serial output from one arduino board and feed it into the serial input for the other board. The code below the fold works but I imagine I'll change it before I'm finished, so please check the SVN web repository when I've installed that for the latest code.<br />
<span id="more-13"></span></p>
<p>The first two scripts are for testing, the full version is at bottom, but contains a lot more project-specific code.</p>
<p><strong>simple ssl client</strong></p>
<pre class="python">&nbsp;
<span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Receive number from client where -10 &amp;lt; number &amp;lt; 10.</span>
<span style="color: #808080; font-style: italic;"># Send that number to attached arduino.</span>
<span style="color: #808080; font-style: italic;"># Also receive number from arduino, send that to client. Again, -10 &amp;lt; number &amp;lt; 10</span>
<span style="color: #808080; font-style: italic;"># Log everything.</span>
<span style="color: #808080; font-style: italic;"># SUPERSEDED BY arduino_ssl_relay.py</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">logging</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">from</span> serial <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
<span style="color: #dc143c;">logging</span>.<span style="color: black;">basicConfig</span><span style="color: black;">&#40;</span>level=<span style="color: #dc143c;">logging</span>.<span style="color: black;">DEBUG</span>,
                    format=<span style="color: #483d8b;">'%(asctime)s %(levelname)s %(message)s'</span>,
                    filename=<span style="color: #483d8b;">'ssl_echo_client.log'</span>,
                    filemode=<span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
NAME = <span style="color: #483d8b;">&quot;SSL Echo Client&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span>ip=<span style="color: #483d8b;">'192.168.1.101'</span><span style="color: black;">&#41;</span>:
&nbsp;
	<span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span>NAME + <span style="color: #483d8b;">&quot;started&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
	ser = Serial<span style="color: black;">&#40;</span>port=<span style="color: #483d8b;">&quot;/dev/ttyUSB0&quot;</span>, baudrate=<span style="color: #ff4500;">9600</span><span style="color: black;">&#41;</span>
	<span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Serial startd on &quot;</span> + ser.<span style="color: black;">portstr</span><span style="color: black;">&#41;</span>
&nbsp;
	HOST = ip   <span style="color: #808080; font-style: italic;"># The remote host</span>
	PORT = <span style="color: #ff4500;">50008</span>              <span style="color: #808080; font-style: italic;"># The same port as used by the server</span>
	s = <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span>
	s.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>HOST, PORT<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	<span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Connected to &quot;</span>+HOST+<span style="color: #483d8b;">&quot; at port &quot;</span>+ <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>PORT<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
	data = <span style="color: #483d8b;">'0'</span>
&nbsp;
	s.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Hello, world'</span><span style="color: black;">&#41;</span>
	<span style="color: #808080; font-style: italic;">#ssl_data = s.recv(1024)</span>
	<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
		<span style="color: #ff7700;font-weight:bold;">try</span>:
			line = ser.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>   <span style="color: #808080; font-style: italic;">#read a '\n' terminated line</span>
			<span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;received from arduino: &quot;</span> + line<span style="color: black;">&#41;</span>
			matches = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'log: arduino says computed pot_val: (<span style="color: #000099; font-weight: bold;">\d</span>{1,2})'</span>,line<span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">if</span> matches:
				val = matches.<span style="color: black;">groups</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
				<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>val<span style="color: black;">&#41;</span> &amp;gt; <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>val<span style="color: black;">&#41;</span> &amp;lt; <span style="color: #ff4500;">20</span>:
					olddata = data
					data = val + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
					<span style="color: #ff7700;font-weight:bold;">if</span> data != olddata: <span style="color: #808080; font-style: italic;"># only send if there's a change</span>
						ssl_send = data
						s.<span style="color: black;">send</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
						<span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Sent data to server:&quot;</span> + data<span style="color: black;">&#41;</span>
				<span style="color: #ff7700;font-weight:bold;">else</span>:
					<span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Got an invalid value from arduino: &quot;</span> + val<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">finally</span>:
			<span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Closing sockets&quot;</span><span style="color: black;">&#41;</span>
			s.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			ser.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			<span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Shut down done&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
	main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p><strong>simple ssl echo server</strong></p>
<pre class="python">&nbsp;
<span style="color: #808080; font-style: italic;"># Echo server program</span>
<span style="color: #808080; font-style: italic;"># testing</span>
<span style="color: #808080; font-style: italic;"># SUPERSEDED BY arduino_ssl_relay.py</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">from</span> serial <span style="color: #ff7700;font-weight:bold;">import</span> *
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	HOST = <span style="color: #483d8b;">''</span>                 <span style="color: #808080; font-style: italic;"># Symbolic name meaning the local host</span>
	PORT = <span style="color: #ff4500;">50009</span>              <span style="color: #808080; font-style: italic;"># Arbitrary non-privileged port</span>
	s = <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span>
	s.<span style="color: black;">bind</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>HOST, PORT<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	s.<span style="color: black;">listen</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
	conn, addr = s.<span style="color: black;">accept</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Connected by'</span>, addr
	<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
	    data = conn.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
	    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> data: <span style="color: #ff7700;font-weight:bold;">break</span>
	    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Got data from client'</span>, data
	    conn.<span style="color: black;">send</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># have it echo back whatever it gets until we have two setups</span>
	conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
	main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p><strong>Combined (and a little more project specific</strong></p>
<pre class="python">&nbsp;
<span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># Arduino Serial SSL Relay</span>
<span style="color: #808080; font-style: italic;"># Relays output from one arduino to another arduino via SSL.</span>
<span style="color: #808080; font-style: italic;"># @author: Allen Riddell &lt;http:&gt;</span>
<span style="color: #808080; font-style: italic;"># @date:   2008-03-26</span>
<span style="color: #808080; font-style: italic;"># For the Last Miles Project: http://dukevisualstudies/lastmiles/</span>
<span style="color: #808080; font-style: italic;"># only supports IP4.</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># TODO</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># * more detailed log information (ip address)</span>
<span style="color: #808080; font-style: italic;"># * simplify server and client connection variable (no s and conn, that's confusing)</span>
<span style="color: #808080; font-style: italic;"># * standardized transmission format -- when one has multiple messages (i.e. pot, and others)</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> serial
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">optparse</span> <span style="color: #ff7700;font-weight:bold;">import</span> OptionParser
&nbsp;
<span style="color: #808080; font-style: italic;"># logging</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">logging</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #dc143c;">logging</span>.<span style="color: black;">basicConfig</span><span style="color: black;">&#40;</span>level=<span style="color: #dc143c;">logging</span>.<span style="color: black;">DEBUG</span>,
                    format=<span style="color: #483d8b;">'%(asctime)s %(levelname)s %(message)s'</span>,
                    filename=<span style="color: #483d8b;">'/tmp/arduino_ssl_relay.log'</span>,
                    filemode=<span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#DEBUG: change this to &quot;a&quot; when done</span>
<span style="color: #808080; font-style: italic;"># console logging</span>
console = <span style="color: #dc143c;">logging</span>.<span style="color: black;">StreamHandler</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span><span style="color: black;">&#41;</span>
console.<span style="color: black;">setLevel</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">logging</span>.<span style="color: black;">INFO</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;"># formatter = logging.Formatter('%(message)s')</span>
<span style="color: #808080; font-style: italic;"># console.setFormatter(formatter)</span>
logger = <span style="color: #dc143c;">logging</span>.<span style="color: black;">getLogger</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
logger.<span style="color: black;">addHandler</span><span style="color: black;">&#40;</span>console<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Constants</span>
PORT = <span style="color: #ff4500;">50009</span> <span style="color: #808080; font-style: italic;"># arbitrary ssl port</span>
DEV = <span style="color: #483d8b;">&quot;/dev/ttyUSB0&quot;</span> <span style="color: #808080; font-style: italic;"># port to which arduino is connected. /dev/ttyUSB0 on my linux box.</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span>ip=<span style="color: #483d8b;">''</span>, server=<span style="color: #008000;">True</span>, dev=DEV, port=PORT<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #808080; font-style: italic;"># open serial connection to arduino, fail if not available.</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        ser = serial.<span style="color: black;">Serial</span><span style="color: black;">&#40;</span>port=dev, baudrate=<span style="color: #ff4500;">9600</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> serial.<span style="color: black;">serialutil</span>.<span style="color: black;">SerialException</span>, e : <span style="color: #808080; font-style: italic;"># fix this.</span>
        <span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;couldn't establish serial connection&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Serial connection started on &quot;</span> + ser.<span style="color: black;">portstr</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># open ssl connection, fail if not available.</span>
&nbsp;
    HOST = ip                 <span style="color: #808080; font-style: italic;"># Symbolic name meaning the local host</span>
    PORT = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>port<span style="color: black;">&#41;</span>              <span style="color: #808080; font-style: italic;"># Arbitrary non-privileged port</span>
&nbsp;
    s = <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span>
    mode_name = <span style="color: #483d8b;">&quot;server&quot;</span> <span style="color: #ff7700;font-weight:bold;">if</span> server <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: #483d8b;">&quot;client&quot;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># SERVER SSL Setup</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> server:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            s.<span style="color: black;">bind</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>HOST, PORT<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            s.<span style="color: black;">listen</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Starting &quot;</span> + mode_name + <span style="color: #483d8b;">&quot;, listening for connections.&quot;</span><span style="color: black;">&#41;</span>
            conn, addr = s.<span style="color: black;">accept</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Connected by'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>addr<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">Exception</span>, e:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">critical</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Couldn't establish connection: &quot;</span>+ <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            s.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            ser.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;"># CLIENT SSL Setup</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            s.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>HOST, PORT<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Connected to &quot;</span>+HOST+<span style="color: #483d8b;">&quot; at port &quot;</span>+ <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>PORT<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            s.<span style="color: black;">settimeout</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">error</span>, e:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">critical</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Couldn't establish connection: &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            s.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            ser.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># ssl settings for both</span>
    <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Socket timeout is: &quot;</span>+ <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>s.<span style="color: black;">gettimeout</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>   
&nbsp;
    <span style="color: #808080; font-style: italic;"># main loop</span>
    data = <span style="color: #008000;">None</span>
    sslsend = <span style="color: #483d8b;">'10'</span> + <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #808080; font-style: italic;"># default is to tell the servo not to move '10'</span>
    ssldata = <span style="color: #008000;">None</span>
    line = <span style="color: #008000;">None</span>
    loop_count = <span style="color: #ff4500;">0</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
        <span style="color: #808080; font-style: italic;"># handle serial connection</span>
        <span style="color: #ff7700;font-weight:bold;">try</span>:
<span style="color: #808080; font-style: italic;">#           line = ser.readline()   #read a '\n' terminated line</span>
            line = ser.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">256</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> ser.<span style="color: black;">inWaiting</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> &amp;gt; <span style="color: #ff4500;">256</span>:
                wait = ser.<span style="color: black;">inWaiting</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;serial info ser.inWaiting(): &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>wait<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                line = ser.<span style="color: black;">read</span><span style="color: black;">&#40;</span>ser.<span style="color: black;">inWaiting</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: black;">&#40;</span><span style="color: #008000;">KeyboardInterrupt</span>, <span style="color: #008000;">SystemExit</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">break</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> line:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;received from arduino: &quot;</span> + line<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">-1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># get rid of final '\n'</span>
        matches = <span style="color: #dc143c;">re</span>.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'log: arduino says computed pot_val: (<span style="color: #000099; font-weight: bold;">\d</span>{1,2})'</span>,line<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> matches:
            val = matches<span style="color: black;">&#91;</span><span style="color: #ff4500;">-1</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;"># use last match</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>val<span style="color: black;">&#41;</span> &amp;gt; <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>val<span style="color: black;">&#41;</span> &amp;lt; <span style="color: #ff4500;">20</span>:
                olddata = data
                data = val + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                sslsend = data
<span style="color: #808080; font-style: italic;">#                if data != olddata: # only send if there's a change</span>
<span style="color: #808080; font-style: italic;">#                    sslsend = data</span>
<span style="color: #808080; font-style: italic;">#                else:</span>
<span style="color: #808080; font-style: italic;">#                    sslsend = None</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># first send ssl data &quot;sslsend&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> sslsend:
            <span style="color: #ff7700;font-weight:bold;">try</span>:
                <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;attempting to send ssl data&quot;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> server:
                    conn.<span style="color: black;">send</span><span style="color: black;">&#40;</span>sslsend<span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                    s.<span style="color: black;">send</span><span style="color: black;">&#40;</span>sslsend<span style="color: black;">&#41;</span>
                <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sent ssl data:&quot;</span> + sslsend<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">-1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">timeout</span>, e:
                <span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;failed to send ssl data:&quot;</span> + sslsend<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">-1</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;, error: &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">continue</span>
            <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">error</span>, e:
                <span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;failed to send ssl data:&quot;</span> + sslsend<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">-1</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;, error: &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">break</span>
        <span style="color: #808080; font-style: italic;"># receive ssl data &quot;ssldata&quot;</span>
        oldssldata = ssldata
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;attempting to receive ssl data&quot;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> server:
                ssldata = conn.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                ssldata = s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> ssldata:
                <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;received ssl data:&quot;</span> + ssldata<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">-1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">timeout</span>, e:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;failed to receive ssl data, error: &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">continue</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">error</span>, e:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">critical</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;failed to receive ssl data, error: &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">break</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: black;">&#40;</span><span style="color: #008000;">KeyboardInterrupt</span>, <span style="color: #008000;">SystemExit</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">break</span>
        <span style="color: #808080; font-style: italic;"># send ssldata to arduino</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> ssldata:
            ssldata = ssldata<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">-1</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;">#strip \n -- maybe use string.rstrip(os.linesep)</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> ssldata != oldssldata <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>ssldata<span style="color: black;">&#41;</span> &amp;lt; <span style="color: #ff4500;">3</span>:
                <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>ssldata<span style="color: black;">&#41;</span> &amp;gt; <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>ssldata<span style="color: black;">&#41;</span> &amp;lt; <span style="color: #ff4500;">20</span>:
                    ser.<span style="color: black;">write</span><span style="color: black;">&#40;</span>ssldata + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
                    <span style="color: #dc143c;">logging</span>.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sent arduino ssl data:&quot;</span> + ssldata<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #dc143c;">logging</span>.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;didn't receive data from remote connection&quot;</span><span style="color: black;">&#41;</span>
        loop_count += <span style="color: #ff4500;">1</span>
    <span style="color: #808080; font-style: italic;"># shut down, close connections</span>
    <span style="color: #dc143c;">logging</span>.<span style="color: black;">critical</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;shutting down, closing sockets&quot;</span><span style="color: black;">&#41;</span>
    s.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    ser.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> parseOpts<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #dc143c;">parser</span> = OptionParser<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;-c&quot;</span>, <span style="color: #483d8b;">&quot;--client&quot;</span>, dest=<span style="color: #483d8b;">&quot;mode&quot;</span>,
                      default=SERVER,
                      <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;run in client mode (provide an IP to connect to) (IP4 only)&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_args</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>        
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    usage = <span style="color: #483d8b;">&quot;usage: %prog [options] ip_address&quot;</span>
    <span style="color: #dc143c;">parser</span> = OptionParser<span style="color: black;">&#40;</span>usage=usage<span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;-d&quot;</span>, <span style="color: #483d8b;">&quot;--device&quot;</span>, dest=<span style="color: #483d8b;">&quot;dev&quot;</span>, default=DEV,
                      <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;Use an alternate serial device. Default is: &quot;</span>+DEV<span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;-p&quot;</span>, <span style="color: #483d8b;">&quot;--port&quot;</span>, dest=<span style="color: #483d8b;">&quot;port&quot;</span>, default=PORT,
                      <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;Use an alternate port. Default is: &quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>PORT<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: black;">&#40;</span>options, args<span style="color: black;">&#41;</span> = <span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_args</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> args:
        main<span style="color: black;">&#40;</span>dev=options.<span style="color: black;">dev</span>,ip=args<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>,port=options.<span style="color: black;">port</span>,server=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        main<span style="color: black;">&#40;</span>dev=options.<span style="color: black;">dev</span>,port=options.<span style="color: black;">port</span><span style="color: black;">&#41;</span>
&lt;/http:&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=13</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling a Parallax (Futaba) Continuous Rotation Servo with Arduino</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=11</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=11#comments</comments>
		<pubDate>Sat, 15 Mar 2008 01:36:40 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[basic stamp]]></category>
		<category><![CDATA[continuous rotation servo]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=11</guid>
		<description><![CDATA[So there's a presentation on controlling a basic servo at ITP on the very subject: class 3 (communication, servos, and pwm). As luck would have it, I have a continuous rotation servo, which functions a bit differently than the servo described in the presentation. In short, both types of servos use pulse width modulation (PWM) [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Parallax (Futaba) Continuous Rotation Servo" href="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/03/servo.jpg"><img src="http://dukevisualstudies.org/lastmiles/wp-content/uploads/2008/03/servo.thumbnail.jpg" alt="Parallax (Futaba) Continuous Rotation Servo" align="right" /></a>So there's a presentation on controlling a basic servo at ITP on the very subject: <a class="urllink" rel="nofollow" href="http://todbot.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class3.pdf">class 3 (communication, servos, and pwm)</a>. As luck would have it, I have a <a href="http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/List/1/ProductID/102/Default.aspx">continuous rotation servo</a>, which functions a bit differently than the servo described in the presentation. In short, both types of servos use pulse width modulation (PWM) but the continuous rotation servo operates in terms of a "set point" and left and right rotation. You can also control speed.</p>
<p><strong>UPDATE 2008-8-3:</strong> We ended up using "normal" (i.e. non-continuous) servos. So things work a bit differently now.</p>
<p><span id="more-11"></span>The servo is pictured above. I found <a href="http://www.parallax.com/Portals/0/Downloads/docs/prod/motors/crservo.pdf">a pdf with specifications and Basic Stamp</a> code on Parallax's web site. From the instructions I figured out the important numbers. The servo wants intervals of 20ms and pulse widths of 1.5ms if it's going to do nothing. Widths greater than 1.5ms turn the servo counterclockwise, widths lower than 1.5ms turn the servo clockwise. When the servo is receiving 1.5ms width pulses, it's possible to adjust the set point with a tiny Phillips screw driver.</p>
<p>Here's my translation of BASIC Stamp 1 code into Arduino. The code should make the servo stay still, rotate left, rotate right (and repeat).</p>
<p><strong>Basic Stamp 1 code</strong><br />
<code><br />
SYMBOL Temp = W0           'Work space for FOR NEXT<br />
SYMBOL Servo_pin   = 0     'I/O pin that is connected to servo<br />
FOR temp = 0 TO 200 '<br />
PULSOUT Servo_pin,150<br />
PAUSE 20<br />
NEXT<br />
FOR temp = 0 TO 200<br />
PULSOUT Servo_pin,180<br />
PAUSE 20<br />
NEXT<br />
FOR temp = 0 TO 200<br />
PULSOUT Servo_pin,120<br />
PAUSE 20<br />
NEXT<br />
Stop<br />
</code></p>
<p><strong>Arduino</strong></p>
<p><code><br />
int servoPin = 7;<br />
void setup()<br />
{<br />
pinMode(servoPin,OUTPUT);<br />
}<br />
void loop()<br />
{<br />
int temp;<br />
for (temp = 0; temp &lt;= 200; temp++)<br />
{<br />
digitalWrite(servoPin,HIGH);<br />
delayMicroseconds(1500); // 1.5ms<br />
digitalWrite(servoPin,LOW);<br />
delay(20); // 20ms<br />
}<br />
for (temp = 0; temp &lt;= 200; temp++)<br />
{<br />
digitalWrite(servoPin,HIGH);<br />
delayMicroseconds(1800); // 1.8ms<br />
digitalWrite(servoPin,LOW);<br />
delay(20); // 20ms<br />
}<br />
for (temp = 0; temp &lt;= 200; temp++)<br />
{<br />
digitalWrite(servoPin,HIGH);<br />
delayMicroseconds(1200); // 1.2ms<br />
digitalWrite(servoPin,LOW);<br />
delay(20); // 20ms<br />
}<br />
}<br />
</code></p>
<p>That's it!</p>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=11</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Learning Arduino, AMD64 Ubuntu NBs</title>
		<link>http://dukevisualstudies.org/lastmiles/?p=8</link>
		<comments>http://dukevisualstudies.org/lastmiles/?p=8#comments</comments>
		<pubDate>Tue, 04 Mar 2008 00:51:48 +0000</pubDate>
		<dc:creator>Allen</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[amd64]]></category>
		<category><![CDATA[arduino]]></category>

		<guid isPermaLink="false">http://dukevisualstudies.org/lastmiles/?p=8</guid>
		<description><![CDATA[First hiccup I encountered was that the Arduino software doesn't run out of the box on an AMD64 platform (i.e. my desktop). Thankfully Tero Karvinen has a quick HOWTO on making the Arduino IDE run on an AMD64.
Got through the "Hello World" equivalent for Arduino, i.e. make an LED flash. Next on my list was [...]]]></description>
			<content:encoded><![CDATA[<p>First hiccup I encountered was that the Arduino software doesn't run out of the box on an AMD64 platform (i.e. my desktop). Thankfully <a href="http://myy.helia.fi/~karte/index.html">Tero Karvinen</a> has a quick <a href="http://myy.helia.fi/~karte/arduino_editor_on_64_bit_ubuntu_gutsy.html">HOWTO on making the Arduino IDE run on an AMD64</a>.</p>
<p>Got through the "Hello World" equivalent for Arduino, i.e. make an LED flash. Next on my list was getting the servomotor to move. As luck would have it there's a presentation from ITP on the very subject: <a class="urllink" rel="nofollow" href="http://todbot.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class3.pdf">class 3 (communication, servos, and pwm)</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dukevisualstudies.org/lastmiles/?feed=rss2&amp;p=8</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
