Crashes in loop and turn led off

I’m having trouble with an error.
I’m making code for 1 addressable led to do ‘breathing rgb’ this works on an arduino, but i would’ve liked to use a NodeMCU ESP8266 in order to control it with mqtt.

The led doesn’t want to turn off when i send 0.
And when i press 1 the led only does what I want it to do for like 2 sec and then crashes.

I’d like to know how to turn the led off and how to get a loop without it crashing.

Code and serial monitor are attached

Thank you

RGBBreathingESP8266.ino (2.52 KB)

  for (int i = 0; i < length; i++) {

The NULL should go in the [length] position. You do not know that there IS a position 2 in the array. Nor, really, do you know that there is a length position.

If you need to make a string out of payload, you need to copy it to an array that IS large enough to hold the payload data AND the terminating NULL.

On the other hand, you never treat payload as a string, so writing to the [2] element of an array is not needed and MIGHT be the cause of the crashing (by writing to memory you don’t own).

We can’t see your serial data, so there is no proof that you are receiving what you say you are.

The serial is an attachement. and it shows that i do receive the 0 and the 1 it is in the loop that something goes wrong when i googled it it said something about a loop in a loop but i don’t see how.

Also how do i turn the led off, because if i send 0 the led stays the same color ?

I will NOT look at pictures of text. NEVER post another picture of text.

Also how do i turn the led off, because if i send 0 the led stays the same color ?

You have, or should have, made some code changes. I can't see your current code, or your serial output, so I can not way why what ought to work doesn't.