Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT Published BUG #4

Open
XiaoKaiRen opened this issue Oct 28, 2018 · 3 comments
Open

MQTT Published BUG #4

XiaoKaiRen opened this issue Oct 28, 2018 · 3 comments

Comments

@XiaoKaiRen
Copy link

ha_mqtt_ledstrip.ino Line 178

void sendState() {`
  StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;

  JsonObject& root = jsonBuffer.createObject();

  JsonObject& color = root.createNestedObject("color");
  color["r"] = red;
  color["g"] = green;
  color["b"] = blue;
  root["white_value"] = white;
  
  root["state"] = (stateOn) ? on_cmd : off_cmd;
  root["brightness"] = brightness;
  root["effect"] = currentEffect;
  root["speed"] = fxspeed;
  

  char buffer[root.measureLength() + 1];
  root.printTo(buffer, sizeof(buffer));

  client.publish(light_state_topic, buffer, true);
}

if r = 255 g = 255 b = 255 can't send message

i fix Line 187

  root["w"] = white;

reduce the length of mqtt message
this can work!!

@rorist
Copy link
Owner

rorist commented Oct 28, 2018

Hello,

Thanks for the report, is there a maximum length of the message that's been reached there ?
I don't think I have a problem setting rgb 255.

Cheers

@XiaoKaiRen
Copy link
Author

XiaoKaiRen commented Oct 29, 2018

This https://github.com/knolleary/pubsubclient/blob/54be6e87db16d7dbc60d4c4674566ec08b0115c2/src/PubSubClient.cpp

Line 366

MQTT_MAX_PACKET_SIZE = 128

boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) {
    if (connected()) {
 here --->  if (MQTT_MAX_PACKET_SIZE < 5 + 2+strlen(topic) + plength) {
            // Too long
            return false;
        }
        // Leave room in the buffer for header and variable length field
        uint16_t length = 5;
        length = writeString(topic,buffer,length);
        uint16_t i;
        for (i=0;i<plength;i++) {
            buffer[length++] = payload[i];
        }
        uint8_t header = MQTTPUBLISH;
        if (retained) {
            header |= 1;
        }
        return write(header,buffer,length-5);
    }
    return false;
}

@rorist
Copy link
Owner

rorist commented Oct 29, 2018

Ok perfect, if you want you can do a pull request so the commit is properly credited to you ? Otherwhise I can do the change. Nice catch !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants