Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
flowagent
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node-red
flowagent
Commits
573dd9df
Commit
573dd9df
authored
Nov 09, 2019
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
01463e11
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
16 deletions
+25
-16
coordinator.js
+9
-2
index.js
+1
-13
mqttclient.js
+15
-1
No files found.
coordinator.js
View file @
573dd9df
...
@@ -3,15 +3,23 @@ module.exports.create = create
...
@@ -3,15 +3,23 @@ module.exports.create = create
const
events
=
require
(
'events'
);
const
events
=
require
(
'events'
);
const
Coordinator
=
function
(
param
=
{})
{
const
Coordinator
=
function
(
param
=
{})
{
let
that
=
this
;
console
.
log
(
param
)
this
.
remoteclient
=
param
.
remoteclient
;
this
.
remoteclient
=
param
.
remoteclient
;
this
.
localserver
=
param
.
localserver
;
this
.
localserver
=
param
.
localserver
;
this
.
localserver
.
on
(
'client_subscribe'
,
function
(
data
){
this
.
localserver
.
on
(
'client_subscribe'
,
function
(
data
){
console
.
log
(
'client subscribe'
,
data
.
deviceid
,
data
.
topic
);
console
.
log
(
'client subscribe'
,
data
.
deviceid
,
data
.
topic
);
that
.
remoteclient
.
subscribe
(
'@shadow/data/updated/+/+/99a7e50a-d9e3-49c4-a7f0-f09b670ebf96'
);
that
.
remoteclient
.
subscribe
(
'@device/status/changed/+/+/99a7e50a-d9e3-49c4-a7f0-f09b670ebf96'
);
});
});
this
.
localserver
.
on
(
'client_unsubscribe'
,
function
(
data
){
this
.
localserver
.
on
(
'client_unsubscribe'
,
function
(
data
){
console
.
log
(
'client unsubscribe'
,
data
.
deviceid
,
data
.
topic
);
console
.
log
(
'client unsubscribe'
,
data
.
deviceid
,
data
.
topic
);
that
.
remoteclient
.
unsubscribe
(
'@shadow/data/updated/+/+/99a7e50a-d9e3-49c4-a7f0-f09b670ebf96'
);
that
.
remoteclient
.
unsubscribe
(
'@device/status/changed/+/+/99a7e50a-d9e3-49c4-a7f0-f09b670ebf96'
);
});
});
}
}
...
@@ -24,4 +32,4 @@ Coordinator.prototype.start = function() {
...
@@ -24,4 +32,4 @@ Coordinator.prototype.start = function() {
function
create
(
param
)
{
function
create
(
param
)
{
return
new
Coordinator
(
param
);
return
new
Coordinator
(
param
);
}
}
\ No newline at end of file
index.js
View file @
573dd9df
...
@@ -3,16 +3,13 @@ require('dotenv').config();
...
@@ -3,16 +3,13 @@ require('dotenv').config();
const
config
=
require
(
'config'
);
const
config
=
require
(
'config'
);
const
localBrokerURI
=
require
(
'url'
).
parse
(
config
.
get
(
'config.local_broker_uri'
));
const
localBrokerURI
=
require
(
'url'
).
parse
(
config
.
get
(
'config.local_broker_uri'
));
console
.
log
(
localBrokerURI
)
const
MQTTClient
=
require
(
'./mqttclient'
);
const
MQTTClient
=
require
(
'./mqttclient'
);
const
MQTTServer
=
require
(
'./mqttserver'
);
const
MQTTServer
=
require
(
'./mqttserver'
);
const
Coordinatior
=
require
(
'./coordinator'
);
const
Coordinatior
=
require
(
'./coordinator'
);
let
remoteclient
=
MQTTClient
.
create
({
let
remoteclient
=
MQTTClient
.
create
({
host
:
config
.
get
(
'config.remote_broker_uri'
),
host
:
config
.
get
(
'config.remote_broker_uri'
),
options
:
{
options
:
{
clientId
:
config
.
get
(
'config.flowagent_id'
),
clientId
:
config
.
get
(
'config.flowagent_id'
),
username
:
config
.
get
(
'config.flowagent_username'
),
username
:
config
.
get
(
'config.flowagent_username'
),
password
:
config
.
get
(
'config.flowagent_password'
),
password
:
config
.
get
(
'config.flowagent_password'
),
...
@@ -25,14 +22,5 @@ let localserver = MQTTServer.create({
...
@@ -25,14 +22,5 @@ let localserver = MQTTServer.create({
port
:
parseInt
(
localBrokerURI
.
port
)
||
1883
port
:
parseInt
(
localBrokerURI
.
port
)
||
1883
});
});
// localserver.on('client_subscribe', function(data){
// console.log('client subscribe', data.deviceid, data.topic);
// });
// localserver.on('client_unsubscribe', function(data){
// console.log('client unsubscribe', data.deviceid, data.topic);
// });
let
coordinatior
=
Coordinatior
.
create
({
remoteclient
,
localserver
});
let
coordinatior
=
Coordinatior
.
create
({
remoteclient
,
localserver
});
coordinatior
.
start
();
coordinatior
.
start
();
mqttclient.js
View file @
573dd9df
...
@@ -33,7 +33,21 @@ MQTTClient.prototype.connect = function() {
...
@@ -33,7 +33,21 @@ MQTTClient.prototype.connect = function() {
}
}
MQTTClient
.
prototype
.
publish
=
function
(
topic
,
payload
)
{
MQTTClient
.
prototype
.
publish
=
function
(
topic
,
payload
)
{
this
.
client
.
publish
(
topic
,
payload
);
if
(
this
.
client
)
{
this
.
client
.
publish
(
topic
,
payload
);
}
else
{
}
}
MQTTClient
.
prototype
.
subscribe
=
function
(
topic
)
{
if
(
this
.
client
)
{
this
.
client
.
subscribe
(
topic
);
}
else
{
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment