Rob Braggaar
Published © CC BY-SA

Pycom Simple Telnet

Simple Telnet client to work with Pycom boards.

BeginnerProtip2,949
Pycom Simple Telnet

Things used in this project

Story

Read more

Schematics

Just connect your WiPy or Lopy to a power supply

Code

simple_telnet.py

Python
Requires python (v2) to run.
"""
Simple telnet client for Pycom.

Fire up a telnet connection between your pc and Lopy/Wipy with a simple
script.

No need to install additional programs (besides Python itself).
"""
import telnetlib
import time
import sys
import msvcrt


__author__ = "Rob Braggaar"
__license__ = "CC-BY-SA"

sys.ps1 = ''
sys.ps2 = ''
# timeout value for blocking operations [s]
TO = 5 

# host, 192.168.4.1 by default
host = "192.168.4.1"

# username and password for telnet
username = "micro"
password = "python"

# create telnet object
tel = telnetlib.Telnet(host, port=23, timeout=TO)

# login process
print tel.read_until("Login as: ")
print username
tel.write(username + "\r\n")
print tel.read_until("Password: ", timeout=TO)
print ''
time.sleep(1)
tel.write(password + "\r\n")
time.sleep(.5)
print tel.read_until(">>> ", timeout=TO).strip('>>> ')

# receive commands from the user as input
# send and execute commands to the pycom device and return the result
while True:
    indent = '    '
    cmd = raw_input('>>> ')
    if len(cmd) > 1:
        while cmd[-1] == ':':
            cmd += '\n' + indent + raw_input('... ' + indent)
            indent += '    '
    tel.write(cmd + '\r\n')
    time.sleep(.5)
    print (tel.read_until(">>> ", timeout=1).strip('>>> ' + cmd).strip('\r\n'))

Credits

Rob Braggaar

Rob Braggaar

3 projects • 13 followers
Professional tinkerer, Node specialist and tech geek

Comments