huawei

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

README

huawei-mini-library

Go Reference

Package huawei provides a lightweight interface for communicating with the Huawei E5336B dongle.

This package simplifies interaction with the Huawei E5336B dongle by offering a minimal API for device communication, SMS management, and connection monitoring.

thanks to max246

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ERROR_LOGIN_ALREADY_LOGIN = 108003
View Source
var ERROR_LOGIN_PASSWORD_WRONG = 108002
View Source
var ERROR_LOGIN_USERNAME_PWD_ORERRUN = 108007
View Source
var ERROR_LOGIN_USERNAME_PWD_WRONG = 108006
View Source
var ERROR_LOGIN_USERNAME_WRONG = 108001
View Source
var ERROR_SYSTEM_BUSY = 100004
View Source
var ERROR_SYSTEM_NO_RIGHTS = "100003"
View Source
var ERROR_SYSTEM_NO_SUPPORT = 100002
View Source
var ERROR_VOICE_BUSY = 120001
View Source
var ERROR_WRONG_TOKEN = 125001

Functions

This section is empty.

Types

type ConnectionStatusResponse

type ConnectionStatusResponse struct {
	XMLName              xml.Name `xml:"response"`
	ConnectionStatus     string   `xml:"ConnectionStatus"`
	SignalStrength       string   `xml:"SignalStrength"`
	SignalIcon           string   `xml:"SignalIcon"`
	CurrentNetworkType   string   `xml:"CurrentNetworkType"`
	CurrentServiceDomain string   `xml:"CurrentServiceDomain"`
	RoamingStatus        string   `xml:"RoamingStatus"`
	BatteryStatus        string   `xml:"BatteryStatus"`
	BatteryLevel         string   `xml:"BatteryLevel"`
	SimlockStatus        string   `xml:"SimlockStatus"`
	WanIPAddress         string   `xml:"WanIPAddress"`
	PrimaryDNS           string   `xml:"PrimaryDns"`
	SecondaryDNS         string   `xml:"SecondaryDns"`
	CurrentWifiUser      string   `xml:"CurrentWifiUser"`
	TotalWifiUser        string   `xml:"TotalWifiUser"`
	ServiceStatus        string   `xml:"ServiceStatus"`
	SimStatus            string   `xml:"SimStatus"`
	WifiStatus           string   `xml:"WifiStatus"`
}

type ErrorResponse

type ErrorResponse struct {
	XMLName xml.Name
}

type Huawei

type Huawei struct {
	IP string
	// contains filtered or unexported fields
}

func NewHuawei

func NewHuawei(ip string) *Huawei

func (*Huawei) Connect

func (h *Huawei) Connect() error

Connect establishes a connection to the Huawei device by sending a POST request to the /api/dialup/dial endpoint with a predefined payload. It returns an error if the request fails or if the response indicates a failure.

Returns:

  • error: An error object if the connection attempt fails, otherwise nil.

func (*Huawei) DeleteSMS

func (h *Huawei) DeleteSMS(index int) error

DeleteSMS deletes an SMS message from the Huawei device by its index. It sends a POST request to the "/api/sms/delete-sms" endpoint with the specified index.

Parameters:

  • index: The index of the SMS message to be deleted.

Returns:

  • error: An error if the request fails or if the response indicates a failure.

func (*Huawei) Disconnect

func (h *Huawei) Disconnect() error

Disconnect sends a request to disconnect the Huawei device. It constructs an XML payload with the action to disconnect, sends the request to the "/api/dialup/dial" endpoint, and checks the response for errors.

Returns an error if the request fails or if the response indicates a failure to disconnect.

func (*Huawei) GetConnectionStatus

func (h *Huawei) GetConnectionStatus() ([]string, error)

GetConnectionStatus retrieves the current connection status from the Huawei device. It sends a GET request to the /api/monitoring/status endpoint and parses the XML response.

Returns a slice of strings containing various connection status details, or an error if the request fails or the response cannot be parsed.

The returned slice contains the following elements in order: - ConnectionStatus - SignalStrength - SignalIcon - CurrentNetworkType - CurrentServiceDomain - RoamingStatus - BatteryStatus - BatteryLevel - SimlockStatus - WanIPAddress - PrimaryDNS - SecondaryDNS - CurrentWifiUser - TotalWifiUser - ServiceStatus - SimStatus - WifiStatus

Returns: - []string: A slice of strings containing the connection status details. - error: An error if the request fails or the response cannot be parsed.

func (*Huawei) GetSmsCount

func (h *Huawei) GetSmsCount() ([]string, error)

GetSmsCount retrieves the count of SMS messages from the Huawei device. It sends a GET request to the /api/sms/sms-count endpoint and parses the response.

Returns a slice of strings containing the counts of various SMS categories: - LocalUnread: Count of unread messages in local storage. - LocalInbox: Count of messages in the local inbox. - LocalOutbox: Count of messages in the local outbox. - LocalDraft: Count of draft messages in local storage. - LocalDeleted: Count of deleted messages in local storage. - SimUnread: Count of unread messages on the SIM card. - SimInbox: Count of messages in the SIM card inbox. - SimOutbox: Count of messages in the SIM card outbox. - SimDraft: Count of draft messages on the SIM card. - LocalMax: Maximum number of messages that can be stored locally. - SimMax: Maximum number of messages that can be stored on the SIM card.

Returns an error if the request fails or the response cannot be parsed.

func (*Huawei) GetSmsList

func (h *Huawei) GetSmsList() ([]SMS, error)

GetSmsList retrieves a list of SMS messages from the Huawei device. It sends a POST request to the /api/sms/sms-list endpoint with the necessary payload. The function returns a slice of SMS messages and an error if any occurred during the process.

Returns:

  • []SMS: A slice of SMS messages retrieved from the device.
  • error: An error if the request failed or the response could not be unmarshaled.

func (*Huawei) GetToken

func (h *Huawei) GetToken() error

GetToken retrieves a token from the Huawei web server. It sends a GET request to the /api/webserver/token endpoint and parses the XML response to extract the token. The token is then stored in the Huawei struct's token field. Returns an error if the request fails, the response cannot be read, or the XML cannot be unmarshaled.

func (*Huawei) IsConnected

func (h *Huawei) IsConnected() (bool, error)

IsConnected checks the connection status of the Huawei device. It returns true if the device is connected (status code "901"), otherwise false. If there is an error retrieving the connection status, it returns false along with the error.

func (*Huawei) Login

func (h *Huawei) Login(username, password string) error

Login authenticates a user with the provided username and password. It encodes the password in base64, constructs an XML payload, and sends a POST request to the Huawei API endpoint for user login. The function sets necessary headers, including a request verification token obtained from the GetToken method. It reads and parses the XML response to determine the login status and returns an error if authentication fails.

Parameters:

  • username: The username for authentication.
  • password: The password for authentication.

Returns:

  • error: An error if the login process fails, otherwise nil.

func (*Huawei) SendSMS

func (h *Huawei) SendSMS(msg, phone string) error

SendSMS sends an SMS message to a specified phone number using the Huawei API. It constructs an XML payload with the message details and sends an HTTP POST request.

Parameters:

  • msg: The message content to be sent.
  • phone: The recipient's phone number.

Returns:

  • error: An error if the SMS sending fails, otherwise nil.

type Response

type Response struct {
	XMLName xml.Name `xml:"response"`
	Status  string   `xml:",chardata"`
}

type SMS

type SMS struct {
	Smstat   string `xml:"Smstat"`
	Index    string `xml:"Index"`
	Phone    string `xml:"Phone"`
	Content  string `xml:"Content"`
	Date     string `xml:"Date"`
	Sca      string `xml:"Sca"`
	SaveType string `xml:"SaveType"`
	Priority string `xml:"Priority"`
	SmsType  string `xml:"SmsType"`
}

type SMSCountResponse

type SMSCountResponse struct {
	XMLName      xml.Name `xml:"response"`
	LocalUnread  string   `xml:"LocalUnread"`
	LocalInbox   string   `xml:"LocalInbox"`
	LocalOutbox  string   `xml:"LocalOutbox"`
	LocalDraft   string   `xml:"LocalDraft"`
	LocalDeleted string   `xml:"LocalDeleted"`
	SimUnread    string   `xml:"SimUnread"`
	SimInbox     string   `xml:"SimInbox"`
	SimOutbox    string   `xml:"SimOutbox"`
	SimDraft     string   `xml:"SimDraft"`
	LocalMax     string   `xml:"LocalMax"`
	SimMax       string   `xml:"SimMax"`
}

type SMSListResponse

type SMSListResponse struct {
	XMLName  xml.Name `xml:"response"`
	Count    int      `xml:"Count"`
	Messages []SMS    `xml:"Messages>Message"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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