Friday, 23 August 2013

Running a web server on a Raspberry Pi

I've been quite frustrated in my attempts to get anything connected to my Raspberry Pi, mainly because it usually involves using a programming language that I only know the basics of, or some obscure application library that isn't very well documented.
As always, back to basics! I've decided to install a web server with PHP and MYSQL, then take it from there - these are tools that I am very proficient in and it will removes the unknowns from the equation. As I expected, this is very easy but I will take it slowly and assume that you are inexperienced. Please feel free to ask questions, point out errors or just generally comment.
Apache is a very popular web server that will let your Raspberry Pi run as a web server which means you will be able to access web pages that have been written and are stored on the Pi.
The web pages are usually written in HTML, but you can add a lot of functionality to the web server by adding another popular programming language called PHP.
Its also good to be able to use a database to store information about any systems that you create on the server.

Step 1 Install Raspbian on your Raspberry Pi.

I arent going to document this as there are hundreds of guides and I will only echo what has already been said. For the record, I used NOOBS (New out of the box software) to install it, then allowed SSH access and used MobaXTerm to access the graphical interface. (This isnt important, you can just as easily do this straight from a normal monitor view)

Step 2 Install Apache, PHP and MYSQL

On the desktop of Raspbian you will see an icon saying "LX Terminal". Click on that and then type this:

sudo apt-get update

The command "sudo" means "run this instruction as an administrator," which in linux is a user called "root".
The apt-get update part tells Raspbian to make sure that all its records of available software are up to date. You will see it trundle off and check lots of things, just leave it alone until you see a coloured command prompt starting "Pi@..."
The next command to type is:

sudo apt-get install apache2 php5 mysql-server

This instructs Raspbian to install the web server (Apache2), PHP version 5 and mysql-server. This will take five minutes or more, its fascinating to read the things that flash by on your screen, all very clever but once you have seen it a couple of dozen times, the delay is just an inconvenience!
You will be asked to set a password for mysql. Make this a secure, complex password and also make sure that you remember it!

Step 3 - Install phpmyadmin

You will now have a web server running (we will check it later) and we could start to add web pages. I've always used a great utility called phpmyadmin which lets you look after any databases running on Apache very easily.
Type this command:

sudo apt-get install phpmyadmin

Again, this takes a while. You will be asked for the MySQL password (the one you specified in step 2) and also for another password which you will use to log on to phpmyadmin once it is installed.

I usually install a GUI interface that is great for controlling a web server, its called webmin. This guide will tell you how to do it, but it isn't essential by any means!

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=63&t=6096

Step 4 - check it all works.

Type this command:

ifconfig

Into the terminal window, and Raspbian will tell you lots of information about how it connects to the network.
Look for  a line that starts "inet addr", followed by an IP address such as 192.168.1.210
This is the IP address of your Raspberry Pi. On any other computer on your network, open a browser and type this IP address into the main URL box. You should see a page that says "It works" - well done!
You can also use "http://192.168.1.200/phpmyadmin" to open the phpmyadmin window. It will ask you for the password that you entered in Step3 (nb, not step 2!)

Any web pages for your web server are stored on your raspberry Pi at /var/www
You should see a file there already called "index,html"

If you have come this far, well done! You will now need to work out how you can edit pages on your server and make it do something useful - watch our for future updates when I will be detailing various methods.

Tuesday, 20 August 2013

Frustrations and good luck

I dont really want to get distracted today - I need a solid day of coding development to work out how I can make the Raspberry Pi do the things I need it to do to control Pondnet.
Last night, after a successful day of re-jigging existing electrical systems to run by remote control, I went to turn the lights on but they wouldn't work. After checking wiring this morning I found that the power supply unit wasn't working. Its a sealed unit, all the components are sealed in resin and its a chunky "brick". As you can see there is an ominous crack on the side of the case so its either let water in or some connection inside has moved and is no longer connected.
Its rated at 12v 30va so I had a look around my spares box for a replacement unit. The only one that I found was a Netgear one rated at 15v but needs must! It won't fit in the box very easily but at least it doesn't involve any more money!
And then I remembered an old set of lights we had bought for our garden seat and stopped using. Luckily it uses exactly the same connector and is 12v 30va so is perfect. Unlike the pond light unit, it isn't a resin filled unit so I will need to enclose it somehow, probably just by keeping it in the distribution box.
Great, now I can devote some day to coding - pass the coffee and turn the Chemical Brothers up loud!

Pondnet is born!

A bit more progress, had a few things to do so it's been slower than I wished. 
I made a complete hash of fitting the solenoid valve, I managed to not only fit it backwards but also the wrong way round so the box lid would have to face the wall. After some head scratching, I had another go! The valve is a spare part from a washing machine and costs less than a fiver, but does run on mains voltage so has to be used with great care. 
I fitted it inside a ip66 container which means it is certified to remain waterproof when used outside. Its a simple case of connecting a washing machine hose as the input and a hose to the pond as the output. Control is via the two spade contacts. Ive fitted everything inside mains conduit, including the pipes so it's safe and quite neat. 

All the mains devices are now terminated with plugs which go into a distribution board inside an ip50 box (the lower number is because the water proof rating is different mainly due to the large cable entry hole). The pump, ultraviolet, air pump, pond lights and water valve can now all be remote controlled. There is enough room inside the box for my raspberry Pi, power supply and possibly an arduino. 

Tomorrow's job will be to get the Pi to control these remote control sockets via a 433mhz transmitter, then I can think about how the web interface can run. Ive ordered a temperature sensor, which runs on from a single gpio line, and an Ultrasonic Sensor which I can get to measure the water level, it needs two gpio lines.

Saturday, 3 August 2013

Setting up a Raspberry Pi to run "Headless"

On my last post I described how frustrating I had found the whole process of setting up my Raspberry Pi. I have had quite a few questions about the method I eventually used, so I am going to go through the eventual method I used in a bit more detail.

Initial Set Up.

This was much harder for me because of the issues in getting my monitor to work.
Plug in a USB keyboard, USB mouse, Ethernet cable and an SD card that has been freshly formatted and has a new uncompressed copy of NOOBS on it.
The two issues I faced here were that I had used a power supply that wasn't compatible (no idea why!) and I couldn't get the display to work. The green light closest to the sound jack socket was flashing in a steady on/off pattern, which I think means that there isn't enough power being delivered (I cant find out if this is the case though, if you have a link to any descriptions, please email me)

Im using a fairly standard VGA-HDMI lead as shown here.
The instructions for this lead mention that you may have to edit a config.txt file to get it to work. With the NOOBS software, this wasn't necessary, plugging a normal VGA lead (With ALL the pins in place, some have pin 9 missing which just adds extra problems)
The problem for me was that when I used a full VGA lead, my monitor displayed a message that I couldn't turn off saying that the resolution was incorrect. When I used a VGA lead with pin 9 missing, the monitor turned itself off after a short while. I spent quite a few hours trying to get this to work properly, in hindsight this was a waste of time!
The NOOBS software lets you choose which OS to install, I picked Raspbian.
After the OS has installed and the Raspberry Pi has rebooted, you will see a configuration menu. Choose the option to enable SSH access and remember to set this as the default. (Ive seen this option in a couple of different places, so I arent going to be precise - its always clearly marked)
Next, we need to get the IP address of the Raspberry Pi. Simply type:
ifconfig
This will display a lot of information, but on the first few lines it will say what the "Inet Addr" is. It will be something like 192.168.1.85
On your PC, download and install Putty and XMing. Double click on Xming to set it running and then open Putty.
Type in the IP address for your Raspberry and then click "Open".
You will be asked for a username which is "Pi" and a password which is "Raspberry"
Next we have to start the graphical interface for Raspbian, which we do by typing:
startlxde
Hopefully, your PC will now open a window in XMing that shows the graphical interface for the Raspberry Pi.
Once you have set this up, you can unplug the keyboard, mouse and monitor from the Raspberry and access it directly from your PC which is I have found to be much simpler.
Good luck, persevere and don't hesitate to get in touch with me if you have any problems.

Wednesday, 31 July 2013

Raspberry Pi frustrations

I was really excited when we were given a Raspberry Pi at school to "do whatever you want" with. I was even more excited when we were given five more by OCR!
I didn't really get much chance to do anything with them until this week. We had bought some HDMI-VGA leads which promised to work properly with the Pi and I had checked the many videos out there on how to set them up.
I had a good clearout at home a few weeks ago, and had thrown out an old keyboard because I had a much better one to use, but of course it is a wireless keyboard so wouldn't work with the Pi.
A new keyboard cost me a full fiver from PC World, and then I plugged everything and booted up.
A red and green LED came on and it all looked good. The green LED flashed on and off and then... nothing!
After much searching through the web for help (and finding none, couldnt find out what a flashing green LED meant, just what the patterns of flashing meant), I unplugged everything and tried again. This time, I swapped to another power supply (same 1.2A rating), and my screen flashed and the other three LEDs came on and it looked to be doing something.
I'm sure it was busy, but I had no idea what it was doing because my monitor was blank.
I knew that I probably had to edit a config.txt file on the SD card, but as I was using NOOBS it was hidden in a partition and I couldn't see it on my Windows laptop.
After several hours of trying every trick I could find on the web, I changed monitor leads from the standard blue D plug VGA lead to a much older lead that had pin 9 missing (which is used to power the EEPROM in the monitor for plug and play purposes)
Success! The display eventually came on and I was able to install Raspbian and get the Pi to boot. The monitor kept going to sleep, and it took a few changes to the settings to get it all running, and even then I had an annoying reminder on the display nagging me to change the screen resolution.
I am no stranger to these kinds of issues, but I can see that this would be really frustrating for an inexperienced user.
Anyway, I went into the settings on the Pi and enabled SSH, then loaded Putty and Xming. You can find the IP address of the Pi by typing:
ifconfig
And then use this to connect to the Pi with Putty, fairly standard and easy to do.
Start Xming, then load Putty and connect to the Pi.
Once you have a Telnet session (in the Putty window), type
startlxde
This should open a window which lets you see and use the Pi desktop.
At long last, I can start to play!

Thursday, 18 July 2013

Getting Loopy with PHP

This lesson starts to extend the skills and knowledge that students will need to be able to use PHP to solve problems.
The lesson starts with a recap on where the files are all stored because this had been causing issues.
It then looks at variables, IF statements and various methods of control structure such as SWITCH, WHILE and FOR.
This "lesson" allowed students to work at their own pace over a four hour period.
I am planning on creating a "PHP recipe book" with a series of scripts for them to copy and try and some graded problems for them to practice with.
Many of these lessons need a pair of HTMLpages, one with a HTML form to input values that can be used on the second page.
This word document has both pages, with different coloured backgrounds so that I can refer to the "green page" or "red page"


Click here to download the Getting Loopy presentation
Click here to download the Getting Loopy worksheet

Using PHP

We are lucky at Horbury Academy to have a web server that our students can access. I have set them all up with an individual FTP account so they can post live web pages and use PHP running on Apache.
This double lesson starts to introduce them to actual coding but also how to upload files to the server.
In practice, syncing between local files, remote files, and the browser cache took the students a while and I would cover this in more detail in future.




 I chose PHP because I think t meets these criteria.
  • Simple to understand
  • Syntax is simple.
  • Powerful 
  • It is widely used in industry, so will be useful for the students later
  • Students can install PHP on their home computers using XAMP
One issue with PHP is that it isnt easy to use an "input" command. This lesson also covers HTML forms (in fact we did forms first)


Click here to download the Using PHP presentation

Click here to download the Creating Web Forms worksheet

HTML Tables

Following on from the HTML Basics lesson, this is a one hour lesson on creating a HTML table.
The lesson reinforces how important that it is to make correctly nested tables.

Click here to download the HTML Tables presentation.

Introduction to HTML

As I have chosen to use PHP as the programming language for OCR computing GCSE, we start with a quick look at HTML.
This presentation is designed to get them started with the basics of HTML. It does not cover more advanced topics such as setting the doctype, but will enable students to create a simple HTML page from scratch.
Click here to download the presentation.
As always, feedback on the resources would be great!

Introduction To GCSE Computing presentation

At the start of a new GCSE course, I like to give an outline of what we will be covering, how the work will be assessed and also a quick look at some of tehe topics.
We start our new timetable two weeks after the June half term, so we have about four weeks of lessons before the Summer break. This gives students the chance to change options if they don't like the course, and most years I gain some and lose some students (this year I lost two and gained three)
The presentation starts with a look at some "celebrities" from the IT world before looking at the OCR course in more depth.
Please add comments if you find this useful, or can see a way to make it better.
Click here to download the GCSE computing introduction presentation.

GCSE Computing Scheme of Work

It can be daunting to approach the planning for a whole new course and writing an outline scheme of work takes a lot of time and effort. This is my first attempt at a scheme of work for our OCR Computing course. I will update it as we go through the year, giving more time for harder topics and either planning extra activities or reducing the time allocation for the ones when we have finished a topic early.
We teach GCSE options in five lessons a week, two doubles and a single sixty minute session.
Ive allowed a generous amount of time to learn how to use PHP and covered all of the theory topics three times. This is an introduction, a second look and a revision session for each topic once the final moderation date has been reached.
Feel free to adapt, adopt and modify, but I would appreciate some feedback so I can make it even better for next year!
Click here to download the scheme of work in Excel format.

Tuesday, 16 July 2013

Straw Poll generator

Easy to use resource!
From time to time in a lesson, it is useful to be able to run a quick "straw poll" to ask students opinions.
You can create great polls using Google Forms, but this web site:
http://strawpoll.me/
...really couldn't be easier!
The only caveat is to remember to tick the "permissive vote duplication" box as most school networks will appear as a single I.P. address and wont allow more than one person to vote.

Friday, 12 July 2013

Binary Addition poster

Binary Addition

This is a poster/ handout aimed at students who are struggling with binary addition.

Its a single page powerpoint page, feel free to adapt/adopt/modify according to the Yorkshire licence agreement, ie please acknowledge the source and but me a pint if you see me in a bar (wont be outside Gods Chosen Country, anyway!)
Link to the full poster 

Key Stage 3 Spreadsheet unit

This is a full scheme of work and resources for a Year 7 ICT spreadsheet unit. It includes a scheme, assessment criteria, home learning resources etc. I publish this on the "Yorkshire" licence, i.e. if you use it, please personalise it for your own use, tell me you have used it, provide feedback as to what went well and what can be improved and above all you owe me a beer when we next meet in a bar!
Here is a link to the full unit, if the link doesnt work, let me know and I will sort it out...

Rationalle...

This is intended to be a link unit between sometimes unsteady KS2 spreadsheet lessons and where we need students to be for key stage 4. I've tried to make it self explanatory but I'm sure that you all know that you learn as you go with a unit like this, get to know its good points and adopt/adapt/modify as you go. Its tailored very closely to my own experience, teaching style and school requirements, and you are completely free to change it as you see fit, just please acknowledge where the original idea came from!

Lesson 1


The first lesson is a recap on basic concepts, terminology and the contents of cells. The lesson focuses on using a spreadsheet to draw a students timetable, and deliberately avoids formula etc.
The home learning task is to identify common spreadsheet functions, its aimed squarely at Excel 2010 but can be adopted easily.

Lesson 2

Lesson 2 looks in more depth at simple formula. The starter activity asks them to create a "battleshiship" game which they then play as a class. The limitations with this activity is that once they have a ship on cell A1, they will win the game! Nevertheless, play it quickly and with pace and it reinforces the aims of the lesson.
This lessons focus is simple formula and cell references:

The main activity is a "macro enabled spreadsheet". Students will need to copy this and enable editing and trusted documents, but will then get feedback for each answer they give.

In practice this gives a surprising split in abilities. Some students march through the process whilst others flounder. Please let me know how your cohorts get on, and I will modify as we move forward.

Lesson 3

Lesson 3 introduces functions.

This should let students work very independently and work through the topic.

It has been really surprising how different groups of students get though this at different rates. The activities explain them selves, but you do need to go through them first.

Lesson 4

This lesson starts with a "knowledge hunt", where students look for the answer to certain questions from posters that you leave around the room.

Students will then have to create three different types of graph and annotate them to explain what they show.

The home learning activity is to answer various questions about the graphs.

Lesson 5

Lesson 5 looks at the filtering available and some sorting tools:
Although this is fairly closely tailored to Horbury Academy, it is easily modified to your own situation.

Lesson 6

The final lesson is a test, good old style assessment!
It should allow you to grade students fairly easily according to the assessment criteria.

As I said earlier, this is a bridging unit and should provide year 7 students with the knowledge, skills and understanding to move on to what we need them to be able to do in KS4.
In practice, I usually find that they still need frequent "top ups" on spreadsheets and until they need tp use one "in real life", they dont make radical progress!.

Please, please, please, email me with comments, links and other resources and I can improve what I have attempted to do.

Sunday, 30 June 2013

Hello World

Well, in the best traditions in a geek experiment, here is my "Hello World" activity. This blog is my method of sharing experiences of teaching ICT and computing.
I suppose most people will come here to download the resources, lesson plans, schemes of work and other classroom ready tools for secondary teachers in the UK. I may also post some ideas that may trigger debate and can be developed into something useful.
First, a bit about me.
I started using computers was back in 1979 when a window salesman (as in the things you look out of) called at our house and mentioned that he had a Sinclair ZX80 that he wasn't happy with. My dad bought it from him for £30 and we set it up on our TV.
The ZX80 had a built in BASIC interpreter, ran with 1k of RAM and the hardware was so limited that it couldn't run the display at the same time as processing a program! The screen would go blank and then return when the program either ended or hit a PAUSE instruction (in capitals because the keywords were all entered by pressing a key)
I was hooked! I spent any nights staying up all night to enter or debug something that I was developing. Clearly my dad was also hooked because he bought a 16k Tandy TRS80 L2 system, complete with green screen monitor and cassette storage. On the Tandy, I could delve into machine code and had to learn a whole load of theory including how to poke the hand crafted machine code into memory byte by byte.
I may say a bit more about my computing journey later, but you may notice how closely the skills I was learning fit the GCSE Computing specification. They are either key skills, or hopelessly outdated!