The MIME protocol can be used to exchange data between MyGeotab and an external device when the total message size exceeds the packet.
The complete MIME message is broken into chunks and sent as binary data packets. The first byte within the message is a sequence counter. All the remaining bytes contain the MIME data.
To accommodate external devices with memory constraints, the packet size is adjustable when sending messages to/from MyGeotab. The packets have a maximum size of 1000 bytes.
Bytes | Position | |
---|---|---|
Sequence number [1] | 1 | 0 |
MIME data | x | 1 |
[1] A sequence number of 0 is only used for the first packet. The sequence number increments by 1 for each subsequent packet. If the sequence number reaches 255 (0xFF) and more packets need to be sent, the sequence number must reset to a value of 1 and continue counting.
Bytes | Position | |
---|---|---|
MIME type length = x | 1 | 0 |
MIME type in ASCII | x | 1 |
Payload length = y | 4 | 1 + x |
Binary payload | y | 5 + x |
When transferring MIME data from the external device to MyGeotab, once the complete message is received MyGeotab will reply with an acknowledge message indicating the total number of payload bytes received.
Bytes | Position | |
---|---|---|
Sequence number = 0 | 1 | 0 |
MIME type length = 3 | 1 | 1 |
MIME type in ASCII = 'ACK' | 3 | 2 |
Payload length | 4 | 5 |
Total number of payload bytes received | x | 9 |
This is an example of binary data packets for image data transferred using the MIME type “image/jpeg”. The image size is 83000 bytes. The packet size is 235.
Bytes | Position | |
---|---|---|
Sequence number = 0 | 1 | 0 |
MIME type length = 10 | 1 | 1 |
MIME type (“image/jpeg”) | 10 | 2 |
Payload length = 83000 | 4 | 12 |
Binary payload (the first 219 bytes) | 219 | 16 |
Bytes | Position | |
---|---|---|
Sequence number = 1 | 1 | 0 |
Binary payload (the next 234 bytes) | 234 | 1 |
To send/receive messages between MyGeotab and the external device, please download the source code of the Starter Kit sample, and replace the Sample API with the following script. The alternative is to paste the script in the Runner.
Once the data has been sent to the cloud, you can use the MyGeotab SDK to pull the message content out of the target database. For each MIME payload, the data is stored within a single TextMessage Object and can be retrieved using the Get method (search criteria can be added):
The payload is stored in MyGeotab in Base64 encoded format. Decoding this payload from Base64 to bytes should yield the expected content which was passed through. In the event that the database has multiple devices sending MIME data at different times, you may want to specify the originating device and/or filter by the time interval during which MIME data was sent: