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 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.º 6
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)