Skip to content
Snippets Groups Projects
Commit c6d6d0ae authored by Marin Karamihalev's avatar Marin Karamihalev
Browse files

README update

parent 4948aa67
No related branches found
Tags 0.0.3
No related merge requests found
Pipeline #8737 passed
......@@ -13,18 +13,18 @@ Helper library for easy usp communication using mqtt over tcp or ws.
const connect = require("usp-js").default
const run = async () => {
// Connect to device
const device = await connect({
// Connect
const usp = await connect({
host: "192.168.1.1",
username: "admin",
password: "admin"
});
// Get property
await device.get("Device.WiFi.").then(console.log);
await usp.get("Device.WiFi.").then(console.log);
// Disconnect
await device.disconnect();
await usp.disconnect();
};
run();
......@@ -36,13 +36,13 @@ run();
- Connect
```javascript
// options are based on https://github.com/mqttjs/MQTT.js#mqttconnecturl-options
const device = await connect(options);
const usp = await connect(options);
```
- Get
- get object - all object end with a dot
```javascript
await device.get("Device.Time.");
await usp.get("Device.Time.");
// => {
// "CurrentLocalTime": "2020-12-15T12:33:19Z",
// "Enable": true,
......@@ -52,12 +52,12 @@ const device = await connect(options);
- get property
```javascript
await device.get("Device.Time.CurrentLocalTime"); // => "2020-12-15T12:33:19Z"
await usp.get("Device.Time.CurrentLocalTime"); // => "2020-12-15T12:33:19Z"
```
- get multiple paths
```javascript
await device.get(["Device.WiFi.Radio.1.", "Device.WiFi.Radio.2."]);
await usp.get(["Device.WiFi.Radio.1.", "Device.WiFi.Radio.2."]);
// => [
// { ... },
// { ... }
......@@ -66,14 +66,14 @@ const device = await connect(options);
- get using pattern
```javascript
await device.get('Device.Ethernet.Interface.[Alias=="WAN"].CurrentBitRate'); // => 0
await usp.get('Device.Ethernet.Interface.[Alias=="WAN"].CurrentBitRate'); // => 0
```
- resolve references in get
```javascript
await device.get("Device.WiFi.Radio.1.").then(device.resolve); // => { ... }
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 device.get("Device.WiFi.Radio.1.").then(msg => device.resolve(msg, 3 /* level - defaults to 1 */)); // => { ... }
await usp.get("Device.WiFi.Radio.1.").then(msg => usp.resolve(msg, 3 /* level - defaults to 1 */)); // => { ... }
```
......@@ -81,39 +81,37 @@ const device = await connect(options);
- 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
await usp.set("Device.WiFi.Radio.1.", { Name: "radio-1" }); // => void
```
- set property
```javascript
await device.set("Device.WiFi.Radio.1.Name", "radio-1"); // => void
await usp.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()");
await usp.operate("Device.SelfTestDiagnostics()");
```
- operate with arguments (for required args check USP Reference)
```javascript
await device.operate("Device.IP.Diagnostics.IPPing()", { Host: "iopsys.eu" });
await usp.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."
await usp.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.", {
await usp.add("Device.NAT.PortMapping.", {
Description: "webserver1-set",
ExternalPort: "80",
Protocol: "TCP",
......@@ -126,5 +124,5 @@ const device = await connect(options);
- Delete
```javascript
await device.del("Device.NAT.PortMapping.4."); // => void
await usp.del("Device.NAT.PortMapping.4."); // => void
```
\ No newline at end of file
{
"name": "usp-js",
"version": "0.0.2",
"version": "0.0.3",
"description": "Helper library for easy usp communication using mqtt over tcp or ws.",
"main": "build/index.js",
"scripts": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment