Skip to content

Method GetDiagnosticsAsync

Namespace: Belay.Core.Examples
Assembly: Belay.Core.dll

GetDiagnosticsAsync()

Get device diagnostics and sensor health information.

csharp
[Task]
[PythonCode("\n        import json\n        import gc\n        import machine\n        import sys\n        \n        # Collect system diagnostics\n        diagnostics = {\n            'systemInfo': {\n                'platform': sys.platform,\n                'version': sys.version,\n                'freqMHz': machine.freq() // 1000000,\n                'freeMemory': gc.mem_free(),\n                'resetCause': machine.reset_cause()\n            },\n            'sensorStatus': {\n                'readingCount': globals().get('reading_count', 0),\n                'errorCount': globals().get('error_count', 0),\n                'lastReadingTime': globals().get('last_reading_time', 0),\n                'monitoringActive': globals().get('monitoring_active', False)\n            },\n            'calibration': globals().get('sensor_calibration', {}),\n            'alerts': globals().get('alert_thresholds', {})\n        }\n        \n        # Add sensor health checks\n        try:\n            # Test temperature sensor\n            temp_raw = temp_adc.read_u16()\n            diagnostics['sensorStatus']['tempSensorRaw'] = temp_raw\n            diagnostics['sensorStatus']['tempSensorOk'] = 1000 < temp_raw < 60000\n            \n            # Test light sensor  \n            light_raw = light_adc.read_u16()\n            diagnostics['sensorStatus']['lightSensorRaw'] = light_raw\n            diagnostics['sensorStatus']['lightSensorOk'] = light_raw > 0\n            \n            # Test I2C humidity sensor\n            i2c.scan()  # This will throw if I2C is not working\n            diagnostics['sensorStatus']['humiditySensorOk'] = 0x44 in i2c.scan()\n            \n        except Exception as e:\n            diagnostics['sensorStatus']['healthCheckError'] = str(e)\n        \n        json.dumps(diagnostics)\n    ", EnableParameterSubstitution = false)]
Task<Dictionary<string, object>> GetDiagnosticsAsync()

Returns

Task<Dictionary<string, object>>

Released under the Apache License 2.0.