mirror of
https://github.com/esphome/esphome-docs.git
synced 2024-12-27 17:37:45 +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>`:
|
||||
|
||||
.. 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
|
||||
--------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user