Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reply with PUBACK when receiving a QoS1 PUBLISH #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions mqtt-sn.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,9 @@ void mqtt_sn_dump_packet(char* packet)
printf("\n");
}

void mqtt_sn_print_publish_packet(publish_packet_t* packet)
int mqtt_sn_print_publish_packet(publish_packet_t* packet)
{
int rc = MQTT_SN_ACCEPTED;
if (verbose) {
int topic_type = packet->flags & 0x3;
int topic_id = ntohs(packet->topic_id);
Expand All @@ -748,6 +749,9 @@ void mqtt_sn_print_publish_packet(publish_packet_t* packet)
if (topic_name) {
printf("%s: %s\n", topic_name, packet->data);
}
else{
rc = MQTT_SN_REJECTED_INVALID;
}
break;
};
case MQTT_SN_TOPIC_TYPE_PREDEFINED: {
Expand All @@ -763,6 +767,7 @@ void mqtt_sn_print_publish_packet(publish_packet_t* packet)
} else {
printf("%s\n", packet->data);
}
return rc;
}

uint16_t mqtt_sn_receive_suback(int sock)
Expand Down Expand Up @@ -823,6 +828,7 @@ int mqtt_sn_select(int sock)
void* mqtt_sn_wait_for(uint8_t type, int sock)
{
time_t started_waiting = time(NULL);
int rc;

while(TRUE) {
time_t now = time(NULL);
Expand All @@ -841,7 +847,11 @@ void* mqtt_sn_wait_for(uint8_t type, int sock)
if (packet) {
switch(packet[1]) {
case MQTT_SN_TYPE_PUBLISH:
mqtt_sn_print_publish_packet((publish_packet_t *)packet);
rc = mqtt_sn_print_publish_packet((publish_packet_t *)packet);
if(type == packet[1]){
return packet;
}
mqtt_sn_send_puback(sock,(publish_packet_t *)packet,rc);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puback is sent in

mqtt_sn_send_puback(sock, packet, MQTT_SN_ACCEPTED);

I am trying to remember why mqtt_sn_print_publish_packet() is inside mqtt_sn_wait_for()

But I guess that is the same reason why you are missing some PUBACKs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, it was because of issue #4

break;

case MQTT_SN_TYPE_REGISTER:
Expand Down
2 changes: 1 addition & 1 deletion mqtt-sn.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void mqtt_sn_receive_connack(int sock);
uint16_t mqtt_sn_receive_regack(int sock);
uint16_t mqtt_sn_receive_suback(int sock);
void mqtt_sn_dump_packet(char* packet);
void mqtt_sn_print_publish_packet(publish_packet_t* packet);
int mqtt_sn_print_publish_packet(publish_packet_t* packet);
int mqtt_sn_select(int sock);
void* mqtt_sn_wait_for(uint8_t type, int sock);
void mqtt_sn_register_topic(int topic_id, const char* topic_name);
Expand Down