Test Patterns for Chunks Endpoint
In this tutorial, we demonstrate how to send a Heartbeat event for a device with
serial number TESTSERIAL
to Memfault's data pipeline without integrating any
part of the Memfault Firmware SDK.
Normally, the Memfault Firmware SDK produces data and packetizes it into one or more Chunks. Each Chunk is uploaded to the Chunks HTTP endpoint. We also provide an iOS library, MemfaultCloud, to facilitate posting Chunks to Memfault from an iOS app.
Read more about the Memfault Data pipeline in a full integration and refer to the Chunks endpoint API documentation for error codes and additional API implementation details.
Posting Test Chunks
Without integrating the Memfault Firmware SDK on a Device, we can use curl to send mock data to the Chunks HTTP API endpoint and see it displayed in the Memfault web application.
Retrieve your Project Key
Your unique Project Key is required to communicate with Memfault's web services. On the web application, you can view and copy your Project Key in your project's settings.
Replace <YOUR_PROJECT_KEY>
with the one you copied for the remainder of this
tutorial.
Send a single Chunk
Download this Chunk test payload and save it in your working directory. This file contains the data of a single Chunk.
Run this curl
command to post the Chunk:
# Chunk 1/1
curl -v -X POST https://chunks.memfault.com/api/v0/chunks/TESTSERIAL \
-H 'Memfault-Project-Key: <YOUR_PROJECT_KEY>' \
-H 'Content-Type: application/octet-stream' \
--data-binary "@chunk_v2_single_chunk_msg.bin"
The HTTP request curl
sends looks like this:
POST /api/v0/chunks/TESTSERIAL HTTP/1.1
Host: chunks.memfault.com
Memfault-Project-Key: <YOUR_PROJECT_KEY>
Content-Type: application/octet-stream
Content-Length: <length of binary chunk data in bytes>
<binary chunk data here>
Send a batch upload with two Chunks
Batch uploading Chunks in a single HTTP request achieves better throughput than uploading them in individual requests. Parallelizing Chunk uploads from the same Device is not permitted.
Download Chunk test payload part 1 of 2 and Chunk test payload part 2 of 2 and save them in your working directory.
Run this curl
command to post both Chunks in one request:
# Event message spanning across two Chunks
# Event will display once both Chunks have arrived
curl -v -X POST https://chunks.memfault.com/api/v0/chunks/TESTSERIAL \
-H 'Memfault-Project-Key: <YOUR_PROJECT_KEY>' \
-H 'Content-Type: multipart/mixed' \
--form 'file=@chunk_v2_chunk_msg_pt1_of_2.bin;headers="Content-Length: 46"' \
--form 'file=@chunk_v2_chunk_msg_pt2_of_2.bin;headers="Content-Length: 44"'
The HTTP request curl
sends looks like this:
POST /api/v0/chunks/TESTSERIAL HTTP/1.1
Host: chunks.memfault.com
Memfault-Project-Key: <YOUR_PROJECT_KEY>
Content-Length: <total length>
Content-Type: multipart/mixed; boundary=77AC153B-FCD2-4224-A8F8-1788947663A0
--77AC153B-FCD2-4224-A8F8-1788947663A0
Content-Length: <chunk 1 of 2 binary data length in bytes>
<chunk 1 of 2 binary data>
--77AC153B-FCD2-4224-A8F8-1788947663A0
Content-Length: <chunk 2 of 2 binary data length in bytes>
<chunk 2 of 2 binary data>
--77AC153B-FCD2-4224-A8F8-1788947663A0--
The curl
command inserts an additional Content-Disposition
header with each
part. These headers are not necessary and will get ignored.
View Chunks in the Processing Log
After sending the test Chunks, you can verify successful delivery by viewing your project's Processing Log.
Troubleshooting Failures with Chunks Debug
When a request to the Chunks HTTP endpoint receives a 202 Accepted
response,
it means the posted Chunks have been enqueued for processing. Failures can occur
in the post-processing phase. To troubleshoot these processing failures, you can
use the
Chunks Debug Log.
This view lists recently received Chunks and any associated post-processing errors.