I am trying to test the MQTT sample project for the ESP32t at GitHub - tuanpmt/esp32-mqtt: ESP32 MQTT sample project for
After cloning the repository and creating the user_config.local.h I try to build the project. There are a number of errors and warnings, most of which are easily addresses. I am left with one class of error that doesn’t make sense to me as the code is valid by GCC strandards yet fails to compile. Thge issue centrers around the initialization fo a structure.
The code in question is:
typedef struct {
mqtt_callback connected_cb;
mqtt_callback disconnected_cb;
mqtt_callback reconnect_cb;
mqtt_callback subscribe_cb;
mqtt_callback publish_cb;
mqtt_callback data_cb;
char host[CONFIG_MQTT_MAX_HOST_LEN];
uint32_t port;
char client_id[CONFIG_MQTT_MAX_CLIENT_LEN];
char username[CONFIG_MQTT_MAX_USERNAME_LEN];
char password[CONFIG_MQTT_MAX_PASSWORD_LEN];
char lwt_topic[CONFIG_MQTT_MAX_LWT_TOPIC];
char lwt_msg[CONFIG_MQTT_MAX_LWT_MSG];
uint32_t lwt_qos;
uint32_t lwt_retain;
uint32_t clean_session;
uint32_t keepalive;
} mqtt_settings;
The initialization is:
mqtt_settings settings = {
.host = "test.mosquitto.org",
#if defined(CONFIG_MQTT_SECURITY_ON)
.port = 8883, // encrypted
#else
.port = 1883, // unencrypted
#endif
.client_id = "mqtt_client_id",
.username = "user",
.password = "pass",
.clean_session = 0,
.keepalive = 120,
.lwt_topic = "/lwt",
.lwt_msg = "offline",
.lwt_qos = 0,
.lwt_retain = 0,
.connected_cb = connected_cb,
.disconnected_cb = disconnected_cb,
.reconnect_cb = reconnect_cb,
.subscribe_cb = subscribe_cb,
.publish_cb = publish_cb,strong text
.data_cb = data_cb
};
which I believe to valid, at least according to GCC standard for designated initializers, Designated initializers
When I build I get the following werror messages:
Error GCC C99 designator 'host' outside aggregate initializer 102:1
Error GCC C99 designator 'lwt_msg' outside aggregate initializer 102:1
Error GCC C99 designator 'lwt_topic' outside aggregate initializer 102:1
Error GCC C99 designator 'password' outside aggregate initializer 102:1
Error GCC C99 designator 'username' outside aggregate initializer 102:1
Error GCC C99 designator 'client_id' outside aggregate initializer 102:1
the standard gives the example:
struct point { int x, y; };
the following initialization
struct point p = { .y = yvalue, .x = xvalue };
is equivalent to
struct point p = { xvalue, yvalue };"
which is what is attempted above. What am I missing?
Thanks