im having a little trouble with a python script that I wrote the other day. This script is for my rasbperry pi that has a digital interface attached to the GPIO pins. The purpose of this script is to test and see if it will unlock a electromechanical lock for 5secs. Though when I run the script nothing happeneds. There are no errors being logged and being new to python scripting im not sure what the problem is. Any suggestions or help would be greatly appreciated.
I know there's nothing wrong with the digital interface and raspberry pi interaction becuase i can run python manually with the commands below, and everything works like it should. The lock release and then I can turn it off. Though when I run my script nothing happeneds.
python
import piface.pfio
piface.pfio.init()
piface.pfio.digital_write(0, 1)
led0 = piface.pfio.LED(0)
led0.turn_off()
My python script
#!/usr/bin/env python3
"""Door Lock: System to control an electric lock"""
import piface.pfio as piface
from time import sleep
class AuthToken:
def _init_(self, id, secret):
self.id=id
self.secret.secret
class TestDoorController:
def send_open_pulse(self):
print "unlock the door"
class BasicAuthenticator:
id = "Andrew"
secretPassword = "1234"
def check(self,token):
print "checking input of '" + token.id + "', + password + : " + token.secret + ", against secret password'" + self.secretPassword +"'"
result = (token.secret == self.secretPassword) & (token.id == self.id)
print "authentication is: " + str(result)
return result
class TestInput:
def getInput(self):
print "checking for input"
authToken + AuthToken("Andrew","1234")
return authInput
class DoorControllerPiFace:
def send_open_pulse(self):
piface.digital_write(0,1)
sleep(5)
piface.digital_write(0,0)
def main():
authInput = TestInput()
authenticator = BasicAuthenticator()
doorController = DoorControllerPiFace()
if(authenticator.check(authInput.getInput())):
doorController.send_open_pulse()
if _name_ == '_main_':
main()
Now im getting that the constructor takes no argument?
File "door_controllerTEST.py", line 47, in main()
File "door_controllerTEST.py", line 43, in main if(authenticator.check(authInput.getInput())):
File "door_controllerTEST.py", line 30, in getInput return AuthToken("Andrew","1234")
TypeError: this constructor takes no arguments
Added in the extra _ to my AuthToken class and it was giving me a error that my pfio wasnt initialized yet. so I added in
import piface.pfio as pfio
pfio.init()
And everything is working after that.