Serial Interface

The serial input plugin, allows to retrieve messages/data from a Serial interface.

Configuration Parameters

Key Description
File Absolute path to the device entry, e.g: /dev/ttyS0
Bitrate The bitrate for the communication, e.g: 9600, 38400, 115200, etc
Min_Bytes The serial interface will expect at least Min_Bytes to be available before to process the message (default: 1)
Separator Allows to specify a separator string that’s used to determinate when a message ends.
Format Specify the format of the incoming data stream. The only option available is ‘json’. Note that Format and Separator cannot be used at the same time.

Getting Started

In order to retrieve messages over the Serial interface, you can run the plugin from the command line or through the configuration file:

Command Line

The following example loads the input serial plugin where it set a Bitrate of 9600, listen from the /dev/tnt0 interface and use the custom tag data to route the message.

  1. $ fluent-bit -i serial -t data -p File=/dev/tnt0 -p BitRate=9600 -o stdout -m '*'

The above interface (/dev/tnt0) is an emulation of the serial interface (more details at bottom), for demonstrative purposes we will write some message to the other end of the interface, in this case /dev/tnt1, e.g:

  1. $ echo 'this is some message' > /dev/tnt1

In Fluent Bit you should see an output like this:

  1. $ fluent-bit -i serial -t data -p File=/dev/tnt0 -p BitRate=9600 -o stdout -m '*'
  2. Fluent Bit v1.x.x
  3. * Copyright (C) 2019-2020 The Fluent Bit Authors
  4. * Copyright (C) 2015-2018 Treasure Data
  5. * Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
  6. * https://fluentbit.io
  7. [2016/05/20 15:44:39] [ info] starting engine
  8. [0] data: [1463780680, {"msg"=>"this is some message"}]

Now using the Separator configuration, we could send multiple messages at once (run this command after starting Fluent Bit):

  1. $ echo 'aaXbbXccXddXee' > /dev/tnt1
  1. $ fluent-bit -i serial -t data -p File=/dev/tnt0 -p BitRate=9600 -p Separator=X -o stdout -m '*'
  2. Fluent-Bit v0.8.0
  3. Copyright (C) Treasure Data
  4. [2016/05/20 16:04:51] [ info] starting engine
  5. [0] data: [1463781902, {"msg"=>"aa"}]
  6. [1] data: [1463781902, {"msg"=>"bb"}]
  7. [2] data: [1463781902, {"msg"=>"cc"}]
  8. [3] data: [1463781902, {"msg"=>"dd"}]

Configuration File

In your main configuration file append the following Input & Output sections:

  1. [INPUT]
  2. Name serial
  3. Tag data
  4. File /dev/tnt0
  5. BitRate 9600
  6. Separator X
  7. [OUTPUT]
  8. Name stdout
  9. Match *

Emulating Serial Interface on Linux

The following content is some extra information that will allow you to emulate a serial interface on your Linux system, so you can test this Serial input plugin locally in case you don’t have such interface in your computer. The following procedure has been tested on Ubuntu 15.04 running a Linux Kernel 4.0.

Build and install the tty0tty module

Download the sources

  1. $ git clone https://github.com/freemed/tty0tty

Unpack and compile

  1. $ cd tty0tty/module
  2. $ make

Copy the new kernel module into the kernel modules directory

  1. $ sudo cp tty0tty.ko /lib/modules/$(uname -r)/kernel/drivers/misc/

Load the module

  1. $ sudo depmod
  2. $ sudo modprobe tty0tty

You should see new serial ports in /dev/ (ls /dev/tnt*) Give appropriate permissions to the new serial ports:

  1. $ sudo chmod 666 /dev/tnt*

When the module is loaded, it will interconnect the following virtual interfaces:

  1. /dev/tnt0 <=> /dev/tnt1
  2. /dev/tnt2 <=> /dev/tnt3
  3. /dev/tnt4 <=> /dev/tnt5
  4. /dev/tnt6 <=> /dev/tnt7