Not sure if I am in the right place. I have a manual toggle switch connected to the Raspberry GPIO. Is there anyway to have the switch status log to an SQL database. In other words, keeping track of the time/date when turned on or off?
Not sure if I am in the right place. I have a manual toggle switch connected to the Raspberry GPIO. Is there anyway to have the switch status log to an SQL database. In other words, keeping track of the time/date when turned on or off?
It's certainly possible, the GPIO pins can be setup to interrupt on change. So you just need to write a bit of code that waits for the interrupt and when received logs that data into the db in whatever way you need.
Thanks selsinork. Now that I know it can be done, all I need is someone to write me some code since I am only familiar with PHP :-( I wouldn't know where to start.
Thanks selsinork. Now that I know it can be done, all I need is someone to write me some code since I am only familiar with PHP :-( I wouldn't know where to start.
No reason you couldn't do it in php, everything is a file after all 
Maybe start here http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=7509 there's a demo program in C which just waits for an interrupt and then prints something to the screen as well as various references to other ways to access the feature from different languages.
If you can catch the interrupts then writing to the database should be easy - I've not done enough in php to know how easy it would be though. Php being what it is, googling for 'php poll' just really isn't helpful 
I'm not sure how to read interrupts from php either, but if the demo C program can do this, then one method would be:
1. modify the C program so that it print out something in some defined format so that you know what interrupt occurred/switch got pressed
2. in your php, use exec($prog, $outarr)
3. compare $outarr[x] with what you expect (where x is the line number, I forget if it begins with 0 or 1)
4. write to the database (assuming you know how to do this - requires php-mysql installed).
Alternatively, you could do this entirely in one language (C) because there is a mysql API for C (again, not sure
if that is avail for RP or not, but it is available for x86).
Both of the above definitely work on x86 Linux (not tried RP for this).
Also, there may be cleaner ways but I'm not sure.