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
689cf194
Commit
689cf194
authored
Jan 27, 2020
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update but still not working
parent
20e8460a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
115 additions
and
32 deletions
+115
-32
coordinator.js
+6
-2
flowagent.js
+22
-12
flowemitter.js
+31
-0
index.js
+41
-16
package.json
+2
-2
run.js
+13
-0
No files found.
coordinator.js
View file @
689cf194
...
...
@@ -9,8 +9,10 @@ const Coordinator = function(param={}) {
let
that
=
this
;
this
.
remoteclient
=
param
.
remoteclient
;
this
.
localserver
=
param
.
localserver
;
// this.localserver = param.localserver || null;
this
.
flowemitter
=
param
.
flowemitter
;
/*
this.localserver.on('clientConnected', function(client){
console.log('client connected', client.id);
let deviceid = client.id.split(':')[0];
...
...
@@ -147,12 +149,14 @@ const Coordinator = function(param={}) {
that.localserver.publish(localtopic, payload);
}
});
*/
}
Coordinator
.
prototype
=
new
events
.
EventEmitter
;
Coordinator
.
prototype
.
start
=
function
()
{
this
.
remoteclient
.
connect
();
this
.
localserver
.
start
();
//this.localserver.start();
this
.
flowemitter
.
start
();
}
function
create
(
param
)
{
...
...
flowagent.js
View file @
689cf194
module
.
exports
.
create
=
create
const
MQTTClient
=
require
(
'./mqttclient'
);
const
MQTTServer
=
require
(
'./mqttserv
er'
);
const
FlowEmitter
=
require
(
'./flowemitt
er'
);
const
Coordinatior
=
require
(
'./coordinator'
);
const
events
=
require
(
'events'
);
let
FlowAgent
=
function
(
options
)
{
const
FlowAgent
=
function
(
option
=
{}
)
{
let
that
=
this
;
this
.
option
=
{
broker_uri
:
option
.
broker_uri
,
flowagentid
:
option
.
flowagentid
,
flowagentsecret
:
option
.
flowagentsecret
}
this
.
context
=
option
.
context
;
this
.
remoteclient
=
MQTTClient
.
create
({
host
:
options
.
remote_
broker_uri
,
host
:
that
.
option
.
broker_uri
,
options
:
{
clientId
:
options
.
flowagent_
id
,
username
:
options
.
flowagent_username
,
password
:
options
.
flowagent_password
,
clientId
:
Date
.
now
()
+
'-'
+
that
.
option
.
flowagent
id
,
username
:
that
.
option
.
flowagentid
,
password
:
that
.
option
.
flowagentsecret
,
keepalive
:
30
}
});
this
.
flowemitter
=
FlowEmitter
.
create
();
this
.
localserver
=
MQTTServe
r
.
create
({
host
:
options
.
localBrokerURI
.
hostname
||
'0.0.0.0'
,
port
:
parseInt
(
options
.
localBrokerURI
.
port
)
||
1883
this
.
coordinatior
=
Coordinatio
r
.
create
({
remoteclient
:
that
.
remoteclient
,
flowemitter
:
that
.
flowemitter
});
this
.
coordinatior
=
Coordinatior
.
create
({
remoteclient
:
that
.
remoteclient
,
localserver
:
that
.
localserver
});
}
FlowAgent
.
prototype
=
new
events
.
EventEmitter
;
FlowAgent
.
prototype
.
start
=
function
()
{
this
.
coordinatior
.
start
();
}
function
create
(
options
)
{
return
FlowAgent
(
options
);
function
create
()
{
return
new
FlowAgent
(
);
}
flowemitter.js
0 → 100644
View file @
689cf194
module
.
exports
.
create
=
create
const
events
=
require
(
'events'
);
const
FlowEmitter
=
function
(
param
=
{})
{
this
.
sublist
=
{};
this
.
globalcontext
=
param
.
globalcontext
;
}
FlowEmitter
.
prototype
=
new
events
.
EventEmitter
;
FlowEmitter
.
prototype
.
start
=
function
()
{
let
that
=
this
;
}
// a method for ndoe-red block to register
FlowEmitter
.
prototype
.
register
=
function
(
deviceid
,
devicetoken
)
{
let
that
=
this
;
}
FlowEmitter
.
prototype
.
deregister
=
function
(
deviceid
)
{
let
that
=
this
;
}
function
create
()
{
return
new
FlowEmitter
();
}
index.js
View file @
689cf194
require
(
'dotenv'
).
config
();
const
config
=
require
(
'config'
);
const
localBrokerURI
=
require
(
'url'
).
parse
(
config
.
get
(
'config.local_broker_uri'
));
/*
module.exports.create = create
const MQTTClient = require('./mqttclient');
const
MQTTServer
=
require
(
'./mqttserv
er'
);
const
FlowEmitter = require('./flowemitt
er');
const Coordinatior = require('./coordinator');
let
remoteclient
=
MQTTClient
.
create
({
host
:
config
.
get
(
'config.remote_broker_uri'
),
const events = require('events');
const FlowAgent = function(option = {}) {
let that = this;
let this.option = {
broker_uri : option.broker_uri,
flowagentid : option.flowagentid,
flowagentsecret : option.flowagentsecret
}
this.context = option.context;
this.remoteclient = MQTTClient.create({
host: that.option.broker_uri,
options: {
clientId
:
config
.
get
(
'config.flowagent_id'
)
,
username
:
config
.
get
(
'config.flowagent_username'
)
,
password
:
config
.
get
(
'config.flowagent_password'
)
,
clientId: Date.now()+'-'+that.option.flowagentid
,
username: that.option.flowagentid
,
password: that.option.flowagentsecret
,
keepalive: 30
}
});
});
this.flowemitter = FlowEmitter.create();
this.coordinatior = Coordinatior.create({
remoteclient: that.remoteclient,
flowemitter: that.flowemitter
});
}
FlowAgent.prototype = new events.EventEmitter;
FlowAgent.prototype.start = function() {
this.coordinatior.start();
let
localserver
=
MQTTServer
.
create
({
host
:
localBrokerURI
.
hostname
||
'0.0.0.0'
,
port
:
parseInt
(
localBrokerURI
.
port
)
||
1883
});
}
let
coordinatior
=
Coordinatior
.
create
({
remoteclient
,
localserver
});
coordinatior
.
start
();
function create() {
return new FlowAgent();
}
*/
\ No newline at end of file
package.json
View file @
689cf194
...
...
@@ -2,9 +2,9 @@
"name"
:
"
flowagent
"
,
"version"
:
"1.0.0"
,
"description"
:
""
,
"main"
:
"
index
.js"
,
"main"
:
"
flowagent
.js"
,
"scripts"
:
{
"start"
:
"node
index
.js"
"start"
:
"node
run
.js"
},
"author"
:
"NEXPIE Company Limited (https://nexpie.com)"
,
"license"
:
"
ISC
"
,
...
...
run.js
0 → 100644
View file @
689cf194
require
(
'dotenv'
).
config
();
const
config
=
require
(
'config'
);
const
localBrokerURI
=
require
(
'url'
).
parse
(
config
.
get
(
'config.local_broker_uri'
));
const
flowagent
=
require
(
'./FlowAgent'
).
create
({
broker_uri
:
config
.
get
(
'config.remote_broker_uri'
),
flowagentid
:
config
.
get
(
'config.flowagent_username'
),
flowagentsecret
:
config
.
get
(
'config.flowagent_password'
),
mqttenabled
:
true
});
flowagent
.
start
();
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