I'm trying to use WebIOPi but I'm quite lost in getting it to work with my project.
Background: I'm using Raspberry Pi B+ running Wheezy. I'm working on a web-based application that will only be accessed locally. I have a bunch of php files in /var/www that run on Apache. Now I need to get my coin acceptor to with the project. The coin acceptor http://www.adafruit.com/products/787 sends single pulses (I only need one coin). I first tried the coin acceptor with a python script using interrupts and it works fine.
GPIO.setup(PIN_COIN_INTERRUPT,GPIO.IN)
GPIO.add_event_detect(PIN_COIN_INTERRUPT,GPIO.FALLING,callback=coinEventHandler)
But now I need to be able to capture those pulses and show them on a php page, updating the amount for every coin insert. I've been studying WebIOPi for hours but I can only find info on reading a pin's status, not listening for interrupts. Can anybody point me to the right direction?
Any help would be greatly appreciated. Thank you!
So, you seem to have two problems: 1. how do I, on the server, detect a new coin event 2. how do I then push this to the client browser.
I don't know webiopi at all, so I can't say there's not a way to use that to solve both, but as an alternative:
For part 1: you have a python program which you said works; I would suggest running as a background service and just have it do something simple like writing the latest value of coinage to a file:
GPIO.setup(PIN_COIN_INTERRUPT,GPIO.IN)
GPIO.add_event_detect(PIN_COIN_INTERRUPT,GPIO.FALLING,callback=coinEventHandler)
def coinEvenHandler(*arguments):
try:
f = open("coin.txt","rt")
cnt = int(f.read())
f.close()
except: # handle file doesn't exist and file doesn't contain an int
cnt = 0
f = open("coin.txt","wt")
f.write(str(cnt))
f.close()
For part 2: 1. Create a page which returns the value of "coin.txt" 2. Use Ajax (e.g. jquery) to poll for this value from your client page.