mqtt_publisher (Mosquitto) example
Example use of the MQTT protocol in KasperskyOS.
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 is an implementation of an MQTT publisher that publishes the current time with a 5-second interval.
When the example starts and runs successfully, an MQTT subscriber started on the host operating system prints a "received PUBLISH" message with a "datetime" topic.
The example also demonstrates the use of various virtual file systems (VFS) in a single solution:
- The
VfsNetprogram is used for working with the network. - The
VfsSdCardFsprogram is used to work 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 subscriber on the host system, run the following command:
$ mosquitto_sub -d -t "datetime"
Supplied resources
- The directory
./resources/edlcontains thePublisher.edlfile, which contains a static description of thePublisherprogram. - The directory
./resources/hdd/etccontains the configuration files for theVfsNet,DhcpcdandNtpdprograms:hosts,dhcpcd.confandntp.conf, respectively.
Example files
The code of the example and build scripts are available at the following path:
/opt/KasperskyOS-Community-Edition-<version>/examples/mqtt_publisher
Building and running example
See Building and running examples section.