@alteriom/mqtt-schema 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,6 +33,10 @@ Firmware emits structured MQTT payloads that must remain tightly aligned with we
33
33
  - Helpful error paths (JSON Pointer style)
34
34
  - Lightweight (Ajv peer dependency, schemas embedded)
35
35
  - Ships original schema JSON files (optional consumption)
36
+ - **NEW in v0.7.0**: Best-in-class OTA management with security, rollback, and delta updates
37
+ - **NEW in v0.6.0**: Enhanced location/geolocation support for asset tracking
38
+ - **NEW in v0.6.0**: Extended sensor metadata (accuracy, calibration, operational range)
39
+ - **NEW in v0.6.0**: Comprehensive gateway health metrics (storage, network, errors)
36
40
 
37
41
  ## Installation
38
42
 
@@ -147,9 +151,155 @@ mqttClient.subscribe(`alteriom/nodes/${command.device_id}/responses`, (message)
147
151
  - Success boolean and error codes in responses
148
152
  - Latency tracking for performance monitoring
149
153
 
150
- ## OTA Firmware Manifest Schema (v0.3.1+)
154
+ ## Enhanced Location & Environment Tracking (v0.6.0+)
151
155
 
152
- The package includes OTA firmware manifest schema with both rich and minimal formats.
156
+ Track device location and deployment context for asset management and map-based visualization:
157
+
158
+ ```ts
159
+ import { validators, isSensorDataMessage } from '@alteriom/mqtt-schema';
160
+
161
+ const sensorData = {
162
+ schema_version: 1,
163
+ device_id: 'SN456',
164
+ device_type: 'sensor',
165
+ timestamp: new Date().toISOString(),
166
+ firmware_version: 'SN 2.1.0',
167
+ // Standardized location for map visualization
168
+ location: {
169
+ latitude: 43.6532,
170
+ longitude: -79.3832,
171
+ altitude: 76.5,
172
+ accuracy_m: 10.0,
173
+ zone: 'warehouse_A',
174
+ description: 'Shelf 3, Row B'
175
+ },
176
+ // Deployment context
177
+ environment: {
178
+ deployment_type: 'indoor',
179
+ power_source: 'battery',
180
+ expected_battery_life_days: 365
181
+ },
182
+ sensors: {
183
+ temperature: {
184
+ value: 22.3,
185
+ unit: 'C',
186
+ // Enhanced sensor metadata
187
+ timestamp: '2025-10-19T20:59:58.000Z',
188
+ accuracy: 0.5,
189
+ last_calibration: '2025-01-15',
190
+ error_margin_pct: 2.0,
191
+ operational_range: { min: -40, max: 85 },
192
+ quality_score: 0.95
193
+ }
194
+ },
195
+ battery_level: 78,
196
+ signal_strength: -65
197
+ };
198
+
199
+ const result = validators.sensorData(sensorData);
200
+ if (result.valid && isSensorDataMessage(sensorData)) {
201
+ // Display on map using location data
202
+ displayOnMap(sensorData.location.latitude, sensorData.location.longitude);
203
+
204
+ // Show sensor health based on metadata
205
+ if (sensorData.sensors.temperature.accuracy) {
206
+ console.log(`Temperature accuracy: ±${sensorData.sensors.temperature.accuracy}${sensorData.sensors.temperature.unit}`);
207
+ }
208
+
209
+ // Check calibration status
210
+ const lastCal = new Date(sensorData.sensors.temperature.last_calibration);
211
+ const daysSinceCalibration = (Date.now() - lastCal.getTime()) / (1000 * 60 * 60 * 24);
212
+ if (daysSinceCalibration > 365) {
213
+ console.warn('Sensor calibration overdue');
214
+ }
215
+ }
216
+ ```
217
+
218
+ **Location & Environment Features:**
219
+ - GPS coordinates (latitude, longitude, altitude) with accuracy tracking
220
+ - Zone-based organization (warehouses, floors, rooms)
221
+ - Human-readable location descriptions
222
+ - Deployment type tracking (indoor/outdoor/mobile)
223
+ - Power source information for battery management
224
+ - Per-sensor timestamps for async polling scenarios
225
+ - Sensor accuracy and calibration tracking
226
+ - Operational range validation support
227
+
228
+ ## Enhanced Gateway Metrics (v0.6.0+)
229
+
230
+ Comprehensive system health monitoring for gateways:
231
+
232
+ ```ts
233
+ import { validators, isGatewayMetricsMessage } from '@alteriom/mqtt-schema';
234
+
235
+ const metrics = {
236
+ schema_version: 1,
237
+ device_id: 'GW002',
238
+ device_type: 'gateway',
239
+ timestamp: new Date().toISOString(),
240
+ firmware_version: 'GW 1.4.0',
241
+ metrics: {
242
+ uptime_s: 86400,
243
+ cpu_usage_pct: 15.3,
244
+ memory_usage_pct: 42.7,
245
+ temperature_c: 45.2,
246
+ // Enhanced storage metrics
247
+ storage_usage_pct: 45.2,
248
+ storage_total_mb: 512,
249
+ storage_free_mb: 280.5,
250
+ // Network bandwidth tracking
251
+ network_rx_kbps: 125.4,
252
+ network_tx_kbps: 89.3,
253
+ active_connections: 5,
254
+ // System health indicators
255
+ error_count_24h: 3,
256
+ warning_count_24h: 12,
257
+ restart_count: 2,
258
+ last_restart_reason: 'firmware_update',
259
+ // Mesh network metrics
260
+ connected_devices: 12,
261
+ mesh_nodes: 8,
262
+ packet_loss_pct: 0.5
263
+ }
264
+ };
265
+
266
+ const result = validators.gatewayMetrics(metrics);
267
+ if (result.valid && isGatewayMetricsMessage(metrics)) {
268
+ // Storage monitoring
269
+ if (metrics.metrics.storage_usage_pct > 80) {
270
+ console.warn('Storage usage critical:', metrics.metrics.storage_usage_pct);
271
+ }
272
+
273
+ // Network health
274
+ const totalBandwidth = metrics.metrics.network_rx_kbps + metrics.metrics.network_tx_kbps;
275
+ console.log(`Total bandwidth: ${totalBandwidth.toFixed(1)} kbps`);
276
+
277
+ // Error trend analysis
278
+ if (metrics.metrics.error_count_24h > 10) {
279
+ console.error('High error rate detected:', metrics.metrics.error_count_24h);
280
+ }
281
+
282
+ // Restart tracking
283
+ console.log(`Last restart: ${metrics.metrics.last_restart_reason}`);
284
+ console.log(`Total restarts: ${metrics.metrics.restart_count}`);
285
+ }
286
+ ```
287
+
288
+ **Enhanced Gateway Metrics Features:**
289
+ - Storage usage tracking (percentage, total, free space)
290
+ - Network bandwidth monitoring (RX/TX rates)
291
+ - Active connection counting
292
+ - Error and warning counters (24-hour rolling window)
293
+ - Restart tracking with reason codes
294
+ - All metrics are optional for gradual firmware adoption
295
+
296
+ ## OTA Firmware Management (v0.7.0+)
297
+
298
+ Comprehensive best-in-class OTA solution based on 2024 industry standards.
299
+
300
+ ### OTA Manifest Schema
301
+
302
+ The package includes OTA firmware manifest schema with both rich and minimal formats, enhanced with enterprise-grade features.
153
303
 
154
304
  **Preferred: Stable alias import** (v0.3.1+):
155
305
  ```ts
@@ -184,6 +334,104 @@ Supported formats:
184
334
  - **Minimal environment map**: environment → channels mapping
185
335
  - **Chunk variants**: structured objects or SHA256 array
186
336
 
337
+ ### Enhanced OTA Features (v0.7.0+)
338
+
339
+ **Security & Authenticity:**
340
+ ```ts
341
+ const manifest = {
342
+ environment: "universal-sensor",
343
+ branch: "main",
344
+ manifests: {
345
+ prod: {
346
+ build_type: "prod",
347
+ file: "firmware-v2.0.0.bin",
348
+ size: 456789,
349
+ sha256: "a1b2c3...",
350
+ firmware_version: "2.0.0",
351
+ built: "2025-10-19T12:00:00Z",
352
+ ota_url: "https://firmware.example.com/v2.0.0.bin",
353
+
354
+ // Digital signature for authenticity
355
+ signature: "MEUCIQDx...",
356
+ signature_algorithm: "ECDSA-SHA256",
357
+ signing_key_id: "prod-signing-key-2025",
358
+
359
+ // Version constraints
360
+ min_version: "1.5.0", // Minimum version to upgrade from
361
+ max_version: "1.9.99", // Prevent downgrades
362
+
363
+ // Release management
364
+ release_notes_url: "https://docs.example.com/v2.0.0",
365
+ criticality: "high", // low | medium | high | critical
366
+ mandatory: true, // Must be installed
367
+
368
+ // Staged rollout
369
+ rollout_percentage: 25, // Start with 25% of fleet
370
+ rollout_target_groups: ["beta-testers", "early-adopters"],
371
+
372
+ // Delta updates (60-90% bandwidth reduction)
373
+ delta_from_version: "1.9.0",
374
+ delta_patch_url: "https://firmware.example.com/patches/1.9.0-to-2.0.0.patch",
375
+ delta_patch_size: 45678,
376
+ delta_patch_sha256: "c3d4e5..."
377
+ }
378
+ }
379
+ };
380
+ ```
381
+
382
+ **Firmware Update Status Tracking:**
383
+ ```ts
384
+ import { validators, isFirmwareStatusMessage } from '@alteriom/mqtt-schema';
385
+
386
+ // Enhanced status tracking
387
+ const status = {
388
+ schema_version: 1,
389
+ device_id: "SN789",
390
+ device_type: "sensor",
391
+ timestamp: new Date().toISOString(),
392
+ firmware_version: "2.0.0",
393
+
394
+ status: "downloading", // New: rolled_back, rollback_pending, rollback_failed
395
+ progress_pct: 42,
396
+
397
+ // Progress details
398
+ download_speed_kbps: 125.5,
399
+ bytes_downloaded: 196608,
400
+ bytes_total: 456789,
401
+ eta_seconds: 28,
402
+
403
+ // Rollback support
404
+ rollback_available: true,
405
+ previous_version: "1.9.0",
406
+
407
+ // Security verification
408
+ update_type: "delta", // full | delta | patch
409
+ signature_verified: true,
410
+ checksum_verified: true,
411
+
412
+ // Operational context
413
+ battery_level_pct: 85,
414
+ free_space_kb: 2048,
415
+ retry_count: 0
416
+ };
417
+
418
+ const result = validators.firmwareStatus(status);
419
+ if (result.valid) {
420
+ console.log(`Download progress: ${status.progress_pct}% at ${status.download_speed_kbps} kbps`);
421
+ console.log(`ETA: ${status.eta_seconds} seconds`);
422
+ }
423
+ ```
424
+
425
+ **OTA Best Practices:**
426
+ - **Security**: Always use digital signatures for production firmware
427
+ - **Rollback**: Maintain backup partition for automatic rollback on failures
428
+ - **Delta Updates**: Use delta patches for bandwidth-constrained deployments (60-90% reduction)
429
+ - **Staged Rollout**: Start with 5-10% rollout, monitor, then expand gradually
430
+ - **Version Control**: Use min_version to prevent upgrades from incompatible versions
431
+ - **Criticality**: Mark security patches as "critical" with mandatory: true
432
+
433
+ See `docs/OTA_MANIFEST.md` for comprehensive guide and best practices.
434
+
187
435
  ## API Surface
188
436
 
189
437
  ```ts
@@ -1,9 +1,24 @@
1
1
  /**
2
2
  * Auto-generated TypeScript types for Alteriom MQTT Schema v1
3
3
  * Source: docs/mqtt_schema/*.schema.json
4
- * Generation Date: 2025-09-20
4
+ * Generation Date: 2025-10-19
5
5
  * NOTE: This file is maintained in firmware repo for UI alignment. Changes require coordinated review.
6
6
  */
7
+ export interface LocationInfo {
8
+ latitude?: number;
9
+ longitude?: number;
10
+ altitude?: number;
11
+ accuracy_m?: number;
12
+ zone?: string;
13
+ description?: string;
14
+ [k: string]: unknown;
15
+ }
16
+ export interface EnvironmentInfo {
17
+ deployment_type?: 'indoor' | 'outdoor' | 'mobile' | 'mixed';
18
+ power_source?: 'battery' | 'mains' | 'solar' | 'mixed' | 'other';
19
+ expected_battery_life_days?: number;
20
+ [k: string]: unknown;
21
+ }
7
22
  export interface BaseEnvelope {
8
23
  schema_version: 1;
9
24
  device_id: string;
@@ -11,6 +26,8 @@ export interface BaseEnvelope {
11
26
  timestamp: string;
12
27
  firmware_version?: string;
13
28
  hardware_version?: string;
29
+ location?: LocationInfo;
30
+ environment?: EnvironmentInfo;
14
31
  [k: string]: unknown;
15
32
  }
16
33
  export interface SensorEntry {
@@ -22,6 +39,14 @@ export interface SensorEntry {
22
39
  name?: string;
23
40
  location?: string;
24
41
  additional_data?: Record<string, unknown>;
42
+ timestamp?: string;
43
+ accuracy?: number;
44
+ last_calibration?: string;
45
+ error_margin_pct?: number;
46
+ operational_range?: {
47
+ min: number;
48
+ max: number;
49
+ };
25
50
  [k: string]: unknown;
26
51
  }
27
52
  export interface SensorDataMessage extends BaseEnvelope {
@@ -67,6 +92,16 @@ export interface GatewayMetricsMessage extends BaseEnvelope {
67
92
  mesh_nodes?: number;
68
93
  packet_loss_pct?: number;
69
94
  data_throughput_kbps?: number;
95
+ storage_usage_pct?: number;
96
+ storage_total_mb?: number;
97
+ storage_free_mb?: number;
98
+ network_rx_kbps?: number;
99
+ network_tx_kbps?: number;
100
+ active_connections?: number;
101
+ error_count_24h?: number;
102
+ warning_count_24h?: number;
103
+ restart_count?: number;
104
+ last_restart_reason?: string;
70
105
  [k: string]: unknown;
71
106
  };
72
107
  }
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Auto-generated TypeScript types for Alteriom MQTT Schema v1
4
4
  * Source: docs/mqtt_schema/*.schema.json
5
- * Generation Date: 2025-09-20
5
+ * Generation Date: 2025-10-19
6
6
  * NOTE: This file is maintained in firmware repo for UI alignment. Changes require coordinated review.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });