Keeping an eye on a website with rpi0 and Scroll pHAT HD


I just finished my first rpi project and I wanted to share it. I made a clock that works as usual until a production website runs into problems. Then intead of showing time, it blinks continuously to draw my attention to the problem. The website uses “normal.css” if everything is ok and “hot.css” if there is a problem. So the clock looks at the name of the css file the website is using and acts accordingly.

I don’t know much python so I recyled example code. Improvements or comments are welcome. Here is the /home/pi/ I created:

#!/usr/bin/env python

import os
import time
import signal
import math
import scrollphathd
from scrollphathd.fonts import font3x5

def warning():
        speed_factor = 10
        scale = (math.sin(time.time() * speed_factor) + 1) / 2
        offset = 0
        for x in range(scrollphathd.width):
            for y in range(scrollphathd.height):
                offset += 1
                color = 0.85 * scale * (offset % 2)
                scrollphathd.pixel(x, y, color)

def clock():
        str1 = time.strftime("%H%M") 
        scrollphathd.write_string(str1, x=1, y=1, font=font3x5, brightness=0.01)

while True:
        web = os.popen("curl -s | grep .css").read()
        t_end = time.time() + 60 * 1
        if "hot.css" in web:
                while time.time() < t_end:
                while time.time() < t_end:

After this I created a cron job to make sure that the script above is running and to restart it if it is not working. Since the only python program running in this rpi0 is the above clock script, the restart script simply looks if any python program is running and if there is none, restarts the clock script. Here is /home/pi/ I created:


if [ "$(pidof python)" ]
  nohup /home/pi/ &>/dev/null &


crontab -e

and add the line:

* * * * * /home/pi/

That’s all.

I was not happy with the look of the font so I changed it a bit as well, see the forum_post about it.



Great little idea. Nice use of os.popen, curl and grep to do the heavy lifting ;)