Merge pull request #2165 from alexandruioanp/check-ipv6addrconv-mqtt

Check broker IP conversion. Adjust state machine accordingly
This commit is contained in:
George Oikonomou 2017-04-02 00:33:43 +01:00 committed by GitHub
commit e4da7c66e0
2 changed files with 13 additions and 6 deletions

View file

@ -1333,7 +1333,9 @@ mqtt_connect(struct mqtt_connection *conn, char *host, uint16_t port,
conn->connect_vhdr_flags |= MQTT_VHDR_CLEAN_SESSION_FLAG; conn->connect_vhdr_flags |= MQTT_VHDR_CLEAN_SESSION_FLAG;
/* convert the string IPv6 address to a numeric IPv6 address */ /* convert the string IPv6 address to a numeric IPv6 address */
uiplib_ip6addrconv(host, &ip6addr); if(uiplib_ip6addrconv(host, &ip6addr) == 0) {
return MQTT_STATUS_ERROR;
}
uip_ipaddr_copy(&(conn->server_ip), ipaddr); uip_ipaddr_copy(&(conn->server_ip), ipaddr);

View file

@ -698,10 +698,15 @@ static void
connect_to_broker(void) connect_to_broker(void)
{ {
/* Connect to MQTT server */ /* Connect to MQTT server */
mqtt_connect(&conn, conf->broker_ip, conf->broker_port, mqtt_status_t conn_attempt_result = mqtt_connect(&conn, conf->broker_ip,
conf->pub_interval * 3); conf->broker_port,
conf->pub_interval * 3);
state = MQTT_CLIENT_STATE_CONNECTING; if(conn_attempt_result == MQTT_STATUS_OK) {
state = MQTT_CLIENT_STATE_CONNECTING;
} else {
state = MQTT_CLIENT_STATE_CONFIG_ERROR;
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
@ -827,8 +832,8 @@ state_machine(void)
} }
break; break;
case MQTT_CLIENT_STATE_NEWCONFIG: case MQTT_CLIENT_STATE_NEWCONFIG:
/* Only update config after we have disconnected */ /* Only update config after we have disconnected or in the case of an error */
if(conn.state == MQTT_CONN_STATE_NOT_CONNECTED) { if(conn.state == MQTT_CONN_STATE_NOT_CONNECTED || conn.state == MQTT_CONN_STATE_ERROR) {
update_config(); update_config();
DBG("New config\n"); DBG("New config\n");