in qr-reader-function/src/qr_reader.py [0:0]
def reading_qr_run():
process_running = True
status = {}
local_storage = LocalStorage()
while process_running:
# Check order process or refilling process are still proceeded
logger.info(local_storage.read("is_process"))
logger.info(local_storage.read("qrType"))
is_process = local_storage.read("is_process")
if is_process:
time.sleep(3)
continue
qr_code = local_storage.read("qr_code")
local_storage.clear("qr_code")
if qr_code:
# Checking QR code is for shop to refill things or QR from customer
if REFILL_QR == qr_code:
status.update(qrType="REFILL")
status.update(is_process=True)
local_storage.write(status)
# Stopping reading QR code process
payload_info = json.dumps({"type": "TEXT", "data": {"title": "refill"}}).encode()
gg_client.publish(topic="refill", queueFullPolicy="AllOrException",payload=payload_info)
continue
# Publish messages authentication
else:
# Calling scan api for getting token
pay_result = scan_amazon_pay(str(qr_code))
status.update(pay_result)
local_storage.write(status)
logger.info(local_storage.read("is_error"))
if local_storage.read("is_error"):
cmd = "aplay -D plughw:{},{} cant_read_qr.wav".format(AUDIO_CARD,AUDIO_DEVICE)
subprocess.call(cmd, shell=True)
status.update(is_error=False, is_process=False, qrType="")
local_storage.write(status)
continue
else:
status.update(qrType="CUSTOMER")
status.update(is_process=True)
local_storage.write(status)
# Debugging App. This topic does not contain debug. However, this is used for debug application
payload_info = json.dumps({'type': 'TEXT', 'data': {
'title': 'Authentication', 'text': 'Valid authentication QRCode', 'value': qr_code, 'completedStepIndex': 0}}).encode()
gg_client.publish(topic='{}/debug'.format(STACK_NAME), payload=payload_info)
# Sending publishing message to door open process
payload_info = json.dumps({'type': 'TEXT', 'data': {'title': 'authenticate'}}).encode()
gg_client.publish(topic='authenticate', queueFullPolicy="AllOrException", payload=payload_info)
time.sleep(3)