loading

Step 4: Setting Up the Web Server (Apache2)

Setting up Apache2

As I described above, we are going to use a PHP script on the Linux side of the Edison to collect the weather data and pass it to the Arduino sketch. So the first thing we need to do is install Apache2 (a popular webserver) and then install PHP.

It install it, you’ll need to use “AlexT’s” software repository. You can find it here (http://alextgalileo.altervista.org/edison-package-repo-configuration-instructions.html ) along with all the needed documentation. Once the repo is setup you can run the following to install apache:

opkg install apache2
opkg install php-modphp

Once Apache2 is installed you’ll need to change the port that the Apache2 service will watch. You do that by editing the Apach2 config file: /etc/apache2/httpd.conf

There are two ways to edit the file. You can use an editor like VI to create and edit the file in place, or you can use WinSCP to remotely manipulate the file. WinSCP works over a SSH connection to allow you to manipulate the file system of a remove Linux box. For more information on WinSCP and the Intel Edison you should read over the following Instructable: https://www.instructables.com/id/Intel-Edison-Upda...

Once you’re ready to edit the file locate the “listen” line (around line 52) and update it to:

Listen 84

Now you’ll need to configure Apache2 to start on reboot (commonly refereed to as making it persistent) and you’ll also want to start the service. You can do those things with the following commandlines:

systemstl stop apache2
systemstl enable apache2
systemstl start apache2

Apache2 and PHP should now be running on your Edison. The default directory for the root of the webserver is at : /usr/share/apache2/htdocs.

It’s now time to test Apache2. Load a web browser on a computer on the same network, and access the Edison at:

http://[EDISONS-IP]:84/index.html

The rename “index.html” to “index.php” and used the other computer to load:

http://[EDISONS-IP]:84/index.php

Setting up the PHP script.

Now we’ll need to put the "weather-set-1.php" file (linked below) into the Edison’s web root (/usr/share/apache2/htdocs). You can use either WinSCP or create and edit the file with an editor like VI.

https://github.com/nam37/weathergrid/blob/master/w...

Once the file is created or copied over you can test the script using:

http://[EDISONS-IP]:84/weather-set-1.php/weather-s...

and

http://[EDISONS-IP]:84/weather-set-1.php/weather-s...

As before, it’s outside of the scope of this Instructable to fully explain every line of the script, but in general there are two important things going on here. First we are using ipinfo.io for geolocation. To do this we use “file_get_contents” to hit the ipinfo.io site and they reply back with our zip code. We then take this zip code and (using “file_get_contents” again) request our weather from Yahoo Weather using an edited version of a script from http://www.hastuts.com/display-weather-forecast-b... . Finally, we take the weather or temperature data and pass it to the Arduino via the web server running on the Arduino.

A more complete structure of the script:

  • The beginning of the script sets the local time zone. You should set yours to the applicable time zone. For more information, look here: http://php.net/manual/en/function.date-default-ti...
  • Next script determines if we’re attempting to set the temperature or the weather code based on the querystring.
  • Finally the script ends with the functions the make it all work.
<p>Thankyou man<br>And good luck with your new project!</p>
<p>ohh yeah and when is 2.0 coming out?</p>
<p>Honestly I'm not sure. I'm currently working on a new project (with the MediaTek LinkIt One) and then my schedule starts to get pretty tight with the holidays.</p>
<p>Heym this project is amazing.<br>I was wondering, how could i modify this so instead of just showing current weather conditions, it would show the current condition and conditions for later on in the day. An answer would be great thanks!</p>
<p>Sure... Off the top of my head you could either:<br>- have two (smaller?) separate grids or one grid and two LCDs</p><p>- have it alternate colors for current and future conditions</p><p>- have the current weather in the grid and the future weather in the LCD</p><p>Whichever way you did it, you would then just adjust the PHP script (add more querystring options), and then add the new PHP functions to the cron tab.</p>
<p>Great project and very well explained!</p>
<p>I posted a link to this project on 2 weather forums. </p>
<p>Cool thanks.</p>
<p>Nice project! I like the front plate design and weathered look.</p><p>Did you consider mounting some dividers inside to prevent unwanted images to light up?</p>
<p>&gt;&gt; Did you consider mounting some dividers inside to prevent unwanted images to light up?</p><p>Yup. That's one of the changes I'm going to add to my 2.0 build. That said, in person the bleed isn't nearly as bad as it looks in the pictures.</p>
<p>looking forward to the 2.0 version. Good luck!</p>

About This Instructable

2,485views

75favorites

License:

More by nam37:The Weather Grid (Powered By Intel Edison) 
Add instructable to: