Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TSMatch
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IIoT_external
TSMatch
Commits
35ad090c
Commit
35ad090c
authored
3 years ago
by
Erkan Karabulut
Browse files
Options
Downloads
Patches
Plain Diff
update the readme file of tsmatch connector
parent
93c97d56
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tsmatch-connector/README.md
+94
-26
94 additions, 26 deletions
tsmatch-connector/README.md
with
94 additions
and
26 deletions
tsmatch-connector/README.md
+
94
−
26
View file @
35ad090c

==
# TSMatch Connector
TSMatch Connector allows you to easily connect to a given TSMatch instance and use all the functionalities that TSMatch provides.
TSMatch Connector allows you to easily connect to a given TSMatch instance
and use all the functionalities that it provides. TSMatch uses the MQTT
protocol to communicate with the outside world. This connector includes
a MQTT client to connect to a TSMatch instance.
## Table of Contents
*
[
Installation
](
#installation
)
*
[
Import
](
#import
)
*
[
Initialization
](
#initialization
)
*
[
Examples
](
#examples
)
*
[
APIs
](
#apis
)
...
...
@@ -19,28 +23,45 @@ TSMatch Connector allows you to easily connect to a given TSMatch instance and u
import TSMatchConnector from "tsmatch-connector";
```
<a
name=
"examples"
></a>
## Examples
1.
Connecting to a TSMatch instance:
```
import TSMatchConnector from "tsmatch-connector";
let connectionInfo = {
url: "mqtt://localhost:1883",
options: {
username: "admin",
password: "password"
}
<a
name=
"initialization"
></a>
## Initialization
Initializing a TSMatchConnector requires connection options
to the MQTT broker that TSMatch uses to communicate with
the outside world. After a connection attempt, the connector
triggers a given callback function with a result object that
specifies if the connection attempt was successful.
```
import TSMatchConnector from "tsmatch-connector";
let connectionInfo = {
url: "mqtt://localhost:1883",
options: {
username: "admin",
password: "password"
}
let connector = new TSMatchConnector(connectionInfo, ((isConnected: boolean) => {
if (isConnected) {
// successfuly connected to the given TSMatch instance
}
}));
```
}
2.
Subscribing to sensor discovery events:
let connector = new TSMatchConnector(connectionInfo, ((isConnected: boolean) => {
if (isConnected) {
// successfuly connected to the given TSMatch instance
}
}));
```
1.
`{connectionOptions}`
: MQTT connection options
1.
`url`
: URL address of the MQTT broker
`required`
2.
`{options}`
:
1.
`username`
: a username of a given MQTT broker
2.
`password`
: password of the user
2.
`callback`
: A function that is triggered with the
following parameters after a connection attempt to a
given MQTT broker
1.
isConnected: specifies if the connection attempt
was successful
<a
name=
"examples"
></a>
## Examples
1.
Subscribing to sensor discovery events:
```
...
connector.subscribeThingDiscovery(((payload: any) => {
...
...
@@ -48,7 +69,7 @@ import TSMatchConnector from "tsmatch-connector";
}));
```
3
.
Creating a service request:
2
.
Creating a service request:
```
...
let serviceRequest = {
...
...
@@ -64,11 +85,11 @@ import TSMatchConnector from "tsmatch-connector";
};
let responseReceived = (response: any) => {
console.log(response.toString());
console.log(
"Response to the service request:",
response.toString());
}
let observationReceived = (observation: any) => {
console.log(observation.toString());
console.log(
"Received an observation:",
observation.toString());
}
connector.serviceRequest(serviceRequest, responseReceived, observationReceived);
...
...
@@ -76,7 +97,6 @@ import TSMatchConnector from "tsmatch-connector";
<a
name=
"apis"
></a>
## APIs
*
<a
href=
"#connect"
><code>
TSMatchConnector.
<b>
connect()
</b></code></a>
*
<a
href=
"#discovery"
><code>
TSMatchConnector.
<b>
subscribeThingDiscovery()
</b></code></a>
*
<a
href=
"#removal"
><code>
TSMatchConnector.
<b>
subscribeThingRemoval()
</b></code></a>
*
<a
href=
"#unsubDiscovery"
><code>
TSMatchConnector.
<b>
unSubscribeThingDiscovery()
</b></code></a>
...
...
@@ -84,5 +104,53 @@ import TSMatchConnector from "tsmatch-connector";
*
<a
href=
"#requestAll"
><code>
TSMatchConnector.
<b>
requestAllThings()
</b></code></a>
*
<a
href=
"#serviceRequest"
><code>
TSMatchConnector.
<b>
serviceRequest()
</b></code></a>
*
<a
href=
"#deleteRequest"
><code>
TSMatchConnector.
<b>
deleteRequest()
</b></code></a>
---
<a
name=
"discovery"
></a>
### TSMatchConnector.subscribeThingDiscovery(callback)
Subscribe to thing discovery events.
1.
`callback`
will be called with a newly
discovered thing in JSON format, after a new
thing registered in the TSMatch.
<a
name=
"removal"
></a>
### TSMatchConnector.subscribeThingRemoval(callback)
Subscribe to thing removal events.
1.
`callback`
will be called with a newly
removed thing in JSON format, after a new
thing removed in the TSMatch.
<a
name=
"unsubDiscovery"
></a>
### TSMatchConnector.unSubscribeThingDiscovery()
Unsubscribe from thing discovery events. After
unsubscribing the given callback in thing
discovery method won't be called in case of
thing discovery.
<a
name=
"unsubRemoval"
></a>
### TSMatchConnector.unSubscribeThingRemoval()
Unsubscribe from thing removal events. After
unsubscribing the given callback won't be called
in case of thing removal.
<a
name=
"requestAll"
></a>
### TSMatchConnector.requestAllThings(callback)
Request all available things that are registered
in the TSMatch
1.
`callback`
will be called for each of the
thing that are registered in the TSMatch.
<a
name=
"serviceRequest"
></a>
### TSMatchConnector.serviceRequest(requestDescription, responseCallback, observationCallback)
Send a service request to the TSMatch
1.
`requestDescription`
service request description
in JSOn format, must be in
[
ServiceRequestInterface
](
src/interface/ServiceRequestInterface.ts
)
format
2.
`responseCallback`
will be triggered with the response to the service request in JSON format
3.
`observationCallback`
will be continuously triggered with the thing observations in JSON format
<a
name=
"deleteRequest"
></a>
### TSMatchConnector.deleteRequest(deleteRequest)
Delete a service request
1.
`deleteRequest`
distinctive attributes of
a service description, must be in
[
RequestDeletionInterface
](
src/interface/RequestDeletionInterface.ts
)
format
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