Website monitoring using headless Raspberry Pi

As a webmaster, there is nothing more embarrassing than a client calling you to tell you that their site is down, when you’re the one that should be monitoring it can calling them instead. I had this happen to me once and that was enough for me to formulate a solution. I had a raspeberry pi sitting in my desk draw doing nothing for almost a year and I thought, this might be a good time to pull it out and put it to work. After some quick google searches I found this great solution online – https://github.com/fzaninotto/uptime. This Uptime node app allowed you the ability to monitor multiple sites and receive email alerts when status changes.

First matter of business was to get the RPI up and running. This was a unique challenge because I didn’t have an extra keyboard, and monitor to configure it once the OS was installed. So essentially I need a solution that allowed me boot the PI and auto-configure it. After downloading and burning Rasbian Jessie Lite, I was able to enable ssh and auto-configure the wireless card automatically. To enable ssh on boot, create a file “ssh” on the boot partition on the sd card. When the pi starts and see’s this file it will automatically enable ssh access to it. For the wifi dongle (yes I went with wifi instead of ethernet cable) I was able to have it automatically get an IP address from DHCP by creating a file called “wpa_supplicant.conf” with the wifi configuration information in there (note the below configuration assumes no password on the wifi AP).

network={
    ssid="my_wifi_name"
    scan_ssid=1
    id_str="home_wifi_1"
    proto=RSN
    key_mgmt=NONE
}

Here’s a quick breakdown on using wpa_subplicant.conf and longer man page

Once the PI has booted it will connect to the wifi network “my_wifi_name” and ask for an IP address. And with the ssh file installed on the boot partition, ssh is enabled you can use you favorite ssh tool (putty) or just the ssh command in the terminal (macOS) to access the box. Remember the default username for Rasbian is “pi” and the password “raspberry”. It be wise to run “sudo raspi-config” once logged in and configure your local, hostname and change your password.

The second thing was to install the necessary tools you would need to get the server up; you can get ’em all via apt-get.

sudo apt-get install git
sudo apt-get install nodejs
sudo npm cache clean -f
sudo npm install -g n
sudo n 6.0
git clone git://github.com/fzaninotto/uptime.git
cd uptime
npm install
npm remove nodemailer
npm install nodemailer@3.1.5
node app

You will notice in the list of commands npm install -g n and n 6.0, I discovered that uptime works well with node 6, so this line installs the node helper utility n and then uses n to upgrade nodejs to version 6. Also the uptime email plugin works well with nodemailer version 3.1.5, hence the command to remove what’s installed and install that specific version.

If you intend to use the emailer plugin then you will have to fix a bug in the emailer code.

nano ./uptime/plugins/email/index.js

on line 60 change “var mailer = nodemailer.createTransport(config.method, config.transport);” to “var mailer = nodemailer.createTransport(config.transport);”. This change is to facilitate the new syntax for the createTransport command. I got the clue from this post: http://stackoverflow.com/questions/33792811/node-js-nodemailer-smtptransport-causes-typeerror-this-mailcomposer-setmessageo.

var mailer = nodemailer.createTransport(config.transport);
//var mailer = nodemailer.createTransport(config.method, config.transport);

Lastly I had to make the uptime start whenever the Pi restarts. To do this edit the the rc.local file

sudo nano /etc/rc.local

And add the lines right be fore the exit 0

#run uptime monitor
cd /home/pi/uptime/; node app &

Now you’re good to go with your uptime server, all you need to do is follow the instructions on Fzaninotto’s git wiki and setup your website monitoring.

Barcode Check-in using google forms

I was enlisted to help with technical setup of a conference with approx two hundred (200) attendees over seven days. We were faced with a problem of tracking all meals taken by the conference attendees, essentially a meal check-in system, mostly for billing purposes and capacity planning. The main requirement was a simple automated or online system with ability to quickly track and report on meals taken by the attendees. So essentially, we would need to track Person/Room, meal type taken (Breakfast, lunch, break, dinner etc..), and any comments. We also needed a way to quickly identify attendees without having to ask for a name, or search through a list of names or manually punch cards or long list on a clipboard. And if that’ wasn’t enough I had a huge time constraint – one night (it had to be demoed and decided on in a meeting the following day).

I first thought of putting together a simple web page with a database back-end, that idea was quickly discredited because of the time frame given and the software development, bugs, and deployment headache. Then I thought, maybe I can do a quick online survey type form, that seemed possible and quickly doable. After some thought I began hacking together a solution. Firstly, google forms can be used to create a quick online form that can be shared among the administrators to effectively collect the required meal information. Google forms also , tracks every response along with timestamps and even gives you quick charts. So that solved the first bit of how to collect data and ascertain good inform

meal_check_in_form
Meal Check-In form

ation. So I went ahead and created the Meal Check-In form. A very simple form with Name, Meal time (type of meal) and Comments.

Now I had one last problem to solve, how to quickly identify attendees (by name or room number), I thought of QR or bar codes, but how do you
1. create bar codes based on text and
2. scan them into the online form?
I went searching. I found an android app called Barcodescanner Keyboard. It costs $3.99 but there’s a demo version that works equally well for a trail period of 30 days. This app is a keyboard with bar code scanning features, so once you engage that feature and scan a code the app simulates typing on the keyboard i.e. it adds the text to the textbox (pretty nifty). This was perfect as it would allow the administrators the ability to scan a bar code with the attendees information directly into the form.

Now came the final piece of the puzzle, how to generate codes for each attendee. After some more research I found a little trick on google docs. It’s not specific to google docs but google sheets allowed me to use a formula along with a link to generate the bar code. There is a website that generates barcodes from text (https://www.barcodesinc.com/). I used a link to that website and a formula in google sheets. So in column one of the sheet I added the names of the attendees and in column 2 I added the formula

=image("http://www.barcodesinc.com/generator/image.php?code=" & substitute(A1," ","%20") & "&style=197&type=C128B&width=200&height=100&xres=1&font=3", 3)

All the above does is use the “image” function to generate an image from the returned 64bit encoded string from the link. The substitute was used to replace spaces with the proper URL encoding of %20 from the cell that contained the Name. the only other option I changed was the width and height of the resulting image which you can do by changing

&width=200&height=100
barcode_sheet
Barcode sheet

That left me with a barcode sheet. After filling in the entire sheet with all the attendees (copy and paste from another sheet). I was able to produce all the barcodes needed. I then passed this on to the administrators who happily printed the sheet, laminated, cut them into separate tags and added key rings to them for easy handling by the attendees. Meanwhile I focused on training other administrators on the check-in process

Meal Check-In Report
Meal Check-In Report

The final product looked awesome and worked great. We encountered one issue, because the barcodes were being scanned from a phone, the ability for the phone to pickup the barcode for the dinner at night was a bit difficult. This was solved by either standing under a good light source or turning on the “Flashlight” feature of the phone before check-in the person.

Finally for reporting, I added a second sheet to the responses sheet and added a pivot table that counted meals by day and meal type.

This was an interesting and exciting little project as I gave me autonomy to seek out a solution using freely available tools and it resulted in hassle free mean check-ins

Final Product
Final Product
Bittorent Sync is the future of sharing

Bittorent Sync is the future of sharing

bittorrent-sync
Two years ago I was a dropbox advocate, one year ago I said forget dropbox, google drive is the way to go, now i’m blown away by Bittorrent Sync. Now don’t get me wrong these incumbent technologies are still useful and is in no way phased out but bittorent sync is nascent, raises the bar and will affect our paradigm of file syncing in a significant manner while being very timely in light of net neutrality and all the supposed NSA spying going on.

First allow me to explain what bittorent sync is and why I believe it’s the future of sharing. Bittorrent sync is built on the trusted and well known P2P bittorrent technology that allows users to sync files between their storage devices along with create private sharing networks between friends. So imagine all your images on your phone being synced back to a folder on your computer and your NAS device at home, all done securely (encrypted) over the wire, with no cloud access or unknown man in the middle service. Cool huh! But it gets better, you can share with others via email, QR code or link, and they are either prompted o accept for the data to commence syncing or download bittorrent sync. You can read more on btsync or download it here

Here are some videos on the same topic: