Skip to main content

Update Health

Description

The update_health function updates the most recent health report for a device on the web service. It sends a new JSON payload containing updated status information for the device.

Function Signature:

def update_health(ws_config: WebServiceConfig, device_name: str, health_json: str) -> WebServiceResult:

Parameters

  • ws_config (WebServiceConfig): Configuration object for the web service.
  • device_name (str): The name or serial number of the device updating its health report.
  • health_json (str): A JSON-formatted string containing the updated health data for the device.

Returns

  • WebServiceResult: The result of the web service request, which includes:
    • http_response_code: The HTTP response code from the server (e.g., 200 for success).
    • http_response_string: The raw response body returned by the server.
    • json_data: The parsed JSON response data, if available.

Example Usage

ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
device_name = "Drone-42"
health_data = {
"gpsFix": true,
"networkStrength": 78,
"internalTemp": 64.2
}
result = update_health(ws_config, device_name, json.dumps(health_data))
print(result.http_response_code, result.json_data)

Behavior

  • Sends a POST request to the v1/devicehealth/updatelatest endpoint.
  • The request body contains a JSON object with deviceName and healthJSON.
  • The endpoint is expected to update the latest health report for the specified device.
  • Returns a WebServiceResult with HTTP status, response content, and parsed JSON data if present.

Error Handling

  • General Exception: If an error occurs during request preparation or sending, the function logs the exception, sets code to -1, and fills the description field with the error message.