-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi.go
188 lines (145 loc) · 4.87 KB
/
wifi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package shelly
import (
"context"
"github.com/mongoose-os/mos/common/mgrpc"
"github.com/mongoose-os/mos/common/mgrpc/frame"
)
type WifiStatus struct {
// StaIP is the IP of the device in the network (null if disconnected).
StaIP *string `json:"sta_ip,omitempty"`
// Status of the connection. Range of values: disconnected, connecting, connected, got ip
Status string `json:"status,omitempty"`
// SSID of the network (null if disconnected)
SSID *string `json:"ssid,omitempty"`
// RSSI is the strength of the signal in dBms.
RRSI *float64 `json:"rssi,omitempty"`
// APClientCount is the number of clients connected to the access point. Present only when
// AP is enabled and range extender functionality is present and enabled.
APClientCount *int `json:"ap_client_count,omitempty"`
}
type WifiGetStatusRequest struct{}
func (r *WifiGetStatusRequest) Method() string {
return "Wifi.GetStatus"
}
func (r *WifiGetStatusRequest) NewTypedResponse() *WifiStatus {
return &WifiStatus{}
}
func (r *WifiGetStatusRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *WifiGetStatusRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*WifiStatus,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
type WifiConfig struct {
// AP is information about the access point.
AP *WifiAPConfig `json:"ap,omitempty"`
// STA is the wifi station config.
STA *WifiStationConfig `json:"sta,omitempty"`
// STA1 will be used as fallback when the device is unable to connect to the sta network.
STA1 *WifiStationConfig `json:"sta1,omitempty"`
Roam *WifiRoamConfig `json:"roam,omitempty"`
}
type WifiAPConfig struct {
// SSID is the readonly SSID of the access point
SSID *string `json:"ssid,omitempty"`
// Pass is the password for the ssid, writeonly. Must be provided if you provide ssid.
Pass *string `json:"pass,omitempty"`
// IsOpen is true if the access point is open, false otherwise.
IsOpen *bool `json:"is_open,omitempty"`
// Enable is true if the access point is enabled, false otherwise
Enable *bool `json:"enable,omitempty"`
// RangeExtender configuration object, available only when range extender functionality
// is present.
RangeExtender *WifiAPRangeExtenderConfig `json:"range_extender,omitempty"`
}
type WifiAPRangeExtenderConfig struct {
// Enable is true if range extender functionality is enabled, false otherwise
Enable *bool `json:"enable,omitempty"`
}
type WifiStationConfig struct {
// SSID of the network.
SSID *string `json:"ssid,omitempty"`
// Pass is the password for the ssid, writeonly. Must be provided if you provide ssid.
Pass *string `json:"pass,omitempty"`
// IsOpen is true if the network is open, i.e. no password is set, false otherwise,
// readonly.
IsOpen *bool `json:"is_open,omitempty"`
// Enable is true if the configuration is enabled, false otherwise.
Enable *bool `json:"enable,omitempty"`
// IPv4Mode Range of values: dhcp, static
IPv4Mode *string `json:"ipv4mode,omitempty"`
// IP to use when ipv4mode is static.
IP *string `json:"ip,omitempty"`
// Netmask to use when ipv4mode is static
Netmask *string `json:"netmask,omitempty"`
// GW is the gateway to use when ipv4mode is static
GW *string `json:"gw,omitempty"`
// Nameserver to use when ipv4mode is static
Nameserver *string `json:"nameserver,omitempty"`
}
type WifiRoamConfig struct {
// RSSI_Thr is the RSSI threshold - when reached will trigger the access point
// roaming. Default value: -80
RSSI_Thr *float64 `json:"rssi_thr,omitempty"`
// Interval at which to scan for better access points. Enabled if set to positive
// number, disabled if set to 0. Default value: 60
Interval *float64 `json:"interval,omitempty"`
}
type WifiGetConfigRequest struct{}
func (r *WifiGetConfigRequest) Method() string {
return "Wifi.GetConfig"
}
func (r *WifiGetConfigRequest) NewTypedResponse() *WifiConfig {
return &WifiConfig{}
}
func (r *WifiGetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *WifiGetConfigRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*WifiConfig,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
type WifiSetConfigRequest struct {
Config WifiConfig `json:"config"`
}
func (r *WifiSetConfigRequest) Method() string {
return "Wifi.SetConfig"
}
func (r *WifiSetConfigRequest) NewTypedResponse() *SetConfigResponse {
return &SetConfigResponse{}
}
func (r *WifiSetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *WifiSetConfigRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*SetConfigResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}