Here’s the comprehensive fix addressing all three focus areas:
MQTT/WebSocket Event Handling: The issue is twofold - initialization timing and topic pattern mismatch. First, ensure MQTT connects before dashboard initialization:
await mqttClient.connect();
await dashboardManager.initialize();
Consider switching to WebSocket for dashboard updates as it has better reconnection handling in cciot-24.
Firmware Status Event Emission: Your firmware service needs to publish to the correct topic pattern. Update your publisher:
firmwareService.publishStatus(deviceId, status, {
topic: `device/${deviceId}/firmware/status`,
qos: 1
});
The widget expects the ‘device/+/firmware/status’ pattern. Your current ‘firmware/status/#’ pattern isn’t matched by the default subscription.
Dashboard Subscription Logic: The built-in firmware widget in cciot-24 has a configuration option for custom topic patterns. In your dashboard configuration file, add:
"widgets": {
"firmwareStatus": {
"subscriptions": [
"device/+/firmware/status",
"firmware/bulk-update/status"
],
"autoRefresh": true,
"refreshInterval": 5000
}
}
The key insight is that the widget’s subscription is set up during dashboard initialization. If your MQTT client isn’t connected at that moment, the subscription silently fails and the widget falls back to polling mode (which you’ve disabled).
Alternatively, if you can’t change the firmware service’s topic pattern, you can implement a topic bridge that subscribes to ‘firmware/status/#’ and republishes to ‘device/+/firmware/status’. This is cleaner than modifying the widget configuration.
After making these changes, verify the subscription is active by checking the MQTT broker logs. You should see the dashboard client subscribing to the correct topics immediately after connection establishment.