Let me provide a comprehensive solution addressing all three aspects of your issue:
1. MQTT Broker Payload Size Configuration
The broker-side 1MB limit you set is correct, but you need to verify it’s actually applied. Check the MQTT broker logs (typically in SAP IoT Data Services) to confirm the maxPayloadSize parameter is active. Also ensure your MQTT topic permissions allow large payloads - some default security policies restrict payload sizes regardless of broker settings.
2. OTA Firmware Update Process
Implement a two-phase approach:
- Phase 1: Device handshake - device publishes its capabilities including max MQTT payload size
- Phase 2: Adaptive chunking - OTA service calculates optimal chunk size as min(device_max_payload - 16KB overhead, 240KB safe_limit)
The 16KB overhead accounts for MQTT headers, JSON wrapping, and base64 encoding if you’re using it.
3. Chunked Firmware Transfer Logic
Here’s the key fix - modify your chunking algorithm:
// Calculate safe chunk size per device
const deviceMaxPayload = deviceProfile.mqttMaxPayload || 256000;
const safeChunkSize = Math.min(deviceMaxPayload - 16384, 240000);
const totalChunks = Math.ceil(firmwareSize / safeChunkSize);
In your SAP IoT Application Enablement custom service, you’ll need to:
- Create a device capability table in IoT Data Storage Module to persist MQTT constraints per device
- Modify the firmware update service to query this table before starting transfers
- Implement retry logic with exponentially decreasing chunk sizes (240KB → 128KB → 64KB) if transfers still fail
Implementation Steps:
First, enhance your device registration to capture MQTT capabilities. When devices connect, have them publish to devices/{deviceId}/capabilities:
{
"mqttMaxPayload": 256000,
"firmwareVersion": "1.2.3",
"availableMemory": 512000
}
Then update your OTA service’s chunking logic to respect these limits. The service should fetch device capabilities before calculating chunks and adjust accordingly.
For your immediate issue:
Since you can’t reflash all devices now, configure your OTA service to use a conservative 220KB chunk size globally. This leaves enough headroom for all devices with 256KB limits. You can optimize this later as you upgrade device firmware to support larger payloads.
Also check your SAP IoT Edge Gateway configuration if you’re routing through gateways - they have their own payload limits that can create bottlenecks even if broker and devices support larger sizes.
This approach has worked for several deployments I’ve supported with mixed device capabilities ranging from 128KB to 1MB MQTT payload support.