diff --git a/src/mqttsn-messages.cpp b/src/mqttsn-messages.cpp index 91326a5..d61bc88 100644 --- a/src/mqttsn-messages.cpp +++ b/src/mqttsn-messages.cpp @@ -180,12 +180,13 @@ void MQTTSN::dispatch() { } waiting_for_response = false; + memset(response_message, 0, MAX_BUFFER_SIZE); } void MQTTSN::send_message() { message_header* hdr = reinterpret_cast(message_buffer); -#ifdef USE_RF12 + #ifdef USE_RF12 while (!rf12_canSend()) { rf12_recvDone(); Sleepy::loseSomeTime(32); diff --git a/src/mqttsn.h b/src/mqttsn.h index 746c7ce..fd59fdb 100644 --- a/src/mqttsn.h +++ b/src/mqttsn.h @@ -98,70 +98,70 @@ struct message_header { uint8_t type; }; -struct msg_advertise : public message_header { +struct __attribute__ ((packed)) msg_advertise : public message_header { uint8_t gw_id; uint16_t duration; }; -struct msg_searchgw : public message_header { +struct __attribute__ ((packed)) msg_searchgw : public message_header { uint8_t radius; }; -struct msg_gwinfo : public message_header { +struct __attribute__ ((packed)) msg_gwinfo : public message_header { uint8_t gw_id; char gw_add[0]; }; -struct msg_connect : public message_header { +struct __attribute__ ((packed)) msg_connect : public message_header { uint8_t flags; uint8_t protocol_id; uint16_t duration; char client_id[0]; }; -struct msg_connack : public message_header { +struct __attribute__ ((packed)) msg_connack : public message_header { return_code_t return_code; }; -struct msg_willtopic : public message_header { +struct __attribute__ ((packed)) msg_willtopic : public message_header { uint8_t flags; char will_topic[0]; }; -struct msg_willmsg : public message_header { +struct __attribute__ ((packed)) msg_willmsg : public message_header { char willmsg[0]; }; -struct msg_register : public message_header { +struct __attribute__ ((packed)) msg_register : public message_header { uint16_t topic_id; uint16_t message_id; char topic_name[0]; }; -struct msg_regack : public message_header { +struct __attribute__ ((packed)) msg_regack : public message_header { uint16_t topic_id; uint16_t message_id; uint8_t return_code; }; -struct msg_publish : public message_header { +struct __attribute__ ((packed)) msg_publish : public message_header { uint8_t flags; uint16_t topic_id; uint16_t message_id; char data[0]; }; -struct msg_puback : public message_header { +struct __attribute__ ((packed)) msg_puback : public message_header { uint16_t topic_id; uint16_t message_id; uint8_t return_code; }; -struct msg_pubqos2 : public message_header { +struct __attribute__ ((packed)) msg_pubqos2 : public message_header { uint16_t message_id; }; -struct msg_subscribe : public message_header { +struct __attribute__ ((packed)) msg_subscribe : public message_header { uint8_t flags; uint16_t message_id; union { @@ -170,14 +170,14 @@ struct msg_subscribe : public message_header { }; }; -struct msg_suback : public message_header { +struct __attribute__ ((packed)) msg_suback : public message_header { uint8_t flags; uint16_t topic_id; uint16_t message_id; uint8_t return_code; }; -struct msg_unsubscribe : public message_header { +struct __attribute__ ((packed)) msg_unsubscribe : public message_header { uint8_t flags; uint16_t message_id; union { @@ -186,23 +186,23 @@ struct msg_unsubscribe : public message_header { }; }; -struct msg_unsuback : public message_header { +struct __attribute__ ((packed)) msg_unsuback : public message_header { uint16_t message_id; }; -struct msg_pingreq : public message_header { +struct __attribute__ ((packed)) msg_pingreq : public message_header { char client_id[0]; }; -struct msg_disconnect : public message_header { +struct __attribute__ ((packed)) msg_disconnect : public message_header { uint16_t duration; }; -struct msg_willtopicresp : public message_header { +struct __attribute__ ((packed)) msg_willtopicresp : public message_header { uint8_t return_code; }; -struct msg_willmsgresp : public message_header { +struct __attribute__ ((packed)) msg_willmsgresp : public message_header { uint8_t return_code; };