From 560f72a320f5a3c75f649c82c022dfdac4f339bc Mon Sep 17 00:00:00 2001 From: cschwinne Date: Thu, 12 Nov 2020 09:13:08 +0100 Subject: [PATCH] Add JSON receiving to MQTT /api --- CHANGELOG.md | 4 ++++ wled00/mqtt.cpp | 12 +++++++++--- wled00/wled.h | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbbb98f2..4581c0ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### Development versions after the 0.10.2 release +#### Build 2011120 + +- Added the ability for the /api MQTT topic to receive JSON API payloads + #### Build 2011040 - Inversed Rain direction (fixes #1147) diff --git a/wled00/mqtt.cpp b/wled00/mqtt.cpp index 546d9d06..15cb0c5d 100644 --- a/wled00/mqtt.cpp +++ b/wled00/mqtt.cpp @@ -85,9 +85,15 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE); } else if (strcmp(topic, "/api") == 0) { - String apireq = "win&"; - apireq += (char*)payload; - handleSet(nullptr, apireq); + if (payload[0] == '{') { //JSON API + DynamicJsonDocument doc(JSON_BUFFER_SIZE); + deserializeJson(doc, payload); + deserializeState(doc.as()); + } else { //HTTP API + String apireq = "win&"; + apireq += (char*)payload; + handleSet(nullptr, apireq); + } } else if (strcmp(topic, "") == 0) { parseMQTTBriPayload(payload); diff --git a/wled00/wled.h b/wled00/wled.h index 55bdb728..064a1f2b 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2011040 +#define VERSION 2011120 // ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS).