Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
usp-js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WebSDK
usp-js
Commits
39de3af0
Commit
39de3af0
authored
4 years ago
by
Marin Karamihalev
Browse files
Options
Downloads
Patches
Plain Diff
Improved README
parent
cf950b8d
No related branches found
Branches containing commit
Tags
0.0.4
Tags containing commit
No related merge requests found
Pipeline
#8600
failed
4 years ago
Stage: install
Stage: unit-testing
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+103
-1
103 additions, 1 deletion
README.md
src/index.ts
+2
-2
2 additions, 2 deletions
src/index.ts
src/types.d.ts
+1
-1
1 addition, 1 deletion
src/types.d.ts
with
106 additions
and
4 deletions
README.md
+
103
−
1
View file @
39de3af0
...
...
@@ -4,10 +4,13 @@ Helper library for easy usp communication using mqtt over tcp or ws.
[
USP Reference
](
https://usp-data-models.broadband-forum.org/tr-181-2-13-0-usp.html
)
# Installation
`npm install usp-js`
# Usage
```
javascript
const
connect
=
require
(
"
usp-js
"
);
const
connect
=
require
(
"
usp-js
"
)
.
default
;
const
options
=
{
host
:
"
192.168.1.1
"
,
...
...
@@ -30,3 +33,102 @@ const run = async () => {
run
();
```
# API
-
Connect
```
javascript
// options are based on https://github.com/mqttjs/MQTT.js#mqttconnecturl-options
const
device
=
await
connect
(
options
);
```
-
Get
-
get object - all object end with a dot
```
javascript
await
device
.
get
(
"
Device.Time.
"
);
// => {
// "CurrentLocalTime": "2020-12-15T12:33:19Z",
// "Enable": true,
// ...
// }
```
- get property
```javascript
await device.get("Device.Time.CurrentLocalTime"); // => "2020-12-15T12:33:19Z"
```
- get multiple paths
```javascript
await device.get(["Device.WiFi.Radio.1.", "Device.WiFi.Radio.2."]);
// => [
// { ... },
// { ... }
// ]
```
- get using pattern
```javascript
await device.get('Device.Ethernet.Interface.[Alias=="WAN"].CurrentBitRate'); // => 0
```
- resolve references in get
```javascript
await device.get("Device.WiFi.Radio.1.").then(device.resolve); // => { ... }
// or if deeper resolution is needed (be careful when using level, going above 3 often causes an infinite reference loop)
await device.get("Device.WiFi.Radio.1.").then(msg => device.resolve(msg, 3 /* level - defaults to 1 */)); // => { ... }
```
-
Set
-
set object - does not need to have all attributes, but some may be required (check USP Reference)
```
javascript
await
device
.
set
(
"
Device.WiFi.Radio.1.
"
,
{
Name
:
"
radio-1
"
});
// => void
```
-
set property
```
javascript
await
device
.
set
(
"
Device.WiFi.Radio.1.Name
"
,
"
radio-1
"
);
// => void
```
-
Operate - WIP (response message not working yet)
-
operate without no arguments
```
javascript
await
device
.
operate
(
"
Device.SelfTestDiagnostics()
"
);
```
-
operate with arguments (for required args check USP Reference)
```
javascript
await
device
.
operate
(
"
Device.IP.Diagnostics.IPPing()
"
,
{
Host
:
"
iopsys.eu
"
});
```
-
Add
-
add with no arguments - adds a new default object
<br>
```
javascript
await
device
.
add
(
"
Device.NAT.PortMapping.
"
);
// => "Device.NAT.PortMapping.3."
```
-
add with arguments - adds a new object with provided values
<br>
```
javascript
await
device
.
add
(
"
Device.NAT.PortMapping.
"
,
{
Description
:
"
webserver1-set
"
,
ExternalPort
:
"
80
"
,
Protocol
:
"
TCP
"
,
Interface
:
"
Device.IP.Interface.1
"
,
Enable
:
"
true
"
,
InternalClient
:
"
192.168.1.125
"
,
InternalPort
:
"
5000
"
,
});
// => "Device.NAT.PortMapping.4."
```
-
Delete
```
javascript
await
device
.
del
(
"
Device.NAT.PortMapping.4.
"
);
// => void
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/index.ts
+
2
−
2
View file @
39de3af0
...
...
@@ -80,7 +80,7 @@ const makeSet = (send: SendFn) => (path: string, value: JSType) =>
path
)
as
Promise
<
void
>
;
const
makeAdd
=
(
send
:
SendFn
)
=>
(
path
:
string
,
input
:
JSObject
)
=>
const
makeAdd
=
(
send
:
SendFn
)
=>
(
path
:
string
,
input
?
:
JSObject
)
=>
handleSend
(
send
(
"
add
"
,
{
path
,
input
}),
path
)
as
Promise
<
string
>
;
const
makeDel
=
(
send
:
SendFn
)
=>
(
path
:
string
|
string
[])
=>
...
...
@@ -175,4 +175,4 @@ const connect = async (
};
};
export
default
connect
;
export
default
connect
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/types.d.ts
+
1
−
1
View file @
39de3af0
...
...
@@ -31,7 +31,7 @@ interface Device {
get
:
(
path
:
string
|
string
[])
=>
Promise
<
JSType
>
;
set
:
(
path
:
string
,
value
:
JSType
)
=>
Promise
<
void
>
;
operate
:
(
path
:
string
,
input
?:
JSObject
)
=>
Promise
<
JSType
>
;
add
:
(
path
:
string
,
values
:
JSObject
)
=>
Promise
<
string
>
;
add
:
(
path
:
string
,
values
?
:
JSObject
)
=>
Promise
<
string
>
;
del
:
(
path
:
string
|
string
[])
=>
Promise
<
void
>
;
resolve
:
(
msg
:
JSType
,
level
:
number
=
1
)
=>
Promise
<
JSType
>
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment