Skip to content

UDP socket

Aim of UDP socket is controling FeitCSI via external tools and make a research/work easier. To run FeitCSI as UDP socket use command feitcsi --udp-socket. Then FeitCSI is listening on the port 8008. For controlling FeitCSI just send via UDP command string as in the case of the console, e.g. feitcsi --frequency 5180 --channel-width 160 --format HESU --output-file csi.dat.

Warning

Only one user can inject frames and extract CSI data at the same time on the device.

Matlab example

Example of matlab script to inject frames on one device and extracting frames on second device.

udpExample.m
% SETTINGS START
TRANSMITTER_IP = "192.168.0.240";
RECEIVER_IP = "192.168.0.241";
FREQUENCY = "2412";
CHANNEL_WIDTH = "20";
FRAME_FORMAT = "HT";
MCS_INDEX = "0";
INJECT_DELAY = "100000"; %in microseconds, time between frames
TX_POWER = "1"; %in dBm
% SETTINGS END

udpReceiver = udpport("datagram");
udpReceiver.Timeout = 60;

udpTransmitter = udpport("datagram");
udpTransmitter.Timeout = 60;

write(udpTransmitter,"stop","uint8",TRANSMITTER_IP,8008);
write(udpTransmitter,sprintf("feitcsi --frequency %s --channel-width %s --format %s --mcs %s --inject-delay %s --tx-power %s --mode inject", FREQUENCY, CHANNEL_WIDTH, FRAME_FORMAT, MCS_INDEX, INJECT_DELAY, TX_POWER),"uint8",TRANSMITTER_IP,8008);

write(udpReceiver,"stop","uint8",RECEIVER_IP,8008);
write(udpReceiver,sprintf("feitcsi --frequency %s --channel-width %s --format %s", FREQUENCY, CHANNEL_WIDTH, FRAME_FORMAT),"uint8",RECEIVER_IP,8008);


for i = 1:10 % receive  10 csi
    raw_datas = read(udpReceiver, 1);
    raw_csi_bytes = uint8(raw_data.Data);
    % parse raw_csi_bytes data, example is in FeitCSI parsing scripts page
end

% stop injecting/extracting
write(udpTransmitter,"stop","uint8",TRANSMITTER_IP,8008);
write(udpReceiver,"stop","uint8",RECEIVER_IP,8008);

FeitCSI as service

If you have an external device where you want to use the FeitCSI tool is very useful to run FeitCSI as a service. You then just turn on the device and you can connect to it from everywhere via a UDP socket (not necessary connect to the device and start FeitCSI by manually way).

Create file /etc/systemd/system/feitcsi.service and edit path ExecStart= to FeitCSI binary.

feitcsi.service
# /etc/systemd/system/feitcsi.service
[Unit]
Description=FeitCSI service
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

StartLimitIntervalSec=500
StartLimitBurst=10

[Service]
Restart=on-failure
RestartSec=5s

ExecStart=/usr/local/bin/feitcsi --udp-socket

[Install]
WantedBy=multi-user.target

Then enable service

sudo systemctl enable feitcsi

and start it

sudo systemctl start feitcsi

After this operations, FeitCSI will automatically run on system startup and listen for the UDP socket on port 8008.