marstek

package module
v0.0.0-...-99a45f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

Golang-based Marstek local API

Introduction

This Golang-based Marstek local API can connect to any Marstek local API enabled device like Marstek Venus A or Venus D/E.

For details have a look at the API documentation. It can be referenced here: https://godoc.org/github.com/tknie/marstek

Error table

Code Error message Description
-32700 Parse error Invalid JSON was received by the server.An error occurred on the server while parsing the JSON text
-32600 Invalid Request The JSON sent is not a valid Request object.
-32601 Method not found The method does not exist / is not available.
-32602 Invalid params Invalid method parameter(s).
-32603 Internal error Internal JSON-RPC error.
-32000 to -32099 Server error Reserved for implementation-defined server-errors.

Documentation

Index

Constants

View Source
const MaxManualSchedules = 10

MaxManualSchedules defines the maximum number of manual schedules that can be set for the device. This is based on the device's capabilities and ensures that we do not exceed the allowed number of schedules when clearing them.

Variables

View Source
var MaxRetries = 4

MaxRetries defines the maximum number of retry attempts when a read timeout occurs while waiting for a response from the device. This allows for multiple attempts to get a response in case of temporary issues with the device or network.

View Source
var ReadTimeout = 15

ReadTimeout defines the duration in seconds to wait for a response from the device before considering it a timeout. This is used to set the read deadline when waiting for a response, allowing for a reasonable amount of time for the device to respond before retrying or giving up.

View Source
var RetryDelay = 1

RetryDelay defines the delay in seconds between retry attempts when a read timeout occurs while waiting for a response from the device. This allows for a brief pause before retrying the request, which can help in cases where the device may be temporarily unresponsive or experiencing network issues.

Functions

This section is empty.

Types

type Marstek

type Marstek struct {
	Services   string
	Connection net.Conn
}

func New

func New(service string) *Marstek

New creates a new instance of the Marstek struct with the provided service address. It initializes the Services field with the given address and returns a pointer to the Marstek instance. This function is used to create a new Marstek object that can be used to interact with the device.

func (*Marstek) BluetoothLock

func (m *Marstek) BluetoothLock(enable bool) error

BluetoothLock sets the Bluetooth lock status of the device by sending a request to the device. It constructs a JSON request using a template and sends it to the device to update the Bluetooth lock settings. The method takes in a boolean parameter to enable or disable the Bluetooth lock and returns any error encountered during the process. The enable parameter determines whether to enable (true) or disable (false) the Bluetooth lock, and the method sends the appropriate request to the device based on the value of this parameter.

func (*Marstek) ClearManualSchedule

func (m *Marstek) ClearManualSchedule() error

ClearManualSchedule clears all manual schedules by sending a request to set each schedule to disabled with default values. It iterates through the maximum number of allowed manual schedules and sends a request for each one to ensure they are all cleared.

func (*Marstek) GetBatStatus

func (m *Marstek) GetBatStatus() (map[string]interface{}, error)

GetBatStatus retrieves the battery status of the device by sending a request to the device. It constructs a JSON request and sends it to the device to obtain the battery status information. The method returns the battery status as a map and any error encountered during the process.

func (*Marstek) GetBluetoothStatus

func (m *Marstek) GetBluetoothStatus() (map[string]interface{}, error)

GetBluetoothStatus retrieves the Bluetooth status of the device by sending a request to the device. It constructs a JSON request and sends it to the device to obtain the Bluetooth status information. The method returns the Bluetooth status as a map and any error encountered during the process.

func (*Marstek) GetDevice

func (m *Marstek) GetDevice(bleMac string) (map[string]interface{}, error)

GetDevice retrieves the device information by sending a request to the device using its BLE MAC address. It constructs a JSON request with the provided BLE MAC address and sends it to the device to obtain the device information. The method returns the device information as a map and any error encountered during the process.

func (*Marstek) GetEnergyMeterStatus

func (m *Marstek) GetEnergyMeterStatus() (map[string]interface{}, error)

GetEnergyMeterStatus retrieves the energy meter status of the device by sending a request to the device. It constructs a JSON request and sends it to the device to obtain the energy meter status information. The method returns the energy meter status as a map and any error encountered during the process.

func (*Marstek) GetEnergySystemStatus

func (m *Marstek) GetEnergySystemStatus() (map[string]interface{}, error)

GetEnergySystemStatus retrieves the energy system status of the device by sending a request to the device. It constructs a JSON request and sends it to the device to obtain the energy system status information. The method returns the energy system status as a map and any error encountered during the process.

func (*Marstek) GetMode

func (m *Marstek) GetMode() (map[string]interface{}, error)

GetMode retrieves the current mode of the device by sending a request to the device. It constructs a JSON request using a template and sends it to the device to obtain the mode information. The method returns the mode information as a map and any error encountered during the process.

func (*Marstek) GetPVStatus

func (m *Marstek) GetPVStatus() (map[string]interface{}, error)

GetPVStatus retrieves the photovoltaic (PV) status of the device by sending a request to the device. It constructs a JSON request and sends it to the device to obtain the PV status information. The method returns the PV status as a map and any error encountered during the process.

func (*Marstek) GetWifiStatus

func (m *Marstek) GetWifiStatus() (map[string]interface{}, error)

GetWifiStatus retrieves the Wi-Fi status of the device by sending a request to the device. It constructs a JSON request and sends it to the device to obtain the Wi-Fi status information. The method returns the Wi-Fi status as a map and any error encountered during the process.

func (*Marstek) LEDControl

func (m *Marstek) LEDControl(enable bool) error

LEDControl sets the LED control status of the device by sending a request to the device. It constructs a JSON request using a template and sends it to the device to update the LED control settings. The method takes in a boolean parameter to enable or disable the LED control and returns any error encountered during the process. The enable parameter determines whether to enable (true) or disable (false) the LED control, and the method sends the appropriate request to the device based on the value of this parameter.

func (*Marstek) PassivePowerConsumption

func (m *Marstek) PassivePowerConsumption(power, cdTime int) error

PassivePowerConsumption sets the environment power consumption by sending a request to the device. It constructs a JSON request using a template and sends it to the device to update the power consumption settings. The method takes in the desired power level and cooldown time as parameters and returns any error encountered during the process. The negative power value indicates the power consumption level into the battery, positive power value indicates the power output level from the battery, and zero means no power consumption or output.

func (*Marstek) SetAIMode

func (m *Marstek) SetAIMode(enable bool) error

SetAIMode sets the device to AI mode by sending a request to the device. It constructs a JSON request using a template and sends it to the device to update the mode settings. The method takes in a boolean parameter to enable or disable AI mode and returns any error encountered during the process.

func (*Marstek) SetAutoMode

func (m *Marstek) SetAutoMode(enable bool) error

SetAutoMode sets the device to auto mode by sending a request to the device. It constructs a JSON request using a template and sends it to the device to update the mode settings. The method returns any error encountered during the process.

func (*Marstek) SetDOD

func (m *Marstek) SetDOD(value int) error

SetDOD sets the depth of discharge (DOD) value for the device by sending a request to the device. It constructs a JSON request using a template and sends it to the device to update the DOD settings. The method takes in the desired DOD value as a parameter and returns any error encountered during the process. The DOD value must be between 33 and 88, and the method will return an error if the value is out of range.

func (*Marstek) SetManualSchedule

func (m *Marstek) SetManualSchedule(schedule *Schedule) error

SetManualSchedule sets a manual schedule for the device by sending a request to the device. It constructs a JSON request using a template and sends it to the device to update the manual schedule settings. The method takes in a Schedule struct as a parameter, which contains the schedule details, and returns any error encountered during the process.

func (*Marstek) SetUPSMode

func (m *Marstek) SetUPSMode(enable bool) error

SetUPSMode sets the device to UPS mode by sending a request to the device. It constructs a JSON request using a template and sends it to the device to update the mode settings. The method takes in a boolean parameter to enable or disable UPS mode and returns any error encountered during the process.

func (*Marstek) Summary

func (m *Marstek) Summary() (map[string]interface{}, error)

type Schedule

type Schedule struct {
	Id        int
	Power     int
	Enable    bool
	TimeNum   int
	StartTime string
	EndTime   string
	WeekSet   int
}

Directories

Path Synopsis
cmd
client command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL