wendlers / mpfshell

A simple shell based file explorer for ESP8266 Micropython based devices ⛺
MIT License
396 stars 84 forks source link

Problems entering raw repl #54

Closed fstengel closed 5 years ago

fstengel commented 6 years ago

I am currently experiencing issues when trying to connect using mpfshell (i.e. failure 19 cases in 20) with my wemos D1 mini. The error message being: "could not enter raw repl".

Browsing around I discovered that in ampy, which uses a slightly different version of pyboard.py, a delay is added before sending the double ctrl-C when entering raw repl.

So I added a 1 second delay just before line 63 in pyboard.py, in enter_raw_repl (i.e. just before self.con.write(b'\r\x03\x03')). The code now looks like

    def enter_raw_repl(self):

        time.sleep(1)
        self.con.write(b'\r\x03\x03')  # ctrl-C twice: interrupt any running program

The result being that I can now consistently open the board. I tried reducing the delay. 0.2 second works, 0.15 doesn't. Currently I am working with a 0.5 second delay.

torntrousers commented 6 years ago

Thanks @fstengel this has fixed the same for me too. Bit weird was that mpfshell had been working fine for me on a few different ESP8266 boards then all of a sudden it stoped working and just failing with error message: "could not enter raw repl". Nothing I tried would fix it until stumbling on this solution here which fixes it.

skorokithakis commented 5 years ago

Does this happen with USB or Websocket? Or both? Good to know that a delay fixes it, but I'd like to investigate some more before just adding a delay, it feels a bit like a hack.

torntrousers commented 5 years ago

With USB. I know a bit more about all this now so I can go debug it a bit more...

skorokithakis commented 5 years ago

That would be fantastic, thank you.

torntrousers commented 5 years ago

I've had a bit more of a look and I think its just the code runs too fast and when it does the ctrl-c's here its just a bit too soon and the board is still reseting (the ESP8266 on the Wemos D1 mini does a reset when its connected to) so the ctrl-c's happen a bit too soon. A sleep of 0.2 seems to reliably fix it for me.

skorokithakis commented 5 years ago

Sounds good to me, would you be interested in submitting a PR? We should probably play it safe and go for 0.5, but this sounds like an acceptable fix to me.

skorokithakis commented 5 years ago

This should be fixed, thanks to @torntrousers.