rshell should now work with the WiPy

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
User avatar
dhylands
Posts: 3637
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

rshell should now work with the WiPy

Post by dhylands » Thu Nov 19, 2015 6:39 am

I checked in a new version of rshell.py (and updated the pyboard.py) that seems to be working with the WiPy over telnet.
https://github.com/dhylands/upy-shell/t ... ter/rshell

It doesn't work completely over the USB serial link with the WiPy. I think that characters are being dropped on the serial link, but I need to investigate further (I see flow control signals - so I may just need to enable HW flow control).

I was able to copy files into and out of /flash on the WiPy using the telnet link. This probably isn't quite as useful as it is on the pyboard since you can copy files in and out using ftp as well, but having other options is good in my books.

User avatar
pythoncoder
Posts: 5144
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: rshell should now work with the WiPy

Post by pythoncoder » Sat Nov 21, 2015 10:30 am

While it works better with the Pyboard (no delay removing junk from the serial line), I'm getting no joy with the WiPy, wirelessly or via the expansion board USB. The only thing unusual is that I'm using a fixed IP. I'll raise an issue with full details.
Peter Hinch

User avatar
dhylands
Posts: 3637
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell should now work with the WiPy

Post by dhylands » Sat Nov 21, 2015 5:02 pm

It doesn't work over the expansion serial for me either. I also had to update the pyboard.py file to match the latest from micropython.

vikebo
Posts: 15
Joined: Sun Mar 15, 2015 8:15 pm
Location: Norway

Re: rshell should now work with the WiPy

Post by vikebo » Thu Dec 03, 2015 9:43 pm

I tried using rshell for WiPy, but have some problems.

I have all the files in the same folder and have python3-serial installed. Python3 is version 3.4.2 and MicroPython on the WiPy is v1.5-1-ge954604. WiPy is not operating as an AP, and with a fixed IP of 192.168.0.14. Still using standard username and password which seems to be the default in rshell.py.

After making rshell executable and starting it with ./rshell.py I try this:

connect telnet 192.168.0.14

With this result:
Connecting to (192.168.0.14) ...
Traceback (most recent call last):
File "./rshell.py", line 2176, in <module>
main()
File "./rshell.py", line 2173, in main
shell.cmdloop(cmd_line)
File "./rshell.py", line 1252, in cmdloop
cmd.Cmd.cmdloop(self)
File "/usr/lib/python3.4/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "./rshell.py", line 1283, in onecmd
return cmd.Cmd.onecmd(self, line)
File "/usr/lib/python3.4/cmd.py", line 217, in onecmd
return func(arg)
File "./rshell.py", line 1593, in do_connect
connect_telnet(name)
File "./rshell.py", line 961, in connect_telnet
dev = DeviceNet(name, ip_address, user, password)
File "./rshell.py", line 1182, in __init__
Device.__init__(self, pyb)
File "./rshell.py", line 1003, in __init__
self.has_buffer = self.remote_eval(test_buffer)
File "./rshell.py", line 1084, in remote_eval
return eval(self.remote(func, *args, **kwargs))
File "./rshell.py", line 1065, in remote
self.pyb.enter_raw_repl()
File "shorter_path/pyboard.py", line 168, in enter_raw_repl
data = self.read_until(1, b'soft reboot\r\nraw REPL; CTRL-B to exit\r\n')
File "shorter_path/pyboard.py", line 139, in read_until
elif self.serial.inWaiting() > 0:
File "shorter_path/pyboard.py", line 113, in inWaiting
data = self.tn.read_eager()
File "/usr/lib/python3.4/telnetlib.py", line 382, in read_eager
return self.read_very_lazy()
File "/usr/lib/python3.4/telnetlib.py", line 405, in read_very_lazy
raise EOFError('telnet connection closed')
EOFError: telnet connection closed

Telnet works ok from the normal shell, as well as ftp with FileZilla. I haven't tried rshell before, so maybe I'm doing something wrong? However, telnetlib.py seems to be part of python3.4, so I'm not sure if the problem is with Python3 or Micropython.

Any pointers will be appreciated.
Eivind

User avatar
dhylands
Posts: 3637
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell should now work with the WiPy

Post by dhylands » Thu Dec 03, 2015 11:56 pm

Does your boot.py print anything?

If you login using telnet and then press Control-D at the REPL it will do a soft reset. I see the following:

Code: Select all

PYB: soft reboot
MicroPython v1.5-2-g126373a on 2015-11-16; WiPy with CC3200
Type "help()" for more information.
>>> 
If your boot.py prints anything then it will show up between the PYB:soft reboot and the MicroPython line. When rshell tries to enter the raw repl, pyboard.py is looking for the string soft reboot\r\nraw REPL; CTRL-B to exit\r\n. The print shows up in the middle of the string (right after the soft reboot\r\n) so pyboard.py eventually times out.

I've opened an issue: https://github.com/micropython/micropython/issues/1491 but haven't gotten around to fixing it yet.

I've also recently added tab filename completion and an edit command to rshell. If you ask to edit a file on the pyboard/wipy, it copies it locally, invokes an editor (default is vi, but you can change it) and if you make any changes to the file it will copy it back.

You need to be really careful if you edit boot.py, because if it contains any errors, that will wind up tripping up rshell due to the above issue (when the traceback for the error gets printed).

User avatar
dhylands
Posts: 3637
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell should now work with the WiPy

Post by dhylands » Fri Dec 04, 2015 12:11 am

I just submitted a PR that fixes pyboard.py

https://github.com/micropython/micropython/pull/1680

I also updated the copy of pyboard.py in the rshell repository in anticipation that the PR will be accepted.

vikebo
Posts: 15
Joined: Sun Mar 15, 2015 8:15 pm
Location: Norway

Re: rshell should now work with the WiPy

Post by vikebo » Fri Dec 04, 2015 6:33 am

Thank you for your reply.

boot.py did print two comments, but removing them made no change. Also tried updating pyboard.py with your changes and still get the same error message.

However, I have the configuration of WiPy as a station instead of an access point in boot.py which will probably case it to loose the connection in case of a reset. Will have to look for a better solution for this then.

User avatar
dhylands
Posts: 3637
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell should now work with the WiPy

Post by dhylands » Fri Dec 04, 2015 7:17 am

My wipy is setup as a station as well (also with a static IP).

If you reinitialize it to be a station every time, then yeah that would drop the connection. When pyboard (which rshell derives from) enters the raw repl it causes a soft reset. rshell does this at least once, and sometimes several times for each shell command executed.

My boot.py looks like this:

Code: Select all

501 >rshell.py 
Connecting to /dev/ttyACM0 ...
Welcome to rshell. Use Control-D to exit.
/home/dhylands> 
dhylands@dave ~ 
502 >rshell.py -p wipy
Connecting to wipy (192.168.0.63) ...
Welcome to rshell. Use Control-D to exit.
/home/dhylands> cat /flash/boot.py
import machine

from machine import UART
import os
uart = UART(0, baudrate=115200)
os.dupterm(uart)

if machine.reset_cause() != machine.SOFT_RESET:
    import wlan_static as wlan
    wlan.set()
/home/dhylands> 
I have wlan_static.py and wlan_dhcp.py and can switch between them by changing the import statement. Here is my wlan_static.py:

Code: Select all

import machine

from network import WLAN
wlan = WLAN() # get current object, without changing the mode

ssid     = 'Your-SSID-Here'
password = 'Your-Password'
ip       = '192.168.0.63'
net_mask = '255.255.255.0'
gateway  = '192.168.0.1'
dns      = '8.8.8.8'

def init():
    wlan.init(WLAN.STA)
    wlan.ifconfig(config=(ip, net_mask, gateway, dns))

def connect():
    wlan.connect(ssid, auth=(WLAN.WPA2, password), timeout=5000)
    while not wlan.isconnected():
        machine.idle() # save power while waiting
    cfg = wlan.ifconfig()
    print('WLAN connected ip {} gateway {}'.format(cfg[0], cfg[2]))

def set():
    init()
    if not wlan.isconnected():
        connect()
and my wlan_dhcp.py looks like:

Code: Select all

import machine
from network import WLAN

wlan = WLAN() # get current object, without changing the mode

ssid = 'Your-SSID-Here'
password = 'Your-password'

def init():
    wlan.init(WLAN.STA)

def connect():
    # change the line below to match your network ssid, security and password
    wlan.connect(ssid, auth=(WLAN.WPA2, password), timeout=5000)
    while not wlan.isconnected():
        machine.idle() # save power while waiting
    cfg = wlan.ifconfig()
    print('WLAN connected ip {} gateway {}'.format(cfg[0], cfg[2]))

def set():
    init()
    if not wlan.isconnected():
        connect()
I can also import wlan_static.py or wlan_dhcp.py and call the set method from the REPL to switch back and forth.

vikebo
Posts: 15
Joined: Sun Mar 15, 2015 8:15 pm
Location: Norway

Re: rshell should now work with the WiPy

Post by vikebo » Sun Dec 06, 2015 6:23 pm

That makes sense now. I haven't really used REPL very much, but rshell seems like a good tool.
Thanks a lot for the files also, they will be helpful.

User avatar
dhylands
Posts: 3637
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell should now work with the WiPy

Post by dhylands » Sun Dec 06, 2015 7:47 pm

I just pushed some more changes recently that allow rshell to be a bit more reliable when the telnet session goes away and comes back (so instead of dumping a huge error dump it catches the exception caused).

It will still require boot.py to not reset the telnet session each time.

There is also an edit command in rshell (you need to be at the rshell prompt and not at the REPL). You can do edit /flash/foo.py and it will copy the file locally, invoke an editor (vi by default but you can change that) and then when you quit the editor, if there were any changes it will copy the file back.

Post Reply