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
8022cacf
Commit
8022cacf
authored
4 years ago
by
Marin Karamihalev
Browse files
Options
Downloads
Patches
Plain Diff
README: Re-added new connection requirements
parent
7d36b408
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+65
-47
65 additions, 47 deletions
README.md
package.json
+1
-1
1 addition, 1 deletion
package.json
with
66 additions
and
48 deletions
README.md
+
65
−
47
View file @
8022cacf
...
...
@@ -2,23 +2,28 @@
Helper library for easy usp communication using mqtt over tcp or ws.
*
[
API documentation for usp-js
](
https://iopsys.se/usp-js/index.html
)
*
[
BBF's USP reference documentation
](
https://usp-data-models.broadband-forum.org/tr-181-2-13-0-usp.html
)
-
[
API documentation for usp-js
](
https://iopsys.se/usp-js/index.html
)
-
[
BBF's USP reference documentation
](
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
"
).
default
const
connect
=
require
(
"
usp-js
"
).
default
;
const
run
=
async
()
=>
{
// Connect
const
usp
=
await
connect
({
host
:
"
192.168.1.1
"
,
username
:
"
admin
"
,
password
:
"
admin
"
host
:
"
my.ip.here
"
,
username
:
"
username
"
,
password
:
"
password
"
,
port
:
90001
,
protocol
:
"
ws
"
,
fromId
:
"
from::id
"
,
toId
:
"
to::id
"
,
});
// Get property
...
...
@@ -33,8 +38,8 @@ run();
# API
-
Connect
```
javascript
// options are based on https://github.com/mqttjs/MQTT.js#mqttconnecturl-options
// they additionaly require fromId and toId, more info: url.here
...
...
@@ -42,51 +47,60 @@ const usp = await connect(options);
```
-
Get
-
get object - all object end with a dot
```
javascript
await
usp
.
get
(
"
Device.Time.
"
);
// => {
// "CurrentLocalTime": "2020-12-15T12:33:19Z",
// "Enable": true,
// ...
// }
```
- get property
```javascript
await usp.get("Device.Time.CurrentLocalTime"); // => "2020-12-15T12:33:19Z"
```
- get multiple paths
```javascript
await usp.get(["Device.WiFi.Radio.1.", "Device.WiFi.Radio.2."]);
// => [
// { ... },
// { ... }
// ]
```
- get using pattern
```javascript
await usp.get('Device.Ethernet.Interface.[Alias=="WAN"].CurrentBitRate'); // => 0
```
- resolve references in get
```javascript
await usp.get("Device.WiFi.Radio.1.").then(usp.resolve); // => { ... }
// or if deeper resolution is needed (be careful when using level, going above 3 often causes an infinite reference loop)
await usp.get("Device.WiFi.Radio.1.").then(msg => usp.resolve(msg, 3 /* level - defaults to 1 */)); // => { ... }
```
-
get object - all object end with a dot
```
javascript
await
usp
.
get
(
"
Device.Time.
"
);
// => {
// "CurrentLocalTime": "2020-12-15T12:33:19Z",
// "Enable": true,
// ...
// }
```
-
get property
```
javascript
await
usp
.
get
(
"
Device.Time.CurrentLocalTime
"
);
// => "2020-12-15T12:33:19Z"
```
-
get multiple paths
```
javascript
await
usp
.
get
([
"
Device.WiFi.Radio.1.
"
,
"
Device.WiFi.Radio.2.
"
]);
// => [
// { ... },
// { ... }
// ]
```
-
get using pattern
```
javascript
await
usp
.
get
(
'
Device.Ethernet.Interface.[Alias=="WAN"].CurrentBitRate
'
);
// => 0
```
-
resolve references in get
```
javascript
await
usp
.
get
(
"
Device.WiFi.Radio.1.
"
).
then
(
usp
.
resolve
);
// => { ... }
// or if deeper resolution is needed (be careful when using level, going above 3 often causes an infinite reference loop)
await
usp
.
get
(
"
Device.WiFi.Radio.1.
"
)
.
then
((
msg
)
=>
usp
.
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
usp
.
set
(
"
Device.WiFi.Radio.1.
"
,
{
Name
:
"
radio-1
"
});
// => void
```
-
set property
```
javascript
await
usp
.
set
(
"
Device.WiFi.Radio.1.Name
"
,
"
radio-1
"
);
// => void
```
...
...
@@ -94,26 +108,29 @@ const usp = await connect(options);
-
Operate - WIP (response message not working yet)
-
operate without no arguments
```
javascript
await
usp
.
operate
(
"
Device.SelfTestDiagnostics()
"
);
```
-
operate with arguments (for required args check USP Reference)
```
javascript
const
[
ping
,
cleanPing
]
=
await
usp
.
operate
(
"
Device.IP.Diagnostics.IPPing()
"
);
const
results
=
await
ping
({
Host
:
"
iopsys.eu
"
})
await
cleanPing
()
// clears ping subscription (optional)
const
results
=
await
ping
({
Host
:
"
iopsys.eu
"
})
;
await
cleanPing
()
;
// clears ping subscription (optional)
```
-
Add
-
add with no arguments - adds a new default object
```
javascript
await
usp
.
add
(
"
Device.NAT.PortMapping.
"
);
// => "Device.NAT.PortMapping.3."
await
usp
.
add
(
"
Device.NAT.PortMapping.
"
);
// => "Device.NAT.PortMapping.3."
```
-
add with arguments - adds a new object with provided values
```
javascript
await
usp
.
add
(
"
Device.NAT.PortMapping.
"
,
{
Description
:
"
webserver1-set
"
,
...
...
@@ -127,6 +144,7 @@ const usp = await connect(options);
```
-
Delete
```
javascript
await
usp
.
del
(
"
Device.NAT.PortMapping.4.
"
);
// => void
```
\ No newline at end of file
```
This diff is collapsed.
Click to expand it.
package.json
+
1
−
1
View file @
8022cacf
{
"name"
:
"usp-js"
,
"version"
:
"0.0.
8
"
,
"version"
:
"0.0.
9
"
,
"description"
:
"Helper library for easy usp communication using mqtt over tcp or ws."
,
"main"
:
"build/index.js"
,
"scripts"
:
{
...
...
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