Exemplo n.º 1
0
 def __init__(self,
              room,
              floor,
              building,
              host,
              port,
              command_topic,
              status_topic,
              actuator_pin,
              pin_numbering='BCM',
              activeState=1,
              CS=8,
              MOSI=10,
              MISO=9,
              SCLK=11):
     self.room = room
     self.floor = floor
     self.building = building
     self.id = str(self.room) + str(building)
     self.mqtt = MQTT_Client(
         room,
         floor,
         building,
         host,
         port,
         command_topic,
         status_topic,
     )
     self.door = Door(actuator_pin=actuator_pin,
                      numbering=pin_numbering,
                      activeState=activeState)
     self.rfid = RFID_Reader(CS=CS, MOSI=MOSI, MISO=MISO, SCLK=SCLK)
     self.available_commands = {b'open': self.door.open}
Exemplo n.º 2
0
import npyscreen, queue
import json, time
from MQTT_Client import MQTT_Client

# for debugging
import logging


# create the queue for received messages:
msgs = queue.Queue()

# create the MQTT client instance with the default
# parameters since we're connecting to a server on the localhost
# and default port

mqtt = MQTT_Client()
topic = "user_db"

# set the logging level
logging.basicConfig(level=logging.INFO)


# create the UI instance
class ClientApp(npyscreen.NPSAppManaged):
    def onStart(self):
        self.registerForm("MAIN", ManagementForm())


class ManagementForm(npyscreen.Form):
    OK_BUTTON_TEXT = "Exit (Ctrl + C)"
Exemplo n.º 3
0
class Room():
    def __init__(self,
                 room,
                 floor,
                 building,
                 host,
                 port,
                 command_topic,
                 status_topic,
                 actuator_pin,
                 pin_numbering='BCM',
                 activeState=1,
                 CS=8,
                 MOSI=10,
                 MISO=9,
                 SCLK=11):
        self.room = room
        self.floor = floor
        self.building = building
        self.id = str(self.room) + str(building)
        self.mqtt = MQTT_Client(
            room,
            floor,
            building,
            host,
            port,
            command_topic,
            status_topic,
        )
        self.door = Door(actuator_pin=actuator_pin,
                         numbering=pin_numbering,
                         activeState=activeState)
        self.rfid = RFID_Reader(CS=CS, MOSI=MOSI, MISO=MISO, SCLK=SCLK)
        self.available_commands = {b'open': self.door.open}

    def command_handler(self, client, userdata, message):
        logger.info(f'received command {message.payload}')
        self.available_commands.get(message.payload,
                                    self.command_error)(message.payload)

    def command_error(self, command):
        logger.error(f'got corrupted command  - {command}')

    def routine_start(self):
        self.mqtt.handler = self.command_handler
        self.rfid.handler = self.mqtt.request_open
        self.mqtt.connect()
        while True:
            uid = self.rfid.readUID()
            if uid is not None:
                logger.debug(f'uid is {uid}')
                self.rfid.handler(uid)
                logger.info(
                    f'{time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())} access attempt by {uid}'
                )
                uid_old, uid_new = uid, uid
                while uid_old == uid_new:

                    uid_new = self.rfid.readUID()
                    if uid_new is None:
                        uid_new = self.rfid.readUID()
                    logger.debug(f'new uid is {uid_new}')
                    if uid is None:
                        break
                    time.sleep(0.1)
            else:
                time.sleep(0.1)
Exemplo n.º 4
0
    t_getData.start()  # Start thread

    initialGuess = findIG(get_array(
        q_cpp_output))  # Determine initial guess based on magnet's location

# Error handling in case thread spawning fails (2/2)
except Exception as e:
    print("Could NOT create thread, check .cpp")
    print("Error type {}".format(type(e)))
    print("Error Arguments {}".format(e.args))
    sleep(2.5)
    quit()  # Shutdown entire program

# Start MQTT Client
MQTT_IP_ADDRESS = "ENTER ADDRESS"  # IP address for MQTT broker
MQTT = MQTT_Client(MQTT_IP_ADDRESS)  # Start MQTT client

# Setup Tkinter's GUI
gui = Tk()
dial = counter(gui)
dial.pack(side=TOP, expand=YES, fill=BOTH)
dial.set_str()
gui.attributes("-fullscreen", True)
gui.update()

# ************************************************************************
# =========================> MAKE IT ALL HAPPEN <=========================
# ************************************************************************

print("Ready in 3 "),
sleep(1.0)