Update docs about MQTT lambdas (#809)

Co-authored-by: Mateusz <mateusz@kijowski.info>
This commit is contained in:
matikij 2020-12-21 00:51:36 +01:00 committed by GitHub
parent c9a03a99f5
commit 7c55cdad9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -334,9 +334,15 @@ Configuration variables:
This action can also be used in :ref:`lambdas <config-lambda>`:
.. code-block:: yaml
mqtt:
# Give the mqtt component an ID
id: mqtt_client
.. code-block:: cpp
App.get_mqtt_client()->subscribe("the/topic", [=](const std::string &payload) {
id(mqtt_client).subscribe("the/topic", [=](const std::string &payload) {
// do something with payload
});
@ -397,9 +403,15 @@ Configuration variables:
This action can also be used in :ref:`lambdas <config-lambda>`:
.. code-block:: yaml
mqtt:
# Give the mqtt component an ID
id: mqtt_client
.. code-block:: cpp
App.get_mqtt_client()->subscribe_json("the/topic", [=](JsonObject &root) {
id(mqtt_client).subscribe_json("the/topic", [=](JsonObject &root) {
// do something with JSON-decoded value root
});
@ -522,6 +534,22 @@ the MQTT broker.
then:
- logger.log: MQTT is connected!
.. note::
This action can also be written in :ref:`lambdas <config-lambda>`:
.. code-block:: yaml
mqtt:
# Give the mqtt component an ID
id: mqtt_client
.. code-block:: cpp
if (id(mqtt_client)->is_connected()) {
// do something if MQTT is connected
}
See Also
--------