Serial interface
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
The Serial input plugin lets you retrieve messages and data from a serial interface.
This plugin has the following configuration parameters:
File
Absolute path to the device entry. For example, /dev/ttyS0
.
none
Bitrate
The bit rate for the communication. For example: 9600
, 38400
, 115200
.
none
Min_Bytes
The serial interface expects at least Min_Bytes
to be available before processing the message.
1
Separator
Specify a separator string that's used to determinate when a message ends.
none
Format
Specify the format of the incoming data stream. Format
and Separator
can't be used at the same time.
json
(no other options available)
To retrieve messages by using the Serial interface, you can run the plugin from the command line or through the configuration file:
The following example loads the input serial plugin where it set a Bitrate
of 9600
, listens from the /dev/tnt0
interface, and uses the custom tag data
to route the message.
fluent-bit -i serial -t data -p File=/dev/tnt0 -p BitRate=9600 -o stdout -m '*'
The interface (/dev/tnt0
) is an emulation of the serial interface. Further examples will write some message to the other end of the interface. For example, /dev/tnt1
.
echo 'this is some message' > /dev/tnt1
In Fluent Bit you can run the command:
fluent-bit -i serial -t data -p File=/dev/tnt0 -p BitRate=9600 -o stdout -m '*'
Which should produce output like:
...
[0] data: [1463780680, {"msg"=>"this is some message"}]
...
Using the Separator
configuration, you can send multiple messages at once.
Run this command after starting Fluent Bit:
echo 'aaXbbXccXddXee' > /dev/tnt1
Then, run Fluent Bit:
fluent-bit -i serial -t data -p File=/dev/tnt0 -p BitRate=9600 -p Separator=X -o stdout -m '*'
This should produce results similar to the following:
...
[0] data: [1463781902, {"msg"=>"aa"}]
[1] data: [1463781902, {"msg"=>"bb"}]
[2] data: [1463781902, {"msg"=>"cc"}]
[3] data: [1463781902, {"msg"=>"dd"}]
...
In your main configuration file append the following sections:
pipeline:
inputs:
- name: serial
tag: data
file: /dev/tnt0
bitrate: 9600
separator: X
outputs:
- name: stdout
match: '*'
You can emulate a serial interface on your Linux system and test the serial input plugin locally when you don't have an interface in your computer. The following procedure has been tested on Ubuntu 15.04 running Linux Kernel 4.0.
tty0tty
moduleDownload the sources:
git clone https://github.com/freemed/tty0tty
Unpack and compile:
cd tty0tty/module
make
Copy the new kernel module into the kernel modules directory:
sudo cp tty0tty.ko /lib/modules/$(uname -r)/kernel/drivers/misc/
Load the module:
sudo depmod
sudo modprobe tty0tty
You should see new serial ports in dev
(ls /dev/tnt\*\
).
Give appropriate permissions to the new serial ports:
sudo chmod 666 /dev/tnt*
When the module is loaded, it will interconnect the following virtual interfaces:
/dev/tnt0 <=> /dev/tnt1
/dev/tnt2 <=> /dev/tnt3
/dev/tnt4 <=> /dev/tnt5
/dev/tnt6 <=> /dev/tnt7