esp32m / core

ESP32 Manager core
MIT License
26 stars 4 forks source link

Adding a Shell/Repl #11

Closed jetpax closed 10 months ago

jetpax commented 10 months ago

I wanted to add Shellminator from @dani007200964 as it works really nicely over websockets as well as UART and the accompanying Commander is easy to use, well documented anf full featured. I'm not clear how this would coexist with your console logging however.

I see that you have used the esp-idf console component which has a repl, but does not seem to be activated??

Do you have any plans to add a functioning shell/Repl?

dyarkovoy commented 10 months ago

You're right, there's REPL that works over UART, you need to new Ui(&ui::Console::instance()); to activate it. It has been a while since we used/tested it, so there may be issues, but you're welcome to test it. Logging module is very flexible, you can turn off console/UART logging and/or redirect it to UDP/another UART/file

dani007200964 commented 10 months ago

Shellminator and Commander can be redirected to any Stream class-based child class. If it is a solution, you can map it to any other Serial port on the panel.

Also, it is a possible solution, to create a Stream-based child class that has a relatively large buffer and put the logging data there instead of Serial. Later you can dump its content to the console with a dedicated terminal command.

dyarkovoy commented 10 months ago

I see, but the problem is Shellmitator depends on Arduino libraries, whereas esp32m is based on the native ESP-IDF develompent environment, which does not have Stream class, therefore I am afraid Shellmitator will not work with esp32m

jetpax commented 10 months ago

Well I tried enabling the console instance as you suggested and it works just fine. Indeed with the addition of

      #if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) || defined(CONFIG_ESP_CONSOLE_UART_CUSTOM)
          _uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
      #elif defined(CONFIG_ESP_CONSOLE_USB_CDC)
          _uart_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT();
      #elif defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG)
          logI("setting USJconfig");
          _uart_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT();
      #endif

.
.
.

      #if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) || defined(CONFIG_ESP_CONSOLE_UART_CUSTOM)
          ESP_ERROR_CHECK(esp_console_new_repl_uart(&_uart_config, &_repl_config, &_repl));
      #elif defined(CONFIG_ESP_CONSOLE_USB_CDC)
          ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&_uart_config, &_repl_config, &_repl));
      #elif defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG)
          ESP_ERROR_CHECK(esp_console_new_repl_usb_serial_jtag(&_uart_config, &_repl_config, &_repl));
      #endif

it works fine with the USB JTAG serial port which is all my hardware has.

However, my main reason for having a shell was to support serialization of the system API for scripting purposes, and on reading your docs a little it seems that it would be much better to use the JSON API directly, and dispense with a console repl entirely.

dyarkovoy commented 10 months ago

Good point. JSON API is pretty straightforward, all you need is to open devtools/network in your browser while navigating through the esp32m web UI to see relevant requests/responses, and use them for your scripting purposes.