From 9a0aac4745fdcfeae4b627b6dff8875120f27335 Mon Sep 17 00:00:00 2001 From: acshef Date: Sat, 24 Apr 2021 17:37:16 -0600 Subject: [PATCH] Add IP Address to JsonInfo (#1912) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add IP Address to JsonInfo The value is added to the JSON only if the device is connected to the network, and uses the JSON key `"sip"` to match [wled00/xml.cpp](wled00/xml.cpp#L249). The overarching goal of this is to expose the IP Address to the Home Assistant WLED Integration, so that Home Assistant can provide a link to the WLED device (either directly through the Integration/Device page 🤞 or *ad hoc* in Lovelace). * IP in JSON info Empty string if not connected Co-authored-by: Aircoookie --- wled00/json.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wled00/json.cpp b/wled00/json.cpp index ffb2714ca..db8ecd87c 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -549,6 +549,13 @@ void serializeInfo(JsonObject root) root[F("brand")] = "WLED"; root[F("product")] = F("FOSS"); root["mac"] = escapedMac; + char s[16] = ""; + if (Network.isConnected()) + { + IPAddress localIP = Network.localIP(); + sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]); + } + root["ip"] = s; } void setPaletteColors(JsonArray json, CRGBPalette16 palette)