mirror of
https://github.com/esphome/esphome-docs.git
synced 2024-12-28 17:48:35 +01:00
Update docs about MQTT lambdas (#809)
Co-authored-by: Mateusz <mateusz@kijowski.info>
This commit is contained in:
parent
c9a03a99f5
commit
7c55cdad9d
@ -334,9 +334,15 @@ Configuration variables:
|
|||||||
|
|
||||||
This action can also be used in :ref:`lambdas <config-lambda>`:
|
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
|
.. 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
|
// do something with payload
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -397,9 +403,15 @@ Configuration variables:
|
|||||||
|
|
||||||
This action can also be used in :ref:`lambdas <config-lambda>`:
|
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
|
.. 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
|
// do something with JSON-decoded value root
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -522,6 +534,22 @@ the MQTT broker.
|
|||||||
then:
|
then:
|
||||||
- logger.log: MQTT is connected!
|
- 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
|
See Also
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user