Skip to content

Move pubsub samples to SDK #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.1)

option(BUILD_DEPS "Builds aws common runtime dependencies as part of build, only do this if you don't want to control your dependency chain." OFF)
option(BUILD_SAMPLES "Build samples as part of the build" ON)

if (DEFINED CMAKE_PREFIX_PATH)
file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
Expand Down Expand Up @@ -115,8 +116,11 @@ find_package(aws-crt-cpp REQUIRED)
add_subdirectory(jobs)
add_subdirectory(shadow)
add_subdirectory(discovery)
add_subdirectory(samples/jobs/describe_job_execution)
add_subdirectory(samples/shadow/shadow_sync)
add_subdirectory(samples/greengrass/basic_discovery)


if (BUILD_SAMPLES)
add_subdirectory(samples/mqtt/basic_pub_sub)
add_subdirectory(samples/mqtt/raw_pub_sub)
add_subdirectory(samples/jobs/describe_job_execution)
add_subdirectory(samples/shadow/shadow_sync)
add_subdirectory(samples/greengrass/basic_discovery)
endif()
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,54 @@ cmake --build . --target install
```
# Samples

## Basic MQTT Pub-Sub

This sample uses the
[Message Broker](https://docs.aws.amazon.com/iot/latest/developerguide/iot-message-broker.html)
for AWS IoT to send and receive messages through an MQTT connection.
On startup, the device connects to the server and subscribes to a topic.

The terminal prompts the user for input. Type something and press enter to publish a message to the topic.
Since the sample is subscribed to the same topic, it will also receive the message back from the server.
Type `quit` and press enter to end the sample.

Source: `samples/mqtt/basic_pub_sub`

Your Thing's
[Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html)
must provide privileges for this sample to connect, subscribe, publish,
and receive.

```json
{
"Effect": "Allow",
"Action": [
"iot:Receive",
"iot:Publish"
],
"Resource": [
"arn:aws:iot:<your-region>:<your-id>:topic/a/b"
],
},
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:<your-region>:<your-id>:topicfilter/a/b"
]
}
```

## Raw MQTT Pub-Sub
This sample is similar to the Basic Pub-Sub, but the connection setup is more manual.
This is a starting point for using custom
[Configurable Endpoints](https://docs.aws.amazon.com/iot/latest/developerguide/iot-custom-endpoints-configurable.html).

source: `samples/mqtt/raw_pub_sub`


## Shadow

This sample uses the AWS IoT
Expand Down
30 changes: 30 additions & 0 deletions samples/mqtt/basic_pub_sub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
project(basic-pub-sub CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")

file(GLOB PUB_SUB_SRC
"*.cpp"
)

set(PUB_SUB_PROJECT_NAME basic-pub-sub)
add_executable(${PUB_SUB_PROJECT_NAME} ${PUB_SUB_SRC})
set_target_properties(${PUB_SUB_PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

set(CMAKE_C_FLAGS_DEBUGOPT "")

#set warnings
if (MSVC)
target_compile_options(${PUB_SUB_PROJECT_NAME} PRIVATE /W4 /WX /wd4068)
else ()
target_compile_options(${PUB_SUB_PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()

if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(${PUB_SUB_PROJECT_NAME} PRIVATE "-DDEBUG_BUILD")
endif ()

target_include_directories(${PUB_SUB_PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

target_link_libraries(${PUB_SUB_PROJECT_NAME} AWS::aws-crt-cpp)
Loading