Toit: jag monitor proxy

While developing on ESP32 boards at Lightbug on some of our newer products, I have repeatedly wanted to run Toit and Jaguar without WiFi enabled during a development setting. Either to have WiFi off to keep power consumption lower, turn off the default network so that I can make use of a secondary network or set up my own hotspot, and most recently, so that I can quickly iterate while using ESP-NOW.

Many months ago @floitsch told me about the --proxy option for the jag monitor command in Discord, and I finally have gotten around to trying it out this week. Here is how it went…

Using –proxy

The --proxy argument exists on the jag monitor command, which is essentially a slightly fancy serial / COM port monitor.

Adding this argument will attempt to proxy the device to the local network via your computer, rather than via the ESPs own WiFi. As a result, you can turn the WiFi off!

~ jag monitor --help
Monitor the serial output of an ESP32

Usage:
  jag monitor [flags]

Flags:
  -a, --attach            attach to the serial output without rebooting it
      --baud uint         the baud rate for serial monitoring (default 115200)
      --envelope string   name or path of the firmware envelope
  -l, --force-plain       force output to use plain ASCII text
  -r, --force-pretty      force output to use terminal graphics
  -h, --help              help for monitor
  -p, --port string       port to monitor (default "/dev/ttyUSB0")
      --proxy             proxy the connected device to the local network
Code language: Shell Session (shell)

Read more

Reading from USB COM port in go

If you want an easy copy and paste, no nonsense way to print the output of a COM PORT to the terminal in go, then have a look at the code at the bottom of this post.

Firstly, the go.bug.st/serial/enumerator package provides a very nice interface for getting details of connected devices, and includes more details than the example code in go.bug.st/serial that I found first time around.

Thanks to the toit devs for being responsive and helping me quickly figure out how I could make my ESP spit some USB content out over the COM port.

The code

In a nutshell is this:

  • Loops forever
  • Targets a specific device ID, such a 1a86:7523
  • Waits for it to appear as connected
    • Uses baud rate 115200
    • Opens the port
    • Prints all output received to the console

Read more