-
Notifications
You must be signed in to change notification settings - Fork 3
/
service.py
73 lines (50 loc) · 1.54 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
""" Service daemon for the fingerprint module.
MQTT
topic:
device/fingerprint/request
payload {
method: <enroll>|<search>|<delete>|<query>
[reqId:]
}
device/fingerprint/response
payload {
event: <request-finger-press>|
<request-finger-release>|
<enrolled>|
<fail>|
<match>
}
"""
import fpsensor
import time
import sys
from perif.deviceIface import DeviceHandler, AbstractDevice
import json
RESP_GRP="device/fingerprint/response"
class FingerprintSensor( AbstractDevice ):
def name(self):
return "fingerprint"
def methods(self):
return ["enroll","search","delete"]
def __init__(self):
AbstractDevice.__init__(self)
fpsensor.setup()
def _req_finger_press(self, mqttc, jobj):
mqttc.publish(RESP_GRP,payload=json.dumps({
"event":"request-finger-press",
"respId": jobj.get('respId')
})
def _req_finger_release(self, mqttc, jobj):
mqttc.publish(RESP_GRP,payload=json.dumps({
"event":"request-finger-release",
"respId": jobj.get('respId')
})
def enroll(self, mqttc, jobj):
def msg_handler( msg ):
if msg == "press finger":
self._req_finger_press(mqttc, jobj)
elif msg == "press release":
self._req_finger_release(mqttc, jobj)
def search(self, mqttc, jobj):
return fpsensor.matchModel()