31.07.2015 Views

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A TEACHER’S GUIDE TO THE INTEL® GALILEO | 60Explanation of <strong>the</strong> codeThe code for this web server makes use of two different libraries with built in functions forweb servers: <strong>the</strong> SocketServer library and <strong>the</strong> SimpleHTTPServer library. The MyTCPServerclass makes use of <strong>the</strong> SocketServer library while <strong>the</strong> HandleRequests class makes use of <strong>the</strong>SimpleHTTPServer library.In this code we basically create a MyTCPServer serving at port 8080 and <strong>the</strong>n call <strong>the</strong> serve_forever method. This method will cause <strong>the</strong> do_GET method <strong>to</strong> be called whenever <strong>the</strong>re is aGET request from <strong>the</strong> browser. Thus whenever <strong>the</strong> user refreshes <strong>the</strong> browser this code will becalled.Inside <strong>the</strong> do_GET method, <strong>the</strong> temperature is read from <strong>the</strong> currentTemperature file in<strong>to</strong> aglobal variable called currentTemp.Then a multiline string is formed for <strong>the</strong> html for <strong>the</strong> page with <strong>the</strong> current temp beingsubstituted in for <strong>the</strong> %s inside <strong>the</strong> html. The rest of <strong>the</strong> code is Javascript for creating <strong>the</strong>Google Chart which calls on Javascript code within <strong>the</strong> browser. See below for tu<strong>to</strong>rials on how<strong>to</strong> implement Google Charts.Starting <strong>the</strong> Web ServerOpen up a browser and go <strong>to</strong> <strong>the</strong> web address http:XX.XX.XX.XX:8081 (where XX.XX.XX.XX isyour IP address of your <strong>Galileo</strong>). Refresh <strong>the</strong> browser <strong>to</strong> display <strong>the</strong> latest ambient temperaturefrom your <strong>Galileo</strong>.Going Fur<strong>the</strong>rYou can use Google Charts <strong>to</strong> plot all sorts of different charts. For example, we could writetemperature every 10 minutes for 12 hours overnight in<strong>to</strong> a file on <strong>the</strong> <strong>Galileo</strong> and <strong>the</strong>n plot anight’s worth of temperature on our web server as a Line Graph using Google Charts. You couldalso use <strong>the</strong> <strong>Galileo</strong> <strong>to</strong> record soil moisture readings and <strong>the</strong>n plot <strong>the</strong>m using Google Charts.Resources on Google Chartshttps://developers.google.com/chart/interactive/docs/quick_starthttps://developers.google.com/chart/interactive/docs/examples#gauge_examplehttp://code.tutsplus.com/tu<strong>to</strong>rials/easy-graphs-with-google-chart-<strong>to</strong>ols--net-11771

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!