Sometimes you just need a simple tool to get the job done. But you also want it to be cross platform, and to fit within your workflow. I found myself in just this situation recently while working on networking between embedded devices in my Raver Lights project.

I had two ESP8266 devices that were talking over WiFi. Debugging on embedded devices that don't run an OS is kinda tricky, and usually I just resort to the embedded equivalent of console.log in JavaScript: printing to a serial port.

Historically, I used the serial monitor in the Arduino IDE to do this:

Arduino IDE Serial Monitor

This worked...OK. It wasn't great though. I always had to remember to close the monitor when I needed to reprogram the ESP (which is done over serial too). I recently hit a bigger roadblock though: you can only monitor one serial port at a time.

What I really wanted was a way to monitor serial ports from the command line, since my programming tools were also CLI based. You would think this would be easy, but I wasn't able to figure out a way to monitor the raw output of a serial port (NOT open a TTY terminal using screen or similar commands), much less in a way that is cross platform.

So I decided to write my own and call it Serial Log!

Given that I'm a Node.js developer, I of course wrote this tool in Node.js. Actually printing serial port data to the console is really easy with the serialport npm module, consisting of only 4 lines of code:

const portInstance = new SerialPort(port, options);  
portInstance.on('data', (data) => {  
  process.stdout.write(data);
});

I could probably reduce this to two lines of code using pipe, but I'm lazy ;-).

If you open up the code though, you'll notice about 100 lines of code, so what is everything else doing? Input validation! I wanted to make sure that this app is easy to use, yet flexible enough to have two terminals side-by-side connected to two different serial ports.

I used yargs to process user input and do most of the input validation. The seriallog command takes two optional arguments: --baudrate and --port.

Passing Explicit Parameters

If these options are not specified, then seriallog attempts to figure out as much as it can. It defaults to 115200 baud if no baudrate is specified. I chose this value because a) it's a pretty common baudrate and b) it's my preferred baudrate (hey, it's my tool after all :-P).

If no port is specified, Serial Log will try and figure it out for you. It filters out any serial ports that don't look right, such as /dev/cu.Bluetooth-Modem which is used on OS X for Bluetooth tethering. It then takes the filtered list and does one of two things: 1) if there is only a single port left, it uses that one, or 2) if there is more than one port, it prompts the user to select one.

User Prompting for Port

Node.js runs on the three main operating systems, and most platform dependence is abstracted away from us. In order to get this running on Windows and *NIX, I did have to do a little bit of custom work though with my serial port filtering algorithm because Windows and *NIX use different naming schemes for serial devices. Once that was done though, I got it working flawlessly on all of the major OSes!

So that's Serial Log in a nutshell. Give it a try by installing it from npm:

npm install -g seriallog  

If you have any questions, run into any bugs, or have a feature request, open an issue!.