Installing and configuring the OS
Raspbian OS
The first step was to install the operating system on the Pi. This was easy do and once installed the SSH could be configured to allow for remote access to the Raspberry Pi's command line from any computer on the network.
SSH
To gain SSH access the Pi had to be set with a static IP address so that it could be logged onto using PuTTY on Windows 7. This was done using the nano text editor in LXTerminal e.g "nano /etc/network/interfaces"
Once the SSH was set up we could now start installing some software and writing some scripts. Since Python is the Raspberry Pi's native language it made the most sense to use this, along with the fact that it is a brilliant language to code in. What we needed to do however was connect to the Arduino's serial port and start reading in some data.
Python and PySerial
Python scripts can be ran in the terminal by using "python" and then writing your script into the compiler. You can also run scripts that have been saved with the .py extension so if you create a script using "nano script_name.py" you will be then be able to type "python script_name.py" and it will run the script. Scripts can be set to auto run which gives us the capability to create whole automation scripts that could potentially control many devices according to the temperatures read, for example opening the windows when warm or setting the thermostat when too hot or too cold.It's easy install libraries and other software in the terminal and once installed in can be imported into any python script.
Just include serial in your python script now and you will have full access to the serial port and you can finally start reading and sending data over the serial port.
LAMP Server - Linux, Apache, MySql and PHP
After installing Apache, MySql and PHP on your machine you will gain the ability to serve up web pages to the local network which can be accessed by the IP Address you assigned earlier e.g "192.168.1.51". With PHPMyAdmin you can gain access, with a little configuring, to "192.168.1.51/phpmyadmin" which will allow you to run MySql code in your database.
PHP scripts can be used then to make a connection to the database and display it on the site for the user to view. It can also send values over the site which can run scripts to update databases to add new sensors or send states to devices such as lights or electrical devices e.g immersions etc.
When an Arduino is connected to the Pi, the Pi can run a python script to read values from the Arduino's sensors and then store them in the MySql database or on the Pi's local disk. The PHP files on the site can then update the site with the new data as well as send back commands to the Raspberry Pi which can control different devices on it's own GPIO pins or send commands towards the Arduino to control devices connected to that.
Speeding Up the Pi
Since the Pi is only accessed over SSH and the GUI doesn't need to be given much memory, the memory that had been allocated to the GUI was reset to give more to the hardware and I also overclocked the Pi to a safe enough level. Since the Pi is going to be dealing with so much requests it may be a good option to create an image of the OS on a usb stick or hard drive and point towards that image on a boot file on the SD card which you would normally install the OS on. This is because there is a limited amount of read/writes on an sd card and since there will be so much data being updated and stored on the SD card over time, we want to ensure that none of it gets corrupted or lost. A Raspberry Pi if it's configured properly can serve up website that are in the top 30% fastest loading times in the world of the internet.
Next thing to do is write to the Arduino to start control some device states and turn on some leds.
-Conor


No comments:
Post a Comment