mirror of
https://github.com/esphome/esphome-docs.git
synced 2025-04-09 19:15:52 +02:00
Update `json::parse_json
` examples (#3949)
This commit is contained in:
parent
ae079c6f40
commit
40757fe09c
@ -55,9 +55,9 @@ Configuration variables:
|
||||
|
||||
Without the root certificate bundle, certificates used by the remote HTTPS server cannot be verified, opening the
|
||||
HTTPS connection up to person-in-the-middle attacks.
|
||||
|
||||
|
||||
To maximize security, do not set ``verify_ssl`` to ``false`` *unless:*
|
||||
|
||||
|
||||
- a custom CA/self-signed certificate is used,
|
||||
- the Arduino framework is used, or
|
||||
- the device does not have sufficient memory to store the certificate bundle
|
||||
@ -257,8 +257,9 @@ whose ``id`` is set to ``player_volume``:
|
||||
on_response:
|
||||
then:
|
||||
- lambda: |-
|
||||
json::parse_json(body, [](JsonObject root) {
|
||||
json::parse_json(body, [](JsonObject root) -> bool {
|
||||
id(player_volume).publish_state(root["vol"]);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@ Share data directly between ESPHome nodes
|
||||
|
||||
In certain special cases it might be desired to avoid placing any middleware like an MQTT or a home automation server just to transfer small bits of data from one node to another. Direct data polling is possible using HTTP, but beware that the involved components are resource hungry and may be less stable on long term. The webserver embedded in the node is not designed to constantly serve a large amount of requests.
|
||||
|
||||
The primary node holding the data we need to retrieve from will be the server, and the others polling for it will be the clients (can be multiple).
|
||||
The primary node holding the data we need to retrieve from will be the server, and the others polling for it will be the clients (can be multiple).
|
||||
|
||||
Server part
|
||||
-----------
|
||||
@ -44,16 +44,17 @@ In the example below we request the value of a sensor from the server node, and
|
||||
interval:
|
||||
- interval: 60s
|
||||
then:
|
||||
- http_request.get:
|
||||
- http_request.get:
|
||||
url: http://ip or nodename.local/sensor/ID_of_the_sensor
|
||||
on_response:
|
||||
then:
|
||||
- lambda: |-
|
||||
json::parse_json(id(http_request_id).get_string(), [](JsonObject root) {
|
||||
json::parse_json(id(http_request_id).get_string(), [](JsonObject root) -> bool {
|
||||
id(template_sensor_id).publish_state(root["value"]);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
|
||||
Result
|
||||
------
|
||||
|
||||
@ -99,15 +100,16 @@ Add an ``Authorization`` header to your ``http_request.get`` action. The simples
|
||||
interval:
|
||||
- interval: 60s
|
||||
then:
|
||||
- http_request.get:
|
||||
- http_request.get:
|
||||
url: http://ip or nodename.local/sensor/ID_of_the_sensor
|
||||
headers:
|
||||
Authorization: 'Digest username="admin", realm="asyncesp", nonce="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", uri="/sensor/ID_of_the_sensor", response="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", opaque="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", qop=auth, nc=xxxxxxxx, cnonce="xxxxxxxxxxxxxxxx"'
|
||||
on_response:
|
||||
then:
|
||||
- lambda: |-
|
||||
json::parse_json(id(http_request_id).get_string(), [](JsonObject root) {
|
||||
json::parse_json(id(http_request_id).get_string(), [](JsonObject root) -> bool {
|
||||
id(template_sensor_id).publish_state(root["value"]);
|
||||
return true;
|
||||
});
|
||||
|
||||
See Also
|
||||
|
Loading…
Reference in New Issue
Block a user