OpenWrt Forum Archive

Topic: Monitoring UART

The content of this topic has been archived on 1 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello,

Not sure if this is the best forum to ask this, but here it goes:

I want to connect an UART device to my openwrt router. Its basically an arduino that sends messages via its USB UART.
This arduino has some presence sensors and is sleeping all the time.  Whenever some presence is detected, it generates an interrupt and sends a message to USB UART. This is not the native router's UART, its a /dev/ttyUSBxx that appears when connecting the arduino to the openwrt.

With minicom, I'm able to see the messages coming to the router, but what I need is to have somekind of script listening to the UART, that wakes up when a new message arrives, and then makes some action, like sending an e-mail or something.

I don't even know what would be the correct terms to search for.

Anyone could point me into the right direction?

Thanks,
Jabss

If the data is plain text, separated by newlines, you can do

#!/bin/sh

ListeningDaemon()
{
    while read line
    do
          #  handle line
          echo $line >/tmp/logfile
    done

}

# set baudrate etc.
stty -F /dev/ttyUSB0 9600
# start 'daemon'
ListeningDaemon </dev/ttyUSB0 >/dev/null 2>/dev/null &

Thanks for that.

Really impressive arguments for the ListeningDaemon function smile

I had to make a few minor tweaks to make it work, I'll post it here so everybody could benefit from it:

#!/bin/sh

ListeningDaemon()
{
    while read line
    do
          #  handle line
          echo $line >>/tmp/logfile
    done

}

# set baudrate etc.
stty -F /dev/ttyUSB4 9600 -icrnl -parity cs8 -cstopb
# start 'daemon'
ListeningDaemon </dev/ttyUSB4 >/dev/null 2>/dev/null &

Now let's see how stable would the /dev/ttyUSB connection be along the coming days/weeks/months.

Thanks,
Jabss

The discussion might have continued from here.