forked from espressif/esp-protocols
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request espressif#502 from espressif-abhikroy/component/co…
…nsole_cmd_mqtt feat(console): Added component with mqtt command
- Loading branch information
Showing
20 changed files
with
1,012 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: "console_cmd_mqtt: build-tests" | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
types: [opened, synchronize, reopened, labeled] | ||
|
||
jobs: | ||
build_console_cmd_mqtt: | ||
if: contains(github.event.pull_request.labels.*.name, 'console') || github.event_name == 'push' | ||
name: Build | ||
strategy: | ||
matrix: | ||
idf_ver: ["latest", "release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3"] | ||
idf_target: ["esp32"] | ||
test: [ { app: mqtt_ssl_auth_console, path: "components/console_cmd_mqtt/examples" }] | ||
runs-on: ubuntu-22.04 | ||
container: espressif/idf:${{ matrix.idf_ver }} | ||
steps: | ||
- name: Checkout esp-protocols | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }} | ||
shell: bash | ||
working-directory: ${{matrix.test.path}} | ||
run: | | ||
. ${IDF_PATH}/export.sh | ||
pip install idf-component-manager idf-build-apps --upgrade | ||
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app |
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,8 @@ | ||
--- | ||
commitizen: | ||
bump_message: 'bump(console): $current_version -> $new_version' | ||
pre_bump_hooks: python ../../ci/changelog.py console_cmd_mqtt | ||
tag_format: console_cmd_mqtt-v$version | ||
version: 1.0.0 | ||
version_files: | ||
- idf_component.yml |
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,7 @@ | ||
# Changelog | ||
|
||
## [1.0.0](https://github.com/espressif/esp-protocols/commits/console_cmd_mqtt-v1.0.0) | ||
|
||
### Features | ||
|
||
- Added component with mqtt command ([1fcc5b1d](https://github.com/espressif/esp-protocols/commit/1fcc5b1d)) |
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,7 @@ | ||
idf_component_register(SRCS "console_mqtt.c" | ||
INCLUDE_DIRS "." | ||
PRIV_REQUIRES esp_netif console mqtt) | ||
|
||
if(CONFIG_MQTT_CMD_AUTO_REGISTRATION) | ||
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u console_cmd_mqtt_register") | ||
endif() |
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,15 @@ | ||
menu "MQTT Configuration" | ||
|
||
config MQTT_CMD_AUTO_REGISTRATION | ||
bool "Enable Console command mqtt Auto-registration" | ||
default y | ||
help | ||
Enabling this allows for the autoregistration of the wifi command. | ||
|
||
config MQTT_BROKER_URL | ||
string "Broker URL or IP address" | ||
default "mqtt://mqtt.eclipseprojects.io" | ||
help | ||
URL or IP address of the broker to connect to | ||
|
||
endmenu |
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,87 @@ | ||
# Console command mqtt | ||
The component provides a console where mqtt commands can be executed. | ||
|
||
|
||
## MQTT Configuration: | ||
1. Broker: Use menuconfig **"MQTT Configuration"** to configure the broker url. | ||
|
||
|
||
## API | ||
|
||
### Steps to enable console in an example code: | ||
1. Add this component to your project using ```idf.py add-dependency``` command. | ||
2. In the main file of the example, add the following line: | ||
```c | ||
#include "console_mqtt.h" | ||
``` | ||
3. Ensure esp-netif is initialized and default event loop is created in your app_main(): | ||
```c | ||
ESP_ERROR_CHECK(esp_netif_init()); | ||
ESP_ERROR_CHECK(esp_event_loop_create_default()); | ||
``` | ||
4. In your app_main() function, add the following line as the last line: | ||
```c | ||
ESP_ERROR_CHECK(console_cmd_init()); // Initialize console | ||
|
||
// Register all plugin command added to your project | ||
ESP_ERROR_CHECK(console_cmd_all_register()); | ||
|
||
// To register only mqtt command skip calling console_cmd_all_register() | ||
ESP_ERROR_CHECK(console_cmd_mqtt_register()); | ||
|
||
ESP_ERROR_CHECK(console_cmd_start()); // Start console | ||
``` | ||
|
||
Note: Auto-registration of a specific plugin command can be disabled from menuconfig. | ||
|
||
### Certificate Integration for Mutual Authentication | ||
To enhance security and enable secure communication over MQTT, three functions have been added to the API, allowing users to set client certificates, client keys, and broker certificates separately. | ||
|
||
Setting the client certificate: | ||
```c | ||
set_mqtt_client_cert(client_cert_pem_start, client_cert_pem_end); | ||
``` | ||
Setting the client key: | ||
```c | ||
set_mqtt_client_key(client_key_pem_start, client_key_pem_end); | ||
``` | ||
Setting the broker certificate: | ||
```c | ||
set_mqtt_broker_certs(broker_cert_pem_start, broker_cert_pem_end); | ||
``` | ||
Each function takes pointers to the start and end of the respective PEM-encoded data, allowing users to specify the necessary certificate and key information independently. For a complete secure MQTT setup, users should call all three functions in their application code. | ||
To utilize these certificates, users need to include additional arguments when establishing MQTT connections using the library. Specifically, users should provide the `--cert`, `--key`, and `--cafile` options along with the MQTT connection command. | ||
### Adding a plugin command or component: | ||
To add a plugin command or any component from IDF component manager into your project, simply include an entry within the `idf_component.yml` file. | ||
For more details refer [IDF Component Manager](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html) | ||
## Suported command: | ||
### mqtt: | ||
``` | ||
mqtt [-CsD] [-h <host>] [-u <username>] [-P <password>] [--cert] [--key] [--cafile] | ||
mqtt command | ||
-C, --connect Connect to a broker (flag, no argument) | ||
-h, --host=<host> Specify the host uri to connect to | ||
-s, --status Displays the status of the mqtt client (flag, no argument) | ||
-u, --username=<username> Provide a username to be used for authenticating with the broker | ||
-P, --password=<password> Provide a password to be used for authenticating with the broker | ||
--cert Define the PEM encoded certificate for this client, if required by the broker (flag, no argument) | ||
--key Define the PEM encoded private key for this client, if required by the broker (flag, no argument) | ||
--cafile Define the PEM encoded CA certificates that are trusted (flag, no argument) | ||
--use-internal-bundle Use the internal certificate bundle for TLS (flag, no argument) | ||
-D, --disconnect Disconnect from the broker (flag, no argument) | ||
|
||
mqtt_pub [-t <topic>] [-m <message>] | ||
mqtt publish command | ||
-t, --topic=<topic> Topic to Subscribe/Publish | ||
-m, --message=<message> Message to Publish | ||
|
||
mqtt_sub [-U] [-t <topic>] | ||
mqtt subscribe command | ||
-t, --topic=<topic> Topic to Subscribe/Publish | ||
-U, --unsubscribe Unsubscribe from a topic | ||
``` |
Oops, something went wrong.