Beispiel #1
0
    def __init__(self, ip, password):

        ConBase.__init__(self)
        threading.Thread.__init__(self)

        self.daemon = True

        self.fifo = deque()
        self.fifo_lock = threading.Lock()

        # websocket.enableTrace(logging.root.getEffectiveLevel() < logging.INFO)
        self.ws = websocket.WebSocketApp(
            "ws://%s:8266" % ip,
            on_message=self.on_message,
            on_error=self.on_error,
            on_close=self.on_close,
        )

        self.start()

        self.timeout = 5.0

        if b"Password:"******"\r")
            if b"WebREPL connected" not in self.read(25, blocking=False):
                raise ConError()
        else:
            raise ConError()

        self.timeout = 1.0

        logging.info("websocket connected to ws://%s:8266" % ip)
    def __init__(self, ip, password):

        ConBase.__init__(self)
        threading.Thread.__init__(self)

        self.daemon = True

        self.fifo = deque()
        self.fifo_lock = threading.Lock()

        # websocket.enableTrace(logging.root.getEffectiveLevel() < logging.INFO)
        self.ws = websocket.WebSocketApp("ws://%s:8266" % ip,
                                         on_message=self.on_message,
                                         on_error=self.on_error,
                                         on_close=self.on_close)

        self.start()

        self.timeout = 10.0

        if b'Password:'******'WebREPL connected' in self.read(25, blocking=False):
                print("\nWebREPL Password Error")
                raise ConError()
        else:
            print(
                "\nWebREPL Remote IP does not respond, check belong to the same network."
            )
            raise ConError()

        self.timeout = 5.0

        logging.info("websocket connected to ws://%s:8266" % ip)
Beispiel #3
0
    def __init__(self, ip, user, password):
        ConBase.__init__(self)

        if sys.version_info < (3, 0):
            self.read = self.__read2
        else:
            self.read = self.__read3

        self.tn = telnetlib.Telnet(ip)
        if user=='':
            self.fifo = deque()
            return

        if b'Login as:' in self.tn.read_until(b'Login as:', timeout=5.0):
            self.tn.write(bytes(user.encode('ascii')) + b"\r\n")

            if b'Password:'******'Password:'******'ascii')) + b"\r\n")

                if b'for more information.' in self.tn.read_until(b'Type "help()" for more information.', timeout=5.0):
                    self.fifo = deque()
                    return

        raise ConError()
Beispiel #4
0
    def __init__(self, port, baudrate=115200, reset=False):
        ConBase.__init__(self)

        try:
            self.serial = Serial(port, baudrate=baudrate, interCharTimeout=1)

            if reset:
                logging.info("Hard resetting device at port: %s" % port)

                self.serial.setDTR(True)
                time.sleep(0.25)
                self.serial.setDTR(False)

                self.serial.close()
                self.serial = Serial(port,
                                     baudrate=baudrate,
                                     interCharTimeout=1)

                while True:
                    time.sleep(2.0)
                    if not self.inWaiting():
                        break
                    self.serial.read(self.inWaiting())

        except Exception as e:
            logging.error(e)
            raise ConError(e)
Beispiel #5
0
    def __init__(self, ip, password):

        ConBase.__init__(self)
        threading.Thread.__init__(self)

        self.daemon = True
        self.fifo_lock = threading.Lock()
        self.fifo = deque()
        self.ws = None
        self.active = True
        self.start()

        # websocket.enableTrace(logging.root.getEffectiveLevel() < logging.INFO)
        #websocket.enableTrace(True)

        success = False
        for t in range(5):  # try 5 times
            print("Allocating new websocket.")
            self.ws = websocket.WebSocketApp("ws://%s:8266" % ip,
                                             on_message=self.on_message,
                                             on_error=self.on_error,
                                             on_close=self.on_close)
            self.ws.keep_running = True

            self.timeout = 5.0

            inp1 = self.read(256, blocking=False)
            if b'Password:'******'WebREPL connected' in inp2:
                    pass
                else:
                    success = True
                    break
            # reset socket and prepare to reconnect
            print("Retrying.")
            oldws = self.ws
            self.ws = None
            oldws.keep_running = False
            try:
                oldws.close()
            except:
                pass
            self.cleanup()

        if not success:
            self.close()
            raise ConError()

        # we were successful to connect
        self.timeout = 1.0

        logging.info(
            "websocket connected to ws://{}:8266 after {} tries.".format(
                ip, t))
Beispiel #6
0
    def __init__(self, constr, reset=False):
        """
        Supports the following connection strings.

            ser:/dev/ttyUSB1,<baudrate>
            tn:192.168.1.101,<login>,<passwd>
            ws:192.168.1.102,<passwd>

        :param constr:      Connection string as defined above.
        """

        self.reset = reset

        try:
            Pyboard.__init__(self, self.__con_from_str(constr))
        except Exception as e:
            raise ConError(e)

        self.dir = None
        self.sysname = None
        self.setup()