Пример #1
0
def on_message(channel, method_frame, header_frame, body):
    message = json.loads(body)
    if message['type'] == 'nfc.uuid.read':
        logger.info('Got message! Call Timr.')
        logger.debug('Message: ' + json.dumps(message))
        conn = httplib.HTTPConnection(server, 80, timeout=5)
        conn.request("GET", uri + message["uuid"])

        r = conn.getresponse()
        if r.status == 200:
            ret = r.getheader('X-Return')
            logger.info('Reply from Timr: ' + ret)
            if re.match('\d', ret) is not None:
                for i in range(0, int(ret)):
                    blinkled(GREEN, 0.05, True)
                    time.sleep(0.1)
            else:
                for i in range(0, 6):
                    blinkled(RED, 0.02, True)
                    time.sleep(0.05)
        else:
            for i in range(0, 7):
                blinkled(RED, 0.02, True)
                time.sleep(0.05)
        conn.close()

    channel.basic_ack(delivery_tag=method_frame.delivery_tag)
Пример #2
0
#!/usr/bin/python

import json
import time

from solongo.raspitools import RED, init_gpio, init_mifare, get_uid, blinkled, GREEN, piep
from solongo.rmqtools import publish
from solongo.tools import create_logger
from solongo.types import MsgNfc

logger = create_logger('nfc-reader.log')
logger.info("NFC Start")
init_gpio()
mifare = init_mifare()

while True:
    uid = get_uid(mifare, RED, 0.1, logger)
    if uid is not None:
        logger.info("Chip read: " + uid)
        nfc = MsgNfc(uid)
        message = json.dumps(nfc, default=lambda o: o.__dict__)
        logger.info("Publish: " + message)
        blinkled(GREEN, 0.5, True)
        publish(message)
        time.sleep(3)
    time.sleep(1)