Overview
The Growatt SDK provideslogin() and logout() methods for session-based authentication with the Growatt API server. All API requests require an active authenticated session.
Login Method
Signature
true on successful authentication.
Parameters
Your Growatt account username
Your Growatt account password (will be MD5 hashed automatically)
Returns
Returns
Ok(true) on successful login, Ok(false) if already logged in with valid session, or Err(GrowattError) on failureBehavior
- If already logged in with a valid session, returns
trueimmediately without making a new request - Stores credentials internally for automatic session renewal
- Sets session expiry time based on configured session duration (default 30 minutes)
- Extracts and stores authentication token from the response
- Password is automatically hashed using MD5 before transmission
Example
Error Handling
The
login() method stores your credentials internally to enable automatic session renewal when the session expires.Logout Method
Signature
Returns
Returns
Ok(true) on successful logout, Ok(false) if no active session exists, or Err(GrowattError) on failureBehavior
- Clears session state and credentials
- Sets
is_logged_intofalse - Clears session expiry time
- Returns
falseif no active session exists (no-op) - Growatt API returns 302 redirect on successful logout
Example
Complete Authentication Workflow
Source Reference
login()implementation: src/lib.rs:161logout()implementation: src/lib.rs:248- Password hashing: src/lib.rs:151