MQTT Data Usage
The message payload, MQTT protocol frames that wrap the payload, and the TCP overhead used to communicate with hosted systems are the primary factors that determine data usage.
TCP Protocol Overhead
For detailed information about the TCP protocol, see https://en.wikipedia.org/wiki/Transmission_Control_Protocol.
A TCP connection uses approximately 96 bytes (SYN, SYN-ACK, ACK). On sending and receiving data, each transmission uses approximately 64 bytes of overhead (PSH, ACK).
In a send and reply scenario, such as an API call from a device to Device Cloud, the following affects the data usage:
-
If the reply occurs in less than one millisecond, the transaction uses 96 bytes of overhead (PSH, PSH-ACK, ACK).
-
If the reply is slower, the transaction uses 128 bytes of overhead (PSH, ACK, PSH, ACK).
MQTT Protocol Overhead
For more information about the protocol, see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html.
An MQTT connection uses approximately 86 bytes of data (CONN and CONNACK).
In a send and reply scenario, such as an API call from the device to Device Cloud, the following affects the data usage:
-
A PUBLISH from the device to the cloud uses 15 bytes of overhead (PUBLISH).
-
A PUBLISH from the cloud to the device with the reply uses another 15 bytes of overhead (PUBLISH).
In a server topic scenario of pushing data, the following affects the data usage:
-
A PUBLISH from the device to the cloud uses 15 bytes of overhead (PUBLISH).
-
If the QOS is set to one, the PUBACK from the cloud to the device uses two bytes of overhead (PUBACK).
MQTT defines a heartbeat interval, and at this interval, the client sends a PINGREQ packet to the server and in response, the server sends a PINGRSP. Each of these packets uses two bytes of overhead. The interval for the heartbeats is configurable and affects the delay after a network outage that the client and server detect that there is a communication error.
A heartbeat interval of 24 hours results in one heartbeat per day, but in the event of a network outage, the client and server will not recognize the outage until the heartbeat message is sent. This may or may not be acceptable based on your application design.
TR50 Protocol Overhead
TR50 uses JSON encoded messages (ASCII protocol). You can use zlib to compress messages to reduce data usage.
For information about sample API messages to use when sizing, see Device Cloud Service Interface.
You can use the API Tester in the Management Portal to see the sizes of different raw and compressed requests.
Example Data Usage Scenarios
The following data calculations are based on ideal network conditions with no spurious connectivity loss that would result in a reconnection.
Activity |
TR50 |
MQTT |
TCP |
Total |
Explanation |
---|---|---|---|---|---|
TCP Connect |
|
|
96 |
96 |
|
MQTT Connect |
|
64 |
128 |
192 |
|
MQTT Heartbeat |
|
4 |
96 |
100 |
one hour heartbeat interval |
TR50 Publish Property (request) |
109 |
15 |
64 |
188 |
|
TR50 Publish Property (reply) |
47 |
15 |
64 |
126 |
|
|
|
|
|
|
|
Total data per hour |
|
|
|
702 B |
|
Total data per month |
|
|
|
500 KB |
|
Activity |
TR50 |
MQTT |
TCP |
Total |
Explanation |
---|---|---|---|---|---|
TCP Connect |
|
|
96 |
96 |
|
MQTT Connect |
|
64 |
128 |
192 |
|
MQTT Heartbeat |
|
4 |
96 |
100 |
one hour heartbeat interval |
TR50 Publish Property (request) |
109 |
15 |
64 |
188 |
|
TR50 Publish Property (reply) |
47 |
15 |
64 |
126 |
|
|
|
|
|
|
|
Total data per hour |
|
|
|
414 B |
Not counting connect |
Total data per month |
|
|
|
298 KB |
|
Activity |
TR50 |
MQTT |
TCP |
Total |
Explanation |
---|---|---|---|---|---|
TCP Connect |
|
|
96 |
96 |
|
MQTT Connect |
|
64 |
128 |
192 |
|
MQTT Heartbeat |
|
4 |
96 |
100 |
one hour heartbeat interval |
TR50 Publish Property (request) |
1635 |
15 |
64 |
1714 |
Assuming batching 100 properties with 85% compression |
TR50 Publish Property (reply) |
47 |
15 |
64 |
126 |
|
|
|
|
|
|
|
Total data per hour |
|
|
|
1.9 KB |
Not counting connect |
Total data per month |
|
|
|
1.4 MB |
|