コード例 #1
0
ファイル: util.py プロジェクト: return007/yarc
def render_qrcode(text):
    """
    Displays a QR code with the given ``text`` on the terminal.
    """
    qr = QRCode()
    qr.add_data(text)
    qr.print_tty()
def print_qr(data):
    qr = QRCode()
    qr.add_data(data)
    qr.print_tty()
コード例 #3
0
    with open('./secret', 'w') as handle:
        handle.write(partymode_totp_secret)

partymode_totp = pyotp.TOTP(partymode_totp_secret)
partymode_enabled = False
partymode_enabled_date = None
topic_bell = "w17/door/bell/state"
topic_party_set = "w17/door/partymode/enabled/set"
topic_party_state = "w17/door/partymode/enabled"
topic_door_lock_state = "w17/door/lock/state"

# print provisioning qrcode to terminal
print("QRCode, usable with TOTP Application:")
qr = QRCode()
qr.add_data(partymode_totp.provisioning_uri('enable key', 'w17/door/partymode'))
qr.print_tty()

# connection with mqtt broker, subscribe to updates for several states
def on_connect(client, userdata, flags, rc):
    print("Verbunden mit mqtt.")
    client.subscribe([
        (topic_bell, 0),  # Does the bell ring?
        (topic_party_set, 0),  # Does somebody try to en/disable the partymode?
        (topic_door_lock_state, 0)  # Is the door locked?
    ])

# receive updates from mqtt broker
def on_message(client, userdata, msg):
    global partymode_enabled

    # Read topic and payload from message