mqtt_publisher (Mosquitto) example

The example demonstrates support for the MQTT (Message Queue Telemetry Transport) messaging protocol in KasperskyOS, and the integration of several virtual file systems (hereinafter VFS) in one solution. For more information about using multiple VFS programs, please refer to the File systems and network section.

Example directory in the SDK

The code of the example and build scripts are available at the following path:

/opt/KasperskyOS-Community-Edition-<platform>-<version>/examples/mqtt_publisher

List of programs

When you build an example for the target hardware platform, platform-specific drivers are automatically included in the solution:

Initialization description

The solution initialization description file named init.yaml is generated during the solution build process based on the ./einit/src/init.yaml.in template. Macros in @INIT_*@‌ ‌format contained in the template are automatically expanded in the resulting init.yaml file. For more details, refer to init.yaml.in template.

Security policy description

The security.psl file contains a description of a security policy for a KasperskyOS-based solution and is located in the ./einit/src directory. The declarations in the PSL file are provided with comments that explain the purpose of these declarations.

Resources

The ./resources/xdl/mqtt_publisher directory contains the Publisher.edl file, which is the EDL description for the Publisher program.

The directory ./resources/hdd/etc contains the configuration files for the VfsNet, Dhcpcd and Ntpd programs: hosts, dhcpcd.conf and ntp.conf, respectively.

The ./resources/hdd/var/db/dhcpcd directory is used by the Dhcpcd program to store network connection data.

Operating scenario

In this example, an MQTT subscriber must be started on the host operating system, and an MQTT publisher must be started on KasperskyOS. The Publisher program, which operates as an MQTT publisher, periodically (at an interval of 5 seconds) publishes the current time in the "datetime" topic.

When the example starts and runs successfully, an MQTT subscriber started on the host operating system prints a "received PUBLISH" message specifying the "datetime" topic and obtained time value.

Building and running the example

The CMake system, which is included with KasperskyOS Community Edition, is used to build and run the example.

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 subscriber on the host system, run the following command:

$ mosquitto_sub -d -t "datetime"

See Building and running examples section.

Page top