tag:blogger.com,1999:blog-60529263317413361722024-03-12T23:45:35.265-07:00Fern Tree ShackShack Dwellerhttp://www.blogger.com/profile/03435683760389118162noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-6052926331741336172.post-40468954265744472152012-04-30T03:15:00.000-07:002012-04-30T03:15:09.633-07:00Temporary wifi solutionWhile I'm waiting for the parts to arrive for me to build the real wifi controller board, I found this temporary solution in the local computer shop today.<br /><div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk5Xhyphenhyphen21ZJEEkF5DeJ81VS7ERGTjeq7MSs3N-gvbXbipKKTpi8ThlZYSMrrNASglejyNo5LhOzqPNsNiPj5uN8mzA2QnEyI2CWhXfnKW-4VYB-ghcHa4WAr3wTzvimRFq3KEvY4HKNJ6q6/s1600/Vonets-VAP11G.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk5Xhyphenhyphen21ZJEEkF5DeJ81VS7ERGTjeq7MSs3N-gvbXbipKKTpi8ThlZYSMrrNASglejyNo5LhOzqPNsNiPj5uN8mzA2QnEyI2CWhXfnKW-4VYB-ghcHa4WAr3wTzvimRFq3KEvY4HKNJ6q6/s320/Vonets-VAP11G.jpg" style="cursor: move;" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Vonets VAP11G</td></tr>
</tbody></table>
It's a wifi ethernet bridge, and at around $25 I thought it was worth a shot. Sadly I can't put it to use tonight as the little CD only has software to configure it from a windows machine and frankly, I don't have any of those laying around..<br />
<br />
<br />I'll sort it out tomorrow, until then have a look at what Simon has been doing with google calendar.<br /><a href="http://simonslinuxworld.blogspot.se/2012/04/google-command-line-tools-google.html">http://simonslinuxworld.blogspot.se/2012/04/google-command-line-tools-google.html</a><br />Shack Dwellerhttp://www.blogger.com/profile/03435683760389118162noreply@blogger.com0tag:blogger.com,1999:blog-6052926331741336172.post-70529660432991600282012-04-25T14:23:00.001-07:002012-04-25T14:23:44.069-07:00mBed - Google API source codeA few people have asked me to post the source code. Here it is. Even though I have been programming for years in various database and IBM mainframe languages, I've never done much C, so feel free to send me a few tips. I'm not sure why, for example, it works only when ctTime and buffer[21] are declared outside of the subroutine they're used in??<br />
<br />
<br />
All the libraries used can all be found on the mbed website.<br />
<br />
<br />
#include "mbed.h"<br />#include "DS18B20.h"<br />#include "DS18S20.h"<br />#include "OneWireDefs.h"<br />#include "EthernetNetIf.h"<br />#include "HTTPClient.h"<br />#include "NTPClient.h"<br /><br />#define THERMOMETER DS18S20<br />#define HOSTNAME "mbed"<br />string calendar = "<<< YOUR CALENDAR PRIVATE ADDRESS >>>";<br /><br />EthernetNetIf eth(HOSTNAME);<br />HTTPClient http;<br />NTPClient ntp;<br />THERMOMETER device(true, false, false, p21);<br /><br />DigitalOut led1(LED1, "led1");<br />DigitalOut led2(LED2, "led2");<br />DigitalOut led3(LED3, "led3");<br />DigitalOut led4(LED4, "led4");<br /><br />DigitalOut heater(p10);<br />time_t ctTime;<br />char buffer[21];<br />int targetTemp = 0;<br /><br />string getURL() {<br /> char url[256];<br /> char endTime[21];<br /> char startTime[21];<br /> ctTime = time(NULL);<br /> strftime(buffer, 20, "%Y-%m-%dT%H:%M:00Z", localtime(&ctTime));<br /> strcpy(startTime,buffer);<br /> ctTime = time(NULL)+60;<br /> strftime(buffer, 20, "%Y-%m-%dT%H:%M:00Z", localtime(&ctTime));<br /> strcpy(endTime,buffer); <br /> //printf("start %s\n",startTime);<br /> //printf("end %s\n",endTime);<br /> sprintf(url, "%s?start-min=%s&start-max=%s", calendar, startTime, endTime);<br /> //printf("url %s\n",url);<br /> return url;<br />}<br /><br />string getPage(char url[256]) {<br /> printf("\nQuery Google API... \n");<br /> HTTPText txt("text/html",5000);<br /> HTTPResult r = http.get(url, &txt);<br /> <br /> if (r==HTTP_OK) {<br /> printf("Result Ok\n");<br /> led2 = 0;<br /> return txt.gets();<br /> } else {<br /> printf("Error %d\n",r);<br /> led2 = 1;<br /> return "FAIL";<br /> }<br />}<br /><br />void getAPI() {<br /> string testres;<br /> string results;<br /> char to[3];<br /> char url[256];<br /> strcpy(url,(char*)getURL().c_str());<br /> results = getPage(url);<br /> //printf("results API %s\n",results);<br /> <br /> if (results == "FAIL") {<br /> printf("%s\n","Bad Result");<br /> // Make no changes to the target temperature<br /> } else {<br /> testres = strstr(results.c_str(),"<title type='html'>");<br /> //printf("\n\n\n%s\n",testres);<br /> if (testres == "") {<br /> // no temperature set for this time<br /> printf("%s\n","No calendar entry for this time");<br /> targetTemp = 0;<br /> led3 = 0;<br /> } else {<br />
// grab the temperature (this assumes I've entered a 2 digit int in the event title)<br /> strncpy(to, testres.c_str()+19, 2);<br /> printf("result: %s\n", to);<br /> targetTemp = atoi(to);<br /> led3 = 1;<br /> }<br /> }<br />}<br /><br />void getNTP() {<br /> ctTime = time(NULL);<br /> printf("Current time is (UTC): %d %s\n", ctTime, ctime(&ctTime));<br /> printf("NTP setTime...\n");<br /> Host server(IpAddr(), 123, "pool.ntp.org");<br /> printf("Result : %d\n", ntp.setTime(server));<br /> ctTime = time(NULL);<br /> printf("Time is now (UTC): %d %s\n", ctTime, ctime(&ctTime));<br />}<br /><br />void checkTemperature() {<br /> float temp = device.readTemperature();<br /> if (temp > (targetTemp+0.5)) {<br /> heater = 0;<br /> led4 = 0;<br /> } <br /> if (temp < targetTemp) {<br /> heater = 1;<br /> led4 = 1;<br /> }<br />}<br /><br />int main() {<br /> EthernetErr ethErr;<br /> int count = 0;<br /> do {<br /> printf("Setting up %d...\n", ++count);<br /> ethErr = eth.setup();<br /> if (ethErr) printf("Timeout\n", ethErr);<br /> } while (ethErr != ETH_OK);<br /><br /> printf("Connected OK\n");<br /> const char* hwAddr = eth.getHwAddr();<br /> printf("HW address : %02x:%02x:%02x:%02x:%02x:%02x\n",<br /> hwAddr[0], hwAddr[1], hwAddr[2],<br /> hwAddr[3], hwAddr[4], hwAddr[5]);<br /><br /> IpAddr ethIp = eth.getIp();<br /> printf("IP address : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);<br /> printf("Check router DHCP table for name : %s\n", eth.getHostname());<br /><br /> getNTP();<br /> getAPI();<br /> <br /> Timer pollTemp;<br /> pollTemp.start();<br /> Timer pollAPI;<br /> pollAPI.start();<br /> Timer pollNTP;<br /> pollNTP.start();<br /> Timer lookAlive;<br /> lookAlive.start();<br /> <br /> while (true) {<br /> if (lookAlive.read() > 1) {<br /> led1 = !led1;<br /> lookAlive.start();<br /> }<br /> if (pollTemp.read() > 10) {<br /> checkTemperature();<br /> pollTemp.start();<br /> }<br /> if (pollAPI.read() > 30) {<br /> getAPI();<br /> printf("Target Temp: %i\n",targetTemp);<br /> pollAPI.start();<br /> }<br /> if (pollNTP.read() > 21000) {<br /> pollNTP.start();<br /> getNTP();<br /> }<br /> }<br />}Shack Dwellerhttp://www.blogger.com/profile/03435683760389118162noreply@blogger.com12tag:blogger.com,1999:blog-6052926331741336172.post-6120230698139649202012-04-24T22:44:00.002-07:002012-04-25T00:24:26.016-07:00The Google API and smartphone featuresThe Google API developers guide is a scary read at first if you're about to program in C and you're not a C programmer, but I discovered a much easier way to play with this.<br />
<br />
<a href="https://developers.google.com/google-apps/calendar/v2/developers_guide_protocol">https://developers.google.com/google-apps/calendar/v2/developers_guide_protocol</a><br />
<br />
It talks about oAuth and fun things like this, but I discovered that you don't have to authenticate if you use the xml private address found on your calendar settings page.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ4Vy8iefM1RJdRBzwoby_-dwSNWx3rgWPJzJ-VurFHVqbc22EMNhPAbDWVy944JpaXluX4ZY2YXEUlLvT9RHd6FtV1JKmFaJh0JlJbDcptFedIrvsYEfPladivSTetVgIE6PTRsW95WxW/s1600/Screenshot+at+2012-04-25+15:29:50.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="250" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ4Vy8iefM1RJdRBzwoby_-dwSNWx3rgWPJzJ-VurFHVqbc22EMNhPAbDWVy944JpaXluX4ZY2YXEUlLvT9RHd6FtV1JKmFaJh0JlJbDcptFedIrvsYEfPladivSTetVgIE6PTRsW95WxW/s400/Screenshot+at+2012-04-25+15:29:50.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Getting the Private address</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
Now you can use any of the read-only API features as GET requests from google calendar. On the mBed I set the realtime clock using NTP and then format the time in RFC 3339, then the time plus one minute. It will return an XML of a event that is current.<br />
<br />
<a href="https://developers.google.com/google-apps/calendar/v2/reference#Parameters">https://developers.google.com/google-apps/calendar/v2/reference#Parameters</a><br />
<br />
example:<br />
?start-min=2012-04-21T18:30:00%2b10:00&start-max=2012-04-21T18:31:00%2b10:00<br />
<br />
<br />
<br />
So far so good. The final feature I wanted was the ability to enter events using my smart phone. Here's the time where I'm going to have to mention that I don't have an Android or open source smart phone, I carry an iPhone... *hides*<br />
<br />
There were a few websites that I found useful getting multiple google calendars to sync with my phone's calendar. Have a read and you'll work it out.<br />
<br />
<br />
Setting up google sync on iOS:<br />
<a href="http://support.google.com/mobile/bin/answer.py?hl=en&answer=138740">http://support.google.com/mobile/bin/answer.py?hl=en&answer=138740</a><br />
<br />
Using google sync with multiple calendars:<br />
<a href="http://support.google.com/mobile/bin/answer.py?hl=en&answer=139206">http://support.google.com/mobile/bin/answer.py?hl=en&answer=139206</a><br />
<br />
<br />
Finally, I've ordered some more bits to make the mBed connect via my wireless network as I don't currently have a wired one. Right now I'm using a computer as a wireless bridge and connecting the mBed using a crossover cable. These parts should arrive early next week.Shack Dwellerhttp://www.blogger.com/profile/03435683760389118162noreply@blogger.com2tag:blogger.com,1999:blog-6052926331741336172.post-54697020906397979512012-04-24T22:23:00.001-07:002012-04-24T22:23:04.905-07:00Wiring it up - Heater Automation<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
In the video posted below, I was controlling the heater by simply cutting the power supply to it. This was good because it meant that I hadn't played around with the built in safety features, but bad because it beeped every time the power cycled. Time to break out the screwdrivers!<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq2ZM1XyrWOWP3rR2Zd9gNkmdXLksLp5M39lNRQgwdb0kDK663NIZm_ufRZqrsGeqCVqYVBXrl7wyIdo7VsFKMjuy3xscQExcQlLQUyBvAXxAZeG5ecdEKeM8WRIywxFgSwtZ5h5ltVBdu/s1600/IMG_1611.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq2ZM1XyrWOWP3rR2Zd9gNkmdXLksLp5M39lNRQgwdb0kDK663NIZm_ufRZqrsGeqCVqYVBXrl7wyIdo7VsFKMjuy3xscQExcQlLQUyBvAXxAZeG5ecdEKeM8WRIywxFgSwtZ5h5ltVBdu/s320/IMG_1611.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The built in controller</td></tr>
</tbody></table>
The built in controller is fairly simple and I quickly figured out which was the signal between the two boards that caused the relay to switch. I then had a think about if it was safe to drive that relay myself, or should I be putting a second on in series with it, meaning I've got a fail safe with the on board temperature controller if my controller forgot to switch it off. I can wind the on board one up to a temperature at the highest level that I'll ever want, and that is as hot as the room will get in the event of a failure.<br />
<br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn81kpEcwNrqyU8TsWDsloGRsYxP4eePuynEjz3pOJx50fey43rZijbrQRAPJaZTwYlgUSjU7sJghyRdVouTTmWrnNVHCJFCt1FLgE8gwodpDUvUUu2uXN3jnRa5gzrF5bSH5-4C6yh9pp/s1600/IMG_1612.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn81kpEcwNrqyU8TsWDsloGRsYxP4eePuynEjz3pOJx50fey43rZijbrQRAPJaZTwYlgUSjU7sJghyRdVouTTmWrnNVHCJFCt1FLgE8gwodpDUvUUu2uXN3jnRa5gzrF5bSH5-4C6yh9pp/s320/IMG_1612.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">40A Solid State relay</td></tr>
</tbody></table>
I discovered when I went to my local electronics shop that they had some rather grunty solid state relays available for around $45 each. I grabbed a handful of 40A AC ones and one 100A DC for another project.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4pG6mpSb8Vr3dVd6MtC5BZHlJBzLWy3awzPCrY4Ypa3RzZl-9nYd0R5nFY2tdagdp2XvDTFWCfkI-uNR-Yy5_AGSf8u0BCSTbgpPWtyudaunD-poqCUnqvq4pnS3288sjj7_AJRNnCSos/s1600/IMG_1613.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4pG6mpSb8Vr3dVd6MtC5BZHlJBzLWy3awzPCrY4Ypa3RzZl-9nYd0R5nFY2tdagdp2XvDTFWCfkI-uNR-Yy5_AGSf8u0BCSTbgpPWtyudaunD-poqCUnqvq4pnS3288sjj7_AJRNnCSos/s320/IMG_1613.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">It fits in the space!! :)</td></tr>
</tbody></table>
As I said, I wired it in series with the existing controller for safety reasons. I'm not much of a C programmer so I figured this was the best option.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmSiJfOypZZYe9ToW8c2CAkkItE2iMfRd9DL7FXpFZdxAP9Hj84BYbt8VYh-lA9e7PaTik6MR7oZokC_9CS9CtSX1lohUBxfPLVz3kwl1hyphenhyphenH1EhElszbQ67xGI-eekynuXClHb_lCk9mPB/s1600/IMG_1614.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmSiJfOypZZYe9ToW8c2CAkkItE2iMfRd9DL7FXpFZdxAP9Hj84BYbt8VYh-lA9e7PaTik6MR7oZokC_9CS9CtSX1lohUBxfPLVz3kwl1hyphenhyphenH1EhElszbQ67xGI-eekynuXClHb_lCk9mPB/s320/IMG_1614.JPG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Wired up, taped up, stuck in</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx0WzEWVAV0V-JOqbwuv04yHEBK51hmJx7bRpoTe_-1ew7ftsStva7SexHdvTVeuobUDFyB447BsU731y_GmzNoKQIVDV7IL_uNSIinib7kQ8xWt65lvoWtMWuSbfDvNgZicLZ5p63cTvl/s1600/IMG_1616.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx0WzEWVAV0V-JOqbwuv04yHEBK51hmJx7bRpoTe_-1ew7ftsStva7SexHdvTVeuobUDFyB447BsU731y_GmzNoKQIVDV7IL_uNSIinib7kQ8xWt65lvoWtMWuSbfDvNgZicLZ5p63cTvl/s320/IMG_1616.JPG" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Ready to play</td></tr>
</tbody></table>Shack Dwellerhttp://www.blogger.com/profile/03435683760389118162noreply@blogger.com3tag:blogger.com,1999:blog-6052926331741336172.post-33901813843268125292012-04-24T03:52:00.003-07:002012-04-24T03:52:54.984-07:00Google Calendar Automation - part 1<div style="text-align: left;">
I've been thinking about what automated features I'd like in my new house which I hope to build in the coming year. This is the first of many ideas, programming the schedule and temperature of my heating using Google Calendar!<br /><br />I'm using an mBed in this video, but I've also got another board which is being designed by my friend Stu. Watch this space</div>
<div class="separator" style="clear: both; text-align: center;">
<br /><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/NlhNqCOUpZ4?feature=player_embedded' frameborder='0'></iframe></div>
<br />
I'll post some photos soon, tomorrow I'll be pulling the heater apart to wire it up properly. In the video you'll notice a 'beep' when it cuts in and out. This is not a desirable feature which is about to get fixed.Shack Dwellerhttp://www.blogger.com/profile/03435683760389118162noreply@blogger.com5