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>
diff --git a/src/apps/mqtt/mqtt.c b/src/apps/mqtt/mqtt.c
index a0d4f95..1929a6d 100644
--- a/src/apps/mqtt/mqtt.c
+++ b/src/apps/mqtt/mqtt.c
@@ -1187,13 +1187,14 @@
* 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 @@
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;
diff --git a/src/include/lwip/apps/mqtt.h b/src/include/lwip/apps/mqtt.h
index a0e48bd..7028990 100644
--- a/src/include/lwip/apps/mqtt.h
+++ b/src/include/lwip/apps/mqtt.h
@@ -204,7 +204,7 @@
/** 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 */
diff --git a/src/include/lwip/apps/mqtt_opts.h b/src/include/lwip/apps/mqtt_opts.h
index 7d7d29d..ffefacd 100644
--- a/src/include/lwip/apps/mqtt_opts.h
+++ b/src/include/lwip/apps/mqtt_opts.h
@@ -72,13 +72,6 @@
#endif
/**
- * MQTT server port to connect to
- */
-#ifndef MQTT_PORT
-#define MQTT_PORT 1883
-#endif
-
-/**
* Seconds between each cyclic timer call.
*/
#ifndef MQTT_CYCLIC_TIMER_INTERVAL