Skip to main content

Overview

Retrieves fault logs for a specific device at a plant. This method allows you to query device errors and warnings with filtering options by date, device type, and fault type.
get_plant_fault_logs() is an alias method that calls get_fault_logs() with identical parameters. Both methods can be used interchangeably.

Method Signature

pub async fn get_fault_logs(
    &mut self,
    plant_id: &str,
    date: Option<&str>,
    device_sn: &str,
    page_num: i32,
    device_flag: i32,
    fault_type: i32
) -> Result<serde_json::Value>

// Alias for backward compatibility
pub async fn get_plant_fault_logs(
    &mut self,
    plant_id: &str,
    date: Option<&str>,
    device_sn: &str,
    page_num: i32,
    device_flag: i32,
    fault_type: i32
) -> Result<serde_json::Value>

Parameters

plant_id
&str
required
The unique identifier of the plant. This parameter cannot be empty.
date
Option<&str>
The date for which to retrieve fault logs in YYYY-MM-DD format. If None is provided, the current date will be used automatically.
device_sn
&str
required
The serial number of the device to query. Can be an empty string to query all devices.
page_num
i32
required
The page number for paginated results. Use 1 for the first page.
device_flag
i32
required
Device type identifier. See the Device Flag Values section below for valid values.
fault_type
i32
required
Type of fault to filter by. See the Fault Type Values section below for valid values.

Returns

Returns a Result<serde_json::Value> containing the fault log data on success, or a GrowattError on failure.

Errors

This method may return the following errors:
  • GrowattError::InvalidResponse - If the plant ID is empty, or if the response is empty or null
  • GrowattError::NetworkError - If there is a network communication error
  • GrowattError::AuthenticationError - If the session has expired or authentication failed

Device Flag Values

The device_flag parameter specifies the type of device to query:
  • 0 - All devices
  • 1 - Inverter
  • 2 - Storage (Battery)
  • 3 - MAX (AC coupled storage)
  • 4 - MIX (Hybrid inverter)
  • 5 - SPA (Smart Plug)
  • 6 - Environmental sensor

Fault Type Values

The fault_type parameter specifies the severity or category of faults:
  • 0 - All fault types
  • 1 - Errors only
  • 2 - Warnings only
  • 3 - Information messages

Example

use growatt_rs::GrowattApi;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut api = GrowattApi::new()?;
    
    // Login first
    api.login("username", "password").await?;
    
    let plant_id = "123456";
    let device_sn = "ABC123DEF456";
    
    // Get fault logs for today, all fault types, inverter devices
    let logs = api.get_fault_logs(
        plant_id,
        None,           // Use current date
        device_sn,
        1,              // First page
        1,              // Inverter devices
        0               // All fault types
    ).await?;
    
    println!("Fault logs: {:?}", logs);
    
    // Or use the alias method
    let logs = api.get_plant_fault_logs(
        plant_id,
        Some("2024-03-15"),
        device_sn,
        1,
        4,              // MIX devices
        1               // Errors only
    ).await?;
    
    println!("Error logs: {:?}", logs);
    
    Ok(())
}

Query All Devices

To query fault logs for all devices in a plant, pass an empty string for device_sn and 0 for device_flag:
let logs = api.get_fault_logs(
    plant_id,
    None,
    "",             // Empty string for all devices
    1,
    0,              // All device types
    0               // All fault types
).await?;

Pagination

Fault logs are returned in paginated format. To retrieve subsequent pages, increment the page_num parameter:
// Get first page
let page1 = api.get_fault_logs(plant_id, None, device_sn, 1, 1, 0).await?;

// Get second page
let page2 = api.get_fault_logs(plant_id, None, device_sn, 2, 1, 0).await?;
This method automatically checks if you are logged in before making the request. If the session has expired, you will need to call login() again.

Build docs developers (and LLMs) love