Hi guys,
Im trying to print the variable packet. The packet variable contains hex value '0x00'. When i try to print the value unit8_t is trim the value from 0x00 to the end. In my case packet wont print because 'var_header' has first value '0x00'. If i take out the first '0x00' value , packet is printing upto next '0x00' value. If any of the value will get misses, the my mqtt broker wont connect. How to solve this?




Below is the code:




Code:
#include <stdio.h>
#include<stdint.h>
#include <string.h>
#define MQTTCONNECT 1<<4
#define KEEPALIVE 15000
void main()
{
    char *id="arun";
    uint8_t var_header[] = {0x00,0x06,0x4d,0x51,0x49,0x73,0x64,0x70,0x03,0x02,0x00,KEEPALIVE/500,0x00,strlen(id)};
    uint8_t fixed_header[] = {MQTTCONNECT,12+strlen(id)+2};
    char packet[sizeof(fixed_header)+sizeof(var_header)+strlen(id)];
    memset(packet,0,sizeof(packet));
    memcpy(packet,fixed_header,sizeof(fixed_header));
    memcpy(packet+sizeof(fixed_header),var_header,sizeof(var_header));
    memcpy(packet+sizeof(fixed_header)+sizeof(var_header),id,strlen(id));
    printf((uint8_t*)packet);
}
Thanks.