-
Notifications
You must be signed in to change notification settings - Fork 65
feat: tedge connect to c8y mqtt service endpoint #3707
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
Open
albinsuresh
wants to merge
18
commits into
thin-edge:main
Choose a base branch
from
albinsuresh:feat/c8y-mqtt-service-connect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
40d34b4
spec: c8y mqtt service connection spec
albinsuresh 9979965
feat: tedge connect to c8y mqtt service endpoint
albinsuresh 4a980a0
fix basic auth based connection to mqtt service
albinsuresh 8675e0f
configurable remote sub topics
albinsuresh 64467ab
System test skeleton
albinsuresh 813f335
fixup! feat: tedge connect to c8y mqtt service endpoint
albinsuresh 86654d9
refactor core mqtt bridge config definition
albinsuresh 6c8700b
feat: builtin bridge support for mqtt service endpoint
albinsuresh 0a06606
fixup! feat: builtin bridge support for mqtt service endpoint
albinsuresh 015ee3d
fixup! feat: tedge connect to c8y mqtt service endpoint
albinsuresh b25610a
fixup! feat: builtin bridge support for mqtt service endpoint
albinsuresh 7a4975c
doc: tedge connect c8y mqtt service documentation
albinsuresh b5d55b1
fixup! doc: tedge connect c8y mqtt service documentation
albinsuresh 702e370
Include MQTT service in tedge c8y connection test
albinsuresh 510ca24
fixup! feat: builtin bridge support for mqtt service endpoint
albinsuresh a1098e8
Remove mqtt service bridge file on tedge disconnect
albinsuresh ad03d81
fixup! doc: tedge connect c8y mqtt service documentation
albinsuresh 9d4ebb0
fixup! fixup! doc: tedge connect c8y mqtt service documentation
albinsuresh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,111 @@ | ||
--- | ||
title: 🚧 Connecting to Cumulocity MQTT Service | ||
tags: [Operate, Cloud, Connection, Cumulocity] | ||
description: Connecting %%te%% to Cumulocity | ||
sidebar_position: 1 | ||
draft: true | ||
--- | ||
|
||
import UserContext from '@site/src/components/UserContext'; | ||
import UserContextForm from '@site/src/components/UserContextForm'; | ||
import BrowserWindow from '@site/src/components/BrowserWindow'; | ||
|
||
:::tip | ||
#### User Context {#user-context} | ||
|
||
You can customize the documentation and commands shown on this page by providing relevant settings which will be reflected in the instructions. It makes it even easier to explore and use %%te%%. | ||
|
||
<UserContextForm settings="DEVICE_ID,C8Y_URL,C8Y_TENANT_ID,C8Y_USERNAME,C8Y_PASSWORD" /> | ||
|
||
The user context will be persisted in your web browser's local storage. | ||
::: | ||
|
||
## MQTT Service | ||
|
||
Cumulocity supports a generic [MQTT service endpoint](https://cumulocity.com/docs/device-integration/mqtt-service) | ||
that allows users to send free-form messages (any arbitrary topic and payload) to it. | ||
It does not replace the existing core MQTT endpoint and hence needs to be connected to, separately. | ||
The following sections cover steps required to establish a connection to the Cumulocity MQTT service endpoint. | ||
|
||
:::caution | ||
Cumulocity MQTT service is still a work-in-progress and the external interfaces are bound to change in future. | ||
The %%te%% interfaces might also change accordingly. | ||
::: | ||
|
||
### Configure the device | ||
|
||
Most of the configurations used to connect to the MQTT service endpoint of Cumulocity are same as | ||
the ones used to connect to the core MQTT endpoint. | ||
|
||
1. Configure Cumulocity tenant URL: | ||
|
||
<UserContext> | ||
|
||
```sh | ||
sudo tedge config set c8y.url $C8Y_URL | ||
``` | ||
didier-wenzek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
</UserContext> | ||
|
||
1. If you're using device certificates to connect to Cumulocity, set the tenant id (skip this when using username/password): | ||
|
||
<UserContext> | ||
|
||
```sh | ||
sudo tedge config set c8y.tenant_id $C8Y_TENANT_ID | ||
``` | ||
|
||
</UserContext> | ||
|
||
1. Enable connection to MQTT service endpoint: | ||
|
||
```sh | ||
sudo tedge config set c8y.mqtt_service.enabled true | ||
``` | ||
|
||
1. Provide a topic to subscribe to (only a single topic is allowed at the moment): | ||
|
||
```sh | ||
sudo tedge config set c8y.mqtt_service.topics demo/topic | ||
``` | ||
|
||
### Configure the cloud to trust the device certificate | ||
|
||
Follow the steps [here](./connect.md#making-the-cloud-trust-the-device) to make Cumulocity trust the device certificate. | ||
|
||
### Connect the device | ||
|
||
The device is connected to MQTT service endpoint along with the core MQTT connection to Cumulocity: | ||
|
||
```sh | ||
sudo tedge connect c8y | ||
``` | ||
|
||
This step establishes the bridge connection to both the core endpoint as well as the mqtt service endpoints simultaneously. | ||
|
||
### Validate the connection | ||
|
||
Once connected, all messages published to `c8y-mqtt/#` topics are forwarded to the MQTT service endpoint. | ||
|
||
To validate the same, connect a different MQTT client directly to the MQTT service endpoint (`mosquitto_sub` in this example) | ||
and subscribe to the desired topic: | ||
|
||
<UserContext> | ||
|
||
```sh | ||
mosquitto_sub -d -v -h $C8Y_URL -p 2883 -i test-client-123 -u $C8Y_TENANT_ID/$C8Y_USERNAME -P $C8Y_PASSWORD -t sub/topic | ||
``` | ||
|
||
</UserContext> | ||
|
||
:::note | ||
The test client must use a client id that is different from the device id. | ||
::: | ||
|
||
Once subscribed, publish to the same topic from the %%te%% device: | ||
|
||
```sh | ||
tedge mqtt pub c8y-mqtt/test/topic "hello world" | ||
``` | ||
|
||
Now, validate that the same message is received by the test client. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accompanying tedge-docs PR that introduces the keys
C8Y_TENANT_ID
andC8Y_PASSWORD
.