{"id":2624,"date":"2008-06-25T08:00:00","date_gmt":"2008-06-25T07:00:00","guid":{"rendered":""},"modified":"2013-07-08T16:39:53","modified_gmt":"2013-07-08T15:39:53","slug":"hacking-a-print-server-for-ethernet-home-automation","status":"publish","type":"post","link":"https:\/\/automatedhome.com\/new-products\/hacking-a-print-server-for-ethernet-home-automation.html","title":{"rendered":"Hacking a Print Server for Ethernet Home Automation"},"content":{"rendered":"<div style=\"text-align: center;\">\n<div style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" alt=\" \" src=\"\/images\/news\/dmps_small.jpg\" width=\"400\" height=\"244\" \/><\/div>\n<\/div>\n<p>Submission by <a href=\"http:\/\/www.yourmissus.com\/printserver\/\" target=\"_blank\">Dan McGrath<\/a>.\u00a0 What&#8217;s all this about then? Well, I&#8217;ve got loads of home automation, and I love it!\u00a0 However, whenever I show it to friends and family, I tend to get one of two responses.\u00a0 The first is that it&#8217;s just a gimmick and they&#8217;d never want anything like that.\u00a0 The second is that it&#8217;s great, but too complicated for them to set up something similar.<\/p>\n<p><div class=\"sj-gblock\">\n<script language=\"javascript\">\n<!--\ngoogle_ad_client = \"ca-pub-5598479065369258\";\ngoogle_ad_width = 300; \ngoogle_ad_height = 250; \ngoogle_ad_format = \"300x250_as\"; \ngoogle_ad_channel = \"7058025304\"; \ngoogle_ad_type = \"text_image\"; \ngoogle_color_border = \"FFFFFF\"; \ngoogle_color_bg = \"FFFFFF\"; \ngoogle_color_link = \"52a79f\"; \ngoogle_color_url = \"CFFFDF\"; \ngoogle_color_text = \"000000\"; \n\/\/--> \n<\/script>\n<script language=\"javascript\"  src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\"><\/script>\n<\/div>So this is my attempt at a simple, in fact very simple home automation device that ANYONE can use, and almost anyone can make.\u00a0 I am actually seriously considering manufacturing these in bulk (well something similar) and selling the whole lot as a managed service for about a tenner a year. (please let me know if this could be of interest to anyone).\u00a0 Anyway, so this is my attempt at cheap home automation for the masses, I hope you like it&#8230;<\/p>\n<p><strong>Design &#8211;\u00a0<\/strong>Right, so I need something that is cheap, reliable, easy to get hold of.\u00a0 Also something that can be triggered by a simple switch, and that switch could be any of the following:<\/p>\n<ul>\n<li>Connect it to a socket, light or any other appliance and use it to montor it.<\/li>\n<li>Attach to a solar panel or LDR to monitor light levels.<\/li>\n<li>Connect a pair of probes and detect water (plants, rain, leaks etc&#8230;)<\/li>\n<li>Connect to a PIR or Reed switch for security,<\/li>\n<li>Connect to a smoke alarm for fire protection,<\/li>\n<li>Connect to a pressure mat etc&#8230;.<\/li>\n<\/ul>\n<p>Most people don&#8217;t want a pc or server running all day, because of the noise, heat and energy consumption. Simple tiny one board computers can now be bought from $50 each (Xport, Arduino, PicoTux, etc..), but even this seems overkill for what I want&#8230;<span style=\"text-align: center;\">\u00a0<\/span><\/p>\n<div style=\"text-align: center;\">\n<table width=\"400\" border=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td>\u00a0<a href=\"http:\/\/www.arduino.cc\/\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" alt=\" \" src=\"\/images\/news\/dmps_arduino.jpg\" width=\"160\" height=\"115\" border=\"0\" \/><\/a><\/td>\n<td>\u00a0<a href=\"http:\/\/www.lantronix.com\/device-networking\/embedded-device-servers\/xport.html\" target=\"_blank\"><img decoding=\"async\" alt=\" \" src=\"\/images\/news\/dmps_xport.jpg\" border=\"0\" \/><\/a><\/td>\n<td>\u00a0<img decoding=\"async\" alt=\" \" src=\"\/images\/news\/dmps_picotux.jpg\" border=\"0\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: left;\">A managed switch, router, firewall, anything with an ethernet port and some kind of web interface was what I was after, but it had to be cheap&#8230; and small&#8230;.\u00a0 Then I came up with the idea of a print server&#8230; Print servers are ideal, they use very little electricity, are designed to be switched on all the time, can respond to a ping and better still have a in-built webserver too. I did a bit of googling around and saw them for as little as a tenner on ebay. Oh and they are tiny too!\u00a0 I had three ideas for this project:<\/p>\n<\/div>\n<ul>\n<li>The first was that I could break or short the transmit pair on the incoming ethernet cable to the print server.\u00a0 Obviously with these shorted or broken the device would be unable to respond to either a ping or a http request.<\/li>\n<\/ul>\n<p>I think it would work, but it seemed a bit barbaric, and I&#8217;m sure I could do better.<\/p>\n<ul>\n<li>The second was just to break the power to the device<\/li>\n<\/ul>\n<p>This had potential from a energy saving point of view as you&#8217;d only be powering the device some of the time, of course when it was powered off you wouldn&#8217;t see either it&#8217;s webpage or a respond to a ping request.\u00a0 I quite liked this idea, the only thing that put me off was that when powered off, it would be impossible to tell if the device was off, or disconnected from the network for another reason &#8211; maybe a failure elsewhere.\u00a0 Also I was unsure how long the device would keep the settings (network etc..) while it was off.<\/p>\n<p>What I really wanted was a way of getting a response from the unit to confirm that it was either in one state or another, that way you could be sure of what was really going on.\u00a0 That&#8217;s where my third idea comes in.<\/p>\n<ul>\n<li>The third idea was to fool the print server that a printer was really attached to it,<\/li>\n<\/ul>\n<p>and then have it so that it appeared that the printer was on or off line.<\/p>\n<p>I did a bit of reasearch, and it appears that pin 13 of the connector is used for this purpose. Take the pin high (i.e apply 5volts to it) and the server thinks that the printer is on_line, take the pin low (i.e remove the voltage)and the server thinks that the printer is off_line.<\/p>\n<p>As all I have to do is apply and remove 5volts, I can just find 5volts somewhere and route it through a switch. Close the switch and it appears that the printer is on_line, open the switch and the printer appears off_line.\u00a0 As I say, this status is reflected in the web interface, so a simple script should be able to poll this page and parse the printer status and then use this information for something useful.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\" \" src=\"\/images\/news\/dmps_ps1.jpg\" width=\"400\" height=\"351\" align=\"left\" \/><strong>Construction &#8211;\u00a0<\/strong>As mentioned above, I used a Edimax PS-1206P parallel print server, which I bought for about 25 pounds online. It was actually more like 22 quid, but postage and packing bump that up a bit. I ended up buying a handful of these as they were so cheap.\u00a0 I&#8217;ve never heard of Edimax before, so the product could be good or bad, but I don&#8217;t care, as long as it&#8217;ll respond to a HTTP request then I&#8217;ll be happy!\u00a0 I was pleasantly surprised when they turned up, they were nicely boxed, and the contents looked ok too:<\/p>\n<p>One thing&#8217;s for sure though, this device will never be plugged into the back of a printer. I&#8217;ll soon have chopped it up into something far more interesting.\u00a0 Details here: <a href=\"http:\/\/www.edimax.com\/en\/produce_detail.php?pd_id=50&amp;pl1_id=2&amp;pl2_id=14\" target=\"_blank\">Edimax PS-1206P<\/a><\/p>\n<p>Ok, so let&#8217;s get the lid off one of these&#8230;.I just love taking stuff apart, but taking brand new stuff apart is especially fun for me, it just seems so wrong!!\u00a0 There are a couple of phillips head screws on the bottom and once these are removed, the case just pulls apart, although you need to squeeze the sides a bit as the two halves clip into each other.<\/p>\n<p>I was pleasantly surprised with the inside of this unit, it was very well put together.\u00a0 The lord only knows what all the bits are for, I guess there is a processor in there, some memory, a bit of I\/O and other stuff I don&#8217;t understand.<\/p>\n<p>Now, you could keep the big 36pin centronics socket on the print server and just get hold of the matching plug to connect to it, but these are quite bulky and it seems a bit over the top especially considering we only need to connect to 2 of these 36 pins.\u00a0 I decided to cut the socket off&#8230; No, I didn&#8217;t do it with an axe, it does look a bit rough at the moment though:<\/p>\n<div style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" alt=\" \" src=\"\/images\/news\/dmps_ps2.jpg\" width=\"400\" height=\"263\" \/><\/div>\n<p>I then desoldered the individual pins from the board and made up a little metal plate to block up the hole left from the missing socket. I drilled a couple of holes in it and connected a pair of screw terminals. A bit of 2 part epoxy and some heatshrink and you have this&#8230;<\/p>\n<div style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" alt=\" \" src=\"\/images\/news\/dmps_ps3.jpg\" width=\"400\" height=\"311\" \/><\/div>\n<p>Pretty neat eh?!\u00a0\u00a0 So that&#8217;s the working prototype, with a bit of luck, bridging those two screw terminals will return an on_line status, and leaving them open will give an off_line.\u00a0 So it&#8217;s time to test.\u00a0 Note: The pictures above show the connections to pins 35 and 36, this is INCORRECT, subsequent testing showed that I actually needed pins 13 and 19.<\/p>\n<p>I decided to measure the power consumption, and I was pleasantly surprised at what I found, it only uses 6watts, which isn&#8217;t very much at all is it? (At 10p per kwh, it&#8217;ll cost about 5 quid per year to run)<\/p>\n<p>As I said above, I&#8217;m going to poll my server with a HTTP request and collect the printer status, but if you want to just see if it&#8217;s there by pinging it, then you can use ping to montior it, using something like:<\/p>\n<p><em>date<br \/>\nn=1<\/em><\/p>\n<p>while [ $n -lt 1000 ]<br \/>\ndo<br \/>\nping -n 1 server_ip<br \/>\necho $n<br \/>\nlet n=n+1<br \/>\ndone<br \/>\ndate<\/p>\n<p>Shows that this device can easily send (and receive) 1000 pings in 52 seconds which is 20 pings a second.\u00a0 So pinging it is a viable option and should give you a fairly prompt response.\u00a0 Of course if you want to just use ping then you&#8217;ll have to either trigger the unit by breaking the power or network connection (it won&#8217;t be affected by printer status).\u00a0 Pings don&#8217;t really work well on the internet, lots of people and routers disable ICMP requests at their boundaries, however the bonus with this device is that it also has a web interface which can be polled to check its availability.\u00a0 This can be done over the internet easily, and again a short script shows that you can make about 1 request per second using&#8230;<\/p>\n<p><em>#!\/usr\/bin\/bash<\/em><\/p>\n<p>user=username<br \/>\npassword=password<br \/>\nurl=server_url<\/p>\n<p>wget &#8211;quiet &#8211;http-user=$user &#8211;http-password=$password \\<br \/>\n&#8211;proxy=$proxy $url<\/p>\n<p>grep Off_line printer.htm &gt; \/dev\/null<\/p>\n<p>if [ &#8220;$?&#8221; == &#8220;0&#8221; ]<br \/>\nthen echo &#8220;Offline&#8221;<br \/>\nelse echo &#8220;Online&#8221;<br \/>\nfi<\/p>\n<p>rm printer.htm<\/p>\n<p>Returns a value based on the printer status. Note the webserver onboard is pretty slow, as expected really, but you get a response in less than a second, so I think it&#8217;ll be feasable to poll every 5-10secs.\u00a0 Replacing the echo commands with mail or additional wget commands could email you or get a URL (maybe use twitter to SMS you etc..)<\/p>\n<p>Ok, an example of how to update your twitter status is given below:<\/p>\n<p>wget &#8211;keep-session-cookies &#8211;http-user=username \\<br \/>\n&#8211;http-password=password &#8211;post-data=message \\<br \/>\nhttp:\/\/twitter.com\/statuses\/update.xml<\/p>\n<p>(Replace username, password and message with, well you know..)<\/p>\n<p>Or better still, here&#8217;s how to send yourself a tweet when something happens:<\/p>\n<p>wget &#8211;keep-session-cookies &#8211;http-user=user \\<br \/>\n&#8211;http-password=password &#8211;post-data=message \\<br \/>\nhttp:\/\/twitter.com\/direct_messages\/new.xml<\/p>\n<p>Note, you have to URL encode the message That&#8217;s pretty cool isn&#8217;t it?\u00a0 See more about the twitter API here. &#8211; <a href=\"http:\/\/groups.google.com\/group\/twitter-development-talk\/\" target=\"_blank\">Twitter API<\/a><\/p>\n<p>To see this from the net, you&#8217;ll need to NAT to your print server, I&#8217;m running a Cisco Router so the following worked for me:<\/p>\n<p>ip nat inside source static tcp\u00a0\u00a0\u00a0\u00a0 extendable<\/p>\n<p>(keep the port number up in the high 50,000s and you&#8217;ll get less people scanning and probing you).\u00a0 If you have a Linksys router then the rule will be different, but something like this should do it:<\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" alt=\" \" src=\"\/images\/news\/dmps_web.jpg\" width=\"488\" height=\"293\" \/><\/p>\n<p>If you haven&#8217;t got either of the above, then you are on your own&#8230; good luck!<\/p>\n<p><strong>Software &#8211;\u00a0<\/strong>Ok, I gave some examples above, below is a working bash shell script that&#8217;ll monitor one of these for you, and twitter SMS you when the state changes.\u00a0 It is a very simple example, but should get you started.<\/p>\n<p><em>#!\/bin\/bash<\/em><\/p>\n<p>## Web Get Parameters<br \/>\nuser=&#8221;admin&#8221;<br \/>\npassword=&#8221;1234&#8243;<br \/>\nurl=&#8221;http:\/\/ip_address\/printer.htm&#8221;<\/p>\n<p>## Twitter Parameters<br \/>\nt_user=user<br \/>\nt_passwd=password<\/p>\n<p>## Other Parameters<br \/>\nstatus=&#8221;closed&#8221;<\/p>\n<p>while true<br \/>\n<em>do<br \/>\nold_status=$status<br \/>\nwget &#8211;quiet &#8211;http-user=$user &#8211;http-passwd=$password $url<\/em><\/p>\n<p>grep Off_line printer.htm &gt; \/dev\/null<\/p>\n<p>if [ &#8220;$?&#8221; == &#8220;0&#8221; ]<br \/>\nthen status=&#8221;open&#8221;<br \/>\nelse status=&#8221;closed&#8221;<br \/>\nfi<\/p>\n<p>rm printer.htm<\/p>\n<p>if [ $status != $old_status ]<br \/>\nthen wget &#8211;quiet &#8211;http-user=$t_user \\<br \/>\n&#8211;http-passwd=$t_passwd &#8211;keep-session-cookies \\<br \/>\n&#8211;post-data=&#8221;user=twitter_username&amp;text=message&#8221; \\<br \/>\nhttp:\/\/twitter.com\/direct_messages\/new.xml<br \/>\nfi<br \/>\nsleep 1<br \/>\ndone<\/p>\n<p>Alternatively, you could use some monitoring software like the excellent <a href=\"http:\/\/www.purplepixie.org\/freenats\/\" target=\"_blank\">freeNATS<\/a> to alert you when something happens.<\/p>\n<p><strong>Conclusion &#8211;\u00a0<\/strong>Well, I hope you&#8217;ve enjoyed what I&#8217;ve done, you have to admit it is home automation<br \/>\non the cheap, and very easy to do.\u00a0 Cheers &#8211; <a href=\"http:\/\/www.yourmissus.com\" target=\"_blank\">Dan<\/a><\/p>\n<p><strong>Useful Links <\/strong><\/p>\n<p><a href=\"http:\/\/www.cpan.org\/\" target=\"_blank\">CPAN<\/a> &#8211; All things Perl<br \/>\n<a href=\"http:\/\/www.perl.com\/\" target=\"_blank\">Perl<\/a> &#8211; More things Perl<br \/>\n<a href=\"http:\/\/www.gnu.org\/software\/wget\/\" target=\"_blank\">WGET<\/a> &#8211; WGET application<br \/>\n<a href=\"http:\/\/www.edimax.com\/\" target=\"_blank\">Edimax<\/a> &#8211; Suppliers of the Print Server Other \/ Misc<br \/>\n<a href=\"http:\/\/www.twitter.com\/\" target=\"_blank\">Twitter<\/a> &#8211; Social Networking Site With SMS<\/p>\n<p>This article reproduced from the <a href=\"http:\/\/www.yourmissus.com\/printserver\/\" target=\"_blank\">Original<\/a> by kind permission of Dan McGrath of <a href=\"http:\/\/www.yourmissus.com\" target=\"_blank\">yourmissus.com<\/a><\/p>\n<p><strong>Want More?<\/strong>\u00a0&#8211;\u00a0<a href=\"http:\/\/twitter.com\/ottomate\">Follow us<\/a>\u00a0on Twitter,\u00a0<a href=\"http:\/\/www.facebook.com\/AutomatedHomeUK\" target=\"_blank\">Like us<\/a>\u00a0on Facebook, or subscribe to our\u00a0<a href=\"http:\/\/feeds2.feedburner.com\/automatedhome\">RSS feed<\/a>. You can even get these news stories\u00a0<a href=\"http:\/\/feedburner.google.com\/fb\/a\/mailverify?uri=AutomatedHome&amp;loc=en_US\">delivered via email<\/a>, straight to your inbox every day<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Submission by Dan McGrath.\u00a0 What&#8217;s all this about then? Well, I&#8217;ve got loads of home automation, and I love it!\u00a0 However, whenever I show it&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":"","apple_news_is_paid":"","apple_news_is_preview":"","apple_news_is_sponsored":"","apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":[],"apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","footnotes":""},"categories":[41,24],"tags":[],"class_list":["post-2624","post","type-post","status-publish","format-standard","hentry","category-hack","category-new-products"],"apple_news_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/posts\/2624"}],"collection":[{"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/comments?post=2624"}],"version-history":[{"count":9,"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/posts\/2624\/revisions"}],"predecessor-version":[{"id":6983,"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/posts\/2624\/revisions\/6983"}],"wp:attachment":[{"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/media?parent=2624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/categories?post=2624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/automatedhome.com\/wp-json\/wp\/v2\/tags?post=2624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}