Beispiel #1
0
    def __init__(self,
                 *subscriber_list,
                 back_plane_ip_address=None,
                 subscriber_port='43125',
                 publisher_port='43124',
                 process_name='RpiPicoGateway',
                 event_loop=None,
                 com_port=None,
                 log=False):
        """
        Set up the gateway for operation

        :param subscriber_list: a tuple or list of subscription topics.
        :param back_plane_ip_address: ip address of backplane or none if local
        :param subscriber_port: backplane subscriber port
        :param publisher_port: backplane publisher port
        :param process_name: name to display on the console
        :param event_loop: optional parameter to pass in an asyncio
                           event loop
        :param com_port: force pymata-express to use this comport
        :param log: enable logging
        """

        # set up logging if requested
        self.log = log
        if self.log:
            fn = str(pathlib.Path.home()) + "/rpi_pico_gw.log"
            self.logger = logging.getLogger(__name__)
            logging.basicConfig(filename=fn, filemode='w', level=logging.DEBUG)
            sys.excepthook = self.my_handler

        # set the event loop to be used. accept user's if provided
        self.event_loop = event_loop
        self.com_port = com_port

        # instantiate tmx-pico-aio that controls the Pico board
        # if user want to pass in a com port, then pass it in
        try:
            self.pico = tmx_pico_aio.TmxPicoAio(loop=self.event_loop,
                                                com_port=com_port)
        except RuntimeError:
            if self.log:
                logging.exception("Exception occurred", exc_info=True)
            raise

        # Initialize the parent
        super(RpiPicoGateway, self).__init__(
            subscriber_list=subscriber_list,
            event_loop=self.event_loop,
            back_plane_ip_address=back_plane_ip_address,
            subscriber_port=subscriber_port,
            publisher_port=publisher_port,
            process_name=process_name,
        )
Beispiel #2
0

async def dht(the_board):
    # set  2 pins to DHT mode
    await the_board.set_pin_mode_dht(DHT_PIN1, the_callback)
    await the_board.set_pin_mode_dht(DHT_PIN2, the_callback)

    # wait forever
    while True:
        try:
            await asyncio.sleep(1)
        except KeyboardInterrupt:
            await board.shutdown()
            sys.exit(0)


# get the event loop
loop = asyncio.get_event_loop()

try:
    board = tmx_pico_aio.TmxPicoAio()
except KeyboardInterrupt:
    sys.exit()

try:
    # start the main function
    loop.run_until_complete(dht(board))
except KeyboardInterrupt:
    loop.run_until_complete(board.reset_board())
    sys.exit(0)