Monitor multiple Raspberry Pi logins using PHP and MySQL

As you can see I recently bought a domain name in order to host a more customisable WordPress blog as well as build a few experiments. One of which is a quick and easy system for logging each of the Raspberry Pi devices that run my custom boot script.

I’d previously created something similar when I got my daughter’s Raspberry Pi to send a tweet whenever it booted up. That was fun but it didn’t scale easily when used with multiple devices. I wanted a central list where all devices were displayed in boot order.

I decided to create a simple MySQL database that could be queried via PHP. The database would contain information sent to it by each Raspberry Pi as it connected to the Internet. I decided initially that I only required device name, username and a timestamp.

I had thought that each Raspberry Pi could run a Python program that opened a connection to the MySQLi database but this appears to be the wrong approach. It seemed much easier to create PHP code that wrote a line to the database using values pulled from the URL (using the $_GET command).

In case it helps, here is some of the PHP to add information to the database:


$sql = "INSERT INTO pilogin (piname, timestamp, username) VALUES ('" . $_GET['piname']."', now(), '" . $_GET['username']."')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "
" . $conn->error;
}
$conn->close();

The final step was to edit /etc/rc.local so that it ran cURL with the appropriate web address and values. I wanted to delay the command until the network connection setup was complete and found that this forum post had a great suggestion for doing this while also allowing other programs to continue running.

I won’t post the actual line for obvious reasons but a similar solution. I’ve also included code that extracts the current Raspberry Pi hostname and user and encodes it into the URL.

Here is an extract from my /etc/rc.local file:

u="$USER" # system variable for user
h=hostname #note the backticks
(sleep 30s; curl "http://webaddress/page.php?hostname=$h&user=$u") &

Happy to hear of any improvements or alternatives!

#CASAberdeen Hub – New Chair Required

I sent the following email to the CAS (Computing At School) Aberdeen hub earlier in the week:

Dear all,

Due to an impending relocation this summer I am looking for a volunteer to take on the chairing of the CAS Aberdeen hub.

The hub has run a number of small but successful events over the past few years for Computing staff and students. Schools across Aberdeen City and Aberdeenshire have benefitted from free professional development, resources and hardware. In short, it would be a real shame for this hub to close.

This position is entirely voluntary but funding is available via the Computing At School organisation to cover tea/coffee expenses for any event you organise.

Please let me know by return email if you are interested.

All the best
Ian Simpson

So what has the Computing At School Aberdeen hub done since its inception in March 2013? As well as providing member schools with a number of Raspberry Pi devices courtesy of the Google Raspberry Pi initiative we have hosted an event by Lego Education UK, delivered professional development sessions on the use of Edmodo and BYOD at the CAS Scotland Conference, created links between primary, secondary and further education in the Aberdeen City and Shire area, demonstrated how to use Raspberry Pi devices in the classroom, ran a Raspberry Pi fun day for students at Satrosphere, Aberdeen and started a resource sharing project between all member schools using GitHub.

I wanted to share it with others who may not yet be a member of the hub (or know of its existence) but would like to get involved – perhaps even chair it for a few years!! Please feel free to get in touch if you want to discuss the role in more detail.

To fork or not to fork: Should there be only one way to share digital resources in a school?

Image by Chris Pluta, CC0

My current school is in the midst of a digital revolution thanks to the 1:1 iPad rollout and Google Apps for Education installation. There are so many options open to staff and students with regards to sharing the digital resources they have curated or created and while this is great for choice and accessibility it can also become a mess of misconceptions, policy conflicts and training needs.

During the pilot with our S3 students I’ve been deliberately hands-off and encouraged experimentation within departments. In January I launched a more formal option (not policy) where teachers were given a structure to work with in Google Drive where they could receive or view work created by students in their class. I’ve received very few comments at all about it but know that more and more subject areas are using Google Drive for sharing resources and receiving student work back. Other options are still being used (and I think it is important to allow this to continue) but I want to provide staff, students and parents with a baseline – a method that can be easily implemented in classrooms but that can also be built upon or adapted with the consensus of individual classes (and by that I mean both students and teachers).

Digital is an abstract medium for many and asking staff or students to suddenly begin to utilise this way of working over and above all others can cause confusion, hit confidence and increase resistance towards future workflow changes. Experimentation followed by discussion on the pros and cons of different systems can help build a more robust workflow that is more immediately useful to a larger number of individuals within the school. I am confident that the discussion to come in the next few weeks will become strong foundations for policy that has been created from the bottom up and is based upon experience rather than sales pitch. However I have a concern that one way of sharing digital resources is not best for all and, very like the variety of subject areas and specialisms in the education system, the standard policy will need to be forked (to use GitHub terminology) to suit other areas.

Perhaps using GitHub is a way forward for school or educational authority policies? The system offers clarity, accountability, accessibility and flexibility. I’d be interested to hear if other schools are allowing departments to remix standard policies (with permission of course) to best suit the educational needs of the student and – like Christopher Ritter – use a service like GitHub to record and approve the changes.