The Digital Free Library is a fun project that will allow you to create your own electronic library to share with others. Similiar to a Little Free Library but digital.

I decided to create this project so I could share my favorite digital magazines and projects with my neighborhood. Hopefully this will get others interested in electronics by showing them stuff they might not have know about.

We will be using a Raspberry Pi Zero and a WiFi adapter to create a hotspot that others can connect to and browse the digital books offered. 

Parts Needed

Prepare Micro SD Card

We will be using Raspbian Jessie Lite, the version I use is September 2016. To find older releases we can go to http://downloads.raspberrypi.org/

You may also want to try a more recent version if that's available and 9/28/2016 isnt working

Once that is done we need to setup the Pi Zero to be used as a ethernet gadget. This will allow us to program it from our computer when it is plugged in to the usb port. 

Follow the Ethernet Gadget and Ethernet Tweaks steps in the following guide. I did not need to do the fixed IP step.

To connect to the Raspberry Pi we will use SSH. If you are not familiar with using SSH to access the Raspberry Pi follow this guide and then come back to here

Now we can connect to the Raspberry Pi using SSH. The hostname we will be connecting to is raspberrypi.local

Now is also a good time to change the default password to something more secure. Enter passwd and follow the prompts.

Before moving to the next step we need to make sure we can connect to the internet. We will ping google.com

ping -c 5 google.com

We will be using Apache for the Web Server. These install instructions were taken from the Raspberry Pi Foundation website. Their guide can be found at www.raspberrypi.org/documentation/remote-access/web-server/apache.md

We will start with installing apache using the following command in terminal. This will take about 5 minutes to install.

sudo apt-get install apache2 -y

 Next we will navigate to where this was just installed.

cd /var/www/

Currently we do not have permissions to the folder html. We will need permissions so we can change the index page and add our files. To do this we will enter this in.

sudo chown pi: html

To test that Apache installed correctly we will open a web browser and go to

http://raspberrypi.local/

We now want to leave this folder and go back to the main directory. We will have issues later in the guide if we stay in /var/www, to exit just enter

cd

For setting up the Raspberry Pi as an access point we will be using most of the steps from the Setting up a Raspberry Pi as a WiFI access point guide but with some changes for our project.

First we install the software onto the Raspberry Pi that will act as the 'hostap' (host access point) 

sudo apt-get install hostapd isc-dhcp-server

Set up DHCP server


Next we will edit /etc/dhcp/dhcpd.conf, a file that sets up our DHCP server - this allows wifi connections to automatically get IP addresses, DNS, etc.

Run this command to edit the file

sudo nano /etc/dhcp/dhcpd.conf

Find the lines that say

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

and change them to add a # in the beginning so they say

#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

Find the lines that say

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

and remove the # so it says

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Then scroll down to the bottom and add the following lines

subnet 192.168.42.0 netmask 255.255.255.0 {
	range 192.168.42.10 192.168.42.50;
	option broadcast-address 192.168.42.255;
	option routers 192.168.42.1;
	default-lease-time 600;
	max-lease-time 7200;
	option domain-name "local";
	option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Save the file by typing in Control-X then Y then return

Run

sudo nano /etc/default/isc-dhcp-server

and scroll down to INTERFACES="" and update it to say INTERFACES="wlan0"

Or whatever the name of your wifi adapter is!

close and save the file

Set up wlan0 for static IP


If you happen to have wlan0 active because you set it up, run sudo ifdown wlan0
There's no harm in running it if you're not sure.

Next we will set up the wlan0 connection to be static and incoming. Run sudo nano /etc/network/interfaces to edit the file

Find the line auto wlan0 and add a # in front of the line, and in front of every line afterwards. If you don't have that line, just make sure it looks like the screenshot below in the end! Basically just remove any old wlan0 configuration settings, we'll be changing them up

Depending on your existing setup/distribution there might be more or less text and it may vary a little bit

Add the lines

iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0

After allow-hotplug wlan0 - see below for an example of what it should look like.  Any other lines afterwards should have a # in front to disable them

Save the file (Control-X Y )

Assign a static IP address to the wifi adapter by running
sudo ifconfig wlan0 192.168.42.1

We will get an error message since we do not have a device connected to wlan0 at the moment.

Configure Access Point

Now we can configure the access point details. 

Create a new file by running sudo nano /etc/hostapd/hostapd.conf

Paste the following in, you can change the text after ssid= to another name, that will be the network broadcast name.

The password can be changed with the text after wpa_passphrase= 

To enable a password remove the # in front of the 5 lines that have wpa in them

interface=wlan0
#driver=rtl871xdrv
ssid=Pi_AP
country_code=US
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
#wpa=2
#wpa_passphrase=Raspberry
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=CCMP
#wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1

I have found that it will load the correct drivers if you comment out the line driver=rtl871xdrv

Save as usual. Make sure each line has no extra spaces or tabs at the end or beginning - this file is pretty picky!

Now we will tell the Pi where to find this configuration file. Run sudo nano /etc/default/hostapd

Find the line #DAEMON_CONF="" and edit it so it says DAEMON_CONF="/etc/hostapd/hostapd.conf"
Don't forget to remove the # in front to activate it!

Then save the file

Likewise, run sudo nano /etc/init.d/hostapd and find the line

DAEMON_CONF=

and change it to

DAEMON_CONF=/etc/hostapd/hostapd.conf

Update hostapd

 I have added this step as required since I could not get it to work with the usb wifi module until I did this.

Before we can run the access point software, we have to update it to a version that supports the WiFi adapter.
First get the new version by typing in

wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip

to download the new version (check the next section for how to compile your own updated hostapd) then

unzip adafruit_hostapd_14128.zip

to uncompress it. Move the old version out of the way with

sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG

And move the new version back with

sudo mv hostapd /usr/sbin

set it up so its valid to run with

sudo chown root:root /usr/sbin/hostapd

sudo chmod 755 /usr/sbin/hostapd

Finishing up!

Now it is time to set it up as a 'daemon' - a program that will start when the Pi boots.

To set the daemon services to run every time on boot enter these commands.

sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable

I have made a simple website that can be uploaded to the Raspberry Pi and show the media to download.

Once you have the file downloaded you can open the index.html file in a word editing program such as WordPad and edit the links for the images and files if you want to add or remove books.

Each book has this piece of code in the file.

<div class="responsive">
  <div class="img">
  <a target="_top" href="issues/coloringbook_1-23-2014.pdf">
    <img src="images/rforrobot.jpg" >
  </a>
  <div class="desc"><p>Ladyada's R is for Robotics is a coloring book adventure with robots, their inventors and more.</p>
<p>Makers of all ages can learn, color and share their favorite robots and roboticists.</p>
<a href="https://www.adafruit.com/products/1936" target="_blank">https://www.adafruit.com/products/1936</a></div>
</div>
</div>

To add aditional books to the page paste the code shown above before the </body> tag in the html file.

If you want to target a different file change the section

<a target="_top" href="issues/coloringbook_1-23-2014.pdf">

Files are placed in the issues folder. 

For changing the image that shows you would change the line with

<img src="images/rforrobot.jpg" >

 For images we named the folder images

You change either folder to any name, but just make sure the code is pointing to the right folder.

To change the description under the image we would edit this part of the code from earlier.

<div class="desc"><p>Ladyada's "E is for Electronics" is a coloring book adventure with electronic components and their inventors.</p>
<p>Makers of all ages can learn, color, and share common parts and historical figures throughout history. Explore the world of electronics with Ladyada as your guide!</p>
<a href="https://www.adafruit.com/products/1000" target="_blank">https://www.adafruit.com/products/1000</a></div>

To get our html page and files to the Raspberry Pi we will be using WinSCP.

Once WinSCP is installed we will open it up and put in raspberrypi.local for the Host name. You can also enter the username and password now or it will prompt you for that info later.

Now we will click Login.

Once we are connected and logged in we will be put in the /home/pi directory. The left side window is your pc and the right side window is the Raspberry Pi

We need to go up two directories. So double-click on the folder with the up arrow twice.

Now we are in the root folder. We need to get to /var/www/html, Double-click on the folder labeled var, then double-click on the folder labeled www, and finally double click the folder labeled html

We first need to delete the index.html file currently there. Then drag the files downloaded previously to this directory.

Currently the Hostname is at the default of raspberrypi, we want something more suited for this project. I will be using library, you could use any name you want or keep it at the default.

To change the hostname we will type

sudo raspi-config

Then select Advanced Options

Then select Hostname

Now you can enter in the Hostname you want to use.

Once you exit the config it will ask if you would like to reboot. Select yes.

When you connect using SSH you will need to enter the new hostname library.local

With the WiFi Dongle plugged in and the Raspberry Pi powered up we should see a Wifi connection labeled Pi_AP or what you had renamed the SSID to earlier. Select that network to connect to. Depending on your device used you might get a no internet connection warning.

In your web browser go library.local this may be different if you used a different hostname.

The library.local link works for most web browsers that I tested except Microsoft Edge. On the Edge browser you need to put in the IP adress. From an earlier step we set that to 192.168.42.1

This guide was first published on Dec 09, 2016. It was last updated on Nov 28, 2016.