Raspberry Pi 4 Website Up-Time Monitor

  • Context: Computer 
  • Thread starter Thread starter Greg Bernhardt
  • Start date Start date
  • Tags Tags
    Monitor Pi Raspberry pi
Click For Summary

Discussion Overview

The discussion revolves around creating a website uptime monitor using a Raspberry Pi 4, focusing on the use of Python for programming. Participants share their excitement about the project, suggest resources, and discuss various technical aspects related to the setup and functionality of the monitor.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant expresses enthusiasm for their Raspberry Pi 4 project, specifically mentioning the intention to create a simple LED uptime monitor.
  • Several participants suggest looking for tutorials, with one recommending "Getting Started with Raspberry PI" and "Raspberry Pi in Easy Steps" as useful resources.
  • There is a discussion about the availability of atomic time feeds and the use of RSS features, although some participants express uncertainty about the specifics.
  • One participant mentions that using standard Linux commands could suffice for the uptime monitoring task, suggesting that Python may be overkill unless tracking statistics is required.
  • Another participant emphasizes the importance of using Raspbian as the operating system and mentions the automatic synchronization of system time with NTP when connected to the internet.
  • There are suggestions regarding the use of IDEs for Python development, with PyCharm and Thonny being mentioned, though some participants note that the choice of IDE may depend on the specific tutorial being followed.
  • Participants discuss the potential complexity of working with LED displays and the advantages of using Python for ease of development and future enhancements.

Areas of Agreement / Disagreement

Participants generally agree on the excitement surrounding the Raspberry Pi project and the utility of Python for development. However, there are competing views on the necessity of using Python versus standard Linux commands for the uptime monitoring task, indicating some disagreement on the best approach.

Contextual Notes

Some participants express uncertainty about specific technical details, such as the exact nature of atomic time feeds and the best practices for using Python with Raspberry Pi. There are also varying opinions on the choice of operating system and development environment, reflecting different user experiences and preferences.

Who May Find This Useful

This discussion may be useful for individuals interested in Raspberry Pi projects, particularly those looking to create monitoring tools or learn about programming in Python. It may also benefit beginners seeking resources and advice on setting up their Raspberry Pi.

Messages
19,881
Reaction score
10,891
For a quarantine project I bought a Raspberry Pi 4 and a breadboard accessory kit. It won't arrive for another couple weeks, but I as super excited to dive in. My first project will be to create a simple LED up time monitor for PF :)

Anyone have some "must read" tutorials? I'll be using python.
 
  • Like
Likes   Reactions: QuantumQuest and sysprog
Physics news on Phys.org
Greg Bernhardt said:
For a quarantine project I bought a Raspberry Pi 4 and a breadboard accessory kit. It won't arrive for another couple weeks, but I as super excited to dive in. My first project will be to create a simple LED up time monitor for PF :)

Anyone have some "must read" tutorials? I'll be using python.
I assume there is an atomic time feed available somewhere which you could import. IIRC it uses RSS features, but I'm not sure, it is too long ago. I once had a "clock page" which displayed the "real time". Real time is local minus three hours: night owl time!
 
  • Like
Likes   Reactions: sysprog
fresh_42 said:
I assume there is an atomic time feed available somewhere which you could import. IIRC it uses RSS features, but I'm not sure, it is too long ago. I once had a "clock page" which displayed the "real time". Real time is local minus three hours: night owl time!
Won't do anything "real-time". Just a simple ping every second.
 
For that even Pi Zero would be an overkill.

At the moment I have five Pi running (I think 2, 2, 3, 0, 0, not entirely sure about exact models). One for automatic backups (about 2 MB per day, so a 64GB SD card will most likely survive me), one for monitoring the street outside, one for my weather station, one for my birdhouse and lately testing one as an NFS with a mechanical HDD attached. NFS is way too slow for any serious application, but I hope it will solve a recurring problem with the street camera - it fills 32 GB in a week (rotating the data) and kills a 32 GB pendrive in about 2 years (typical flash memory doesn't survive more than about 100 writes).

I am not saying these are all I have :wink:
 
  • Like
Likes   Reactions: BvU, sysprog and anorlunda
Greg Bernhardt said:
For a quarantine project I bought a Raspberry Pi 4 and a breadboard accessory kit. It won't arrive for another couple weeks, but I as super excited to dive in. My first project will be to create a simple LED up time monitor for PF :)

Anyone have some "must read" tutorials? I'll be using python.
Well, your machine will be executing machine instructions, when probably some interpreter is parsing your Python -- I think that you already know that some of the PF members, e.g. @jedishrfu and @Mark44, could be go-to guys for you if you decide to look for some assistance -- I'll try to pitch in if I think that I might be able to say something worthwhile ##\dots##
 
That's great Greg! Don't forget to wipe down the box and packaging before touching it as there have been some COVID related isolated instances of Amazon employee protests.

Getting Started with Raspberry PI by Richardson and Wallace (OReilly pub)

Raspberry Pi in Easy Steps (full color) by McGrath

Both are newbie books but sometimes you can find what you need clearly explained.

First you'll have to choose an OS:

https://raspberrytips.com/best-os-for-raspberry-pi/

I have mine configured with Raspbian. It helps to know Python and Linux for any Raspberry PI work although you can also use C.

https://stackoverflow.com/questions/39371772/how-to-install-anaconda-on-raspberry-pi-3-model-b

I've heard that Processing can be run to Raspberry PI but while I like using it I've not installed it yet (I think you need Java and Processing and perhaps some other stuff).

https://pi.processing.org/get-started/

I've also heard that the Anaconda 3 distribution of python can be installed. Anaconda comes with a ton of python modules for doing data science and machine learning... I've installed it on my regular computers and have used the Flask api to created a simple web service.

Lastly, Pycharm is the goto IDE for python development, Jetbrains has a writeup on how to use it to do remote debug on a Pi:

https://www.jetbrains.com/help/pycharm/remote-development-on-raspberry-pi.html
 
  • Like
Likes   Reactions: QuantumQuest, BvU, sysprog and 1 other person
I also use Raspbian for my Pi.

And here is a GitHub website uptime project you can take a look at, but you could just use standard Linux commands in a shell to do this, Python is considerable overkill unless you are planning to maintain tracking statistics (and even then, shell can probably do the job) 🤔
 
  • Like
Likes   Reactions: pbuk and sysprog
It came in the mail... now I just need to order the power supply and mini HDMI converter, whoops :smile:
 
  • Like
Likes   Reactions: sysprog
Greg Bernhardt said:
It came in the mail... now I just need to order the power supply and mini HDMI converter, whoops :smile:
Yup, been there, done that. o0)

Did you order a case for it already? It's good to put it into its plastic case to protect it. Also, did it come with a micro-SD card, or do you already have some? The Pi's we order don't come with one, so we've ordered a bunch for our lab stock.

https://www.raspberrypi.org/documentation/installation/sd-cards.md
 
  • Like
Likes   Reactions: sysprog
  • #10
LOL, I always buy a batch - Pi, power supply, SD card (micro these days, but the old Pi used the standard ones).
 
  • Like
Likes   Reactions: sysprog
  • #11
Greg Bernhardt said:
For a quarantine project I bought a Raspberry Pi 4 and a breadboard accessory kit. It won't arrive for another couple weeks, but I as super excited to dive in. My first project will be to create a simple LED up time monitor for PF :)
An excellent use of time - but be careful, this is addictive!
Greg Bernhardt said:
Anyone have some "must read" tutorials? I'll be using python.
https://www.raspberrypi.org/documentation/usage/python/ - by the second page of that you'll have the LED lit up!
fresh_42 said:
I assume there is an atomic time feed available somewhere which you could import. IIRC it uses RSS features, but I'm not sure, it is too long ago. I once had a "clock page" which displayed the "real time". Real time is local minus three hours: night owl time!
Raspbian (the Pi-specific flavour of Linux that is best for use on the Pi) will automatically use NTP to synchronise system time with a server as soon as you give it an internet connection.
Greg Bernhardt said:
Won't do anything "real-time". Just a simple ping every second.
But you will want to write a log of down times in the next version, so will need a synchronised clock.
jedishrfu said:
First you'll have to choose an OS:
Just go with Raspbian until you find a reason not to (and unless you like getting down and dirty at the OS level, like @jedishrfu @sysprog and of course me, you won't find a reason :smile: ).
jedishrfu said:
I've also heard that the Anaconda 3 distribution of python can be installed. Anaconda comes with a ton of python modules for doing data science and machine learning... I've installed it on my regular computers and have used the Flask api to created a simple web service.
I'd only recommend this if your tutorial uses Anaconda, or more specifically conda for package management. Most Pi tutorials don't (they use pip): there is a version of Anaconda called Miniconda but it is a bit of a niche.
jedishrfu said:
Lastly, Pycharm is the goto IDE for python development, Jetbrains has a writeup on how to use it to do remote debug on a Pi:
PyCharm is great but again it is a bit of a niche on the Pi so again I'd just go with whatever your tutorial uses - the official Rasperry Pi Foundation one I linked at the top uses Thonny.
Tghu Verd said:
And here is a GitHub website uptime project you can take a look at, but you could just use standard Linux commands in a shell to do this, Python is considerable overkill unless you are planning to maintain tracking statistics (and even then, shell can probably do the job) 🤔
But shell is a dead end, and working out how to work the LED display (will this be a 7-segment display, or perhaps a 128x64 OLED?) would be a pain. There is no reason NOT to use Python which will both make the basic task much easier and also enable unlimited future development.
Greg Bernhardt said:
It came in the mail... now I just need to order the power supply and mini HDMI converter, whoops :smile:
Whoops indeed - hope Amazon is still pretty quick where you are. Also is it a Pi specific breadboard kit you have got - if not then one of these to connect to the Pi's GPIO connector is much better than hooking up individual wires:

1586471725321.png

https://www.amazon.com/dp/B01N562X2P/?tag=pfamazon01-20

Enjoy!

PS I use Node on my Pis rather than Python but there is 100x more Python stuff around for the Pi, it is what it was designed for so I'd recommend you go with that unless you specifically want to learn Node.
 
  • Like
Likes   Reactions: QuantumQuest, Borek, chemisttree and 4 others
  • #12
Wow that was a great post @pbuk.
 
  • Like
Likes   Reactions: pbuk, Greg Bernhardt and berkeman
  • #13
Borek said:
At the moment I have five Pi running (I think 2, 2, 3, 0, 0, not entirely sure about exact models).
...
I am not saying these are all I have :wink:
Wow, that's an even worse habit than mine! Although I also have rather a lot of microcontrollers...
 
  • Like
Likes   Reactions: Borek and sysprog
  • #14
I just moved, so I am not getting into any Pi projects right now. I was planning on building a Pi cluster at one point in time, just for giggles to start playing around with parallel programming since my old job was to extend a code to distributed memory processing.
 
  • Like
Likes   Reactions: BvU
  • #15
Wow finally got everything I needed delivered. Got it setup and booting into NOOBS now.
 
  • Like
Likes   Reactions: berkeman
  • #17
Very cool, Greg! I especially like that you color coded the wiring to the Red and Green LEDs. Nice touch. :smile:
 
  • Like
Likes   Reactions: Greg Bernhardt
  • #18
I got the LCD to flash a message too. I'll have an update video later. This is really basic, but super fun. I just need a course in circuits 101 to advance :)
 
  • #20
Three annoyances.

1. Some LEDs dimly light up even if their state is powered off.
2. The right half of my breadboard is busted, nothing on the right gets powered. The GPIO extension board is fine though.
3. Having issues getting the script to write to a cvs file. Works fine in console, but in Cron, it won't write and no errors. Files and folders are all 777. I'm stuck.
Python:
#!/usr/bin/python3

from gpiozero import LED #for breadboard
from datetime import date #get today's date
from datetime import datetime #get today's date
import lcddriver #for lcd screen
import requests #for header info
import time #for time delay
import csv #for record keeping

#register lcd driver function
display = lcddriver.lcd()

# start up time function
def uptime(url,name,gLED_num,rLED_num,bLED_num):

    #check url header
    response = requests.get(url)
    status_code = "Status Code: " + str(response.status_code)

    #define LED colors and locations
    greenLED = LED(gLED_num)
    redLED = LED(rLED_num)
    blueLED = LED(bLED_num)

    #if server responds with header 200 light up green LED and display message on LCD
    if response.status_code == 200:
        gettime = round(response.elapsed.total_seconds(),2)
        display.lcd_display_string(name + " Speed:" + str(gettime), 1)
        display.lcd_display_string(status_code, 2)
        for x in range(0,5):
            greenLED.on()
            time.sleep(0.1)
            greenLED.off()
            time.sleep(0.1)
            if gettime > 1:
                blueLED.on()
                time.sleep(0.1)
                blueLED.off()
                time.sleep(0.1)
              
    #if not 200 then light up red LED and display message on LCD
    else:
        display.lcd_display_string(name + " is Down", 1)
        display.lcd_display_string(status_code, 2)
        for x in range(0,5):
            redLED.on()
            time.sleep(0.1)
            redLED.off()
            time.sleep(0.1)
  
    #Leave on LCD do I can have time to read
    time.sleep(1)
  
    #cleanup
    display.lcd_clear()
    greenLED.off()
    redLED.off()
    blueLED.off()
  
    # write to CSV for historical usage
    now = datetime.now()
    today = date.today()
    getnow = now.strftime('%H:%M')
    getdate = today.strftime('%m/%d/%Y')
    with open("uptime_" + name + ".csv", "a") as uptime_file:
        uptime_writer = csv.writer(uptime_file, delimiter=",",quotechar="'", quoting=csv.QUOTE_MINIMAL)
        uptime_writer.writerow([getdate,getnow,name,response.status_code,gettime])
      
    #debug
    #print(str(getdate) + " " + str(getnow) + " " + name + " " + str(response.status_code) + " " + str(gettime))

#site1 Monitor URL,greenLED,redLED,blueLED WORKS
uptime("https://www.site1.com/","site1",18,23,17)

#site2 Monitor URL,greenLED,redLED,blueLED
uptime("https://www.site2.com/","site2",27,25,5)

#site3 Mon itor URL,greenLED,redLED,blueLED
uptime("https://www.site3.com/","site3",20,16,26)

#site4 Monitor URL,greenLED,redLED,blueLED WORKS
uptime("https://www.site4.com/","site4",21,12,24)
 
Last edited:
  • #21
oh derp, the file was relative, changed to absolute and it works!
 
  • #22
Greg Bernhardt said:
oh derp, the file was relative, changed to absolute and it works!

That's what I was about to suggest :)
 
  • Like
Likes   Reactions: Greg Bernhardt
  • #23
Greg Bernhardt said:
1. Some LEDs dimly light up even if their state is powered off.
Could be a problem with your breadboard shorting, or it could be that some other process is reconfiguring the pins as input pins when your script isn't running (I assume you mean the LEDs are dimly on while the script is not running between cron hits?)

Greg Bernhardt said:
2. The right half of my breadboard is busted, nothing on the right gets powered. The GPIO extension board is fine though.
The quality of this kind of stuff is variable, not surprising as it is ridiculously cheap. I have found Elegoo to be more reliable than others.

Greg Bernhardt said:
3. Having issues getting the script to write to a cvs file. Works fine in console, but in Cron, it won't write and no errors. Files and folders are all 777. I'm stuck.
Already solved and perhaps it's nitpicking but you should never need to use 777 permissions; your Python code runs as you so 644 (files)/755(directories) is plenty.
 
  • Like
Likes   Reactions: Greg Bernhardt

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
Replies
3
Views
2K
  • Sticky
  • · Replies 13 ·
Replies
13
Views
8K
Replies
29
Views
5K
  • · Replies 13 ·
Replies
13
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
13K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
2
Views
5K