Skip to content

Commit 560f72a

Browse files
committed
Add JSON receiving to MQTT /api
1 parent 1b3ed80 commit 560f72a

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
### Development versions after the 0.10.2 release
44

5+
#### Build 2011120
6+
7+
- Added the ability for the /api MQTT topic to receive JSON API payloads
8+
59
#### Build 2011040
610

711
- Inversed Rain direction (fixes #1147)

wled00/mqtt.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
8585
colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE);
8686
} else if (strcmp(topic, "/api") == 0)
8787
{
88-
String apireq = "win&";
89-
apireq += (char*)payload;
90-
handleSet(nullptr, apireq);
88+
if (payload[0] == '{') { //JSON API
89+
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
90+
deserializeJson(doc, payload);
91+
deserializeState(doc.as<JsonObject>());
92+
} else { //HTTP API
93+
String apireq = "win&";
94+
apireq += (char*)payload;
95+
handleSet(nullptr, apireq);
96+
}
9197
} else if (strcmp(topic, "") == 0)
9298
{
9399
parseMQTTBriPayload(payload);

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2011040
11+
#define VERSION 2011120
1212

1313
// 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).
1414

0 commit comments

Comments
 (0)