7

I have an Arduino sending serial data to the computer. I'm able to view the data using a Serial console. But, I want to be able to log it with time stamp.

I want a ready made script or program that logs serial data with time-stamp automatically without me having to change much or mess with code.

Ufoguy
  • 1,210
  • 3
  • 13
  • 21

4 Answers4

7

You can use the ts program from moreutils to add a timestamp to each line.

{ echo foo; sleep 1; echo bar; } | ts
Dec 13 01:07:23 foo
Dec 13 01:07:24 bar

To read from the serial port and output to a file:

ts </dev/ttyS0 >arduino.log

(Replace /dev/ttyS0 by the right path for the serial port device, .)

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • It caused cyclic resets of my Arduino which is probably caused by cyclic open / close port action and changing DTR line, connected to RESET. – Jarek Jan 21 '23 at 12:45
5
kikeenrique
  • 201
  • 3
  • 10
  • Thanks! Grabserial offers a lot more customization, including the ability to show offests and differences with different base times, restarting the logging based on patterns in the output, modifying serial line settings, etc. – nealmcb Oct 15 '19 at 00:29
0

Try

sudo cat /dev/ttyUSB0  | ts >>arduino.log 

  or

sudo stdbuf -o0 cat /dev/ttyUSB0 | ts >>ttyS0.log
Geo
  • 11
  • (1) Please don’t post code-only answers; rather, *explain* the essence of your answer.  (2) Why do you propose using `sudo`?  Don’t use `sudo` by default; use it only when you need to, and you *understand **why*** you need it.  (3) Why use `cat`, especially in your first answer?  Your `cat /dev/ttyUSB0 | ts >>arduino.log` command is equivalent (except for the tty name and the `>>`) to the `ts arduino.log` command which was given almost nine years ago.  (4) What’s the benefit of using `stdbuf` here, and what does `-o0` do? – G-Man Says 'Reinstate Monica' Aug 28 '22 at 21:38
0

Try https://tio.github.io - it supports logging with various timestamp formats. For example:

tio /dev/ttyUSB0 --log --timestamp --timestamp-format=24-hour

Martin
  • 341
  • 2
  • 3