-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3886bd4
commit 45040ef
Showing
27 changed files
with
221 additions
and
1,364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
*.userprefs | ||
|
||
# Build results | ||
[Bb]uild/ | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(mosquitto) | ||
|
||
# Include the Windows Mosquitto installation | ||
if(WIN32) | ||
set(MOSQUITTO_PATH "$ENV{ProgramFiles}/mosquitto/devel") | ||
include_directories(${MOSQUITTO_PATH}) | ||
link_directories(${MOSQUITTO_PATH}) | ||
endif(WIN32) | ||
|
||
link_libraries(mosquitto) | ||
|
||
add_executable(mosquitto_telemetry src/mosquitto_telemetry.cpp) | ||
add_executable(mosquitto_device_twin src/mosquitto_device_twin.cpp) | ||
add_executable(mosquitto_subscribe src/mosquitto_subscribe.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Using the Mosquitto library on Linux | ||
|
||
This samples uses the Mosquitto (MQTT) library to send a message to an Azure IoT Hub from a Linux machine. | ||
|
||
## Windows prerequisites | ||
|
||
1. Follow the [general prerequisites](/README.md#general-rerequisites) | ||
1. Install [Visual Studio](https://visualstudio.microsoft.com/downloads) | ||
|
||
> **NOTE** | ||
> Enable the `Desktop development with C++` workload | ||
1. Install [CMake](https://cmake.org/download/) | ||
|
||
> **NOTE** | ||
> Enable the `Add CMake to the system PATH for all users` option | ||
1. Install the **x64 version** of [Mosquitto](https://mosquitto.org/download/) | ||
|
||
## Linux prerequisites | ||
|
||
1. Follow the [general prerequisites](/README.md#general-rerequisites) | ||
1. Install the build tools: | ||
|
||
```Shell | ||
sudo apt install cmake g++ | ||
``` | ||
|
||
1. Install Mosquitto client library: | ||
|
||
```Shell | ||
sudo apt install libmosquitto-dev | ||
``` | ||
|
||
## Build | ||
|
||
1. Change to the `mosquitto` directory in the cloned repository | ||
1. Edit the `config.h` file and expand the required connection information: | ||
|
||
```c | ||
#define IOTHUBNAME "{iothub_name}" | ||
#define DEVICEID "{device_id}" | ||
#define SAS_TOKEN "{sas_token}" | ||
``` | ||
|
||
1. Build the application: | ||
|
||
```Shell | ||
cmake -Bbuild | ||
cmake --build build | ||
``` | ||
|
||
1. Resulting binaries can be found in the following locations: | ||
1. Linux: `./build` | ||
1. Windows `.\build\Debug` | ||
|
||
## Run telemetry sample | ||
|
||
1. Start monitoring incoming messages on your Hub: | ||
|
||
```Shell | ||
az iot hub monitor-events -n {iothub_name} | ||
``` | ||
|
||
1. Run the sample executable: | ||
|
||
```Shell | ||
mosquitto_telemetry | ||
``` | ||
|
||
1. Confirm the following output is seen from monitor-events: | ||
|
||
```json | ||
{ | ||
"event": { | ||
"origin": "pubsub", | ||
"module": "", | ||
"interface": "", | ||
"component": "", | ||
"payload": "Bonjour MQTT from Mosquitto" | ||
} | ||
} | ||
``` | ||
|
||
## Run subscribe sample | ||
|
||
1. Run the sample executable: | ||
|
||
```Shell | ||
mosquitto_subscribe | ||
``` | ||
|
||
1. Send an event from the Hub to the device: | ||
|
||
```Shell | ||
az iot device c2d-message send --hub-name {iothub_name} --device-id {device_id} --data "hello world" | ||
``` | ||
|
||
1. Confirm the following output from the sample: | ||
|
||
```Shell | ||
Waiting for C2D messages... | ||
C2D message 'hello world' for topic 'devices/pubsub/messages/devicebound/...` | ||
Got message for devices/pubsub/messages/# topic | ||
``` | ||
## Run device twin sample | ||
1. Run the sample executable: | ||
```Shell | ||
mosquitto_device_twin | ||
``` | ||
1. Confirm the following output from the sample, setting and getting a device twin update: | ||
```Shell | ||
Setting device twin reported properties.... | ||
Device twin message '' for topic '$iothub/twin/res/204/?$rid=patch_temp&$version=2' | ||
Setting device twin properties SUCCEEDED. | ||
Getting device twin properties.... | ||
Device twin message '{"desired":{"$version":1},"reported":{"temperature":32,"$version":2}}' for topic '$iothub/twin/res/200/?$rid=123' | ||
Getting device twin properties SUCCEEDED. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#define IOTHUBNAME "{iothub_name}" | ||
#define DEVICEID "{device_id}" | ||
#define SAS_TOKEN "{sas_token}" | ||
|
||
#define CERTIFICATEFILE "../BaltimoreCyberTrustRoot.crt.pem" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.