mqtt: Allow setting server port to connect

This is a mqtt client, so it does not make sense to determinate the server port
at compile time. Update mqtt_client_connect() function to allow setting server
port.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
This commit is contained in:
Axel Lin 2016-12-23 08:52:28 +08:00 committed by Dirk Ziegelmeier
parent 2e4b368c8c
commit bfa0358a52
3 changed files with 5 additions and 11 deletions

View File

@ -1187,13 +1187,14 @@ mqtt_client_new(void)
* Connect to MQTT server
* @param client MQTT client
* @param ip_addr Server IP
* @param port Server port
* @param cb Connection state change callback
* @param arg User supplied argument to connection callback
* @param client_info Client identification and connection options
* @return ERR_OK if successful, @see err_t enum for other results
*/
err_t
mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, mqtt_connection_cb_t cb, void *arg,
mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, mqtt_connection_cb_t cb, void *arg,
const struct mqtt_connect_client_info_t *client_info)
{
err_t err;
@ -1265,10 +1266,10 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, mqtt_connec
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_client_connect: Error binding to local ip/port, %d\n", err));
goto tcp_fail;
}
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_client_connect: Connecting to host: %s at port:%d\n", ipaddr_ntoa(ip_addr), MQTT_PORT));
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_client_connect: Connecting to host: %s at port:%"U16_F"\n", ipaddr_ntoa(ip_addr), port));
/* Connect to server */
err = tcp_connect(client->conn, ip_addr, MQTT_PORT, mqtt_tcp_connect_cb);
err = tcp_connect(client->conn, ip_addr, port, mqtt_tcp_connect_cb);
if(err != ERR_OK) {
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_client_connect: Error connecting to remote ip/port, %d\n", err));
goto tcp_fail;

View File

@ -204,7 +204,7 @@ struct mqtt_client_t
/** Connect to server */
err_t mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ipaddr, mqtt_connection_cb_t cb, void *arg,
err_t mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ipaddr, u16_t port, mqtt_connection_cb_t cb, void *arg,
const struct mqtt_connect_client_info_t *client_info);
/** Disconnect from server */

View File

@ -71,13 +71,6 @@ extern "C" {
#define MQTT_REQ_MAX_IN_FLIGHT 4
#endif
/**
* MQTT server port to connect to
*/
#ifndef MQTT_PORT
#define MQTT_PORT 1883
#endif
/**
* Seconds between each cyclic timer call.
*/