Strange output, but why and how to solve it

char payload[50];

It's not very likely, but you could be writing 55 characters to this array.