Browse Source

Limit size of the MQTT queue to 10 messages when useJson is enabled

fastled
Xose Pérez 7 years ago
parent
commit
e58929dfc0
2 changed files with 6 additions and 0 deletions
  1. +2
    -0
      code/espurna/config/general.h
  2. +4
    -0
      code/espurna/mqtt.ino

+ 2
- 0
code/espurna/config/general.h View File

@ -419,6 +419,8 @@ PROGMEM const char* const custom_reset_string[] = {
#define MQTT_USE_JSON 0 // Group messages in a JSON body
#define MQTT_USE_JSON_DELAY 100 // Wait this many ms before grouping messages
#define MQTT_QUEUE_MAX_SIZE 10 // Size of the MQTT queue when MQTT_USE_JSON is enabled
// These particles will be concatenated to the MQTT_TOPIC base to form the actual topic
#define MQTT_TOPIC_JSON "data"


+ 4
- 0
code/espurna/mqtt.ino View File

@ -140,11 +140,15 @@ void _mqttFlush() {
void mqttSend(const char * topic, const char * message, bool force) {
bool useJson = force ? false : _mqtt_use_json;
if (useJson) {
if (_mqtt_queue.size() >= MQTT_QUEUE_MAX_SIZE) _mqttFlush();
mqtt_message_t element;
element.topic = strdup(topic);
element.message = strdup(message);
_mqtt_queue.push_back(element);
_mqtt_flush_ticker.once_ms(MQTT_USE_JSON_DELAY, _mqttFlush);
} else {
String path = _mqtt_topic + String(topic) + _mqtt_getter;
mqttSendRaw(path.c_str(), message);


Loading…
Cancel
Save