Skip to content

Commit

Permalink
Merge branch 'color_mode_field' into v1.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sidoh committed Sep 27, 2023
2 parents a8815b5 + 2b2ebf2 commit 67a835e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/MQTT/BulbStateUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ void BulbStateUpdater::loop() {
}

inline void BulbStateUpdater::flushGroup(BulbId bulbId, GroupState& state) {
char buffer[200];
StaticJsonDocument<200> json;
StaticJsonDocument<MILIGHT_MQTT_JSON_BUFFER_SIZE> json;
JsonObject message = json.to<JsonObject>();

state.applyState(message, bulbId, settings.groupStateFields);
serializeJson(json, buffer);

if (json.memoryUsage() >= json.capacity()) {
Serial.println(F("ERROR: State is too large for MQTT buffer, continuing anyway. Consider increasing MILIGHT_MQTT_JSON_BUFFER_SIZE."));
}

size_t documentSize = measureJson(message);
char buffer[documentSize + 1];
serializeJson(json, buffer, sizeof(buffer));

mqttClient.sendState(
*MiLightRemoteConfig::fromType(bulbId.deviceType),
Expand Down
4 changes: 4 additions & 0 deletions lib/MQTT/BulbStateUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <CircularBuffer.h>
#include <Settings.h>

#ifndef MILIGHT_MQTT_JSON_BUFFER_SIZE
#define MILIGHT_MQTT_JSON_BUFFER_SIZE 1024
#endif

#ifndef BULB_STATE_UPDATER
#define BULB_STATE_UPDATER

Expand Down

0 comments on commit 67a835e

Please sign in to comment.