<?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>John Roach &#187; embedded device</title>
	<atom:link href="http://johnroach.info/tag/embedded-device/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnroach.info</link>
	<description>Coding for life</description>
	<lastBuildDate>Wed, 25 Apr 2012 07:48:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Blinking lights MSP430 FG461x</title>
		<link>http://johnroach.info/2011/05/14/blinking-lights-msp430-fg461x/</link>
		<comments>http://johnroach.info/2011/05/14/blinking-lights-msp430-fg461x/#comments</comments>
		<pubDate>Sat, 14 May 2011 15:16:23 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[embedded device]]></category>
		<category><![CDATA[homework]]></category>
		<category><![CDATA[john roach]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[msp430]]></category>
		<category><![CDATA[texas instruments]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=576</guid>
		<description><![CDATA[I have been working on MSP430 for sometime now. It is an TI (Texas Instruments ) chip. Very fun to play with. We are using a MSP430FG461x series experimental board. This little experimental board has all the bells and whistles &#8230; <a href="http://johnroach.info/2011/05/14/blinking-lights-msp430-fg461x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 310px"><a href="http://commons.wikipedia.org/wiki/File:MSP430-experimenter_boards.jpg"><img title="Photo of two experimenter boards for the MSP43..." src="http://upload.wikimedia.org/wikipedia/commons/thumb/7/71/MSP430-experimenter_boards.jpg/300px-MSP430-experimenter_boards.jpg" alt="Photo of two experimenter boards for the MSP43..." width="300" height="377" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>I have been working on <a class="zem_slink" title="TI MSP430" rel="wikipedia" href="http://en.wikipedia.org/wiki/TI_MSP430">MSP430</a> for sometime now. It is an TI (<a class="zem_slink" title="Texas Instruments" rel="geolocation" href="http://maps.google.com/maps?ll=32.909256,-96.751054&amp;spn=0.01,0.01&amp;q=32.909256,-96.751054 (Texas%20Instruments)&amp;t=h">Texas Instruments</a> ) chip. Very fun to play with. We are using a MSP430FG461x series experimental board. This little experimental board has all the bells and whistles one may need to create any application from a <a class="zem_slink" title="Home automation" rel="wikipedia" href="http://en.wikipedia.org/wiki/Home_automation">home automation</a> controller to a simple step-motor driver. TI provides very good documentation for this grown up toy.</p>
<p>Our first lab homework for this baby was :</p>
<blockquote><p>By using the MSP430 FG4618 Microcontroller, write a program that controls the LED #1, #2,#4.When we perpetually push the two buttons at the right bottom corner of the board, all ofthe LEDs turn on.When we push perpetually one of the buttons, only the LED #4 blinks, the others turn off.When we push no buttons, the LED #1 and #2 blinks complementarily and the LED#4 turnsoff.</p></blockquote>
<p>My biggest problem with this exercise was to find what led was connected to what port. However in the end I figured it all out.</p>
<p>Below you will find the program :</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<pre name="code" class="c++">#include &lt;msp430xG46x.h&gt;

void initPortPins(void);

void main(void)
{
	 WDTCTL=WDTPW + WDTHOLD;
	 initPortPins();
	 while(1) {
	 	if (P1IN == (0x00))
	 	{
			P2OUT |= 0x06;
			P5OUT |= 0x02;
		}
		else if (P1IN == 0x03)
		{
			P2OUT &amp;= 0x00;
			P5OUT &amp;= 0x00;
			P2OUT |= 0x02;
			__delay_cycles (40000);
			P2OUT &amp;= 0x00;
			P2OUT |= 0x04;
			__delay_cycles (40000);
		}
		else
		{
			P2OUT &amp;= 0x00;
			P5OUT &amp;= 0x00;
			__delay_cycles (40000);
			P5OUT |= 0x02;
			__delay_cycles (40000);
		}
	 }
};

void initPortPins(void)
{
  P1DIR = 0x00;	// Set P2.2,1 as outputs
  P5DIR = 0x02; // Set P5.1 as output
  P2DIR = 0x06; // Set P2.1 to 1
};</pre>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/05/14/blinking-lights-msp430-fg461x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Ångström Linux on BeagleBoard</title>
		<link>http://johnroach.info/2009/11/27/installing-angstrom-linux-on-beagleboard/</link>
		<comments>http://johnroach.info/2009/11/27/installing-angstrom-linux-on-beagleboard/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 07:57:21 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[ip home automation project]]></category>
		<category><![CDATA[angstrom]]></category>
		<category><![CDATA[beagleboard]]></category>
		<category><![CDATA[embedded device]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[paramiko]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sd card]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=164</guid>
		<description><![CDATA[We have been able to install Ångström Linux to our beagle board. Ran into couple problems. The first one was we trusted BeagleBoard Beginners wiki just too much!! You see we learned that we should NOT set any environment variables while using &#8230; <a href="http://johnroach.info/2009/11/27/installing-angstrom-linux-on-beagleboard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We have been able to install Ångström Linux to our beagle board. Ran into couple problems. The first one was we trusted <a title="BeagleBoardBeginners Wiki" href="http://elinux.org/BeagleBoardBeginners" target="_blank">BeagleBoard Beginners</a> wiki just too much!!</p>
<p>You see we learned that we should NOT set any environment variables while using demo u-boot image which was downloaded from <a title="Angstrom demo images" href="http://www.angstrom-distribution.org/demo/beagleboard/" target="_blank">here</a>. In fact what we did is we created our own Ångström image (from Ångström site) and simply installed that to our Linux partition of our SDHC card. And it worked beautifully. Though I must say first boot is a drag, very very slow.</p>
<p><span id="more-164"></span></p>
<p>Ran to some problems again. It seems BeagleBoard only works with DVI-D LCD&#8217;s and we had a HDMI to VGA instead of a HDMI to DVI-D cable.We ended up connecting to it from SSH and installing our programs like that. We really don&#8217;t need an LCD any time soon. And to connect to it from SSH we had to learn it&#8217;s IP from terminal. So no problems there. And we were very happy with the outcome.</p>
<div class="flashalbum" style="width:100%;height:500px;">
<div class="flagallery_swfobject" id="sid_875007029_div"><style type="text/css">
@import url("http://johnroach.info/wp-content/plugins/flash-album-gallery/admin/css/flagallery_nocrawler.css");@import url("http://johnroach.info/wp-content/plugins/flash-album-gallery/admin/css/flagallery_noflash.css");
#fancybox-title-over .title { color: #ff9900; }
#fancybox-title-over .descr { color: #cfcfcf; }
.flag_alternate .flagcatlinks { background-color: #292929; }
.flag_alternate .flagcatlinks a.flagcat { border-color: #ffffff; color: #ffffff; background-color: #292929; }
.flag_alternate .flagcatlinks a.flagcat:hover { border-color: #ffffff; }
.flag_alternate .flagcatlinks a.active, .flag_alternate .flagcatlinks a.flagcat:hover { color: #ffffff; background-color: #737373; }
	.flag_alternate .flagcategory a.flag_pic_alt { background-color: #ffffff; border: 2px solid #ffffff; color: #ffffff; }
.flag_alternate .flagcategory a.flag_pic_alt:hover { background-color: #ffffff; border: 2px solid #4a4a4a; color: #4a4a4a; }
.flag_alternate .flagcategory a.flag_pic_alt.current, .flag_alternate .flagcategory a.flag_pic_alt.last { border-color: #4a4a4a; }
</style>
	<script type="text/javascript">var ExtendVar='fancybox', hitajax = 'http://johnroach.info/wp-content/plugins/flash-album-gallery/lib/hitcounter.php';</script>
	<div id="sid_875007029_jq" class="flag_alternate">
		<div class="flagcatlinks"></div>
			<div class="flagCatMeta">
			<h4>angstrombeagleboard</h4>
			<p></p>
		</div>
		<div class="flagcategory" id="gid_4_sid_875007029">
			<a class="i0 flag_pic_alt" href="http://johnroach.info/wp-content/flagallery/angstrombeagleboard/angstrom.png" id="flag_pic_5" rel="gid_4_sid_875007029" title="">[img src=http://johnroach.info/wp-content/flagallery/angstrombeagleboard/thumbs/thumbs_angstrom.png]<span class="flag_pic_desc" id="flag_desc_5"><strong></strong><br /><span></span></span></a><a class="i1 flag_pic_alt" href="http://johnroach.info/wp-content/flagallery/angstrombeagleboard/image000.jpg" id="flag_pic_6" rel="gid_4_sid_875007029" title="">[img src=http://johnroach.info/wp-content/flagallery/angstrombeagleboard/thumbs/thumbs_image000.jpg]<span class="flag_pic_desc" id="flag_desc_6"><strong></strong><br /><span></span></span></a><a class="i2 flag_pic_alt" href="http://johnroach.info/wp-content/flagallery/angstrombeagleboard/image001.jpg" id="flag_pic_8" rel="gid_4_sid_875007029" title="">[img src=http://johnroach.info/wp-content/flagallery/angstrombeagleboard/thumbs/thumbs_image001.jpg]<span class="flag_pic_desc" id="flag_desc_8"><strong></strong><br /><span></span></span></a>		</div>
	</div>

</div></div>
<script type="text/javascript" defer="defer">
flag_alt['sid_875007029'] = jQuery("div#sid_875007029_jq").clone().wrap(document.createElement('div')).parent().html();
var sid_875007029_div = {
	params : {
		wmode : "opaque",
		allowfullscreen : "true",
		allowScriptAccess : "always",
		saling : "lt",
		scale : "noScale",
		menu : "false",
		bgcolor : "#262626"},
	flashvars : {
		path : "http://johnroach.info/wp-content/plugins/flagallery-skins/default/",
		gID : "4",
		galName : "Gallery",
		skinID : "sid_875007029",
		postID : "164",
		postTitle : "Installing+%C3%85ngstr%C3%B6m+Linux+on+BeagleBoard+"},
	attr : {
		styleclass : "flashalbum",
		id : "sid_875007029"},
	start : function() {
		swfobject.embedSWF("http://johnroach.info/wp-content/plugins/flagallery-skins/default/gallery.swf", "sid_875007029_div", "100%", "100%", "10.1.52", "http://johnroach.info/wp-content/plugins/flash-album-gallery/skins/expressInstall.swf", this.flashvars, this.params , this.attr );
swfobject.createCSS("#sid_875007029","outline:none");
	}
}
sid_875007029_div.start();
</script>
<p>Installing python libraries; as installing python libraries go this one was a little tricky. You see it seems that Ångström doesn&#8217;t update its python libs that frequently. So calling the package by</p>
<p><code>opkg intall python-pycrypto</code></p>
<p>Didn&#8217;t quite work since installed itself to python2.5 directory. Had to install pycrypto manually. I hated every moment of it. I  than uploaded my own program and I was very happy with the outcome. The program worked perfectly.</p>
<p>Stay tuned for more updates on The Black Box project! Remember you can find it at<a href="http://sourceforge.net/projects/theblackbox/">http://sourceforge.net/projects/theblackbox/</a> .</p>
<p>Live coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2009/11/27/installing-angstrom-linux-on-beagleboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The BeagleBoard Has Arrived!!</title>
		<link>http://johnroach.info/2009/11/12/the-beagleboard-has-arrived/</link>
		<comments>http://johnroach.info/2009/11/12/the-beagleboard-has-arrived/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 09:16:08 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[ip home automation project]]></category>
		<category><![CDATA[beagleboard]]></category>
		<category><![CDATA[cvs]]></category>
		<category><![CDATA[embedded device]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sd card]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=116</guid>
		<description><![CDATA[The long awaited Beagle board has arrived. Even tough the team&#8217;s enthusiasm was up the roof we were not able to try it out. More on this later. I would also like to inform all people who is following this &#8230; <a href="http://johnroach.info/2009/11/12/the-beagleboard-has-arrived/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The long awaited Beagle board has arrived.<br />
<center><div class="flashalbum" style="width:100%;height:500px;">
<div class="flagallery_swfobject" id="sid_546964516_div"><style type="text/css">
@import url("http://johnroach.info/wp-content/plugins/flash-album-gallery/admin/css/flagallery_nocrawler.css");@import url("http://johnroach.info/wp-content/plugins/flash-album-gallery/admin/css/flagallery_noflash.css");
#fancybox-title-over .title { color: #ff9900; }
#fancybox-title-over .descr { color: #cfcfcf; }
.flag_alternate .flagcatlinks { background-color: #292929; }
.flag_alternate .flagcatlinks a.flagcat { border-color: #ffffff; color: #ffffff; background-color: #292929; }
.flag_alternate .flagcatlinks a.flagcat:hover { border-color: #ffffff; }
.flag_alternate .flagcatlinks a.active, .flag_alternate .flagcatlinks a.flagcat:hover { color: #ffffff; background-color: #737373; }
	.flag_alternate .flagcategory a.flag_pic_alt { background-color: #ffffff; border: 2px solid #ffffff; color: #ffffff; }
.flag_alternate .flagcategory a.flag_pic_alt:hover { background-color: #ffffff; border: 2px solid #4a4a4a; color: #4a4a4a; }
.flag_alternate .flagcategory a.flag_pic_alt.current, .flag_alternate .flagcategory a.flag_pic_alt.last { border-color: #4a4a4a; }
</style>
	<script type="text/javascript">var ExtendVar='fancybox', hitajax = 'http://johnroach.info/wp-content/plugins/flash-album-gallery/lib/hitcounter.php';</script>
	<div id="sid_546964516_jq" class="flag_alternate">
		<div class="flagcatlinks"></div>
			<div class="flagCatMeta">
			<h4>BeagleBoardArrival</h4>
			<p></p>
		</div>
		<div class="flagcategory" id="gid_1_sid_546964516">
			<a class="i0 flag_pic_alt" href="http://johnroach.info/wp-content/flagallery/beagleboardarrival/image023.jpg" id="flag_pic_1" rel="gid_1_sid_546964516" title="">[img src=http://johnroach.info/wp-content/flagallery/beagleboardarrival/thumbs/thumbs_image023.jpg]<span class="flag_pic_desc" id="flag_desc_1"><strong></strong><br /><span></span></span></a><a class="i1 flag_pic_alt" href="http://johnroach.info/wp-content/flagallery/beagleboardarrival/image025.jpg" id="flag_pic_2" rel="gid_1_sid_546964516" title="">[img src=http://johnroach.info/wp-content/flagallery/beagleboardarrival/thumbs/thumbs_image025.jpg]<span class="flag_pic_desc" id="flag_desc_2"><strong></strong><br /><span></span></span></a>		</div>
	</div>

</div></div>
<script type="text/javascript" defer="defer">
flag_alt['sid_546964516'] = jQuery("div#sid_546964516_jq").clone().wrap(document.createElement('div')).parent().html();
var sid_546964516_div = {
	params : {
		wmode : "opaque",
		allowfullscreen : "true",
		allowScriptAccess : "always",
		saling : "lt",
		scale : "noScale",
		menu : "false",
		bgcolor : "#262626"},
	flashvars : {
		path : "http://johnroach.info/wp-content/plugins/flagallery-skins/default/",
		gID : "1",
		galName : "Gallery",
		skinID : "sid_546964516",
		postID : "116",
		postTitle : "The+BeagleBoard+Has+Arrived%21%21+"},
	attr : {
		styleclass : "flashalbum",
		id : "sid_546964516"},
	start : function() {
		swfobject.embedSWF("http://johnroach.info/wp-content/plugins/flagallery-skins/default/gallery.swf", "sid_546964516_div", "100%", "100%", "10.1.52", "http://johnroach.info/wp-content/plugins/flash-album-gallery/skins/expressInstall.swf", this.flashvars, this.params , this.attr );
swfobject.createCSS("#sid_546964516","outline:none");
	}
}
sid_546964516_div.start();
</script></center><br />
Even tough the team&#8217;s enthusiasm was up the roof we were not able to try it out. More on this later. I would also like to inform all people who is following this blog religiously that our project is now hosted on SourceForge.net at <a title="SourceForge.net link" href="http://sourceforge.net/projects/theblackbox/" target="_blank">http://sourceforge.net/projects/theblackbox/</a> . And I have also set up a CVS so those who want to follow the code will be able to follow it from the net.</p>
<p>The CVS code is as follows</p>
<p><code>cvs -d:pserver:anonymous@theblackbox.cvs.sourceforge.net:/cvsroot/theblackbox login</code></p>
<p><code> </code></p>
<p><code>cvs -z3 -d:pserver:anonymous@theblackbox.cvs.sourceforge.net:/cvsroot/theblackbox co -P modulename</code></p>
<p>I am sorry to say due to some weird problem you can not view the CVS modules from Sourceforge. You will need to use some kind of client. I am currently using Eclipse as my development IDE hence all my CVS materials comes from that. I have heard that TortoiseCVS is quite neat in its own way (for Windows) but I&#8217;d rather use Eclipse your choice.</p>
<p><span id="more-116"></span>Please feel free to be a part of the project. Warning us of any bugs will be rewarded with a Cookie.</p>
<p>Now back to the BeagleBoard was indeed a great buy. Small and fast. Though the peripherals cost us quite much. We installed Angstrom Linux  distribution. Which could be found at <a title="Angstrom Distro Site" href="http://www.angstrom-distribution.org/" target="_blank">http://www.angstrom-distribution.org/</a> . Being new in using the BeagleBoard we decided to use some of the sources at hand. We started with the site <a title="BeagleBoard Beginners Site Link" href="http://elinux.org/BeagleBoardBeginners" target="_blank">http://elinux.org/BeagleBoardBeginners</a> . We ran into some problems.</p>
<p>Our first problem was that we did not have a AT-Everex cable to connect to the board. So we had to jump to Step 5 of the steps presented in the web-site.  Which is basicly Linux Boot Formatting the SDHC disc we bought for the board. I beg you please not to follow the steps at elinux.org instead follow <a title="SD card formatting link" href="http://code.google.com/p/beagleboard/wiki/LinuxBootDiskFormat" target="_blank">http://code.google.com/p/beagleboard/wiki/LinuxBootDiskFormat</a> . It is much more clear and you don&#8217;t get side stepped. Once we used the steps in formatting the SD disk in code.google.com we noticed we needed cable so we can tell the board where to boot from. So until we get that cable (or make one for our selves?) the project is at a halt. Just follow this blog for any more updates on the board and follow the Sourceforge.net &#8216;s for the changes on our code.</p>
<p>Peace!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2009/11/12/the-beagleboard-has-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Knowing when to fold ( i.e. SSH is better than Telnet )</title>
		<link>http://johnroach.info/2009/10/28/knowing-when-to-fold-i-e-ssh-is-better-than-telnet/</link>
		<comments>http://johnroach.info/2009/10/28/knowing-when-to-fold-i-e-ssh-is-better-than-telnet/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 16:08:45 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ip home automation project]]></category>
		<category><![CDATA[embedded device]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php ssh connection]]></category>
		<category><![CDATA[php telnet connection]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[telnet]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=93</guid>
		<description><![CDATA[You have probably seen my  previous post on connecting to Telnet through PHP although it was a novel idea I have just learned that (from a Novell site. No pun intended.) Telnet is very insecure!! To make things clearer Telnet &#8230; <a href="http://johnroach.info/2009/10/28/knowing-when-to-fold-i-e-ssh-is-better-than-telnet/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You have probably seen my  previous post on connecting to Telnet through PHP although it was a novel idea I have just learned that (from a Novell site. No pun intended.) Telnet is very insecure!! To make things clearer Telnet usually creates connections as below;</p>
<p style="text-align: center;"><a href="http://johnroach.info/wp-content/uploads/2009/10/Telnet-Client-server-unencrypted.png"><img class="aligncenter size-full wp-image-111" title="Telnet-Client-server-unencrypted" src="http://johnroach.info/wp-content/uploads/2009/10/Telnet-Client-server-unencrypted.png" alt="Telnet-Client-server-unencrypted" width="305" height="209" /></a></p>
<p style="text-align: left;">Up here you can see a hacker can sniff the client-server connection and actually steal the user name and password sent by client. This really won&#8217;t do since if someone can spoof/hack/attack our embedded system which we will be adding to home appliances things may go awry. i.e. you will start seeing automated vacuum cleaners attacking your cat. ( Statistics show that H4X0Rz hate cats. )</p>
<p style="text-align: left;">Hence we can clearly see we need another way for the server and client to talk to each other. After some short Googling I am thinking of using SSH which is native to Linux/Unix based systems. Where the connection will be as below ;</p>
<p style="text-align: left;"><a href="http://johnroach.info/wp-content/uploads/2009/10/SSH-client-server-encrypted.png"><img class="aligncenter size-full wp-image-112" title="SSH-client-server-encrypted" src="http://johnroach.info/wp-content/uploads/2009/10/SSH-client-server-encrypted.png" alt="SSH-client-server-encrypted" width="305" height="209" /></a>As you can see the SSH encryption creates a safer environment for the client and the server plus any DNS attacks and eavesdropping is clearly impossible. (if not probable.)</p>
<p style="text-align: left;">Henceforth a new PHP and Python (this time I will write the server+client in Python) shall be written. Please expect updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2009/10/28/knowing-when-to-fold-i-e-ssh-is-better-than-telnet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connecting to PHP using telnet and sending data to the same port using Java</title>
		<link>http://johnroach.info/2009/10/25/connecting-php-using-telnet-and-sending-data-to-the-same-port-using-java/</link>
		<comments>http://johnroach.info/2009/10/25/connecting-php-using-telnet-and-sending-data-to-the-same-port-using-java/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 10:13:26 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ip home automation project]]></category>
		<category><![CDATA[embedded device]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php telnet connection]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[telnet]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=71</guid>
		<description><![CDATA[Hi there! Have been busy busy busy. What I needed was a way to the following; Above you are looking at a very simple layout. ( Almost childishly simple ) The embedded device has Linux installed with a supposedly very &#8230; <a href="http://johnroach.info/2009/10/25/connecting-php-using-telnet-and-sending-data-to-the-same-port-using-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hi there! Have been busy busy busy. What I needed was a way to the following;<br />
<a href="http://johnroach.info/wp-content/uploads/2009/10/graf.png"><img class="size-medium wp-image-72 aligncenter" title="Very Simple Layout" src="http://johnroach.info/wp-content/uploads/2009/10/graf-300x225.png" alt="Very Simple Layout" width="300" height="225" /></a>Above you are looking at a very simple layout. ( Almost childishly simple ) The embedded device has Linux installed with a supposedly very light JVM ( Java Virtual Machine ) So if I am to send data to and from the server and display it to the user I have to do some scripting both in Java and in PHP. Let us first take a look at our universal Java-Socket program which basically opens and listens to a certain port (socket );</p>
<p><span id="more-71"></span></p>
<pre name="code" class="java">
import java.io.*;
import java.net.*;

//This program will listen to port 8189

public class ThreadedEchoServer{

 public static void main (String[] args){

 try{

 int i =1;
 ServerSocket s = new ServerSocket(8189);

 for (;;)
 {  
 Socket incoming = s.accept( );
 System.out.println("Spawning " + i);
 Thread t = new ThreadedEchoHandler(incoming, i);
 t.start();
 i++;
 }

 }catch (Exception e){

 e.printStackTrace();

 }

 }

}
/**
This class handles the client input for one server socket
connection.
*/
class ThreadedEchoHandler extends Thread
{
/**
 Constructs a handler.
 @param i the incoming socket
 @param c the counter for the handlers (used in prompts)
*/
public ThreadedEchoHandler(Socket i, int c)
{
 incoming = i; counter = c;
}

public void run()
{  
 try
 {  
 BufferedReader in = new BufferedReader
 (new InputStreamReader(incoming.getInputStream()));
 PrintWriter out = new PrintWriter
 (incoming.getOutputStream(), true /* autoFlush */);

 out.println( "Hello! Enter BYE to exit." );

 boolean done = false;
 while (!done)
 {  
 String str = in.readLine();
 if (str == null) done = true;
 else
 {  
 // out.println("Echo (" + counter + "): " + str);
 out.println("Connected to : " + str + "&lt;br/&gt;");
 //this is where you get the dang str!!! that is sent by embedded  device.
 //OR this is where you get the configurations from php server on the embedded device.
 System.out.println("Php server sent the following string :"+str);

 if (str.trim().equals("BYE"))
 done = true;
 }
 }
 incoming.close();
 }
 catch (Exception e)
 {  
 e.printStackTrace();
 }
}

private Socket incoming;
private int counter;
}
</pre>
<p>So we have finished with the Java code. Which both can be installed in the server or the embedded device. Notice that the port is  8189. Let us assume that this nice piece of work is on the embedded device. Now we have to send commands to and from the device via PHP using a telnet like protocol. That is when I started searching Google. Came up with a nice site <a href="http://www.geckotribe.com/php-telnet/" target="_blank">http://www.geckotribe.com/php-telnet/</a></p>
<p>A nice site if you want to send data to and from telnet. And indeed it was what I needed. However I needed to do some modifications to the code they provided. The code below belongs to them;</p>
<p>(PHPTelnet.php)</p>
<pre name="code" class="php">
&lt;?php
/*
PHPTelnet
*/

class PHPTelnet {
 var $show_connect_error=1;

 var $use_usleep=1;    // change to 1 for faster execution default:0
 // don't change to 1 on Windows servers unless you have PHP 5
 var $sleeptime=125000;
 var $loginsleeptime=1000000;

 var $fp=NULL;
 var $loginprompt;

 var $conn1;
 var $conn2;

 /*
 0 = success
 1 = couldn't open network connection
 2 = unknown host
 3 = login failed
 4 = PHP version too low
 */
 function Connect($server,$user,$pass) {
 $rv=0;
 $vers=explode('.',PHP_VERSION);
 $needvers=array(4,3,0);
 $j=count($vers);
 $k=count($needvers);
 if ($k&lt;$j) $j=$k;
 for ($i=0;$i&lt;$j;$i++) {
 if (($vers[$i]+0)&gt;$needvers[$i]) break;
 if (($vers[$i]+0)&lt;$needvers[$i]) {
 $this-&gt;ConnectError(4);
 return 4;
 }
 }

 $this-&gt;Disconnect();

 if (strlen($server)) {
 if (preg_match('/[^0-9.]/',$server)) {
 $ip=gethostbyname($server);
 if ($ip==$server) {
 $ip='';
 $rv=2;
 }
 } else $ip=$server;
 } else $ip='127.0.0.1';

 if (strlen($ip)) {
 if ($this-&gt;fp=fsockopen($ip,8189))
 {

 if( ($user!="")&amp;&amp; ($pass!=""))
 {
 fputs($this-&gt;fp,$this-&gt;conn1);
 $this-&gt;Sleep();

 fputs($this-&gt;fp,$this-&gt;conn2);
 $this-&gt;Sleep();
 $this-&gt;GetResponse($r);
 $r=explode("\n",$r);
 $this-&gt;loginprompt=$r[count($r)-1];

 fputs($this-&gt;fp,"$user\r");
 $this-&gt;Sleep();

 fputs($this-&gt;fp,"$pass\r");
 if ($this-&gt;use_usleep) usleep($this-&gt;loginsleeptime);
 else sleep(1);
 $this-&gt;GetResponse($r);
 $r=explode("\n",$r);
 if (($r[count($r)-1]=='')||($this-&gt;loginprompt==$r[count($r)-1])) {
 $rv=3;
 $this-&gt;Disconnect();
 }

 }
 } else $rv=1;
 }

 if ($rv) $this-&gt;ConnectError($rv);
 return $rv;
 }

 function Disconnect($exit=1) {
 if ($this-&gt;fp) {
 if ($exit) $this-&gt;DoCommand('exit',$junk);
 fclose($this-&gt;fp);
 $this-&gt;fp=NULL;
 }
 }

 function DoCommand($c,&amp;$r) {
 if ($this-&gt;fp) {
 fputs($this-&gt;fp,"$c\r");
 $this-&gt;Sleep();
 $this-&gt;GetResponse($r);
 $r=preg_replace("/^.*?\n(.*)\n[^\n]*$/","$1",$r);
 }
 return $this-&gt;fp?1:0;
 }

 function GetResponse(&amp;$r) {
 $r='';
 do {
 $r.=fread($this-&gt;fp,1000);
 $s=socket_get_status($this-&gt;fp);
 } while ($s['unread_bytes']);
 }

 function Sleep() {
 if ($this-&gt;use_usleep) usleep($this-&gt;sleeptime);
 else sleep(1);
 }

 function PHPTelnet() {
 $this-&gt;conn1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).
 chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).
 chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).
 chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).
 chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).
 chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).
 chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).
 chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).
 chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).
 chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).
 chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).
 chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0);
 $this-&gt;conn2=chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).
 chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21);
 }

 function ConnectError($num) {
 if ($this-&gt;show_connect_error) switch ($num) {
 case 1: echo '&lt;br /&gt;[PHP Telnet] &lt;a href="http://www.geckotribe.com/php-telnet/errors/fsockopen.php"&gt;Connect failed: Unable to open network connection&lt;/a&gt;&lt;br /&gt;'; break;
 case 2: echo '&lt;br /&gt;[PHP Telnet] &lt;a href="http://www.geckotribe.com/php-telnet/errors/unknown-host.php"&gt;Connect failed: Unknown host&lt;/a&gt;&lt;br /&gt;'; break;
 case 3: echo '&lt;br /&gt;[PHP Telnet] &lt;a href="http://www.geckotribe.com/php-telnet/errors/login.php"&gt;Connect failed: Login failed&lt;/a&gt;&lt;br /&gt;'; break;
 case 4: echo '&lt;br /&gt;[PHP Telnet] &lt;a href="http://www.geckotribe.com/php-telnet/errors/php-version.php"&gt;Connect failed: Your server\'s PHP version is too low for PHP Telnet&lt;/a&gt;&lt;br /&gt;'; break;
 }
 }
}

return;
?&gt;
</pre>
<p>However because I needed something that used a different port had to change the port number if you look at the comments in the form you will see where I edited the code.</p>
<p>Also because my Telnet was without a password ( i wanted to test it first) I added an &#8220;if&#8221; statement. Now to the index.php code;</p>
<pre name="code" class="php">
&lt;html&gt;&lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt;&lt;body&gt;

&lt;?php

require_once "PHPTelnet.php";

$telnet = new PHPTelnet();

// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
// the second blank is for the username (may be for embedded device)
// the third blank is for the password (may be for embedded device)
$result = $telnet-&gt;Connect('','','');

if ($result == 0) {
$telnet-&gt;DoCommand('The embedded device!!', $result);
// NOTE: $result may contain newlines
echo $result;
$telnet-&gt;DoCommand('BYE', $result);
echo $result;
// say Disconnect(0); to break the connection without explicitly logging out
$telnet-&gt;Disconnect();
}

?&gt;
&lt;/body&gt;&lt;/html&gt;</pre>
<p>Now to run a test; first run the Java program ( I hope you know how to compile and run a java program from console.) And than simply open index.php ( of course from Apache! ) And voilà!! you have a program that can connect directly to a php server page!!</p>
<p>Questions? Comments just send it in!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2009/10/25/connecting-php-using-telnet-and-sending-data-to-the-same-port-using-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

