2013.11.10

Sir Like-A-Lot

My latest project was sort of a failure, but I’m going to post about it anyway, because such things are important.

For a recent event I wanted to create a unique way for people to LIKE something, and get a reward for it, so I grabbed a Raspberry Pi and got to work. The idea was pretty simple, a full screen display showing the number of Facebook likes, with the URL for people to visit the page (on their mobile devices) and like it. The display would then update in “near” real-time (Well, every 10 seconds) and there would also be a surprise…

Step #1 is always configuring the Raspberry Pi. I installed Raspbian, had it set to boot to the desktop, and installed the packages I needed, mainly Apache and Chromium, since I’d be using a local web server and web browser for the display.

Getting the Raspberry Pi to work as a kiosk display was next. I didn’t want any menus or OS parts showing, so I used Chromium running in kiosk mode. My /etc/xdg/lxsession/LXDE/autostart file looked like this:

# config to launch Chromium in kiosk mode and load our application
@xset s off
@xset -dpms
@xset s noblank
@chromium --kiosk --incognito http://127.0.0.1/likealot/

We got rid of the part that lets a screensaver run, and added in the bits to fire up Chromium in full-screen kiosk mode. (Oh, one note about Kiosk mode, it does not hide the mouse pointer, but we’ll deal with that later.)

LIKES

The results on the screen looked like this. Full screen, no browser or OS bits showing. I like this solution as it can be used for pretty much anything you can code up as a web page.

The display is set to refresh every 10 seconds, so it’s pretty up-to-date, and you’re really only limited by what you can display in a browser (Chromium) running on Linux (on a Raspberry Pi, in this case.)

As for the code, it’s less than 50 lines of Perl running as a CGI, and about a dozen lines of HTML in an HTML::Template file. There’s also a little CSS and an image.

Speaking of the CSS, it was the solution to hiding the mouse pointer for Chromium running in kiosk mode. I just added this bit:

/*
 * using CSS to hide the pointer
 */
* { cursor: none !important }

For an informational kiosk you just want people to look at and not have to interact with using a mouse or keyboard, this solution works well.

JSON

You might be saying “Hey! How do you get the number of likes!?” Well, you just ask JSON, or http://graph.facebook.com/?ids=z2marketing to be more precise. Facebook Graph API data holds the key, you just need the value.

Oh, there was one more really fun bit! When someone liked the page and the page refreshed and the number increased, you’d hear applause!

The original idea was to just have the CGI do a system call to play the file using aplay. That did not work. I also tried mpg321 and that didn’t work. In the end I went the other way around and added… another Perl script! There’s a cron job that runs on startup, which launches a Perl script, which loops forever and looks at the counter file that the CGI uses. Every time the counter file changes (due to the CGI updating the number) the Perl script uses aplay to play the applause file.

The end result is pretty good. A person sees the display, goes to Facebook, likes the page, and within 10 seconds the display updates and you hear some applause!

I planned on making a sign or adding some text to entice people take action and get a “reward”. And of course the URL isn’t as helpful on a mobile device where you probably use an app instead of a browser, but this is all a good start.

Now, I mentioned a failure, so I should explain that part. For anything like this, where it needs to run for hours reliably and not just be a quick technology demo, you need some burn-in time. I had this running for a week with no issue. The first issue that came up was, what to do if you lose the Internet connection. (Hey, we use Time Warner, it happens!) You really don’t want to see a default Apache 500 error page, so the error page looked just like the main page, but with a message that said ‘Please stand by…”. That 500 page was set to redirect to the main page after 10 seconds, which would deal with occasional Internet or network outage situations. Since we were also using a WiFi connection with the Raspberry Pi, there’s always the chance of losing the WiFi connection. This didn’t seem to happen much, but it’s something you may need to deal with.

I also set Apache to not do any logging, as there’s really nothing valuable gained from logging after you’ve got everything running. It also helps to write less data to the SD card that holds the system because… corruption.

Oh yes, corruption! Every now and then I would reboot the system to make sure it would start up properly. It almost always did. Except when it didn’t. Once the Pi booted and there was a warning that the file system needed repair, so I repaired it, and all seemed well. I tested again for another week, and things seemed good. But then…

The day of the event, I had to move the system into place, and when I did that, and started it up, Linux would not boot. Even after 13 years I am still not enough of a Linux expert to fix every problem it throws at me, and I was stuck, and had a dozen other things to do, so it was dead.

I did the dozen other things and then ended up reinstalling Raspbian and trying to quickly reconfigure it, and get all my files in place, and got everything working except the audio… and the WiFi. There are a few tricks to getting audio working properly on the Raspberry Pi. I eventually got it working, but it was too late to deploy it. Oh well…

So next time, I will have a BACKUP SD card ready to put in place when the first one destroys itself. Or maybe I’ll just build two complete Raspberry Pi systems. Backups are good. Backups are good. Backups are good.

But don’t worry, I’ll take all the successful bits of this project and re-implement it in some other way in the future.

6 Responses to “Sir Like-A-Lot”

  1. Matt GaugerNo Gravatar says:

    I feel the pain on the RaspPi corrupting itself. We have a RaspPi hooked up to a giant 60″ TV in our office lobby; I set it as a dashboard for people to see when they walk by. Every couple weeks, it’ll refuse to boot. Sometimes it is the TV no longer wanting to speak HDMI with the RaspPi, and other times it is the FS on the RaspPi being corrupted. I’ve gotten tired of re-burning the Occidentalis image and setting up the wifi (since we can’t run ethernet to that location.) So maybe I need to start thinking about something else cheap to connect to the TV. We’ll seeā€¦

  2. JYodaNo Gravatar says:

    Do you think it could be attributed to improper shutdowns (unplugging without a shutdown -h, which I do A LOT anyway) or was it just a random occurrence? I’ve never had it happen in either case, but I know it could. I would *hope* that a proper shutdown/unmounting would afford some level of protection, though.

  3. Matt, I’ve got a pcDuino I’ve been playing with as well. It may prove more solid that the Raspberry Pi. I originally used it for this project but abandoned it when I wanted to add the audio.

  4. JYoda, good question! I typically ssh in an do a proper shutdown. The first time I had to repair the system there was no improper shutdown that could have caused problems… now, the time when it would not boot I actually did pull the plug, and *not* do a proper shutdown, and I hate to think that could have been the issue (since I had another Pi I did that to a dozen times with no issue) but maybe that was it. (I’m working on configuring my CameraPi project so it can avoid such issues.)

  5. Joe R.No Gravatar says:

    Looks like there is at least one app and a dedicated device that do the same thing. I don’t know that I’d pay $29 for the app though and Fliike looks very cool…but for $400?

    Your solution looks much more affordable and reasonable!

    http://thenextweb.com/apps/2013/12/04/like-counter-pro-pricey-way/?fromcat=apps

  6. Ha! Fliike only goes to 99,999? Coke will never buy one… they are at 76,720,173 and it increases every minute. (I know because I used their data to test Sir Like-A-Lot.

    I do like the QR Code idea, which Drew mentioned on a recent podcast: http://nerdmoment.com/nerd-moment-58/

    So who wants to monetize this with me!?

« | »

buy the button:

Buy The Button

recently at:


top recent artists: