lwip/mqtt_cli/src/mqtt_client.c
/*
 * -----------------------------------------------------------------
 * Implementing the "connection state change" callback
 */
Implementing the "connection state change" callback
Implementing the " connection state change " callback
void mqtt_connection_cb(mqtt_client_t *client, void *arg,
		mqtt_connection_status_t status) {
	err_t err;
	static xTaskHandle mqtt_client_test_handler = NULL;
	if (status == MQTT_CONNECT_ACCEPTED) {
		printf("mqtt_connection_cb: Successfully connected\n");
		mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb,
				mqtt_incoming_data_cb, arg);
		err = mqtt_subscribe(client, "PW/V2/CIAA_NXP/RQ/#", 0,
				mqtt_sub_request_cb, arg);
		if (err != ERR_OK) {
			printf("mqtt_subscribe return: %d\n", err);
		}
		mqtt_client_test_handler = sys_thread_new("mqtt_client_test_thread",
				mqtt_client_test_thread, (void*) client,
				DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO + 1);
	} else {
		printf("mqtt_connection_cb: Disconnected, reason: %d\n", status);
		if (mqtt_client_test_handler != NULL)
			vTaskDelete(mqtt_client_test_handler);
		mqtt_client_do_connect(client);
	}
}
void mqtt_connection_cb ( mqtt_client_t * client , void * arg , mqtt_connection_status_t status ) { err_t err ; static xTaskHandle mqtt_client_test_handler = NULL ; if ( status == MQTT_CONNECT_ACCEPTED ) { printf ( " \n " ) ; mqtt_set_inpub_callback ( client , mqtt_incoming_publish_cb , mqtt_incoming_data_cb , arg ) ; err = mqtt_subscribe ( client , " " , 0 , mqtt_sub_request_cb , arg ) ; if ( err != ERR_OK ) { printf ( " \n " , err ) ; } mqtt_client_test_handler = sys_thread_new ( " " , mqtt_client_test_thread , ( void * ) client , DEFAULT_THREAD_STACKSIZE , DEFAULT_THREAD_PRIO + 1 ) ; } else { printf ( " \n " , status ) ; if ( mqtt_client_test_handler != NULL ) vTaskDelete ( mqtt_client_test_handler ) ; mqtt_client_do_connect ( client ) ; } }
Implementing the "connection state change" callback
Implementing the " connection state change " callback
/* Setup callback for incoming publish requests */ /* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */ /* Create test task after connection. Theoretically, messages can be sent at this point*/ /* If a test task was created, delete it before attempting reconnection */ /* Its more nice to be connected, so try to reconnect */