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
01463e11
Commit
01463e11
authored
Nov 09, 2019
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refacttor and add coordinator
parent
1124bbbe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
5 deletions
+54
-5
coordinator.js
+28
-0
index.js
+13
-5
mqttserver.js
+13
-0
No files found.
coordinator.js
0 → 100644
View file @
01463e11
module
.
exports
.
create
=
create
const
events
=
require
(
'events'
);
const
Coordinator
=
function
(
param
=
{})
{
this
.
remoteclient
=
param
.
remoteclient
;
this
.
localserver
=
param
.
localserver
;
this
.
localserver
.
on
(
'client_subscribe'
,
function
(
data
){
console
.
log
(
'client subscribe'
,
data
.
deviceid
,
data
.
topic
);
});
this
.
localserver
.
on
(
'client_unsubscribe'
,
function
(
data
){
console
.
log
(
'client unsubscribe'
,
data
.
deviceid
,
data
.
topic
);
});
}
Coordinator
.
prototype
=
new
events
.
EventEmitter
;
Coordinator
.
prototype
.
start
=
function
()
{
this
.
remoteclient
.
connect
();
this
.
localserver
.
start
();
}
function
create
(
param
)
{
return
new
Coordinator
(
param
);
}
\ No newline at end of file
index.js
View file @
01463e11
...
@@ -7,9 +7,10 @@ console.log(localBrokerURI)
...
@@ -7,9 +7,10 @@ console.log(localBrokerURI)
const
MQTTClient
=
require
(
'./mqttclient'
);
const
MQTTClient
=
require
(
'./mqttclient'
);
const
MQTTServer
=
require
(
'./mqttserver'
);
const
MQTTServer
=
require
(
'./mqttserver'
);
const
Coordinatior
=
require
(
'./coordinator'
);
let
mqtt
client
=
MQTTClient
.
create
({
let
remote
client
=
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'
),
...
@@ -19,12 +20,19 @@ let mqttclient = MQTTClient.create({
...
@@ -19,12 +20,19 @@ let mqttclient = MQTTClient.create({
}
}
});
});
let
localserver
=
MQTTServer
.
create
({
let
mqttserver
=
MQTTServer
.
create
({
host
:
localBrokerURI
.
hostname
||
'0.0.0.0'
,
host
:
localBrokerURI
.
hostname
||
'0.0.0.0'
,
port
:
parseInt
(
localBrokerURI
.
port
)
||
1883
port
:
parseInt
(
localBrokerURI
.
port
)
||
1883
});
});
mqttclient
.
connect
();
// 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
});
mqttserve
r
.
start
();
coordinatio
r
.
start
();
mqttserver.js
View file @
01463e11
...
@@ -25,6 +25,19 @@ MQTTServer.prototype.start = function() {
...
@@ -25,6 +25,19 @@ MQTTServer.prototype.start = function() {
console
.
log
(
'client connected'
,
client
.
id
);
console
.
log
(
'client connected'
,
client
.
id
);
});
});
this
.
mqttserver
.
on
(
'subscribed'
,
function
(
topic
,
client
)
{
that
.
emit
(
'client_subscribe'
,{
deviceid
:
client
.
id
,
topic
:
topic
});
});
this
.
mqttserver
.
on
(
'unsubscribed'
,
function
(
topic
,
client
)
{
that
.
emit
(
'client_unsubscribe'
,{
deviceid
:
client
.
id
,
topic
:
topic
});
});
}
}
...
...
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