0

I am running an apache web server on my raspberry pi B+ on my home network. My data plan only allows me a certain amount of data a month before they throttle it to almost unusable. I want to set up a python code that can monitor the data usage and activate a LED connected to one of the Pi's GPIO pins when the usage is too high.

I can do the GPIO stuff in python but if there is another better or easier way of doing it i am open to it.

I am currently using the RPi.GPIO library to control the GPIO pins so if possible it would be helpful if i can stick to this.

This is some code i use to update the file on the web server:

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT) #Red LED
GPIO.setup(13, GPIO.OUT) #Green LED

try:
    #do stuff that might throw an error
    GPIO.output(11, False)
    GPIO.output(13, True)

except:
    GPIO.output(11, True)
    GPIO.output(13, False)
Tom White
  • 53
  • 6
  • What device/service are you reading from that tells you your network usage? – OneCricketeer Jun 05 '16 at 03:22
  • Also, you could run a Python Webserver. Apache isn't entirely necessary. – OneCricketeer Jun 05 '16 at 03:24
  • @cricket-007 at the moment i am only using the GPIOs for powering LEDs and i currently don't have anyway to read the usage. i am very new to using a raspberry pi for anything and have never run a webserver befor. Apache was just the first thing i found that i could set up easily. – Tom White Jun 05 '16 at 03:25
  • In about 8 lines of Python, you could use [Flask](http://flask.pocoo.org/) as your webserver. And control your lights from that. – OneCricketeer Jun 05 '16 at 03:28
  • @cricket-007 i have not been able to find how to get a Flask web server off the local network and actually on to the internet. Is this not something it can do or have i just been looking in the wrong places? – Tom White Jun 05 '16 at 04:14
  • You'd have to forward ports on your router to be on the Internet. If you want it to be publicly accessible, then see http://stackoverflow.com/questions/7023052/flask-configure-dev-server-to-be-visible-across-the-network – OneCricketeer Jun 05 '16 at 04:42

0 Answers0