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: http://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:
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:
The rename “index.html” to “index.php” and used the other computer to load:
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.
Once the file is created or copied over you can test the script using:
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.