aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
980 stars 632 forks source link

Incoming packet will be dumped: Packet length exceeds network buffer size #1746

Closed una801 closed 2 years ago

una801 commented 2 years ago

Hi,

I'm going to send hundreds of flying data to IoT Core every second. He is using an LTE modem, and in the process of transmitting data using mqtt, the connection is being disconnected due to an error related to network buffer. In the case of TCP, I understand that the maximum transport network packet is 8 kb, so can we increase this to more than 1024 on sdk?

The current error is as follows.

[INFO] [DEMO] [mqtt_demo_mutual_auth.c:1063] Sending Publish to the MQTT topic PESS/BMS/jeonnam5674.
[INFO] [DEMO] [mqtt_demo_mutual_auth.c:486] Incoming Publish Topic Name: PESS/BMS/jeonnam5674 matches subscribed topic.
Incoming Publish message Packet Id is 2.
Incoming Publish Message : {"can_data":"80:64 00  81:98 1C 00 00 00 00  82:00 00 00 00 00 00  83:FE 01 10 27  85:DF 00 D6 00 ED 00 17 00  84:70 0E 6E 0E 74 0E 06 00  86:02 02 00  100:98 1C 00 00  101:01 00 00 00 00 00  105:00 00  106:00 00 00 00 00 00 00 00  107:04 0F 08 0D 09 05 01 16  200:98 1C 00 00  201:57 00 00 00 00 00  202:FE 01 10 27  203:71 0E 6E 0E 74 0E 06 00  205:00 00  204:E0 00 D8 00 EE 00 16 00  206:00 00 00 00 00 00 00 00  207:03 06 07 15 09 13 01 0B  300:98 1C 00 00  301:01 00 00 00 00 00  303:70 0E 6F 0E 74 0E 05 00  304:DE 00 D6 00 EB 00 15 00  305:00 00  307:04 0F 08 0D 09 05 01 16  306:00 00 00 00 00 00 00 00  400:98 1C 00 00  401:57 00 00 00 00 00  402:FE 01 10 27  403:71 0E 6E 0E 74 0E 06 00  404:E0 00 D8 00 EE 00 16 00  405:00 00  406:00 00 00 00 00 00 00 00  "}.

[INFO] [DEMO] [mqtt_demo_mutual_auth.c:1063] Sending Publish to the MQTT topic PESS/BMS/jeonnam5674.
[ERROR] [MQTT] [core_mqtt.c:852] Incoming packet will be dumped: Packet length exceeds network buffer size.PacketSize=1057, NetworkBufferSize=1024.
[ERROR] [MQTT] [core_mqtt.c:825] Dumped packet. DumpedBytes=1057.
[INFO] [DEMO] [mqtt_demo_mutual_auth.c:1063] Sending Publish to the MQTT topic PESS/BMS/jeonnam5674.
*** Error in `./mqtt_demo_mutual_auth': malloc(): memory corruption: 0x0004e4a8 ***
Aborted (core dumped)

Data flies so fast that it is possible to monitor only when you turn as many circles as possible and transmit a large amount of data. I ask if it is necessary to modify network packets inside LTE modem or if the maximum number of transport packets can be increased through sdk internal definition.

muneebahmed10 commented 2 years ago

Hi @una801,

Transport packets != MQTT packets. TCP fragmentation occurs at the transport layer, while MQTT is an application layer protocol. The coreMQTT library has no knowledge of any packets in the transport layer; your network stack is responsible for assembling them and passing their data to the coreMQTT library through the library's transport interface. The network buffer is the buffer to hold MQTT packets that are received from or sent to the network via the transport interface. For coreMQTT, it needs to be at least as large as the largest MQTT packet you plan to receive. Your error is that you are trying to receive a 1057 byte MQTT packet into a 1024 byte buffer, so you need to increase the network buffer's size.

una801 commented 2 years ago

@muneebahmed10 Thank you for your answer. When we say that we need to increase the network buffer, do you mean that we can modify the definition item inside the sdk? If you change the network buffer part of the definition, there will be an error, so I would like to ask if there is anything additional to modify.

 #define NETWORK_BUFFER_SIZE    ( 1024U )

->Define item in mqtt_mutual_auth part

muneebahmed10 commented 2 years ago

That define is in a file named demo_config.h. It's part of the demo code and not in coreMQTT or any other library in the SDK. You can do whatever you want with the demo code.

aggarg commented 2 years ago

I am closing this issue. Feel free to open a new issue if you have more questions.