Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mqtt_example_init() -> Invalid initialize sequence #13

Open
nguyenlkdn opened this issue Jun 16, 2023 · 0 comments
Open

mqtt_example_init() -> Invalid initialize sequence #13

nguyenlkdn opened this issue Jun 16, 2023 · 0 comments

Comments

@nguyenlkdn
Copy link

nguyenlkdn commented Jun 16, 2023

void
mqtt_example_init(void)
{
#if LWIP_TCP
  mqtt_client = mqtt_client_new();

  mqtt_set_inpub_callback(mqtt_client,
          mqtt_incoming_publish_cb,
          mqtt_incoming_data_cb,
          LWIP_CONST_CAST(void*, &mqtt_client_info));

  mqtt_client_connect(mqtt_client,
          &mqtt_ip, MQTT_PORT,
          mqtt_connection_cb, LWIP_CONST_CAST(void*, &mqtt_client_info),
          &mqtt_client_info);
#endif /* LWIP_TCP */
}

mqtt_set_inpub_callback: This function should be called after mqtt_client_connect() is done!

Due to it will be wipe clean inside mqtt_client_connect() function
https://github.com/particle-iot/lwip/blob/master/src/apps/mqtt/mqtt.c#L1311
then whenever mqtt messages come => it got crashed at line: https://github.com/particle-iot/lwip/blob/master/src/apps/mqtt/mqtt.c#L773 NULL_PTR Callback

So it should be like this:

void
mqtt_example_init(void)
{
#if LWIP_TCP
  mqtt_client = mqtt_client_new();
  mqtt_client_connect(mqtt_client,
          &mqtt_ip, MQTT_PORT,
          mqtt_connection_cb, LWIP_CONST_CAST(void*, &mqtt_client_info),
          &mqtt_client_info);
  mqtt_set_inpub_callback(mqtt_client,
          mqtt_incoming_publish_cb,
          mqtt_incoming_data_cb,
          LWIP_CONST_CAST(void*, &mqtt_client_info));

#endif /* LWIP_TCP */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant