Example use of the MQTT protocol in KasperskyOS.
In this example, an MQTT publisher must be started on the host operating system, and an MQTT subscriber must be started on KasperskyOS. The Subscriber
program is an implementation of an MQTT subscriber.
When the example starts and runs successfully, an MQTT subscriber started on KasperskyOS prints a "Got message with topic: my/awesome/topic, payload: hello"
message.
The example also demonstrates the use of various virtual file systems (VFS) in a single solution. The example uses different VFS to access the functions for working with the file system and functions for working with the network:
VfsNet
program is used for working with the network.VfsRamfs
and VfsSdCardFs
programs are used for working with the file system.The CMake system, which is included with KasperskyOS Community Edition, is used to build and run the example.
Starting Mosquitto
To run this example, a Mosquitto MQTT broker must be installed and started on the host system. To install and start Mosquitto, run the following commands:
$ sudo apt install mosquitto mosquitto-clients
$ sudo /etc/init.d/mosquitto start
To start an MQTT publisher on the host system, run the following command:
$ mosquitto_pub -t "my/awesome/topic" -m "hello"
Supplied resources
The following configuration files are included in the example:
./resources/include/config.h.in
contains a description of the backend file system that will be used in the solution: sdcard
or ramfs
.A separate VFS program (VfsSdCardFs
or VfsRamfs
, respectively) is used for each backend in the solution.
./resources/ramfs/etc
and /resources/sdcard/etc
directories contain configuration files for the VFS
, Dhcpcd
and Ntpd
programs.Example files
The code of the example and build scripts are available at the following path:
/opt/KasperskyOS-Community-Edition-<version>/examples/mqtt_subscriber
Building and running example
To run an example on QEMU, go to the directory containing the example, build the example and run the following commands:
$ cd build/einit
# Before running the following command, be sure that the path to
# the directory with the qemu-system-aarch64 executable file is saved in
# the PATH environment variable. If it is not there,
# add it to the PATH variable.
$ qemu-system-aarch64 -m 2048 -machine vexpress-a15 -nographic -monitor none -sd sdcard0.img -kernel kos-qemu-image
See also Building and running examples section.
Page top