Microptyhon on the ESP32: file management

 While some boards using MicroPython have processors with built-in USB supports, the ESP32 is not one of those. That basically means the ESP32 needs an auxiliary chip to connect to a USB port. But it also means the preferred connection is to emulate a serial connection. Chips like the FTDI's USB to serial, or CP1202, or the CH340G, all are seen as a COM port on the PC side. And here is where the difference matters, as a serial communication matches well the REPL interpreter, but it also prevents the device to appear as any other device to your system (no mouse, no keyboard, no mass storage device). And that is a problem as MicroPython usually relies on the host system to have access to the local storage on the MicroPython device so different files and libraries can be edited a replaced during the development phase.

What does no change, however, is that MicroPython still can have access to the local file system. Just try: 

import os
os.listdir()

So, one way of dealing with this limitation is to use a tool that can offer us access to the local filesystem on the target MicroPython board (ours based on the ESP32 now). And it does this by using the raw-REPL over the serial connection and and some code on the PC side called rshell. This way you can list, copy, delete and create or destroy folders and files on the MicroPython board local-filesystem, all through the serial terminal. Definitely, a useful tool that was not needed when you already could see the MicroPython board local-storage as a mass storage device (as it happened with BlackPill). 

Please note rshell is just a command-line tool and you need to provide an external editor if you want to edit the content of any file. If you don't, then you can do file management and/or start a REPL session. 

But given the ESP32 has wifi connectivity, a question may arise "Is it possible to do that wirelessly?". And the answer is yes. You can do that same work wirelessly using your browser. But some preparation is needed:

  1. On the one hand, you need the ESP32 to connect to your local network on boot (if you have any, or to create its own network and allow you to connect to it if you do not have one wifi network). 
  2. On the other hand, some server code needs to run on the ESP32 side so your browser can interact with it to provide you file-editing and access to the local-filesystem of the board. 
So there is a way to access remotely the REPL on your board, that is by means of WebREPL, that as an added bonus, it allows access to the board's local file-system. But, as it happens sometimes, it did not work for me. After some fighting, I discovered Google Chrome was not allowing a non-ciphered WebSockets connection to be started from code downloaded from a ciphered HTTPS connection. But I learned next that Microsoft's Edge did not have such a limitation. So then I was finally in business.

Please note you can make this work with Google's Chrome browser if you download the WebREPL HTML page to your computer and start it from there (instead of from an HTTPS web page, source files linked in the warning message below). 

At this time, the WebREPL client cannot be accessed over HTTPS connections.
Use a HTTP connection, eg. http://micropython.org/webrepl/.
Alternatively, download the files from GitHub and run them locally.


Comments

Popular posts from this blog

VFD control with Arduino using RS485 link

How to get sinusoidal s-curve for a stepper motor

Importing OpenSCAD designs into Onshape