/* This is our static connect data */
const struct mqtt_connect_pkt mqtt_conn = {
.keep_alive_seconds = 600,
- .clean_session_flag = MQTT_SESSION_RESUME,
+ .clean_session_flag = MQTT_SESSION_NEW, /* or MQTT_SESSION_RESUME */
.client_id = "test",
.will_topic = { .name = "will/temp/test", .QoS = MQTT_QoS_0 },
.will_retain = 1,
header->seqnum = 0;
header->data_len = pkt_len;
header->data_cksum = cksum;
+ header->header_cksum = 0;
/* Compute header chksum */
cksum = 0;
for (i = 0; i < HEADER_SIZE; i++) {
switch (mqtt_comm_state) {
case MQTT_WAITING_CONNECT_ACK: {
/* We must not receive anything before the connect acknowledge */
- struct mqtt_connack_response_pkt* response = (struct mqtt_connack_response_pkt*)(buf + HEADER_SIZE);
- ret = mqtt_check_connack_response_pkt(response);
+ struct mqtt_connack_reply_pkt* reply = (struct mqtt_connack_reply_pkt*)(buf + HEADER_SIZE);
+ ret = mqtt_check_connack_reply_pkt(reply);
if (ret != 0) {
uprintf(dbg_uart, "Not a connack packet (ret: %d) ... protocol flow error\n", ret);
return -3;
}
/* Valid packet, check return code */
- if (response->ret_code == MQTT_CONNACK_ACCEPTED) {
+ if (reply->ret_code == MQTT_CONNACK_ACCEPTED) {
uprintf(dbg_uart, "Connection accepted\n");
mqtt_comm_state = MQTT_IDLE;
} else {
- uprintf(dbg_uart, "Connection refused: %d\n", response->ret_code);
+ uprintf(dbg_uart, "Connection refused: %d\n", reply->ret_code);
mqtt_comm_state = MQTT_UNCONNECTED;
return -4;
}
break;
}
case MQTT_WAITING_PUBACK: {
- struct mqtt_publish_response_pkt* response = (struct mqtt_publish_response_pkt*)(buf + HEADER_SIZE);
- ret = mqtt_check_publish_response_pkt(response, MQTT_WAITING_PUBACK);
+ struct mqtt_publish_reply_pkt* reply = (struct mqtt_publish_reply_pkt*)(buf + HEADER_SIZE);
+ ret = mqtt_check_publish_reply_pkt(reply, MQTT_CONTROL_PUBACK);
if (ret != 0) {
- uprintf(dbg_uart, "Not a connack packet (ret: %d) ... protocol flow error\n", ret);
+ uprintf(dbg_uart, "Not a puback packet (ret: %d) ... protocol flow error\n", ret);
return -5;
}
- if (response->acked_pkt_id != pub_packet_id) {
- uprintf(dbg_uart, "Not a connack for the right packet (got %d, our is %d) ...\n",
- response->acked_pkt_id, pub_packet_id);
+ if (ntohs(reply->acked_pkt_id) != pub_packet_id) {
+ uprintf(dbg_uart, "Not a puback for the right packet (got %d, our is %d) ...\n",
+ ntohs(reply->acked_pkt_id), pub_packet_id);
return -6;
}
+ uprintf(dbg_uart, "Publication accepted\n");
mqtt_comm_state = MQTT_IDLE;
pub_packet_id++;
break;