Datalogging, Timestamp, & Monitor Arduino Data With an Incredible Bash-One-Liner

Introduction: Datalogging, Timestamp, & Monitor Arduino Data With an Incredible Bash-One-Liner


The description doesn't fit on one line -- but the code does!

This is a bash one-liner for logging data from the Arduino, and for processing (e.g. timestamping, reacting to sensor readings, etc.) and then redirecting data file.

I have tried this out on Mac Os X, but I'll verify it on the Raspberry Pi right away (as linux can perform nanosecond timestamping).

Code:

cat /dev/cu.usbmodem1421 | awk '{ for (i=0; i<NF; i++) printf $i + system("date +,%s")}'

To use with your arduino:

Just replace the /dev/cu.usbmodem1421 with your arduino's serial port (an easy way to find this is to see which is checked in the Tools -> Port  of the Arduino IDE menu)

(If you have both /dev/cu.usbmodem and /dev/tty.usbmodem, then use the /dev/cu.usbmodem one)

Real-Time Monitoring:

Real-time monitoring and command line reactions are simple to add-on, for these examples visit (and please star) the project's github.

Be the First to Share

    Recommendations

    • Make It Bridge

      Make It Bridge
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • For the Home Contest

      For the Home Contest

    4 Comments

    0
    Geophysicist
    Geophysicist

    6 years ago

    Hi

    Thank you so much for this interesting project. But, did you manage to try it on raspberry?

    And, if I want to to timestamp sensor readings using GPS synchronized timing do you know how it can be implemented?

    Thank you,

    Alireza, Geophysicist

    0
    jsonius
    jsonius

    8 years ago on Introduction

    Do you need an internet connection for the timestamp to work?

    0
    jabberwocky1396
    jabberwocky1396

    Reply 8 years ago on Introduction

    Hi Jsonius,

    Thanks for the question: no internet connection is required for this method to work. It uses the system's own `date` utility, and can be used completely offline.

    -- Greg

    0
    scruss
    scruss

    8 years ago on Introduction

    Good effort here - there's a lot to learn and use in Linux!

    The command ts (in the Debian/Raspbian/Ubuntu package moreutils) might also do what I think you're trying to do here. Also, if you use gnu awk, it has a strftime function, so you can avoid the system() call and do

    gawk '{print strftime("%s ") $0}'

    You might also want to try grabserial.