The steps that are done in the class are posted in the following link

Setting up Pi as WiFi router

After performing steps in the above link continue the process.

Console connection to Pi:

In order to connect laptop and Pi, the first requirement is that both of them should be on the same network. For windows operating system there is an open source software called PUTTY is used to connect raspberry pi using SSH.

Arduino on PI:

The first step is to load the Arduino environment onto the Raspberry Pi.

Now install the Arduino IDE with:

Arduino WiFi client:

#include <SPI.h>
#include <WiFi.h>char ssid[] = “Harsha”;          //  your network SSID (name)
char pass[] = “raspberry”;   // your network passwordint status = WL_IDLE_STATUS;
IPAddress server(74,125,115,105);  // Google// Initialize the client library
WiFiClient client;void setup() {
Serial.begin(9600);
Serial.println(“Attempting to connect to WPA network…”);
Serial.print(“SSID: “);
Serial.println(ssid);status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println(“Couldn’t get a wifi connection”);
// don’t do anything else:
while(true);
}
else {
Serial.println(“Connected to wifi”);
Serial.println(\nStarting connection…”);
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println(“connected”);
// Make a HTTP request:
client.println(“GET /search?q=arduino HTTP/1.0”);
client.println();
}
}
}void loop() {}

Install Arduino on PI:

The Arduino processor on the Sleepy Pi can be programmed directly from the Raspberry Pi using the serial GPIO lines on the RaspberryPi. By default Raspbian has exclusive access to the serial pins to output status, debug data and logging in. We need to change that using the following steps.

Step 1: Disable Serial login

Raspbian allows you to log in using the serial port. To use the Sleepy Pi we need to disable this.

Step 2. Disable Boot info

When Raspbian boots up it outputs boot information to the serial port and hence streams it to the Sleepy Pi (which is not particularly interested in it). To disable this we need to edit the /boot/cmdline.txt file

change the following line

Step 3. Link the Serial port to the Arduino IDE

The Arduino IDE wants to use the /dev/ttyS0 serial port, but we need to use the /dev/ttyAMA0 which is linked to the GPIO. In order to do

this

we need to create a permanent link that maps AMA0 to S0. We can do this in LXTerminal by the following sequence:

In the new file that it creates type the following:

Save this file as a new file called “80-sleepypi.rules” to: /etc/udev/rules.d/

Setting up the Reset (DTR) pin

wget https://github.com/SpellFoundry/avrdude-rpi/archive/master.zip
sudo unzip master.zip

Next, copy the files to the appropriate places from a LXTerminal window using the following commands: 

This renames your original avrdude

so that you have a backup and can replace it with the new one.

Adding the Sleepy Pi to the Arduino environment

to create folders “hardware” and “sleepy pi” in your Arduino sketchbook.

Download and copy the boards.txt file to the Sleepy Pi folder.

Reboot

And

finally

reboot your Raspberry Pi to complete and load all our changes. You can use:

HTTP server:

Next we are going to configure the router to allow ssh logins and web traffics through its firewall to the Raspberry Pi.

You did remember to change the default password for the pi username didn’t you! If you haven’t already changed the default password then do it now otherwise anyone will be able to login to your Raspberry Pi.

As a home user the ip address used on your local network is a private address range that will not work over the Internet. Instead your ISP will provide a single dynamic IP address which is used by the router. To allow traffic to flow from the Internet to your Raspberry Pi needs the IP address of the Pi to be made to look as though it is from the router. This is a process called Network Address Translation (NAT).

The ports that need to be allowed through are port 80 (http) and if you would like to be able to login to the computer from the Internet then port 22 (ssh).

To do this you will need to consult the instructions on your router. In the case of my Belkin router this is through the Firewall > Virtual servers settings (see below), but Netgear this is Advanced > Security > IP Forwarding.

Belkin wireless router firewall virtual server settings (NAT)

DNS

The final stage is to have a DNS entry point at your router’s IP address. In my case I have cable Internet through Virgin Media. Although it does have a dynamic IP address the address does not normally change. I have a static DNS entry on a Internet DNS server. The entry only needs to be changed about once every year or when Virgin Media perform significance maintenance on the Internet connection.

If you have a dynamic IP address that changes on a more recent basis then you will need to register for a dynamic dns service.

Installing lighttpd

To install the lighttpd web server issue the command.
sudo apt-get install lighttpd

This will install the web server and also pull in any other packages (called dependencies) that are required.

Install mysql database (optional)

 

sudo apt-get install mysql-server

During the install there is a prompt request for a password.
The password is for the mysql root user.

Set permissions on the web directory /var/www/

It is useful to change the permissions on the www directory to allow your user to update the web pages without needing to be root.

Change the directory owner and group
sudo chown www-data:www-data /var/www
allow the group to write to the directory
sudo chmod 775 /var/www
Add the pi user to the www-data group
sudo usermod -a -G www-data pi

You should log out and back in – to pick up group permissions, or if running X you can just start a new terminal.

Testing the server

Once the setup is complete you can access the web page by pointing your browser to the router IP address or DNS entry.

You should get a page back stating that it works, but that there is no content loaded.

Advertisements