1

I'm trying to make the simplest PaHo MQTT example to work with my STM32(https://eclipse.org/paho/clients/c/embedded/ bottom of the page).

I'm using SystemWorkbench AC6 and I have included MQTTPacket.h, which is in ../Middlewares/Third_Party/MQTT/Inc which I've included in the properties of the project.

#include "MQTTPacket.h"

The error when I build the code is Field 'cstring' could not be resolved. Here is my code.

MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
char buf[200];
MQTTString topicString = MQTTString_initializer;
char* payload = "mypayload";
int payloadlen = strlen(payload);
int buflen = sizeof(buf);

data.clientID.cstring = "me"; /* problem here : cstring could not be resolved */
data.keepAliveInterval = 20;
data.cleansession = 1;
int len = MQTTSerialize_connect(buf, buflen, &data); /* 1 */

topicString.cstring = "mytopic";
len += MQTTSerialize_publish(buf + len, buflen - len, 0, 0, 0, 0, topicString, payload, payloadlen); /* 2 */

len += MQTTSerialize_disconnect(buf + len, buflen - len); /* 3 */

int mysock = socket(AF_INET, SOCK_STREAM, 0);

addre.sin_family = AF_INET;
addre.sin_port = htons(1883);
addre.sin_addr.s_addr = htonl(0xC6291EF1);

connect(mysock,(struct sockaddr *)&addre,sizeof(addre));

write(mysock,buf,len);
close(mysock);

The CliendID is part of the MQTTPacket_connectData wich is in MQTTConnect.h

typedef struct
{
    /** The eyecatcher for this structure.  must be MQTC. */
    char struct_id[4];
    /** The version number of this structure.  Must be 0 */
    int struct_version;
    /** Version of MQTT to be used.  3 = 3.1 4 = 3.1.1
      */
    unsigned char MQTTVersion;
    MQTTString clientID;
    unsigned short keepAliveInterval;
    unsigned char cleansession;
    unsigned char willFlag;
    MQTTPacket_willOptions will;
    MQTTString username;
    MQTTString password;
} MQTTPacket_connectData;

CliendID is an MQTTString defined in MQTTPacket.h

typedef struct
{
    char* cstring;
    MQTTLenString lenstring;
} MQTTString;

I don't know why it cannot resolve 'cstring'.

Thank you for your help.

lollol13
  • 11
  • 2
  • Don't know if this is the problem, but, see that you are attributing a string literal to a non const char pointer. More info here: http://stackoverflow.com/questions/9970295/life-time-of-string-literal-in-c – Felipe Lavratti Jan 07 '17 at 14:18

0 Answers0