Recently I went over to FTTN NBN.
I'm about 1.1km from the fibre node and have been experiencing a huge number of dropouts...
I was told that in order for my ISP to lodge a fault with NBN, I needed to make a record of the dropouts...
And hence this script was born.
It's a spattering of code snippets picked up all over the net, and perhaps does not use the most reccomended of methods, but it works for a 5 minute script - feel free to modify as you see fit.
In short, it will log the date, time and status of your connection to a CSV file.
From there you may do some facyness before submitting it like setting conditional formatting etc.
It has 3 parts:
(Before you say it - yes these could quite easily have been a single script)
1: checknet.py (this checks to see if the net is active, by trying to open google.com)
If down - it runs part 2: netlogdown.py - and plays an mp3 to annouce the status - and appends a line to the CSV file
If up - it runs Part 3 netlogup.py - and plays an mp3 to annouce the status - and appends a line to the CSV file.
CSV file generated: /home/osmc/net_status_log.csv
It's triggered by root cron, every 5 minutes (*/5 * * * *)
I'm running this on a Pi B+ running the latest OSMC - hence the file paths.
And now for the code:
checknet.py:
Note: you may wish to alter the mp3 file player, or comment those lines out.
Code: Select all
#!/usr/bin/python
import os
import time
import urllib2
#os.system("gpio mode 6 out && gpio mode 5 out")
while True:
try:
urllib2.urlopen("http://www.google.com").close()
except urllib2.URLError:
print "Not Connected"
os.system("mplayer disconnect.mp3")
os.system("sudo python /home/osmc/netlogdown.py")
time.sleep(60)
else:
print "Connected"
os.system("mplayer connect.mp3")
os.system("sudo python /home/osmc/netlogup.py")
break
Code: Select all
import csv
import time
with open('net_status_log.csv', 'a') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Date', time.strftime("%d/%m/%Y"), time.strftime("%X"), 'Internet Status', 'UP'])
netlogdown.py:
Code: Select all
import csv
import time
with open('net_status_log.csv', 'a') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Date', time.strftime("%d/%m/%Y"), time.strftime("%X"), 'Internet Status', 'DOWN'])