-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqr_read.py
32 lines (29 loc) · 954 Bytes
/
qr_read.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
'''
This module will detect the QR code, decode and send
QR code data to controller.
'''
import time
from paho.mqtt import publish
import paho.mqtt.client as mqtt
from pyaml_env import parse_config, BaseConfig
from module.camera import capture_qr_code
config = BaseConfig(parse_config('./config/config.yml'))
qr = capture_qr_code()
# If capture image is a QR code
if qr:
print("QR code detected...")
time.sleep(5)
print("Send a message to controller")
# Publish the qr code sting to controller
publish.single(
config.client_camera.publish.controller,
payload=qr,
hostname=config.mqtt.host,
port=int(config.mqtt.port),
qos=config.mqtt.qos,
protocol=mqtt.MQTTv311,
auth={
'username': config.client_camera.user,
'password': config.client_camera.password})
print("published to: " + config.client_camera.publish.controller)
print("payload: " + qr)