@@ -124,13 +124,13 @@ mqtt_tcpclient_recv(void *arg, char *pdata, unsigned short len)
124
124
{
125
125
uint8_t msg_type ;
126
126
uint8_t msg_qos ;
127
-
128
127
uint16_t msg_id ;
129
128
130
129
struct espconn * pCon = (struct espconn * )arg ;
131
130
MQTT_Client * client = (MQTT_Client * )pCon -> reverse ;
132
131
133
- INFO ("TCP: data received\r\n" );
132
+ READPACKET :
133
+ INFO ("TCP: data received %d bytes\r\n" , len );
134
134
if (len < MQTT_BUF_SIZE && len > 0 ){
135
135
os_memcpy (client -> mqtt_state .in_buffer , pdata , len );
136
136
@@ -141,7 +141,7 @@ mqtt_tcpclient_recv(void *arg, char *pdata, unsigned short len)
141
141
msg_type = mqtt_get_type (client -> mqtt_state .in_buffer );
142
142
msg_qos = mqtt_get_qos (client -> mqtt_state .in_buffer );
143
143
msg_id = mqtt_get_id (client -> mqtt_state .in_buffer , client -> mqtt_state .in_buffer_length );
144
- INFO ( "MQTT: type: %d, qos: %d, id: %04X\r\n" , msg_type , msg_qos , msg_id );
144
+
145
145
switch (msg_type )
146
146
{
147
147
case MQTT_MSG_TYPE_CONNACK :
@@ -219,24 +219,17 @@ mqtt_tcpclient_recv(void *arg, char *pdata, unsigned short len)
219
219
// statement due to the way protothreads resume.
220
220
if (msg_type == MQTT_MSG_TYPE_PUBLISH )
221
221
{
222
- uint16_t len ;
223
-
224
- // adjust message_length and message_length_read so that
225
- // they only account for the publish data and not the rest of the
226
- // message, this is done so that the offset passed with the
227
- // continuation event is the offset within the publish data and
228
- // not the offset within the message as a whole.
229
222
len = client -> mqtt_state .message_length_read ;
230
- mqtt_get_publish_data (client -> mqtt_state .in_buffer , & len );
231
- len = client -> mqtt_state .message_length_read - len ;
232
- client -> mqtt_state .message_length -= len ;
233
- client -> mqtt_state .message_length_read -= len ;
234
223
235
- if (client -> mqtt_state .message_length_read < client -> mqtt_state .message_length )
224
+ if (client -> mqtt_state .message_length < client -> mqtt_state .message_length_read )
236
225
{
237
226
//client->connState = MQTT_PUBLISH_RECV;
238
227
//Not Implement yet
239
- INFO ("We have more data, read: %d, total: %d\r\n" , client -> mqtt_state .message_length_read , client -> mqtt_state .message_length );
228
+ len -= client -> mqtt_state .message_length ;
229
+ pdata += client -> mqtt_state .message_length ;
230
+
231
+ INFO ("Get another published message\r\n" );
232
+ goto READPACKET ;
240
233
}
241
234
242
235
}
0 commit comments