-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys.go
284 lines (217 loc) · 8.25 KB
/
sys.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package shelly
import (
"context"
"encoding/json"
"github.com/mongoose-os/mos/common/mgrpc"
"github.com/mongoose-os/mos/common/mgrpc/frame"
)
type SysGetConfigRequest struct{}
func (r *SysGetConfigRequest) Method() string {
return "Sys.GetConfig"
}
func (r *SysGetConfigRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*SysConfig,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
func (r *SysGetConfigRequest) NewTypedResponse() *SysConfig {
return &SysConfig{}
}
func (r *SysGetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
type SysSetConfigRequest struct {
// Config sets the updated system config.
Config SysConfig `json:"config"`
}
func (r *SysSetConfigRequest) Method() string {
return "Sys.SetConfig"
}
func (r *SysSetConfigRequest) 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
}
func (r *SysSetConfigRequest) NewTypedResponse() *SetConfigResponse {
return &SetConfigResponse{}
}
func (r *SysSetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
type SysGetStatusRequest struct{}
func (r *SysGetStatusRequest) Method() string {
return "Sys.GetStatus"
}
func (r *SysGetStatusRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*SysStatus,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
func (r *SysGetStatusRequest) NewTypedResponse() *SysStatus {
return &SysStatus{}
}
func (r *SysGetStatusRequest) NewResponse() any {
return r.NewTypedResponse()
}
type SysConfig struct {
// Device contains information about the device.
Device *SysDeviceConfig `json:"device,omitempty"`
// Location contains information about the current location of the device.
Location *SysLocationConfig `json:"location,omitempty"`
// Debug contains information about the device's debug logs.
Debug *SysDebugConfig `json:"debug,omitempty"`
// UI_Data contains user interface data. NOTE: the existance of this field is documented,
// but not the contents.
UI_Data json.RawMessage `json:"ui_data,omitempty"`
// RPC_UDP is the configuration for the RPC over UDP.
RPC_UDP *SysRPC_UDP_Config `json:"rpc_udp,omitempty"`
// SNTP is configuration for the SNTP (time) server.
SNTP *SysSNTP_Config `json:"sntp,omitempty"`
// CfgRev is the configuration revision number. This number will be incremented for every
// configuration change of a device component. If the new config value is the same as the
// old one there will be no change of this property. Can not be modified explicitly by a call
// to Sys.SetConfig.
CfgRev int `json:"cfg_rev,omitempty"`
}
type SysDeviceConfig struct {
// Name of the device.
Name *string `json:"name"`
// EcoMode (experimental) decreases power consumption when set to true, at the cost of reduced
// execution speed and increased network latency.
EcoMode bool `json:"eco_mode"`
// MAC base MAC address of the device (Read-only).
Mac string `json:"mac"`
// FW_ID is the build identifier of the current firmware image.
FW_ID string `json:"fw_id"`
// Profile is the name of the device profile (only applicable for multi-profile devices)
Profile *string `json:"profile,omitempty"`
// Discoverable if true, device is shown in 'Discovered devices'. If false, the device is hidden.
Discoverable bool `json:"discoverable"`
// AddOnType enables/disables addon board (if supported). Range of values: sensor, prooutput;
// null to disable.
AddOnType *string `json:"addon_type,omitempty"`
}
type SysLocationConfig struct {
// TZ is the timezone or null if unavailable.
TZ *string `json:"tz"`
// Lat is the latitude in degress or null if unavailable.
Lat *float64 `json:"lat"`
// Lon is the longitude in degress or null if unavailable.
Lon *float64 `json:"lon"`
}
type SysDebugConfig struct {
// MQTT contains configuration of logs streamed over MQTT.
MQTT SysDebugConfigMQTT `json:"mqtt"`
// Websocket contains configuration of logs stream over websocket.
Websocket SysDebugConfigWebsocket `json:"websocket"`
// UDP contains configuration of logs streamed over UDP
UDP SysDebugConfigUDP `json:"udp"`
// Level is not documented but appears in output.
Level int `json:"level"`
// FileLevel is not documented but appears in output.
FileLevel interface{} `json:"file_level"`
}
type SysDebugConfigMQTT struct {
// Enable will cause logs to be exported over MQTT if true.
Enable bool `json:"enable"`
}
type SysDebugConfigWebsocket struct {
// Enable will cause logs to be exported over websocket if true.
Enable bool `json:"enable"`
}
type SysDebugConfigUDP struct {
// Addr is the address that the device log is streamed to (null to disable logs).
Addr *string `json:"addr"`
}
type SysRPC_UDP_Config struct {
// DstAddr is the destination address for UDP.
DstAddr *string `json:"dst_addr"`
// ListenPort is the port number for inbound UDP RPC channel, null disables. Restart is
// required for changes to apply
ListenPort *int `json:"listen_port"`
}
type SysSNTP_Config struct {
// Server is the name of the SNTP (time) server.
Server string `json:"server"`
}
type SysStatus struct {
// Mac address of the device.
Mac string `json:"mac"`
// RestartRequired will be true if a restart or update requires a system restart before going
// into effect.
RestartRequired bool `json:"restart_required"`
// Time in the format HH:MM (24-hour time format in the current timezone with leading zero). null
// when time is not synced from NTP server.
Time *string `json:"time"`
// UnixTime is the timestamp (in UTC), null when time is not synced from NTP server.
UnixTime *int `json:"unixtime"`
// Uptime is the time in seconds since last reboot.
Uptime float64 `json:"uptime"`
// RamSize is the total size of the RAM in the system in Bytes.
RamSize int `json:"ram_size"`
// RamFree is the size of the free RAM in the system in Bytes
RamFree int `json:"ram_free"`
// FS_Size is the total size of the file system in Bytes.
FS_Size int `json:"fs_size"`
// FS_Free is the size of the free file system in Bytes.
FS_Free int `json:"fs_free"`
// CfgRev is the configuration revision number.
CfgRev int `json:"cfg_rev"`
// KVRev is the KVS (Key-Value Store) revision number.
KVRev int `json:"kvs_rev"`
// SchedulesRev is the revision number, present if schedules are enabled.
ScheduleRev *int `json:"schedule_rev"`
// WebhookRev is the revision number, present if webhooks are enabled.
WebhookRev *int `json:"webhook_rev"`
// Information about available updates, similar to the one returned by Shelly.CheckForUpdate
// (empty object: {}, if no updates available). This information is automatically updated every
// 24 hours. Note that build_id and url for an update are not displayed here
AvailableUpdates *AvailableUpdates `json:"available_updates,omitempty"`
// WakeUpReason contains information about boot type and cause (only for battery-operated devices).
WakeUpReason *WakeUpReason `json:"wakeup_reason,omitempty"`
// Period (in seconds) at which device wakes up and sends "keep-alive" packet to cloud,
// readonly. Count starts from last full wakeup.
WakeUpPeriod float64 `json:"wakeup_period,omitempty"`
// SafeMode is True if device is oprating in Safe Mode and is only present in this mode.
SafeMode *bool `json:"safe_mode,omitempty"`
// ResetReason is not documented, but appears in 1.1.0 responses.
ResetReason *int `json:"reset_reason,omitempty"`
}
type WakeUpReason struct {
// Boot type, one of: poweron, software_restart, deepsleep_wake, internal (e.g. brownout
// detection, watchdog timeout, etc.), unknown.
Boot string `json:"boot"`
// Boot cause, one of: button, usb, periodic, status_update, alarm, alarm_test, undefined
// (in case of deep sleep, reset was not caused by exit from deep sleep).
Cause string `json:"cause"`
}
type AvailableUpdates struct {
// Stable indicates the new stable version of the firmware.
Stable *FirmwareUpdateVersion `json:"stable,omitempty"`
// Beta indicates the new beta version of the firmware.
Beta *FirmwareUpdateVersion `json:"beta,omitempty"`
}