Exemplo n.º 1
0
    def run(self) -> None:
        # ---
        EdgeService.run(self)
        # ----
        print('server socket io run')
        # ----
        """self.sio.on('connect', self.connect_handler)
        self.sio.on('disconnect', self.disconnect_handler)
        self.sio.event('my_event', self.my_event)
        self.sio.event('my_broadcast_event', self.my_broadcast_event)
        self.sio.event('join', self.join)
        self.sio.event('leave', self.leave)
        self.sio.event('close_room', self.close_room)
        self.sio.event('my_room_event', self.my_room_event)
        self.sio.event('disconnect_request', self.disconnect_request)
        self.sio.event('connect', self.connect)
        self.sio.event('disconnect', self.disconnect)"""

        # ----
        # wrap with a WSGI application
        self.app = socketio.WSGIApp(self.sio)
        # ----
        eventlet.wsgi.server(
            eventlet.listen(
                (self.SOCKET_IO_SERVER_ADRESS, self.SOCKET_IO_SERVER_PORT)),
            self.app)
        # ----
        while True:
            pass
Exemplo n.º 2
0
 def run(self) -> None:
     # ----
     EdgeService.run(self)
     # ----
     self.subscribe_command(callback=self.update_playlist,
                            topic=self.LOCAL_PLAYLIST_READY_TOPIC)
     self.subscribe_command(callback=self.mute_player,
                            topic=self.MUTE_TOPIC)
     self.subscribe_command(callback=self.player_ready_callback,
                            topic=self.LOCAL_MQTT_CONNECTED_TOPIC)
Exemplo n.º 3
0
 def run(self) -> None:
     # ---
     EdgeService.run(self)
     # --- 1A86:7523
     # --------------------------------------------- SERIAL
     import sys
     import os
     from serial.tools.list_ports_common import ListPortInfo
     if os.name == 'nt' or sys.platform == 'win32':
         from serial.tools.list_ports_windows import comports
     elif os.name == 'posix':
         from serial.tools.list_ports_posix import comports
     else:
         raise ImportError(
             "Sorry: no implementation for your platform ('{}') available".
             format(os.name))
     # ---
     target_vid = "0x1A86"
     target_pid = "0x7523"
     # ---
     tmp_comp = comports(include_links=None)
     for item in tmp_comp:
         tmp_item: ListPortInfo = item
         print("ARDUINO: {:20} desc: {} hwid: {}".format(
             tmp_item.device, tmp_item.description, tmp_item.hwid))
         if tmp_item.vid and tmp_item.pid and not self.serial_port:
             print(hex(tmp_item.vid), tmp_item.vid == int(target_vid, 16))
             print(hex(tmp_item.pid), tmp_item.pid == int(target_pid, 16))
             # --- 1A86:7523
             if tmp_item.vid == int(target_vid, 16) and tmp_item.pid == int(
                     target_pid, 16):
                 print("-----> arduino add port {}".format(tmp_item))
                 self.serialport = tmp_item.device
                 try:
                     self.serial_port = serial.Serial(self.serialport,
                                                      self.baud,
                                                      timeout=1)
                 except Exception as e:
                     print("{} error: {}".format(self.__class__.__name__,
                                                 e))
                     self.serial_port = None
     # -----------------------------------------------
     while True:
         # ---
         if self.serial_port:
             self.read_serial_device()
             time.sleep(1)
         else:
             # ---
             # ToDo: make plug&play loop scan if new arduino plugged
             # ---
             pass
Exemplo n.º 4
0
    def run(self):
        # ----
        EdgeService.run(self)
        # ----
        while True:
            try:
                self.distance = read_distance(sigGpio)
            except Exception as e:
                print("{} error: {}".format(self.__class__.__name__, e))
            # print("Distance to object is ", distance, " cm or ", distance * .3937, " inches")
            # ----
            self.dispatch_event(topic=RADAR_DISTANCE_TOPIC,
                                payload=str(self.distance))
            # ----

            time.sleep(sigInterval)
Exemplo n.º 5
0
 def __init__(self):
     # ---
     EdgeService.__init__(self)
     # ---
     # explode_topic_to_namespace(tmp_topic="/device/rpi_03/get_event")
     # ---
     self.sio = socketio.Client(logger=False)
     # ---
     # self.sio.on('connect', self.connect_handler)
     # self.sio.on('disconnect', self.disconnect_handler)
     # ---
     if len(self.TOPICS_LIST) > 0:
         for topic_item in self.TOPICS_LIST:
             # print("client: 0 socketIO subscribe to topic:{}".format(topic_item))
             # self.client.subscribe(str(topic_item))
             self.sio.register_namespace(
                 EdgeClientNamespace(str(topic_item)))
Exemplo n.º 6
0
 def run(self):
     # ----
     EdgeService.run(self)
     # ----
     while self.display_connected:
         # Draw a black filled box to clear the image.
         self.draw.rectangle((0, 0, self.width, self.height),
                             outline=0,
                             fill=0)
         # Write two lines of text.
         self.draw.text((self.x, self.top + (self.interligne * 0)),
                        self.line_one,
                        font=self.font,
                        fill=255)
         self.draw.text((self.x, self.top + (self.interligne * 1)),
                        self.line_two,
                        font=self.font,
                        fill=255)
         self.draw.text((self.x, self.top + (self.interligne * 2)),
                        self.line_three,
                        font=self.font,
                        fill=255)
         self.draw.text((self.x, self.top + (self.interligne * 3)),
                        self.line_four,
                        font=self.font,
                        fill=255)
         self.draw.text((self.x, self.top + (self.interligne * 4)),
                        self.line_five,
                        font=self.font,
                        fill=255)
         self.draw.text((self.x, self.top + (self.interligne * 5)),
                        self.line_six,
                        font=self.font,
                        fill=255)
         self.draw.text((self.x, self.top + (self.interligne * 6)),
                        self.line_seven,
                        font=self.font,
                        fill=255)
         self.draw.text((self.x, self.top + (self.interligne * 7)),
                        self.line_eight,
                        font=self.font,
                        fill=255)
         # Display image.
         self.disp.image(self.image)
         self.disp.display()
Exemplo n.º 7
0
    def __init__(self):
        # ---
        EdgeService.__init__(self)
        # ---
        self.sio = socketio.Server(cors_allowed_origins='*',
                                   always_connect=True)
        # ----
        # self.sio.on('connect', self.connect_handler)
        # self.sio.on('disconnect', self.disconnect_handler)

        # ---
        if len(self.TOPICS_LIST) > 0:
            for topic_item in self.TOPICS_LIST:
                print("server: socketIO subscribe to topic:{}".format(
                    topic_item))
                # self.client.subscribe(str(topic_item))
                self.sio.register_namespace(
                    EdgeServerNamespace(str(topic_item)))
                pass
Exemplo n.º 8
0
    def run(self) -> None:
        # ---
        EdgeService.run(self)
        # ---
        if len(self.MIROR_TOPICS_LIST) > 0:
            for mirror_topic_item in self.MIROR_TOPICS_LIST:
                # print("client: 0 socketIO subscribe mirror topic:{}".format(mirror_topic_item))
                self.subscribe_command(callback=self.on_mirror_message,
                                       topic=mirror_topic_item)

        # ---
        while True:
            if not self.sio.connected:
                # ---
                try:
                    self.sio.connect("{0}://{1}:{2}".format(
                        self.SOCKET_IO_SERVER_ADRESS_PROTOCOL,
                        self.SOCKET_IO_SERVER_ADRESS, self.SOCKET_IO_PORT),
                                     transports=['websocket', 'polling'])

                    # ---
                except Exception as e:
                    print("{} error: {}".format(self.__class__.__name__, e))
            time.sleep(5)
Exemplo n.º 9
0
 def __init__(self):
     EdgeService.__init__(self)
     # ----
     self.distance = -1
Exemplo n.º 10
0
 def __int__(self):
     EdgeService.__init__(self)
Exemplo n.º 11
0
 def __int__(self):
     # ----
     EdgeService.__init__(self)
Exemplo n.º 12
0
    def __init__(self):
        # ----
        EdgeService.__init__(self)
        # ----
        self.RST = None  # on the PiOLED this pin isnt used
        self.display_connected = False
        self.interligne = 8
        self.line_one = "Starting ..."
        self.line_two = ""
        self.line_three = ""
        self.line_four = ""
        self.line_five = ""
        self.line_six = ""
        self.line_seven = ""
        self.line_eight = ""

        self.power_on = True
        # 128x64 display with hardware I2C:
        self.disp = Adafruit_SSD1306.SSD1306_128_64(rst=self.RST)

        try:
            # Initialize library.
            self.disp.begin()

            # Clear display.
            self.disp.clear()
            self.disp.display()

            # Create blank image for drawing.
            # Make sure to create image with mode '1' for 1-bit color.
            self.width = self.disp.width
            self.height = self.disp.height

            self.image = Image.new('1', (self.width, self.height))

            # Get drawing object to draw on image.
            self.draw = ImageDraw.Draw(self.image)

            # Draw a black filled box to clear the image.
            self.draw.rectangle((0, 0, self.width, self.height),
                                outline=0,
                                fill=0)

            # Draw some shapes.
            # First define some constants to allow easy resizing of shapes.
            padding = -2
            self.top = padding
            self.bottom = self.height - padding
            # Move left to right keeping track of the current x position for drawing shapes.
            self.x = 0

            # Load default font.
            self.font = ImageFont.load_default()

            # Alternatively load a TTF font.  Make sure the .ttf font file is in the same directory as the python script!
            # Some other nice fonts to try: http://www.dafont.com/bitmap.php
            # font = ImageFont.truetype('Minecraftia.ttf', 8)

            self.display_connected = True

        except OSError:
            self.display_connected = False
            print("no display")