page_type | languages | products | urlFragment | ||
---|---|---|---|---|---|
sample |
|
|
core-samples |
This document explains MQTT pattern samples and how to use them.
The samples' instructions include specifics for Linux based systems. The Linux examples are tailored to Debian/Ubuntu environments. While Linux devices are not likely to be considered constrained, these samples enable developers to test the Azure SDK for Embedded C libraries, debug, and step through the code, even without a real device. We understand not everyone will have a real device to test and that sometimes these devices won't have debugging capabilities.
WARNING: Samples are generic and should not be used in any production-level code.
- Have the following build environment setup:
sudo apt-get update sudo apt-get install build-essential curl zip unzip tar pkg-config
- Have Git installed.
-
Have OpenSSL installed.
Instructions:
Linux:
sudo apt-get install openssl libssl-dev
-
Have CMake installed. The minimum required is 3.11.
Instructions:
Linux:
-
Ubuntu 18.04 or 20.04 or 22.04:
sudo apt-get install cmake
-
Ubuntu 16.04: Download the latest version of CMake.
wget https://cmake.org/files/v3.18/cmake-3.18.3-Linux-x86_64.sh # Use latest version. sudo ./cmake-3.18.3-Linux-x86_64.sh --prefix=/usr
- When prompted to include the default subdirectory, enter
n
so to install in/usr/local
.
- When prompted to include the default subdirectory, enter
-
-
Have the Azure SDK for Embedded C IoT repository cloned.
git clone https://github.com/Azure/azure-sdk-for-c.git
Samples use environment variables for a variety of purposes, including filepaths and connection parameters. Please keep in mind, every time a new terminal is opened, the environment variables will have to be reset. Setting a variable will take the following form:
Linux:
export ENV_VARIABLE_NAME=VALUE
Set the following environment variables for all samples:
-
Set the vcpkg environment variables.
Refer to these directions for more detail.
Linux:
export VCPKG_DEFAULT_TRIPLET=x64-linux <!-- export VCPKG_ROOT=<FULL PATH to vcpkg> -->
-
Set broker details in the sample:
-
Build the Azure SDK for Embedded C directory structure.
From the root of the SDK directory
azure-sdk-for-c
:mkdir build cd build cmake -DAZ_MQTT_TRANSPORT_IMPL=MOSQUITTO -DAZ_PLATFORM_IMPL=POSIX ..
-
Compile and run the sample.
Linux:
cmake --build . ./sdk/samples/core/<sample executable here>
The following settings are needed in settings.json for VSCode (or these set in cmake / use the VSCode CMake extension)
"cmake.configureEnvironment": {
"VCPKG_ROOT": "<path to vcpkg>",
"VCPKG_DEFAULT_TRIPLET": "x64-linux"
},
"cmake.configureSettings": {
"WARNINGS_AS_ERRORS" : "ON",
"TRANSPORT_CURL" : "OFF",
"UNIT_TESTING" : "OFF",
"UNIT_TESTING_MOCKS" : "OFF",
"TRANSPORT_PAHO" : "OFF",
"PRECONDITIONS" : "ON",
"LOGGING" : "ON",
"CMAKE_TOOLCHAIN_FILE" : "<path to vcpkg.cmake>",
"AZ_MQTT_TRANSPORT_IMPL" : "MOSQUITTO",
"AZ_PLATFORM_IMPL" : "POSIX"
},
This project welcomes contributions and suggestions. Find more contributing details here.