Hello
I admire the Mongoose OS project and appreciate the time and effort the developers have invested in making it available. However, I’m struggling with the omission of documentation and examples for the C++ API.
I’m trying to construct a simple MQTT mgos_mqtt_pub
that resets a counter. This code:
static void reset_cb(struct mg_connection *c, const char *topic, int topic_len, const char *msg, int msg_len, void *userdata)
{
cum_on_time_millis = 0;
}
enum mgos_app_init_result mgos_app_init(void)
{
mgos_mqtt_global_subscribe("10/command/reset", reset_cb, NULL);
}
fails on (at least) two points:
(1) all the unused variables in reset_cb
, which the compiler is treating as an error
(2) could not convert '(const char*)"10/command/reset"' from 'const char*' to 'mg_str'
I know enough C++ to realise that mgos_mqtt_global_subscribe
requires some sort of mg_str
, but without any documentation for mg_str
, I don’t know what to do about it.
Could I trouble someone to provide a short example of subscribing to an MQTT topic using the C++ API, in the absence of one in the documentation? I do appreciate your time.