Is there a tutorial for this?
Well, not exactly, but it's pretty straightforward, and there are lots of tutorials for setting up inputs. I use Python because that's the RPi ecosystem standard:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # HCDC boards use BCM numbers
GPIO.setup(index, GPIO.IN) # , pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(index,GPIO.BOTH,callback=Callback,bouncetime=BounceIgnore)
I use Redis for in-memory database, but you can use anything:
def Callback(channel):
time.sleep(BounceSettle/1000.0)
RedisDB.incr(<Name of counter>)
And then in another program (I fire this off every minute in crontab) transfer accumulator to SQL:
count = redisDB.getset(<Name of counter>,0) # reset it
SQLstring = 'insert into Counts(Epoch,Channel,EdgeCount) '
SQLstring += 'VALUES(unix_timestamp(now())'
SQLstring += ',{},{}'.format(channel,EdgeCount)
SQLstring += ');'
cursor.execute(SQLstring)
Then in Yet Another Program, get the last 24 hours of data from SQL:
sql = "select Epoch, EdgeCount "
sql+= "from Counts where Channel = {} ".format(Dict['Channel'])
sql+= "and Epoch >= (unix_timestamp(now())-(60*60*24)) "
sql+= "order by Epoch"
datacursor.execute(sql)
I use matplotlib for graphing, but there are lots of options out there,
https://grafana.com/ seems to be all the rage, but old dog, new tricks, you know....
Does that help?