{"id":48,"date":"2013-01-30T12:43:00","date_gmt":"2013-01-30T12:43:00","guid":{"rendered":"https:\/\/aliciapaterson.com\/wordpress\/?p=48"},"modified":"2023-05-05T15:24:19","modified_gmt":"2023-05-05T15:24:19","slug":"wireless-cat-feeder","status":"publish","type":"post","link":"https:\/\/geekgirl.io\/wordpress\/personal\/wireless-cat-feeder\/","title":{"rendered":"Wireless Cat Feeder"},"content":{"rendered":"\n<p>We have been looking after a cat for quite a little while now.&nbsp; He is a sweet, gentle Russian Blue with a very good nature, however he has a habit of waking us up with meowing and scratching at 4am to tell us he wants his breakfast.<\/p>\n\n\n\n<p>We made a number of attempts to find a happy solution, however we discovered that the extra food left out the night before was not fit for catsumption in the morning and that cats can overcome the muting of a closed door when they really want to be heard.&nbsp; I opted for a smart solution to his early morning antics.<\/p>\n\n\n\n<p>I had seen an automatic candy dispenser available around Xmas as a cheap gift option.&nbsp; At $20 it included a large clear hopper for holding lollies, an infrared sensor to detect a ready hand and a motorised dispensing system to send lollies into a waiting hand.&nbsp; I bought a couple thinking that the hopper would store cat nibbles sufficiently well for freshness and the dispenser should be able to cope with what I took to be a slightly smaller product then the designers had anticipated.<\/p>\n\n\n\n<figure class=\"wp-block-image alignright\"><a href=\"http:\/\/aliciapaterson.com\/wordpress\/wp-content\/uploads\/2013\/01\/candy-dispenser.jpg\"><img decoding=\"async\" src=\"http:\/\/aliciapaterson.com\/wordpress\/wp-content\/uploads\/2013\/01\/candy-dispenser-300x300.jpg\" alt=\"\" class=\"wp-image-447\" title=\"candy dispenser\"\/><\/a><\/figure>\n\n\n\n<p>I toyed with the idea of leaving the IR senor in the future Cat Feeder but expected the cat might just keep on going if a fresh food source was available (he likes his nibbles&#8230;so long as they are fresh).&nbsp; My goal was to hook the device into the existing Home Automation system such that any mobile phone in the household could trigger a food release.&nbsp; This would also allow us to trigger food releases while away from home as well as to script food releases on a schedule.<\/p>\n\n\n\n<p>The&nbsp;<a href=\"http:\/\/aliciapaterson.com\/wordpress\/sample-page\/home-automation\/\">existing Home Automation system<\/a>&nbsp;is run from a PC using WAMP Server &#8211; all automation devices are held in a MySQL database and the front end and switching commands are managed using PHP5.&nbsp; I needed a way to connect the Cat Feeder back to the PC, without having to use additional hardware om the PC side.&nbsp; I toyed with adding X10 capability to it but haven&#8217;t been at all impressed with the performance of X10.&nbsp; Wireless would work best, and WiFi seemed the ideal solution as it could hook into my existing network allowing the PC to address the Cat Feeder directly.<\/p>\n\n\n\n<p>My design was to hack the Cat Feeder to include a WiFi board, put it on my WiFi network at home and have it always listening on HTTP port 80 for a command to turn on.&nbsp; It would then execute a couple of commands to turn the feeder mechanism on for a second then off again.&nbsp; Simple.&nbsp; So I thought.<\/p>\n\n\n\n<p>I did a bit of research on WiFi modules and found a growing number of hardware options with varying levels of sophistication.&nbsp; Since I was already pretty familiar with Arduino I started there and purchased a&nbsp;<a href=\"http:\/\/www.seeedstudio.com\/depot\/wifi-shield-p-1220.html?cPath=139_141\" target=\"_blank\" rel=\"noreferrer noopener\">WiFly WiFi shield<\/a>&nbsp;based on the Roving Networks RN171 chip.&nbsp; This board plugs directly onto an Arduino Uno board, allowing you to connect the Arduino to your computer to quickly program it to send and receive data over WiFi.&nbsp; It has support for all kinds of protocols (from raw TCP sockets to FTP and HTTP) and was cheap at around $60 (compared to the more common WiFi Shield at around $100).<\/p>\n\n\n\n<figure class=\"wp-block-image alignright\"><a href=\"http:\/\/aliciapaterson.com\/wordpress\/wp-content\/uploads\/2013\/01\/WiFly.jpg\"><img decoding=\"async\" src=\"http:\/\/aliciapaterson.com\/wordpress\/wp-content\/uploads\/2013\/01\/WiFly.jpg\" alt=\"\" class=\"wp-image-450\" title=\"WiFly\"\/><\/a><\/figure>\n\n\n\n<p>After getting this board and connecting it up I very quickly ran into troubles.&nbsp; Although Roving Networks has a really good user guide for their chip, writing the require code for the Arduino to communicate over serial to the chip was a big undertaking&#8230;and frankly at the periphery of my abilities.&nbsp; The board manufacturer included a Arduino library which covered the basics (such as associating to a wireless network, sending packets etc) but which seemed more targeted towards using the board to automatically log into a WiFi network and post HTTP data to a server in response to hardware triggers.&nbsp; This made it highly suitable to a telemetry application such as sending temperature readings to a server etc, but become increasingly challenging to get it to listen on port 80 for HTTP traffic and respond intelligently.&nbsp; The library didn&#8217;t provide enough of the groundwork to do what I needed out of the box and tackling the learning curve that would enable me to update the library to support what I needed was more work than I wanted to invest.&nbsp; Furthermore the device had a habit of dropping off the network. I guess if its implementation only called for it to log on to a server over WiFi, send a bunch of data then drop off again but I needed it on all the time.&nbsp;&nbsp; I was also never really happy with it&#8217;s behaviour over a local serial connection; when using the Arduino serial monitor to connect directly to the board the output from it was always highly garbled, in some cases leading to anomalous operation.<\/p>\n\n\n\n<p>So I looked into alternatives.&nbsp; By this stage I was also aware that using an Arduino board was a bit of overkill for this project &#8211; it simply didn&#8217;t require that level of smarts.&nbsp; To cover my bases however I immediately bought three other WiFi options!<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The &#8216;official&#8217;&nbsp;<a href=\"https:\/\/www.sparkfun.com\/products\/11287\" target=\"_blank\" rel=\"noreferrer noopener\">Arduino WiFi Shield<\/a><\/li>\n\n\n\n<li>The&nbsp;<a href=\"https:\/\/www.sparkfun.com\/products\/10822\" target=\"_blank\" rel=\"noreferrer noopener\">RN-Xv WiFi<\/a><a href=\"http:\/\/en.wikipedia.org\/wiki\/XBee\" target=\"_blank\" rel=\"noreferrer noopener\">&nbsp;Xbee<\/a>&nbsp;module<\/li>\n\n\n\n<li>An&nbsp;<a href=\"http:\/\/electricimp.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Electric Imp<\/a>!<\/li>\n<\/ul>\n\n\n\n<p>The official Arduino WiFi shield was a little more expensive but had much better support with a full library covering everything I wanted to do, lots of examples and most importantly a healthy online community for support!<\/p>\n\n\n\n<p>The Electric Imp seemed like it could provide a minimalist solution being the smallest of the lot.&nbsp; Its an amazing little device and I was keen to have a play with it.<\/p>\n\n\n\n<p>The RN-Xv Xbee module I picked up courtesy of a&nbsp;<a href=\"http:\/\/hackaday.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Hack A Day<\/a>&nbsp;article about a guy that used it to control his&nbsp;<a href=\"http:\/\/www.dinnovative.com\/?p=163\" target=\"_blank\" rel=\"noreferrer noopener\">garage door over WiFi<\/a>.&nbsp; He had a pretty good walk through of what he did and I liked that he didn&#8217;t use the Arduino board.<\/p>\n\n\n\n<p>Since I wanted to proceed without using an Arduino board I next tried the RN-XV module.&nbsp; Since it is based on the same chip as the WiFly module I had been playing with, much of the operation was already familiar.&nbsp; Communications between the WiFly and Arduino was managed over a serial link, whereas to connect to the RN-XV I first got it going in ad-hoc wireless network mode by putting 3.3v on pin 8 and turning it on.&nbsp; This allowed it to come up with it&#8217;s own SSID which I could connect my laptop to in order to establish a serial connection to the board.&nbsp; Worked brilliantly and I was quickly able to set my WiFi network parameters (SSID, WPA2 passphrase etc) on it.&nbsp; Removing the 3.3v to pin 8 and rebooting it brought it up on my WiFi network &#8211; success!<\/p>\n\n\n\n<figure class=\"wp-block-image alignleft\"><a href=\"http:\/\/aliciapaterson.com\/wordpress\/wp-content\/uploads\/2013\/01\/20130130_075548-e1359523937864.jpg\"><img decoding=\"async\" src=\"http:\/\/aliciapaterson.com\/wordpress\/wp-content\/uploads\/2013\/01\/20130130_075548-e1359523937864-225x300.jpg\" alt=\"Mr Earl enjoying the new WiFi Cat Feeder\" class=\"wp-image-445\" title=\"WiFi Cat Feeder\"\/><\/a><\/figure>\n\n\n\n<p>I could then telnet to it and send the relevant serial commands to turn the dispenser motor on and off&#8230;however not using Arduino meant that my ability to emulate HTTP on the device was limited (again, at the periphery of my ability).&nbsp; So I instead turned to my PHP code and looked for an easy way to telnet to the device and send commands using PHP.&nbsp; After tinkering with a number of classes based on&nbsp;<a href=\"http:\/\/php.net\/manual\/en\/function.fsockopen.php\">fsockopen<\/a>&nbsp;I found one that worked well &#8211;&nbsp;<a href=\"http:\/\/code.google.com\/p\/telnetdog\/\">TelnetDog<\/a>.<\/p>\n\n\n\n<p>From here it only took a few minutes to update my Home Automation PHP script, add the device to the database and presto! I had a new &#8216;Feed Cat&#8217; button on my Home Remote page!<\/p>\n\n\n\n<p>I&#8217;m happy to report that the cat is indeed eating from the Cat Feeder tray and is not put off by the noise it makes when dispensing his nibbles.<\/p>\n\n\n\n<p>Now if I can only automate the cat litter tray&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have been looking after a cat for quite a little while now.&nbsp; He is a sweet, gentle Russian Blue with a very good nature, however he has a habit of waking us up with meowing and scratching at 4am to tell us he wants his breakfast. We made a number of attempts to find [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":55,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-personal"],"_links":{"self":[{"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":2,"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":50,"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/posts\/48\/revisions\/50"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/media\/55"}],"wp:attachment":[{"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekgirl.io\/wordpress\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}